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.
4
5 #include "media/base/android/media_player_android.h"
6
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"
12
13 namespace media {
14
MediaPlayerAndroid(int player_id,MediaPlayerManager * manager,const RequestMediaResourcesCB & request_media_resources_cb,const GURL & frame_url)15 MediaPlayerAndroid::MediaPlayerAndroid(
16 int player_id,
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),
22 manager_(manager),
23 frame_url_(frame_url),
24 weak_factory_(this) {
25 listener_.reset(new MediaPlayerListener(base::MessageLoopProxy::current(),
26 weak_factory_.GetWeakPtr()));
27 }
28
~MediaPlayerAndroid()29 MediaPlayerAndroid::~MediaPlayerAndroid() {}
30
GetUrl()31 GURL MediaPlayerAndroid::GetUrl() {
32 return GURL();
33 }
34
GetFirstPartyForCookies()35 GURL MediaPlayerAndroid::GetFirstPartyForCookies() {
36 return GURL();
37 }
38
SetCdm(BrowserCdm *)39 void MediaPlayerAndroid::SetCdm(BrowserCdm* /* cdm */) {
40 // Players that support EME should override this.
41 NOTREACHED() << "EME not supported on base MediaPlayerAndroid class.";
42 return;
43 }
44
OnVideoSizeChanged(int width,int height)45 void MediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
46 manager_->OnVideoSizeChanged(player_id(), width, height);
47 }
48
OnMediaError(int error_type)49 void MediaPlayerAndroid::OnMediaError(int error_type) {
50 manager_->OnError(player_id(), error_type);
51 }
52
OnBufferingUpdate(int percent)53 void MediaPlayerAndroid::OnBufferingUpdate(int percent) {
54 manager_->OnBufferingUpdate(player_id(), percent);
55 }
56
OnPlaybackComplete()57 void MediaPlayerAndroid::OnPlaybackComplete() {
58 manager_->OnPlaybackComplete(player_id());
59 }
60
OnMediaInterrupted()61 void MediaPlayerAndroid::OnMediaInterrupted() {
62 manager_->OnMediaInterrupted(player_id());
63 }
64
OnSeekComplete()65 void MediaPlayerAndroid::OnSeekComplete() {
66 manager_->OnSeekComplete(player_id(), GetCurrentTime());
67 }
68
OnMediaPrepared()69 void MediaPlayerAndroid::OnMediaPrepared() {}
70
AttachListener(jobject j_media_player)71 void MediaPlayerAndroid::AttachListener(jobject j_media_player) {
72 jobject j_context = base::android::GetApplicationContext();
73 DCHECK(j_context);
74
75 listener_->CreateMediaPlayerListener(j_context, j_media_player);
76 }
77
DetachListener()78 void MediaPlayerAndroid::DetachListener() {
79 listener_->ReleaseMediaPlayerListenerResources();
80 }
81
82
83 } // namespace media
84