OLD | NEW |
---|---|
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 has_valid_metadata_(false), | 144 has_valid_metadata_(false), |
145 video_frame_provider_client_(NULL), | 145 video_frame_provider_client_(NULL), |
146 pending_playback_(false), | |
147 player_type_(MEDIA_PLAYER_TYPE_URL), | 146 player_type_(MEDIA_PLAYER_TYPE_URL), |
148 is_remote_(false), | 147 is_remote_(false), |
149 media_log_(media_log), | 148 media_log_(media_log), |
150 web_cdm_(NULL), | 149 web_cdm_(NULL), |
151 allow_stored_credentials_(false), | 150 allow_stored_credentials_(false), |
152 is_local_resource_(false), | 151 is_local_resource_(false), |
153 interpolator_(&default_tick_clock_), | 152 interpolator_(&default_tick_clock_), |
154 weak_factory_(this) { | 153 weak_factory_(this) { |
155 DCHECK(player_manager_); | 154 DCHECK(player_manager_); |
156 DCHECK(cdm_manager_); | 155 DCHECK(cdm_manager_); |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 } | 765 } |
767 | 766 |
768 void WebMediaPlayerAndroid::OnPlaybackComplete() { | 767 void WebMediaPlayerAndroid::OnPlaybackComplete() { |
769 // When playback is about to finish, android media player often stops | 768 // When playback is about to finish, android media player often stops |
770 // at a time which is smaller than the duration. This makes webkit never | 769 // at a time which is smaller than the duration. This makes webkit never |
771 // know that the playback has finished. To solve this, we set the | 770 // know that the playback has finished. To solve this, we set the |
772 // current time to media duration when OnPlaybackComplete() get called. | 771 // current time to media duration when OnPlaybackComplete() get called. |
773 interpolator_.SetBounds(duration_, duration_); | 772 interpolator_.SetBounds(duration_, duration_); |
774 client_->timeChanged(); | 773 client_->timeChanged(); |
775 | 774 |
776 // if the loop attribute is set, timeChanged() will update the current time | 775 // If the loop attribute is set, timeChanged() will update the current time |
777 // to 0. It will perform a seek to 0. As the requests to the renderer | 776 // to 0. It will perform a seek to 0. Issue a command to the player to start |
778 // process are sequential, the OnSeekComplete() will only occur | 777 // playing after seek completes. |
779 // once OnPlaybackComplete() is done. As the playback can only be executed | |
780 // upon completion of OnSeekComplete(), the request needs to be saved. | |
781 UpdatePlayingState(false); | |
782 if (seeking_ && seek_time_ == base::TimeDelta()) | 778 if (seeking_ && seek_time_ == base::TimeDelta()) |
783 pending_playback_ = true; | 779 player_manager_->Start(player_id_); |
DaleCurtis
2014/09/18 18:15:33
Isn't the player already started?
qinmin
2014/09/18 18:21:21
when android mediaplayer reaches the end, it will
DaleCurtis
2014/09/18 18:23:33
Is it okay to do this before the seek completes?
| |
784 } | 780 } |
785 | 781 |
786 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { | 782 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { |
787 buffered_[0].end = has_valid_metadata_ ? duration() * percentage / 100 : 0; | 783 buffered_[0].end = has_valid_metadata_ ? duration() * percentage / 100 : 0; |
788 did_loading_progress_ = true; | 784 did_loading_progress_ = true; |
789 } | 785 } |
790 | 786 |
791 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { | 787 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { |
792 DCHECK(main_thread_checker_.CalledOnValidThread()); | 788 DCHECK(main_thread_checker_.CalledOnValidThread()); |
793 client_->requestSeek(time_to_seek.InSecondsF()); | 789 client_->requestSeek(time_to_seek.InSecondsF()); |
794 } | 790 } |
795 | 791 |
796 void WebMediaPlayerAndroid::OnSeekComplete( | 792 void WebMediaPlayerAndroid::OnSeekComplete( |
797 const base::TimeDelta& current_time) { | 793 const base::TimeDelta& current_time) { |
798 DCHECK(main_thread_checker_.CalledOnValidThread()); | 794 DCHECK(main_thread_checker_.CalledOnValidThread()); |
799 seeking_ = false; | 795 seeking_ = false; |
800 if (pending_seek_) { | 796 if (pending_seek_) { |
801 pending_seek_ = false; | 797 pending_seek_ = false; |
802 seek(pending_seek_time_.InSecondsF()); | 798 seek(pending_seek_time_.InSecondsF()); |
803 return; | 799 return; |
804 } | 800 } |
805 interpolator_.SetBounds(current_time, current_time); | 801 interpolator_.SetBounds(current_time, current_time); |
806 | 802 |
807 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 803 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
808 | 804 |
809 client_->timeChanged(); | 805 client_->timeChanged(); |
810 | |
811 if (pending_playback_) { | |
812 play(); | |
813 pending_playback_ = false; | |
814 } | |
815 } | 806 } |
816 | 807 |
817 void WebMediaPlayerAndroid::OnMediaError(int error_type) { | 808 void WebMediaPlayerAndroid::OnMediaError(int error_type) { |
818 switch (error_type) { | 809 switch (error_type) { |
819 case MediaPlayerAndroid::MEDIA_ERROR_FORMAT: | 810 case MediaPlayerAndroid::MEDIA_ERROR_FORMAT: |
820 UpdateNetworkState(WebMediaPlayer::NetworkStateFormatError); | 811 UpdateNetworkState(WebMediaPlayer::NetworkStateFormatError); |
821 break; | 812 break; |
822 case MediaPlayerAndroid::MEDIA_ERROR_DECODE: | 813 case MediaPlayerAndroid::MEDIA_ERROR_DECODE: |
823 UpdateNetworkState(WebMediaPlayer::NetworkStateDecodeError); | 814 UpdateNetworkState(WebMediaPlayer::NetworkStateDecodeError); |
824 break; | 815 break; |
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1834 | 1825 |
1835 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1826 bool WebMediaPlayerAndroid::IsHLSStream() const { |
1836 std::string mime; | 1827 std::string mime; |
1837 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1828 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
1838 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1829 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
1839 return false; | 1830 return false; |
1840 return !mime.compare("application/x-mpegurl"); | 1831 return !mime.compare("application/x-mpegurl"); |
1841 } | 1832 } |
1842 | 1833 |
1843 } // namespace content | 1834 } // namespace content |
OLD | NEW |