0

Updating buffered duration of local resource in android

OnBufferingUpdate does not work for local resources. Because of this
the buffered range does not get updated. This patch updates the bufferd
range atleast untill the video has played so that media controls can be
painted properly.

TBR=abarth@chromium.org
BUG=405474

Review URL: https://codereview.chromium.org/496683002

Cr-Commit-Position: refs/heads/master@{#292837}
This commit is contained in:
amogh.bihani
2014-08-31 23:06:51 -07:00
committed by Commit bot
parent dd5a6c6631
commit ee85a1188e
5 changed files with 35 additions and 6 deletions

@ -147,6 +147,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid(
media_log_(media_log),
web_cdm_(NULL),
allow_stored_credentials_(false),
is_local_resource_(false),
weak_factory_(this) {
DCHECK(player_manager_);
DCHECK(cdm_manager_);
@ -217,6 +218,7 @@ void WebMediaPlayerAndroid::load(LoadType load_type,
}
url_ = url;
is_local_resource_ = IsLocalResource();
int demuxer_client_id = 0;
if (player_type_ != MEDIA_PLAYER_TYPE_URL) {
RendererDemuxerAndroid* demuxer =
@ -280,6 +282,19 @@ void WebMediaPlayerAndroid::DidLoadMediaInfo(
UpdateNetworkState(WebMediaPlayer::NetworkStateIdle);
}
bool WebMediaPlayerAndroid::IsLocalResource() {
if (url_.SchemeIsFile() || url_.SchemeIsBlob())
return true;
std::string host = url_.host();
if (!host.compare("localhost") || !host.compare("127.0.0.1") ||
!host.compare("[::1]")) {
return true;
}
return false;
}
void WebMediaPlayerAndroid::play() {
DCHECK(main_thread_checker_.CalledOnValidThread());
@ -693,7 +708,7 @@ void WebMediaPlayerAndroid::OnMediaMetadataChanged(
DCHECK(main_thread_checker_.CalledOnValidThread());
bool need_to_signal_duration_changed = false;
if (url_.SchemeIs("file"))
if (is_local_resource_)
UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded);
// Update duration, if necessary, prior to ready state updates that may
@ -851,6 +866,8 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
void WebMediaPlayerAndroid::OnTimeUpdate(const base::TimeDelta& current_time) {
DCHECK(main_thread_checker_.CalledOnValidThread());
current_time_ = current_time.InSecondsF();
if (is_local_resource_ && current_time_ <= duration())
buffered_[0].end = current_time_;
}
void WebMediaPlayerAndroid::OnConnectedToRemoteDevice(

@ -287,6 +287,7 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer,
const GURL& first_party_for_cookies,
bool allow_stored_credentials);
bool IsKeySystemSupported(const std::string& key_system);
bool IsLocalResource();
// Actually do the work for generateKeyRequest/addKey so they can easily
// report results to UMA.
@ -489,6 +490,9 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer,
// Whether stored credentials are allowed to be passed to the server.
bool allow_stored_credentials_;
// Whether the resource is local.
bool is_local_resource_;
// NOTE: Weak pointers must be invalidated before all other member variables.
base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_;

@ -21,9 +21,6 @@ using base::android::ScopedJavaLocalRef;
// Time update happens every 250ms.
const int kTimeUpdateInterval = 250;
// blob url scheme.
const char kBlobScheme[] = "blob";
namespace media {
MediaPlayerBridge::MediaPlayerBridge(
@ -79,7 +76,7 @@ void MediaPlayerBridge::Initialize() {
media::MediaResourceGetter* resource_getter =
manager()->GetMediaResourceGetter();
if (url_.SchemeIsFileSystem() || url_.SchemeIs(kBlobScheme)) {
if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) {
resource_getter->GetPlatformPathFromURL(
url_,
base::Bind(&MediaPlayerBridge::ExtractMediaMetadata,
@ -156,7 +153,7 @@ void MediaPlayerBridge::SetVideoSurface(gfx::ScopedJavaSurface surface) {
void MediaPlayerBridge::Prepare() {
DCHECK(j_media_player_bridge_.is_null());
CreateJavaMediaPlayerBridge();
if (url_.SchemeIsFileSystem() || url_.SchemeIs(kBlobScheme)) {
if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) {
manager()->GetMediaResourceGetter()->GetPlatformPathFromURL(
url_,
base::Bind(&MediaPlayerBridge::SetDataSource,

@ -236,6 +236,11 @@ class URL_EXPORT GURL {
(SchemeIsFileSystem() && inner_url() && inner_url()->SchemeIsSecure());
}
// Returns true if the scheme is "blob".
bool SchemeIsBlob() const {
return SchemeIs(url::kBlobScheme);
}
// The "content" of the URL is everything after the scheme (skipping the
// scheme delimiting colon). It is an error to get the origin of an invalid
// URL. The result will be an empty string.

@ -635,4 +635,10 @@ TEST(GURLTest, SchemeIsWSOrWSS) {
EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS());
}
TEST(GURLTest, SchemeIsBlob) {
EXPECT_TRUE(GURL("BLOB://BAR/").SchemeIsBlob());
EXPECT_TRUE(GURL("blob://bar/").SchemeIsBlob());
EXPECT_FALSE(GURL("http://bar/").SchemeIsBlob());
}
} // namespace url