Update V8 to version 4.7.56.
[chromium-blink-merge.git] / media / base / android / media_player_android.cc
blobed38d971b0247694ad743cfd7961d40877cca82b
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/base/android/media_player_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/logging.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "media/base/android/media_drm_bridge.h"
12 #include "media/base/android/media_player_manager.h"
14 namespace media {
16 MediaPlayerAndroid::MediaPlayerAndroid(
17 int player_id,
18 MediaPlayerManager* manager,
19 const RequestMediaResourcesCB& request_media_resources_cb,
20 const GURL& frame_url)
21 : request_media_resources_cb_(request_media_resources_cb),
22 player_id_(player_id),
23 manager_(manager),
24 frame_url_(frame_url),
25 weak_factory_(this) {
26 listener_.reset(new MediaPlayerListener(base::ThreadTaskRunnerHandle::Get(),
27 weak_factory_.GetWeakPtr()));
30 MediaPlayerAndroid::~MediaPlayerAndroid() {}
32 // For most subclasses we can delete on the caller thread.
33 void MediaPlayerAndroid::DeleteOnCorrectThread() {
34 delete this;
37 GURL MediaPlayerAndroid::GetUrl() {
38 return GURL();
41 GURL MediaPlayerAndroid::GetFirstPartyForCookies() {
42 return GURL();
45 void MediaPlayerAndroid::SetCdm(BrowserCdm* /* cdm */) {
46 // Players that support EME should override this.
47 LOG(ERROR) << "EME not supported on base MediaPlayerAndroid class.";
48 return;
51 void MediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
52 manager_->OnVideoSizeChanged(player_id(), width, height);
55 void MediaPlayerAndroid::OnMediaError(int error_type) {
56 manager_->OnError(player_id(), error_type);
59 void MediaPlayerAndroid::OnBufferingUpdate(int percent) {
60 manager_->OnBufferingUpdate(player_id(), percent);
63 void MediaPlayerAndroid::OnPlaybackComplete() {
64 manager_->OnPlaybackComplete(player_id());
67 void MediaPlayerAndroid::OnMediaInterrupted() {
68 manager_->OnMediaInterrupted(player_id());
71 void MediaPlayerAndroid::OnSeekComplete() {
72 manager_->OnSeekComplete(player_id(), GetCurrentTime());
75 void MediaPlayerAndroid::OnMediaPrepared() {}
77 void MediaPlayerAndroid::AttachListener(jobject j_media_player) {
78 jobject j_context = base::android::GetApplicationContext();
79 DCHECK(j_context);
81 listener_->CreateMediaPlayerListener(j_context, j_media_player);
84 void MediaPlayerAndroid::DetachListener() {
85 listener_->ReleaseMediaPlayerListenerResources();
88 void MediaPlayerAndroid::DestroyListenerOnUIThread() {
89 weak_factory_.InvalidateWeakPtrs();
90 listener_.reset();
93 base::WeakPtr<MediaPlayerAndroid> MediaPlayerAndroid::WeakPtrForUIThread() {
94 return weak_factory_.GetWeakPtr();
97 } // namespace media