Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(542)

Side by Side Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 580093005: Fix the loop behavior on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/media/android/webmediaplayer_android.h" 5 #include "content/renderer/media/android/webmediaplayer_android.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 texture_id_(0), 135 texture_id_(0),
136 stream_id_(0), 136 stream_id_(0),
137 is_playing_(false), 137 is_playing_(false),
138 needs_establish_peer_(true), 138 needs_establish_peer_(true),
139 has_size_info_(false), 139 has_size_info_(false),
140 compositor_loop_( 140 compositor_loop_(
141 RenderThreadImpl::current()->compositor_message_loop_proxy()), 141 RenderThreadImpl::current()->compositor_message_loop_proxy()),
142 stream_texture_factory_(factory), 142 stream_texture_factory_(factory),
143 needs_external_surface_(false), 143 needs_external_surface_(false),
144 video_frame_provider_client_(NULL), 144 video_frame_provider_client_(NULL),
145 pending_playback_(false),
146 player_type_(MEDIA_PLAYER_TYPE_URL), 145 player_type_(MEDIA_PLAYER_TYPE_URL),
147 is_remote_(false), 146 is_remote_(false),
148 media_log_(media_log), 147 media_log_(media_log),
149 web_cdm_(NULL), 148 web_cdm_(NULL),
150 allow_stored_credentials_(false), 149 allow_stored_credentials_(false),
151 is_local_resource_(false), 150 is_local_resource_(false),
152 interpolator_(&default_tick_clock_), 151 interpolator_(&default_tick_clock_),
153 weak_factory_(this) { 152 weak_factory_(this) {
154 DCHECK(player_manager_); 153 DCHECK(player_manager_);
155 DCHECK(cdm_manager_); 154 DCHECK(cdm_manager_);
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 } 758 }
760 759
761 void WebMediaPlayerAndroid::OnPlaybackComplete() { 760 void WebMediaPlayerAndroid::OnPlaybackComplete() {
762 // When playback is about to finish, android media player often stops 761 // When playback is about to finish, android media player often stops
763 // at a time which is smaller than the duration. This makes webkit never 762 // at a time which is smaller than the duration. This makes webkit never
764 // know that the playback has finished. To solve this, we set the 763 // know that the playback has finished. To solve this, we set the
765 // current time to media duration when OnPlaybackComplete() get called. 764 // current time to media duration when OnPlaybackComplete() get called.
766 interpolator_.SetBounds(duration_, duration_); 765 interpolator_.SetBounds(duration_, duration_);
767 client_->timeChanged(); 766 client_->timeChanged();
768 767
769 // if the loop attribute is set, timeChanged() will update the current time 768 // If the loop attribute is set, timeChanged() will update the current time
770 // to 0. It will perform a seek to 0. As the requests to the renderer 769 // to 0. It will perform a seek to 0. Issue a command to the player to start
771 // process are sequential, the OnSeekComplete() will only occur 770 // playing after seek completes.
772 // once OnPlaybackComplete() is done. As the playback can only be executed
773 // upon completion of OnSeekComplete(), the request needs to be saved.
774 UpdatePlayingState(false);
775 if (seeking_ && seek_time_ == base::TimeDelta()) 771 if (seeking_ && seek_time_ == base::TimeDelta())
776 pending_playback_ = true; 772 player_manager_->Start(player_id_);
777 } 773 }
778 774
779 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { 775 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) {
780 buffered_[0].end = duration() * percentage / 100; 776 buffered_[0].end = duration() * percentage / 100;
781 did_loading_progress_ = true; 777 did_loading_progress_ = true;
782 } 778 }
783 779
784 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { 780 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) {
785 DCHECK(main_thread_checker_.CalledOnValidThread()); 781 DCHECK(main_thread_checker_.CalledOnValidThread());
786 client_->requestSeek(time_to_seek.InSecondsF()); 782 client_->requestSeek(time_to_seek.InSecondsF());
787 } 783 }
788 784
789 void WebMediaPlayerAndroid::OnSeekComplete( 785 void WebMediaPlayerAndroid::OnSeekComplete(
790 const base::TimeDelta& current_time) { 786 const base::TimeDelta& current_time) {
791 DCHECK(main_thread_checker_.CalledOnValidThread()); 787 DCHECK(main_thread_checker_.CalledOnValidThread());
792 seeking_ = false; 788 seeking_ = false;
793 if (pending_seek_) { 789 if (pending_seek_) {
794 pending_seek_ = false; 790 pending_seek_ = false;
795 seek(pending_seek_time_.InSecondsF()); 791 seek(pending_seek_time_.InSecondsF());
796 return; 792 return;
797 } 793 }
798 interpolator_.SetBounds(current_time, current_time); 794 interpolator_.SetBounds(current_time, current_time);
799 795
800 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); 796 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
801 797
802 client_->timeChanged(); 798 client_->timeChanged();
803
804 if (pending_playback_) {
805 play();
806 pending_playback_ = false;
807 }
808 } 799 }
809 800
810 void WebMediaPlayerAndroid::OnMediaError(int error_type) { 801 void WebMediaPlayerAndroid::OnMediaError(int error_type) {
811 switch (error_type) { 802 switch (error_type) {
812 case MediaPlayerAndroid::MEDIA_ERROR_FORMAT: 803 case MediaPlayerAndroid::MEDIA_ERROR_FORMAT:
813 UpdateNetworkState(WebMediaPlayer::NetworkStateFormatError); 804 UpdateNetworkState(WebMediaPlayer::NetworkStateFormatError);
814 break; 805 break;
815 case MediaPlayerAndroid::MEDIA_ERROR_DECODE: 806 case MediaPlayerAndroid::MEDIA_ERROR_DECODE:
816 UpdateNetworkState(WebMediaPlayer::NetworkStateDecodeError); 807 UpdateNetworkState(WebMediaPlayer::NetworkStateDecodeError);
817 break; 808 break;
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 1818
1828 bool WebMediaPlayerAndroid::IsHLSStream() const { 1819 bool WebMediaPlayerAndroid::IsHLSStream() const {
1829 std::string mime; 1820 std::string mime;
1830 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; 1821 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_;
1831 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) 1822 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime))
1832 return false; 1823 return false;
1833 return !mime.compare("application/x-mpegurl"); 1824 return !mime.compare("application/x-mpegurl");
1834 } 1825 }
1835 1826
1836 } // namespace content 1827 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698