1370d4840bb769f6b76521b16aa740a07aaeeb98
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / VideoActivity.java
1 package com.owncloud.android.ui.activity;
2
3 import android.app.Activity;
4 import android.media.MediaPlayer;
5 import android.media.MediaPlayer.OnCompletionListener;
6 import android.media.MediaPlayer.OnPreparedListener;
7 import android.os.Bundle;
8 import android.view.MotionEvent;
9 import android.widget.VideoView;
10
11 import com.owncloud.android.R;
12
13 public class VideoActivity extends Activity implements OnCompletionListener, OnPreparedListener {
14
15 public static final String EXTRA_PATH = "PATH";
16
17 private VideoView mVideoPlayer;
18 private String mPathToFile;
19
20 /** Called when the activity is first created. */
21 @Override
22 public void onCreate(Bundle savedInstanceState) {
23 super.onCreate(savedInstanceState);
24 setContentView(R.layout.video_layout);
25
26 mPathToFile = getIntent().getExtras().getString(EXTRA_PATH);
27
28 mVideoPlayer = (VideoView) findViewById(R.id.videoPlayer);
29 mVideoPlayer.setOnPreparedListener(this);
30 mVideoPlayer.setOnCompletionListener(this);
31 mVideoPlayer.setKeepScreenOn(true);
32 mVideoPlayer.setVideoPath(mPathToFile);
33 }
34
35 /** This callback will be invoked when the file is ready to play */
36 @Override
37 public void onPrepared(MediaPlayer vp) {
38 mVideoPlayer.start();
39 }
40
41 /** This callback will be invoked when the file is finished playing */
42 @Override
43 public void onCompletion(MediaPlayer mp) {
44 this.finish();
45 }
46
47 /** Use screen touches to toggle the video between playing and paused. */
48 @Override
49 public boolean onTouchEvent (MotionEvent ev){
50 if(ev.getAction() == MotionEvent.ACTION_DOWN){
51 if(mVideoPlayer.isPlaying()){
52 mVideoPlayer.pause();
53 } else {
54 mVideoPlayer.start();
55 }
56 return true;
57 } else {
58 return false;
59 }
60 }
61 }