summaryrefslogtreecommitdiffstats
path: root/webkit/media/android/webmediaplayer_impl_android.cc
blob: fe4d0a5589fde7e501e372cc2b04e19053cc73b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) 2012 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 "webkit/media/android/webmediaplayer_impl_android.h"

#include "base/bind.h"
#include "base/logging.h"
#include "media/base/android/media_player_bridge.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "webkit/media/android/stream_texture_factory_android.h"
#include "webkit/media/android/webmediaplayer_manager_android.h"
#include "webkit/media/android/webmediaplayer_proxy_android.h"

using WebKit::WebMediaPlayerClient;
using WebKit::WebMediaPlayer;

namespace webkit_media {

WebMediaPlayerImplAndroid::WebMediaPlayerImplAndroid(
    WebKit::WebFrame* frame,
    WebMediaPlayerClient* client,
    WebMediaPlayerManagerAndroid* manager,
    WebMediaPlayerProxyAndroid* proxy,
    StreamTextureFactory* factory)
    : WebMediaPlayerAndroid(client, manager, factory),
      frame_(frame),
      proxy_(proxy),
      current_time_(0) {
}

WebMediaPlayerImplAndroid::~WebMediaPlayerImplAndroid() {
  if (proxy_)
    proxy_->DestroyPlayer(player_id());
}

void WebMediaPlayerImplAndroid::enterFullscreen() {
  if (proxy_ && manager()->CanEnterFullscreen(frame_)) {
    proxy_->EnterFullscreen(player_id());
    SetNeedsEstablishPeer(false);
  }
}

void WebMediaPlayerImplAndroid::exitFullscreen() {
  if (proxy_)
    proxy_->ExitFullscreen(player_id());
}

bool WebMediaPlayerImplAndroid::canEnterFullscreen() const {
  return manager()->CanEnterFullscreen(frame_);
}

void WebMediaPlayerImplAndroid::InitializeMediaPlayer(GURL url) {
  GURL first_party_url = frame_->document().firstPartyForCookies();
  if (proxy_) {
    proxy_->Initialize(player_id(), url.spec(), first_party_url.spec());
    if (manager()->IsInFullscreen(frame_))
      proxy_->EnterFullscreen(player_id());
  }

  UpdateNetworkState(WebMediaPlayer::NetworkStateLoading);
  UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing);
}

void WebMediaPlayerImplAndroid::PlayInternal() {
  if (paused() && proxy_)
    proxy_->Start(player_id());
}

void WebMediaPlayerImplAndroid::PauseInternal() {
  if (proxy_)
    proxy_->Pause(player_id());
}

void WebMediaPlayerImplAndroid::SeekInternal(base::TimeDelta time) {
  if (proxy_)
    proxy_->Seek(player_id(), time);
}

float WebMediaPlayerImplAndroid::GetCurrentTimeInternal() const {
  return current_time_;
}

void WebMediaPlayerImplAndroid::ReleaseResourcesInternal() {
  if (proxy_)
    proxy_->ReleaseResources(player_id());
}

void WebMediaPlayerImplAndroid::OnTimeUpdate(base::TimeDelta current_time) {
  current_time_ = static_cast<float>(current_time.InSecondsF());
}

void WebMediaPlayerImplAndroid::OnDidEnterFullscreen() {
  if (!manager()->IsInFullscreen(frame_)) {
    frame_->view()->willEnterFullScreen();
    frame_->view()->didEnterFullScreen();
    manager()->DidEnterFullscreen(frame_);
  }
}

void WebMediaPlayerImplAndroid::OnDidExitFullscreen() {
  SetNeedsEstablishPeer(true);
  // We had the fullscreen surface connected to Android MediaPlayer,
  // so reconnect our surface texture for embedded playback.
  if (!paused())
    EstablishSurfaceTexturePeer();

  frame_->view()->willExitFullScreen();
  frame_->view()->didExitFullScreen();
  manager()->DidExitFullscreen();
  client()->repaint();
}

void WebMediaPlayerImplAndroid::OnMediaPlayerPlay() {
  UpdatePlayingState(true);
  client()->playbackStateChanged();
}

void WebMediaPlayerImplAndroid::OnMediaPlayerPause() {
  UpdatePlayingState(false);
  client()->playbackStateChanged();
}

void WebMediaPlayerImplAndroid::Destroy() {
  proxy_ = NULL;
}

void WebMediaPlayerImplAndroid::SetVideoSurface(jobject j_surface) {}

}  // namespace webkit_media