| Index: content/browser/media/android/audio_focus_manager.cc
|
| diff --git a/content/browser/media/android/audio_focus_manager.cc b/content/browser/media/android/audio_focus_manager.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a258791f6043cf89f934bf4f3d0c4e102e663ecd
|
| --- /dev/null
|
| +++ b/content/browser/media/android/audio_focus_manager.cc
|
| @@ -0,0 +1,70 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/media/android/audio_focus_manager.h"
|
| +
|
| +#include "base/android/jni_android.h"
|
| +#include "base/android/scoped_java_ref.h"
|
| +#include "base/bind.h"
|
| +#include "base/message_loop/message_loop_proxy.h"
|
| +#include "content/browser/media/android/browser_media_player_manager.h"
|
| +
|
| +#include "jni/AudioFocusManager_jni.h"
|
| +
|
| +using base::android::AttachCurrentThread;
|
| +using base::android::CheckException;
|
| +using base::android::ScopedJavaLocalRef;
|
| +
|
| +namespace content {
|
| +
|
| +AudioFocusManager::AudioFocusManager(
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
|
| + base::WeakPtr<BrowserMediaPlayerManager> manager)
|
| + : task_runner_(task_runner),
|
| + manager_(manager) {
|
| + DCHECK(task_runner_.get());
|
| + DCHECK(manager_);
|
| + j_audio_focus_manager_.Reset(
|
| + Java_AudioFocusManager_getInstance(
|
| + AttachCurrentThread(),
|
| + base::android::GetApplicationContext()));
|
| +}
|
| +
|
| +AudioFocusManager::~AudioFocusManager() {}
|
| +
|
| +// static
|
| +bool AudioFocusManager::RegisterAudioFocusManager(JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +void AudioFocusManager::RequestAudioFocus(int player_id) {
|
| + JNIEnv* env = AttachCurrentThread();
|
| + CHECK(env);
|
| + if (!j_audio_focus_manager_.is_null()) {
|
| + Java_AudioFocusManager_requestAudioFocus(
|
| + env, j_audio_focus_manager_.obj(),
|
| + reinterpret_cast<intptr_t>(this),
|
| + player_id);
|
| + }
|
| +}
|
| +
|
| +void AudioFocusManager::AbandonAudioFocus(int player_id) {
|
| + JNIEnv* env = AttachCurrentThread();
|
| + CHECK(env);
|
| + if (!j_audio_focus_manager_.is_null()) {
|
| + Java_AudioFocusManager_abandonAudioFocus(
|
| + env, j_audio_focus_manager_.obj(),
|
| + reinterpret_cast<intptr_t>(this),
|
| + player_id);
|
| + }
|
| +}
|
| +
|
| +void AudioFocusManager::OnMediaInterrupted(JNIEnv*, jobject, jint player_id) {
|
| + if (manager_.get()) {
|
| + task_runner_->PostTask(FROM_HERE, base::Bind(
|
| + &BrowserMediaPlayerManager::OnMediaInterrupted, manager_, player_id));
|
| + }
|
| +}
|
| +
|
| +} // namespace content
|
|
|