OLD | NEW |
---|---|
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 20 matching lines...) Expand all Loading... | |
31 MediaPlayerManager* manager, | 31 MediaPlayerManager* manager, |
32 const RequestMediaResourcesCB& request_media_resources_cb, | 32 const RequestMediaResourcesCB& request_media_resources_cb, |
33 const GURL& frame_url, | 33 const GURL& frame_url, |
34 bool allow_credentials) | 34 bool allow_credentials) |
35 : MediaPlayerAndroid(player_id, | 35 : MediaPlayerAndroid(player_id, |
36 manager, | 36 manager, |
37 request_media_resources_cb, | 37 request_media_resources_cb, |
38 frame_url), | 38 frame_url), |
39 prepared_(false), | 39 prepared_(false), |
40 pending_play_(false), | 40 pending_play_(false), |
41 should_seek_on_prepare_(false), | |
41 url_(url), | 42 url_(url), |
42 first_party_for_cookies_(first_party_for_cookies), | 43 first_party_for_cookies_(first_party_for_cookies), |
43 user_agent_(user_agent), | 44 user_agent_(user_agent), |
44 hide_url_log_(hide_url_log), | 45 hide_url_log_(hide_url_log), |
45 width_(0), | 46 width_(0), |
46 height_(0), | 47 height_(0), |
47 can_pause_(true), | 48 can_pause_(true), |
48 can_seek_forward_(true), | 49 can_seek_forward_(true), |
49 can_seek_backward_(true), | 50 can_seek_backward_(true), |
50 volume_(-1.0), | 51 volume_(-1.0), |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 if (!prepared_) | 332 if (!prepared_) |
332 return height_; | 333 return height_; |
333 JNIEnv* env = base::android::AttachCurrentThread(); | 334 JNIEnv* env = base::android::AttachCurrentThread(); |
334 return Java_MediaPlayerBridge_getVideoHeight( | 335 return Java_MediaPlayerBridge_getVideoHeight( |
335 env, j_media_player_bridge_.obj()); | 336 env, j_media_player_bridge_.obj()); |
336 } | 337 } |
337 | 338 |
338 void MediaPlayerBridge::SeekTo(base::TimeDelta timestamp) { | 339 void MediaPlayerBridge::SeekTo(base::TimeDelta timestamp) { |
339 // Record the time to seek when OnMediaPrepared() is called. | 340 // Record the time to seek when OnMediaPrepared() is called. |
340 pending_seek_ = timestamp; | 341 pending_seek_ = timestamp; |
342 should_seek_on_prepare_ = true; | |
341 | 343 |
342 if (j_media_player_bridge_.is_null()) | 344 if (j_media_player_bridge_.is_null()) |
343 Prepare(); | 345 Prepare(); |
344 else if (prepared_) | 346 else if (prepared_) |
345 SeekInternal(timestamp); | 347 SeekInternal(timestamp); |
346 } | 348 } |
347 | 349 |
348 base::TimeDelta MediaPlayerBridge::GetCurrentTime() { | 350 base::TimeDelta MediaPlayerBridge::GetCurrentTime() { |
349 if (!prepared_) | 351 if (!prepared_) |
350 return pending_seek_; | 352 return pending_seek_; |
(...skipping 11 matching lines...) Expand all Loading... | |
362 Java_MediaPlayerBridge_getDuration(env, j_media_player_bridge_.obj()); | 364 Java_MediaPlayerBridge_getDuration(env, j_media_player_bridge_.obj()); |
363 return duration_ms < 0 ? media::kInfiniteDuration() | 365 return duration_ms < 0 ? media::kInfiniteDuration() |
364 : base::TimeDelta::FromMilliseconds(duration_ms); | 366 : base::TimeDelta::FromMilliseconds(duration_ms); |
365 } | 367 } |
366 | 368 |
367 void MediaPlayerBridge::Release() { | 369 void MediaPlayerBridge::Release() { |
368 if (j_media_player_bridge_.is_null()) | 370 if (j_media_player_bridge_.is_null()) |
369 return; | 371 return; |
370 | 372 |
371 time_update_timer_.Stop(); | 373 time_update_timer_.Stop(); |
372 if (prepared_) | 374 if (prepared_) { |
373 pending_seek_ = GetCurrentTime(); | 375 pending_seek_ = GetCurrentTime(); |
376 should_seek_on_prepare_ = true; | |
377 } | |
378 | |
374 prepared_ = false; | 379 prepared_ = false; |
375 pending_play_ = false; | 380 pending_play_ = false; |
376 SetVideoSurface(gfx::ScopedJavaSurface()); | 381 SetVideoSurface(gfx::ScopedJavaSurface()); |
377 JNIEnv* env = base::android::AttachCurrentThread(); | 382 JNIEnv* env = base::android::AttachCurrentThread(); |
378 Java_MediaPlayerBridge_release(env, j_media_player_bridge_.obj()); | 383 Java_MediaPlayerBridge_release(env, j_media_player_bridge_.obj()); |
379 j_media_player_bridge_.Reset(); | 384 j_media_player_bridge_.Reset(); |
380 DetachListener(); | 385 DetachListener(); |
381 } | 386 } |
382 | 387 |
383 void MediaPlayerBridge::SetVolume(double volume) { | 388 void MediaPlayerBridge::SetVolume(double volume) { |
(...skipping 26 matching lines...) Expand all Loading... | |
410 | 415 |
411 void MediaPlayerBridge::OnMediaPrepared() { | 416 void MediaPlayerBridge::OnMediaPrepared() { |
412 if (j_media_player_bridge_.is_null()) | 417 if (j_media_player_bridge_.is_null()) |
413 return; | 418 return; |
414 | 419 |
415 prepared_ = true; | 420 prepared_ = true; |
416 duration_ = GetDuration(); | 421 duration_ = GetDuration(); |
417 | 422 |
418 // If media player was recovered from a saved state, consume all the pending | 423 // If media player was recovered from a saved state, consume all the pending |
419 // events. | 424 // events. |
420 PendingSeekInternal(pending_seek_); | 425 // if (pending_seek_.InMilliseconds() >= 0) { |
qinmin
2014/10/20 17:16:19
cannot we just change this line to > 0 and it will
whywhat
2014/10/20 18:41:35
Some websites actually do call video.seekTo(0) bef
qinmin
2014/10/20 21:44:52
remove this comments, it is not helpful for unders
dgn
2014/10/21 10:07:18
Done.
| |
426 if (should_seek_on_prepare_) { | |
427 PendingSeekInternal(pending_seek_); | |
whywhat
2014/10/20 18:41:35
should we reset pending_seek_ to 0 and should_seek
dgn
2014/10/21 10:07:18
Done.
| |
428 } | |
whywhat
2014/10/20 18:41:35
nit: no need for curly braces here
dgn
2014/10/21 10:07:17
They are needed now.
| |
421 | 429 |
422 if (pending_play_) { | 430 if (pending_play_) { |
423 StartInternal(); | 431 StartInternal(); |
424 pending_play_ = false; | 432 pending_play_ = false; |
425 } | 433 } |
426 | 434 |
427 UpdateAllowedOperations(); | 435 UpdateAllowedOperations(); |
428 manager()->OnMediaMetadataChanged( | 436 manager()->OnMediaMetadataChanged( |
429 player_id(), duration_, width_, height_, true); | 437 player_id(), duration_, width_, height_, true); |
430 } | 438 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 | 526 |
519 GURL MediaPlayerBridge::GetUrl() { | 527 GURL MediaPlayerBridge::GetUrl() { |
520 return url_; | 528 return url_; |
521 } | 529 } |
522 | 530 |
523 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 531 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
524 return first_party_for_cookies_; | 532 return first_party_for_cookies_; |
525 } | 533 } |
526 | 534 |
527 } // namespace media | 535 } // namespace media |
OLD | NEW |