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
),
25 listener_
.reset(new MediaPlayerListener(base::MessageLoopProxy::current(),
26 weak_factory_
.GetWeakPtr()));
29 MediaPlayerAndroid::~MediaPlayerAndroid() {}
31 GURL
MediaPlayerAndroid::GetUrl() {
35 GURL
MediaPlayerAndroid::GetFirstPartyForCookies() {
39 void MediaPlayerAndroid::SetCdm(BrowserCdm
* /* cdm */) {
40 // Players that support EME should override this.
41 NOTREACHED() << "EME not supported on base MediaPlayerAndroid class.";
45 void MediaPlayerAndroid::OnVideoSizeChanged(int width
, int height
) {
46 manager_
->OnVideoSizeChanged(player_id(), width
, height
);
49 void MediaPlayerAndroid::OnMediaError(int error_type
) {
50 manager_
->OnError(player_id(), error_type
);
53 void MediaPlayerAndroid::OnBufferingUpdate(int percent
) {
54 manager_
->OnBufferingUpdate(player_id(), percent
);
57 void MediaPlayerAndroid::OnPlaybackComplete() {
58 manager_
->OnPlaybackComplete(player_id());
61 void MediaPlayerAndroid::OnMediaInterrupted() {
62 manager_
->OnMediaInterrupted(player_id());
65 void MediaPlayerAndroid::OnSeekComplete() {
66 manager_
->OnSeekComplete(player_id(), GetCurrentTime());
69 void MediaPlayerAndroid::OnMediaPrepared() {}
71 void MediaPlayerAndroid::AttachListener(jobject j_media_player
) {
72 jobject j_context
= base::android::GetApplicationContext();
75 listener_
->CreateMediaPlayerListener(j_context
, j_media_player
);
78 void MediaPlayerAndroid::DetachListener() {
79 listener_
->ReleaseMediaPlayerListenerResources();