| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <deque> | 5 #include <deque> |
| 6 #include <iomanip> | 6 #include <iomanip> |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "examples/media_test/keystroke.h" | 10 #include "examples/media_test/keystroke.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 media_test_ = MediaTest::Create(app_, *input_file_names_iter_); | 98 media_test_ = MediaTest::Create(app_, *input_file_names_iter_); |
| 99 | 99 |
| 100 metadata_shown_ = false; | 100 metadata_shown_ = false; |
| 101 media_test_->RegisterUpdateCallback( | 101 media_test_->RegisterUpdateCallback( |
| 102 [this]() { HandleMediaTestUpdateCallback(); }); | 102 [this]() { HandleMediaTestUpdateCallback(); }); |
| 103 | 103 |
| 104 media_test_->Play(); | 104 media_test_->Play(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void HandleMediaTestUpdateCallback() { | 107 void HandleMediaTestUpdateCallback() { |
| 108 if (media_test_->state() == MediaState::ENDED && | 108 if (media_test_->state() == MediaTest::State::kEnded && |
| 109 media_test_->previous_state() != MediaState::ENDED) { | 109 media_test_->previous_state() != MediaTest::State::kEnded) { |
| 110 // MediaTest doesn't appreciate being deleted in this callback. | 110 // MediaTest doesn't appreciate being deleted in this callback. |
| 111 // Next time Poll runs, we move on to the next file. | 111 // Next time Poll runs, we move on to the next file. |
| 112 base::MessageLoop::current()->PostTask( | 112 base::MessageLoop::current()->PostTask( |
| 113 FROM_HERE, | 113 FROM_HERE, |
| 114 base::Bind(&MediaTestApp::PlayNext, base::Unretained(this))); | 114 base::Bind(&MediaTestApp::PlayNext, base::Unretained(this))); |
| 115 } | 115 } |
| 116 | 116 |
| 117 const MediaMetadataPtr& metadata = media_test_->metadata(); | 117 const MediaMetadataPtr& metadata = media_test_->metadata(); |
| 118 | 118 |
| 119 if (metadata) { | 119 if (metadata) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 << " genre <none>" << kClearLine << std::endl | 162 << " genre <none>" << kClearLine << std::endl |
| 163 << " composer <none>" << kClearLine << std::endl | 163 << " composer <none>" << kClearLine << std::endl |
| 164 << std::endl; | 164 << std::endl; |
| 165 } | 165 } |
| 166 std::cout << " " << state_string() << clear_line() << std::endl; | 166 std::cout << " " << state_string() << clear_line() << std::endl; |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Returns a string describing the MediaTest object's state. | 169 // Returns a string describing the MediaTest object's state. |
| 170 const char* state_string() const { | 170 const char* state_string() const { |
| 171 switch (media_test_->state()) { | 171 switch (media_test_->state()) { |
| 172 case MediaState::FAULT: | 172 case MediaTest::State::kPaused: |
| 173 return "FAULT"; | |
| 174 case MediaState::UNPREPARED: | |
| 175 return "unprepared"; | |
| 176 case MediaState::PAUSED: | |
| 177 return "paused"; | 173 return "paused"; |
| 178 case MediaState::PLAYING: | 174 case MediaTest::State::kPlaying: |
| 179 return "playing"; | 175 return "playing"; |
| 180 case MediaState::ENDED: | 176 case MediaTest::State::kEnded: |
| 181 return "ended"; | 177 return "ended"; |
| 182 } | 178 } |
| 183 return "UNSUPPORTED STATE VALUE"; | 179 return "UNSUPPORTED STATE VALUE"; |
| 184 } | 180 } |
| 185 | 181 |
| 186 // Handles a keystroke. | 182 // Handles a keystroke. |
| 187 void HandleKeystroke(char keystroke) { | 183 void HandleKeystroke(char keystroke) { |
| 188 switch (keystroke) { | 184 switch (keystroke) { |
| 189 case '\n': | 185 case '\n': |
| 190 TogglePlayPause(); | 186 TogglePlayPause(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 << std::endl; | 226 << std::endl; |
| 231 } | 227 } |
| 232 break; | 228 break; |
| 233 } | 229 } |
| 234 } | 230 } |
| 235 } | 231 } |
| 236 | 232 |
| 237 // Toggles between play and pause (prepared) states. | 233 // Toggles between play and pause (prepared) states. |
| 238 void TogglePlayPause() { | 234 void TogglePlayPause() { |
| 239 switch (media_test_->state()) { | 235 switch (media_test_->state()) { |
| 240 case MediaState::PAUSED: | 236 case MediaTest::State::kPaused: |
| 241 media_test_->Play(); | 237 media_test_->Play(); |
| 242 break; | 238 break; |
| 243 case MediaState::PLAYING: | 239 case MediaTest::State::kPlaying: |
| 244 media_test_->Pause(); | 240 media_test_->Pause(); |
| 245 break; | 241 break; |
| 246 case MediaState::ENDED: | 242 case MediaTest::State::kEnded: |
| 247 if (input_file_names_.size() == 1) { | 243 if (input_file_names_.size() == 1) { |
| 248 // Replaying the only file. Reuse the same MediaTest instance. | 244 // Replaying the only file. Reuse the same MediaTest instance. |
| 249 media_test_->Seek(0); | 245 media_test_->Seek(0); |
| 250 media_test_->Play(); | 246 media_test_->Play(); |
| 251 } else { | 247 } else { |
| 252 // Starting a new file. Create a new MediaTest instance. | 248 // Starting a new file. Create a new MediaTest instance. |
| 253 CreateNewMediaTest(); | 249 CreateNewMediaTest(); |
| 254 } | 250 } |
| 255 break; | 251 break; |
| 256 default: | 252 default: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 312 |
| 317 } // namespace examples | 313 } // namespace examples |
| 318 } // namespace media | 314 } // namespace media |
| 319 } // namespace mojo | 315 } // namespace mojo |
| 320 | 316 |
| 321 MojoResult MojoMain(MojoHandle application_request) { | 317 MojoResult MojoMain(MojoHandle application_request) { |
| 322 mojo::ApplicationRunnerChromium runner( | 318 mojo::ApplicationRunnerChromium runner( |
| 323 new mojo::media::examples::MediaTestApp); | 319 new mojo::media::examples::MediaTestApp); |
| 324 return runner.Run(application_request); | 320 return runner.Run(application_request); |
| 325 } | 321 } |
| OLD | NEW |