Motown: media_test minor fixes and cleanup.
R=kulakowski@chromium.org
Review URL: https://codereview.chromium.org/1844093002 .
diff --git a/examples/media_test/media_test.cc b/examples/media_test/media_test.cc
index 0693a3f..d857ae2 100644
--- a/examples/media_test/media_test.cc
+++ b/examples/media_test/media_test.cc
@@ -31,26 +31,6 @@
MediaTest::~MediaTest() {}
-void MediaTest::RegisterUpdateCallback(const UpdateCallback& callback) {
- update_callback_ = callback;
-}
-
-void MediaTest::Play() {
- media_player_->Play();
-}
-
-void MediaTest::Pause() {
- media_player_->Pause();
-}
-
-void MediaTest::Seek(int64_t position_ns) {
- media_player_->Seek(position_ns);
-}
-
-MediaState MediaTest::state() const {
- return state_;
-}
-
int64_t MediaTest::position_ns() const {
// Apply the transform to the current time.
int64_t position;
@@ -74,6 +54,7 @@
MediaPlayerStatusPtr status) {
if (status) {
// Process status received from the player.
+ previous_state_ = state_;
state_ = status->state;
// Create a linear transform that translates local time to presentation
diff --git a/examples/media_test/media_test.h b/examples/media_test/media_test.h
index 0ae4c81..00ce340 100644
--- a/examples/media_test/media_test.h
+++ b/examples/media_test/media_test.h
@@ -27,19 +27,24 @@
~MediaTest();
// Registers a callback signalling that the app should update its view.
- void RegisterUpdateCallback(const UpdateCallback& callback);
+ void RegisterUpdateCallback(const UpdateCallback& callback) {
+ update_callback_ = callback;
+ }
// Starts playback.
- void Play();
+ void Play() { media_player_->Play(); }
// Pauses playback.
- void Pause();
+ void Pause() { media_player_->Pause(); }
// Seeks to the position indicated in nanoseconds from the start of the media.
- void Seek(int64_t position_ns);
+ void Seek(int64_t position_ns) { media_player_->Seek(position_ns); }
+
+ // Returns the previous state of the player.
+ MediaState previous_state() const { return previous_state_; }
// Returns the current state of the player.
- MediaState state() const;
+ MediaState state() const { return state_; }
// Returns the current presentation time in nanoseconds.
int64_t position_ns() const;
@@ -56,7 +61,8 @@
MediaPlayerStatusPtr status = nullptr);
MediaPlayerPtr media_player_;
- MediaState state_;
+ MediaState previous_state_ = MediaState::UNPREPARED;
+ MediaState state_ = MediaState::UNPREPARED;
LinearTransform transform_ = LinearTransform(0, 0, 1, 0);
MediaMetadataPtr metadata_;
UpdateCallback update_callback_;
diff --git a/examples/media_test/media_test_app.cc b/examples/media_test/media_test_app.cc
index c3d91ac..4315a99 100644
--- a/examples/media_test/media_test_app.cc
+++ b/examples/media_test/media_test_app.cc
@@ -34,34 +34,36 @@
if (input_file_names_.empty()) {
std::cout << "Please provide the names of the files you want to play;"
- << " for example:" << std::endl;
- std::cout << "mojo/devtools/common/mojo_run \\" << std::endl;
- std::cout << " \"https://core.mojoapps.io/media_test.mojo \\"
- << std::endl;
- std::cout << " file:///usr/local/google/home/you/superstition.ogg \\"
- << std::endl;
- std::cout << " file:///usr/local/google/home/you/higherground.ogg\""
+ << " for example:" << std::endl
+ << "mojo/devtools/common/mojo_run \\" << std::endl
+ << " \"https://core.mojoapps.io/media_test.mojo \\"
<< std::endl
+ << " http:/localhost/superstition.ogg \\" << std::endl
+ << " http:/localhost/higherground.ogg\"" << std::endl
<< std::endl;
base::MessageLoop::current()->Quit();
return;
}
- std::cout << " <enter> play/pause" << std::endl;
- std::cout << " n<enter> next file" << std::endl;
- std::cout << " p<enter> previous file" << std::endl;
- std::cout << " <digit><enter> seek (0% - 90%)" << std::endl;
- std::cout << " q<enter> quit" << std::endl << std::endl;
+ std::cout << " <enter> play/pause" << std::endl
+ << " n<enter> next file" << std::endl
+ << " p<enter> previous file" << std::endl
+ << " <digit><enter> seek (0% - 90%)" << std::endl
+ << " q<enter> quit" << std::endl
+ << std::endl;
if (paint_) {
- std::cout << " duration <none>" << std::endl;
- std::cout << " title <none>" << std::endl;
- std::cout << " artist <none>" << std::endl;
- std::cout << " album <none>" << std::endl;
- std::cout << " publisher <none>" << std::endl;
- std::cout << " genre <none>" << std::endl;
- std::cout << " composer <none>" << std::endl << std::endl;
- std::cout << std::endl << std::endl << kUp << std::flush;
+ std::cout << " duration <none>" << std::endl
+ << " title <none>" << std::endl
+ << " artist <none>" << std::endl
+ << " album <none>" << std::endl
+ << " publisher <none>" << std::endl
+ << " genre <none>" << std::endl
+ << " composer <none>" << std::endl
+ << std::endl
+ << std::endl
+ << std::endl
+ << kUp << std::flush;
}
CreateNewMediaTest();
@@ -109,7 +111,8 @@
}
void HandleMediaTestUpdateCallback() {
- if (media_test_->state() == MediaState::ENDED) {
+ if (media_test_->state() == MediaState::ENDED &&
+ media_test_->previous_state() != MediaState::ENDED) {
// MediaTest doesn't appreciate being deleted in this callback.
// Next time Poll runs, we move on to the next file.
base::MessageLoop::current()->PostTask(
@@ -136,35 +139,35 @@
metadata_shown_ = true;
std::cout << " duration " << std::fixed << std::setprecision(1)
<< double(metadata->duration) / ns_per_second << " seconds"
- << clear_line() << std::endl;
- std::cout << " title "
+ << clear_line() << std::endl
+ << " title "
<< (metadata->title ? metadata->title : "<none>")
- << clear_line() << std::endl;
- std::cout << " artist "
+ << clear_line() << std::endl
+ << " artist "
<< (metadata->artist ? metadata->artist : "<none>")
- << clear_line() << std::endl;
- std::cout << " album "
+ << clear_line() << std::endl
+ << " album "
<< (metadata->album ? metadata->album : "<none>")
- << clear_line() << std::endl;
- std::cout << " publisher "
+ << clear_line() << std::endl
+ << " publisher "
<< (metadata->publisher ? metadata->publisher : "<none>")
- << clear_line() << std::endl;
- std::cout << " genre "
+ << clear_line() << std::endl
+ << " genre "
<< (metadata->genre ? metadata->genre : "<none>")
- << clear_line() << std::endl;
- std::cout << " composer "
+ << clear_line() << std::endl
+ << " composer "
<< (metadata->composer ? metadata->composer : "<none>")
<< clear_line() << std::endl
<< std::endl;
} else if (paint_) {
- std::cout << " duration <none>" << kClearLine << std::endl;
- std::cout << " title <none>" << kClearLine << std::endl;
- std::cout << " artist <none>" << kClearLine << std::endl;
- std::cout << " album <none>" << kClearLine << std::endl;
- std::cout << " publisher <none>" << kClearLine << std::endl;
- std::cout << " genre <none>" << kClearLine << std::endl;
- std::cout << " composer <none>" << kClearLine << std::endl;
- std::cout << std::endl;
+ std::cout << " duration <none>" << kClearLine << std::endl
+ << " title <none>" << kClearLine << std::endl
+ << " artist <none>" << kClearLine << std::endl
+ << " album <none>" << kClearLine << std::endl
+ << " publisher <none>" << kClearLine << std::endl
+ << " genre <none>" << kClearLine << std::endl
+ << " composer <none>" << kClearLine << std::endl
+ << std::endl;
}
std::cout << " " << state_string() << clear_line() << std::endl;
}