Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: media/base/android/media_player_bridge.cc

Issue 11348199: Free (and pause) audio resources when getting a phone call (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@input_color
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/android/media_player_bridge.h" 5 #include "media/base/android/media_player_bridge.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const std::string& first_party_for_cookies, 49 const std::string& first_party_for_cookies,
50 CookieGetter* cookie_getter, 50 CookieGetter* cookie_getter,
51 bool hide_url_log, 51 bool hide_url_log,
52 MediaPlayerBridgeManager* manager, 52 MediaPlayerBridgeManager* manager,
53 const MediaErrorCB& media_error_cb, 53 const MediaErrorCB& media_error_cb,
54 const VideoSizeChangedCB& video_size_changed_cb, 54 const VideoSizeChangedCB& video_size_changed_cb,
55 const BufferingUpdateCB& buffering_update_cb, 55 const BufferingUpdateCB& buffering_update_cb,
56 const MediaPreparedCB& media_prepared_cb, 56 const MediaPreparedCB& media_prepared_cb,
57 const PlaybackCompleteCB& playback_complete_cb, 57 const PlaybackCompleteCB& playback_complete_cb,
58 const SeekCompleteCB& seek_complete_cb, 58 const SeekCompleteCB& seek_complete_cb,
59 const TimeUpdateCB& time_update_cb) 59 const TimeUpdateCB& time_update_cb,
60 const MediaInterruptedCB& media_interrupted_cb)
60 : media_error_cb_(media_error_cb), 61 : media_error_cb_(media_error_cb),
61 video_size_changed_cb_(video_size_changed_cb), 62 video_size_changed_cb_(video_size_changed_cb),
62 buffering_update_cb_(buffering_update_cb), 63 buffering_update_cb_(buffering_update_cb),
63 media_prepared_cb_(media_prepared_cb), 64 media_prepared_cb_(media_prepared_cb),
64 playback_complete_cb_(playback_complete_cb), 65 playback_complete_cb_(playback_complete_cb),
65 seek_complete_cb_(seek_complete_cb), 66 seek_complete_cb_(seek_complete_cb),
67 media_interrupted_cb_(media_interrupted_cb),
66 time_update_cb_(time_update_cb), 68 time_update_cb_(time_update_cb),
67 player_id_(player_id), 69 player_id_(player_id),
68 prepared_(false), 70 prepared_(false),
69 pending_play_(false), 71 pending_play_(false),
70 url_(url), 72 url_(url),
71 first_party_for_cookies_(first_party_for_cookies), 73 first_party_for_cookies_(first_party_for_cookies),
72 has_cookies_(false), 74 has_cookies_(false),
73 hide_url_log_(hide_url_log), 75 hide_url_log_(hide_url_log),
74 duration_(base::TimeDelta::FromSeconds(kTemporaryDuration)), 76 duration_(base::TimeDelta::FromSeconds(kTemporaryDuration)),
75 width_(0), 77 width_(0),
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 pending_seek_ = GetCurrentTime(); 240 pending_seek_ = GetCurrentTime();
239 if (manager_) 241 if (manager_)
240 manager_->ReleaseMediaResources(this); 242 manager_->ReleaseMediaResources(this);
241 prepared_ = false; 243 prepared_ = false;
242 pending_play_ = false; 244 pending_play_ = false;
243 SetVideoSurface(NULL); 245 SetVideoSurface(NULL);
244 246
245 JNIEnv* env = AttachCurrentThread(); 247 JNIEnv* env = AttachCurrentThread();
246 JNI_MediaPlayer::Java_MediaPlayer_release(env, j_media_player_.obj()); 248 JNI_MediaPlayer::Java_MediaPlayer_release(env, j_media_player_.obj());
247 j_media_player_.Reset(); 249 j_media_player_.Reset();
250
251 listener_.ReleaseMediaPlayerListenerResources();
248 } 252 }
249 253
250 void MediaPlayerBridge::SetVolume(float left_volume, float right_volume) { 254 void MediaPlayerBridge::SetVolume(float left_volume, float right_volume) {
251 if (j_media_player_.is_null()) 255 if (j_media_player_.is_null())
252 return; 256 return;
253 257
254 JNIEnv* env = AttachCurrentThread(); 258 JNIEnv* env = AttachCurrentThread();
255 CHECK(env); 259 CHECK(env);
256 JNI_MediaPlayer::Java_MediaPlayer_setVolume( 260 JNI_MediaPlayer::Java_MediaPlayer_setVolume(
257 env, j_media_player_.obj(), left_volume, right_volume); 261 env, j_media_player_.obj(), left_volume, right_volume);
(...skipping 16 matching lines...) Expand all
274 278
275 void MediaPlayerBridge::OnBufferingUpdate(int percent) { 279 void MediaPlayerBridge::OnBufferingUpdate(int percent) {
276 buffering_update_cb_.Run(player_id_, percent); 280 buffering_update_cb_.Run(player_id_, percent);
277 } 281 }
278 282
279 void MediaPlayerBridge::OnPlaybackComplete() { 283 void MediaPlayerBridge::OnPlaybackComplete() {
280 time_update_timer_.Stop(); 284 time_update_timer_.Stop();
281 playback_complete_cb_.Run(player_id_); 285 playback_complete_cb_.Run(player_id_);
282 } 286 }
283 287
288
289 void MediaPlayerBridge::OnMediaInterrupted() {
290 time_update_timer_.Stop();
291 media_interrupted_cb_.Run(player_id_);
292 }
293
284 void MediaPlayerBridge::OnSeekComplete() { 294 void MediaPlayerBridge::OnSeekComplete() {
285 seek_complete_cb_.Run(player_id_, GetCurrentTime()); 295 seek_complete_cb_.Run(player_id_, GetCurrentTime());
286 } 296 }
287 297
288 void MediaPlayerBridge::OnMediaPrepared() { 298 void MediaPlayerBridge::OnMediaPrepared() {
289 if (j_media_player_.is_null()) 299 if (j_media_player_.is_null())
290 return; 300 return;
291 301
292 prepared_ = true; 302 prepared_ = true;
293 303
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 386
377 bool MediaPlayerBridge::RegisterMediaPlayerBridge(JNIEnv* env) { 387 bool MediaPlayerBridge::RegisterMediaPlayerBridge(JNIEnv* env) {
378 bool ret = RegisterNativesImpl(env); 388 bool ret = RegisterNativesImpl(env);
379 DCHECK(g_MediaPlayerBridge_clazz); 389 DCHECK(g_MediaPlayerBridge_clazz);
380 if (ret) 390 if (ret)
381 ret = JNI_MediaPlayer::RegisterNativesImpl(env); 391 ret = JNI_MediaPlayer::RegisterNativesImpl(env);
382 return ret; 392 return ret;
383 } 393 }
384 394
385 } // namespace media 395 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698