summaryrefslogtreecommitdiffstats
path: root/content/browser/android/content_video_view.h
blob: b42b3c6de75821139035d91046dccc25af79bd64 (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
// 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.

#ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_
#define CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_

#include <jni.h>

#include "base/android/scoped_java_ref.h"
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/timer.h"

namespace webkit_media {
struct MediaMetadataAndroid;
}

namespace content {

class MediaPlayerDelegateAndroid;

// Native mirror of ContentVideoView.java.
class ContentVideoView {
 public:
  ContentVideoView();
  ~ContentVideoView();

  static bool RegisterContentVideoView(JNIEnv* env);
  void Init(JNIEnv*, jobject obj, jobject weak_this);

  // --------------------------------------------------------------------------
  // All these functions are called on UI thread
  int GetVideoWidth(JNIEnv*, jobject obj) const;
  int GetVideoHeight(JNIEnv*, jobject obj) const;
  int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const;
  int GetCurrentPosition(JNIEnv*, jobject obj) const;
  bool IsPlaying(JNIEnv*, jobject obj);
  void SeekTo(JNIEnv*, jobject obj, jint msec);
  int GetPlayerId(JNIEnv*, jobject obj) const;
  int GetRouteId(JNIEnv*, jobject obj) const;
  int GetRenderHandle(JNIEnv*, jobject obj) const;
  void Play(JNIEnv*, jobject obj);
  void Pause(JNIEnv*, jobject obj);
  // --------------------------------------------------------------------------

  void PrepareAsync();
  void DestroyContentVideoView();
  void UpdateMediaMetadata(JNIEnv*, jobject obj);
  void DestroyContentVideoView(JNIEnv*, jobject);
  void DestroyContentVideoView(JNIEnv*, jobject, jboolean release_media_player);
  void CreateContentVideoView(MediaPlayerDelegateAndroid* player);
  void SetSurface(JNIEnv*,
                  jobject obj,
                  jobject surface,
                  jint route_id,
                  jint player_id);
  void UpdateMediaMetadata();

  void OnMediaPlayerError(int errorType);
  void OnVideoSizeChanged(int width, int height);
  void OnBufferingUpdate(int percent);
  void OnPlaybackComplete();

 private:
  // In some certain cases if the renderer crashes, the ExitFullscreen message
  // will never acknowledged by the renderer.
  void OnTimeout();

  webkit_media::MediaMetadataAndroid* GetMediaMetadata();

  int ConvertSecondsToMilliSeconds(float seconds) const;

  MediaPlayerDelegateAndroid* player_;

  base::android::ScopedJavaGlobalRef<jobject> j_content_video_view_;

  // A timer to keep track of when the acknowledgement of exitfullscreen
  // message times out.
  base::OneShotTimer<ContentVideoView> timeout_timer_;

  DISALLOW_COPY_AND_ASSIGN(ContentVideoView);
};

} // namespace content

#endif  // CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_