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/message_loop/message_loop_proxy.h"
10 #include "media/base/android/media_drm_bridge.h"
11 #include "media/base/android/media_player_manager.h"
15 MediaPlayerAndroid::MediaPlayerAndroid(
17 MediaPlayerManager
* manager
,
18 const RequestMediaResourcesCB
& request_media_resources_cb
,
19 const GURL
& frame_url
)
20 : request_media_resources_cb_(request_media_resources_cb
),
21 player_id_(player_id
),
23 frame_url_(frame_url
),
26 listener_
.reset(new MediaPlayerListener(base::MessageLoopProxy::current(),
27 weak_factory_
.GetWeakPtr()));
30 MediaPlayerAndroid::~MediaPlayerAndroid() {}
32 GURL
MediaPlayerAndroid::GetUrl() {
36 GURL
MediaPlayerAndroid::GetFirstPartyForCookies() {
40 void MediaPlayerAndroid::SetCdm(BrowserCdm
* /* cdm */) {
41 // Players that support EME should override this.
42 LOG(ERROR
) << "EME not supported on base MediaPlayerAndroid class.";
46 void MediaPlayerAndroid::OnVideoSizeChanged(int width
, int height
) {
47 manager_
->OnVideoSizeChanged(player_id(), width
, height
);
50 void MediaPlayerAndroid::OnMediaError(int error_type
) {
51 manager_
->OnError(player_id(), error_type
);
54 void MediaPlayerAndroid::OnBufferingUpdate(int percent
) {
55 manager_
->OnBufferingUpdate(player_id(), percent
);
58 void MediaPlayerAndroid::OnPlaybackComplete() {
59 manager_
->OnPlaybackComplete(player_id());
62 void MediaPlayerAndroid::OnMediaInterrupted() {
63 manager_
->OnMediaInterrupted(player_id());
66 void MediaPlayerAndroid::OnSeekComplete() {
67 manager_
->OnSeekComplete(player_id(), GetCurrentTime());
70 void MediaPlayerAndroid::OnMediaPrepared() {}
72 void MediaPlayerAndroid::AttachListener(jobject j_media_player
) {
73 jobject j_context
= base::android::GetApplicationContext();
76 listener_
->CreateMediaPlayerListener(j_context
, j_media_player
);
79 void MediaPlayerAndroid::DetachListener() {
80 listener_
->ReleaseMediaPlayerListenerResources();
83 void MediaPlayerAndroid::SetAudible(bool is_audible
) {
84 if (is_audible_
!= is_audible
) {
85 is_audible_
= is_audible
;
86 manager_
->OnAudibleStateChanged(player_id(), is_audible_
);