Created
August 30, 2013 14:29
-
-
Save omgitstom/6390446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.bugapp; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.Menu; | |
import android.widget.MediaController; | |
import com.brightcove.player.event.*; | |
import com.brightcove.player.view.*; | |
public class MainActivity extends Activity { | |
private final String TAG = this.getClass().getSimpleName(); | |
private static final String POSITION = "position"; | |
private BrightcoveVideoView bcVideoView; | |
private EventEmitter eventEmitter; | |
private int position; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
bcVideoView = (BrightcoveVideoView) findViewById(R.id.bc_video_view); | |
eventEmitter = bcVideoView.getEventEmitter(); | |
bcVideoView.setMediaController(new MediaController(this)); | |
bcVideoView.setVideoPath("http://ruggs.net/temp/fishtank.mp4?pubId=507017973001&videoId=1861071097001"); | |
if (savedInstanceState != null) { | |
Log.v(TAG, "loading saved position"); | |
position = savedInstanceState.getInt(POSITION); | |
} else { | |
Log.v(TAG, "no saved state"); | |
} | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.activity_main, menu); | |
return true; | |
} | |
@Override | |
protected void onStart() { | |
Log.v(TAG, "onStart"); | |
super.onStart(); | |
} | |
@Override | |
protected void onPause() { | |
Log.v(TAG, "onPause"); | |
super.onPause(); | |
bcVideoView.pause(); | |
} | |
@Override | |
protected void onResume() { | |
Log.v(TAG, "onResume: position = " + position); | |
super.onResume(); | |
if (position > 0) { | |
eventEmitter.on(EventType.DID_SEEK_TO, new EventListener() { | |
@Override | |
public void processEvent(Event event) { | |
//Auto start | |
bcVideoView.start(); | |
} | |
}); | |
bcVideoView.seekTo(position); | |
} | |
} | |
@Override | |
protected void onSaveInstanceState(Bundle bundle) { | |
position = bcVideoView.getCurrentPosition(); | |
Log.v(TAG, "onSaveInstanceState: position = " + position); | |
bundle.putInt(POSITION, position); | |
super.onSaveInstanceState(bundle); | |
} | |
@Override | |
protected void onRestart() { | |
Log.v(TAG, "onRestart"); | |
super.onRestart(); | |
} | |
@Override | |
protected void onDestroy() { | |
Log.v(TAG, "onDestroy"); | |
super.onDestroy(); | |
} | |
@Override | |
protected void onStop() { | |
Log.v(TAG, "onStop"); | |
super.onStop(); | |
bcVideoView.stopPlayback(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment