[BackgroundSync] Clean up some tests
[chromium-blink-merge.git] / media / base / android / media_player_android.cc
blob60e1dfc0f823268042381b5e4514931290c3d2b8
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 is_audible_(false),
26 weak_factory_(this) {
27 listener_.reset(new MediaPlayerListener(base::ThreadTaskRunnerHandle::Get(),
28 weak_factory_.GetWeakPtr()));
31 MediaPlayerAndroid::~MediaPlayerAndroid() {}
33 // For most subclasses we can delete on the caller thread.
34 void MediaPlayerAndroid::DeleteOnCorrectThread() {
35 delete this;
38 GURL MediaPlayerAndroid::GetUrl() {
39 return GURL();
42 GURL MediaPlayerAndroid::GetFirstPartyForCookies() {
43 return GURL();
46 void MediaPlayerAndroid::SetCdm(BrowserCdm* /* cdm */) {
47 // Players that support EME should override this.
48 LOG(ERROR) << "EME not supported on base MediaPlayerAndroid class.";
49 return;
52 void MediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
53 manager_->OnVideoSizeChanged(player_id(), width, height);
56 void MediaPlayerAndroid::OnMediaError(int error_type) {
57 manager_->OnError(player_id(), error_type);
60 void MediaPlayerAndroid::OnBufferingUpdate(int percent) {
61 manager_->OnBufferingUpdate(player_id(), percent);
64 void MediaPlayerAndroid::OnPlaybackComplete() {
65 manager_->OnPlaybackComplete(player_id());
68 void MediaPlayerAndroid::OnMediaInterrupted() {
69 manager_->OnMediaInterrupted(player_id());
72 void MediaPlayerAndroid::OnSeekComplete() {
73 manager_->OnSeekComplete(player_id(), GetCurrentTime());
76 void MediaPlayerAndroid::OnMediaPrepared() {}
78 void MediaPlayerAndroid::AttachListener(jobject j_media_player) {
79 jobject j_context = base::android::GetApplicationContext();
80 DCHECK(j_context);
82 listener_->CreateMediaPlayerListener(j_context, j_media_player);
85 void MediaPlayerAndroid::DetachListener() {
86 listener_->ReleaseMediaPlayerListenerResources();
89 void MediaPlayerAndroid::DestroyListenerOnUIThread() {
90 weak_factory_.InvalidateWeakPtrs();
91 listener_.reset();
94 void MediaPlayerAndroid::SetAudible(bool is_audible) {
95 if (is_audible_ != is_audible) {
96 is_audible_ = is_audible;
97 manager_->OnAudibleStateChanged(player_id(), is_audible_);
101 } // namespace media