| 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 "content/browser/android/content_video_view.h" | 5 #include "content/browser/android/content_video_view.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/browser/android/media_player_manager_android.h" | 10 #include "content/browser/android/media_player_manager_android.h" |
| 11 #include "content/common/android/surface_callback.h" | 11 #include "content/common/android/surface_callback.h" |
| 12 #include "content/common/android/surface_texture_peer.h" | 12 #include "content/common/android/surface_texture_peer.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "jni/ContentVideoView_jni.h" | 14 #include "jni/ContentVideoView_jni.h" |
| 15 | 15 |
| 16 using base::android::AttachCurrentThread; | 16 using base::android::AttachCurrentThread; |
| 17 using base::android::CheckException; | 17 using base::android::CheckException; |
| 18 using base::android::ScopedJavaGlobalRef; | 18 using base::android::ScopedJavaGlobalRef; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) { | 22 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) { |
| 23 return RegisterNativesImpl(env); | 23 return RegisterNativesImpl(env); |
| 24 } | 24 } |
| 25 | 25 |
| 26 ContentVideoView::ContentVideoView(MediaPlayerManagerAndroid* manager) | 26 ContentVideoView::ContentVideoView(MediaPlayerManagerAndroid* manager) |
| 27 : manager_(manager) { | 27 : manager_(manager), personality_(PERSONALITY_FULL_SCREEN) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 ContentVideoView::~ContentVideoView() { | 30 ContentVideoView::~ContentVideoView() { |
| 31 DestroyContentVideoView(); | 31 DestroyContentVideoView(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void ContentVideoView::CreateContentVideoView() { | 34 void ContentVideoView::CreateContentVideoView(int personality) { |
| 35 if (!j_content_video_view_.is_null() && personality_ != personality) { |
| 36 DestroyContentVideoView(); |
| 37 } |
| 38 personality_ = personality; |
| 35 if (j_content_video_view_.is_null()) { | 39 if (j_content_video_view_.is_null()) { |
| 36 JNIEnv* env = AttachCurrentThread(); | 40 JNIEnv* env = AttachCurrentThread(); |
| 37 j_content_video_view_.Reset(Java_ContentVideoView_createContentVideoView( | 41 j_content_video_view_.Reset(Java_ContentVideoView_createContentVideoView( |
| 38 env, reinterpret_cast<jint>(this))); | 42 env, reinterpret_cast<jint>(this), static_cast<jint>(personality))); |
| 39 } else { | 43 } else { |
| 40 // Just ask video view to reopen the video. | 44 // Just ask video view to reopen the video. |
| 41 Java_ContentVideoView_openVideo(AttachCurrentThread(), | 45 Java_ContentVideoView_openVideo(AttachCurrentThread(), |
| 42 j_content_video_view_.obj()); | 46 j_content_video_view_.obj()); |
| 43 } | 47 } |
| 44 } | 48 } |
| 45 | 49 |
| 46 void ContentVideoView::DestroyContentVideoView() { | 50 void ContentVideoView::DestroyContentVideoView() { |
| 47 if (!j_content_video_view_.is_null()) { | 51 if (!j_content_video_view_.is_null()) { |
| 48 Java_ContentVideoView_destroyContentVideoView(AttachCurrentThread()); | 52 Java_ContentVideoView_destroyContentVideoView(AttachCurrentThread()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 75 } | 79 } |
| 76 } | 80 } |
| 77 | 81 |
| 78 void ContentVideoView::OnPlaybackComplete() { | 82 void ContentVideoView::OnPlaybackComplete() { |
| 79 if (!j_content_video_view_.is_null()) { | 83 if (!j_content_video_view_.is_null()) { |
| 80 Java_ContentVideoView_onPlaybackComplete(AttachCurrentThread(), | 84 Java_ContentVideoView_onPlaybackComplete(AttachCurrentThread(), |
| 81 j_content_video_view_.obj()); | 85 j_content_video_view_.obj()); |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 | 88 |
| 89 int ContentVideoView::getPersonality() { |
| 90 return personality_; |
| 91 } |
| 92 |
| 85 void ContentVideoView::UpdateMediaMetadata() { | 93 void ContentVideoView::UpdateMediaMetadata() { |
| 86 if (!j_content_video_view_.is_null()) | 94 if (!j_content_video_view_.is_null()) |
| 87 UpdateMediaMetadata(AttachCurrentThread(), j_content_video_view_.obj()); | 95 UpdateMediaMetadata(AttachCurrentThread(), j_content_video_view_.obj()); |
| 88 } | 96 } |
| 89 | 97 |
| 90 int ContentVideoView::GetVideoWidth(JNIEnv*, jobject obj) const { | 98 int ContentVideoView::GetVideoWidth(JNIEnv*, jobject obj) const { |
| 91 media::MediaPlayerBridge* player = manager_->GetFullscreenPlayer(); | 99 media::MediaPlayerBridge* player = manager_->GetFullscreenPlayer(); |
| 92 return player ? player->GetVideoWidth() : 0; | 100 return player ? player->GetVideoWidth() : 0; |
| 93 } | 101 } |
| 94 | 102 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) { | 146 void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) { |
| 139 media::MediaPlayerBridge* player = manager_->GetFullscreenPlayer(); | 147 media::MediaPlayerBridge* player = manager_->GetFullscreenPlayer(); |
| 140 if (player && player->prepared()) | 148 if (player && player->prepared()) |
| 141 Java_ContentVideoView_updateMediaMetadata( | 149 Java_ContentVideoView_updateMediaMetadata( |
| 142 env, obj, player->GetVideoWidth(), player->GetVideoHeight(), | 150 env, obj, player->GetVideoWidth(), player->GetVideoHeight(), |
| 143 player->GetDuration().InMilliseconds(), player->can_pause(), | 151 player->GetDuration().InMilliseconds(), player->can_pause(), |
| 144 player->can_seek_forward(), player->can_seek_backward()); | 152 player->can_seek_forward(), player->can_seek_backward()); |
| 145 } | 153 } |
| 146 | 154 |
| 147 } // namespace content | 155 } // namespace content |
| OLD | NEW |