I did figure this out for the Android VLC SDK. What you need to do is create an Android Surface View, and then instantiate the libVLC object to that surface view. From there, you'll need to figure out where the file is located. Once you have the file path and file name on the local device, you'll provide that to the libVLC instance. When you instantiate the libVLC object, you'll create event listeners. What you'll want to do is start the libVLC playback over from the beginning once the event "EndReached" has signaled. I also, used a boolean to only start the video playing back one time. Otherwise I was getting some events triggered more than once.
Here is what I did. Hope it helps.
Code: Select all
private void playMedia(String media){
// Verify that the application context is not null.
if (mApplicationContext != null) {
// Create a new libVLC object instance from the application context.
try {
mLibVLC = new LibVLC(mApplicationContext);
} catch (IllegalStateException e) {
Log.e(TAG,"Error initializing the libVLC multimedia framework!");
}
Log.d(TAG, "Compiler: " + mLibVLC.compiler());
Log.d(TAG, "libVLC Version: " + mLibVLC.version());
// Create media player
mMediaPlayer = new MediaPlayer(mLibVLC);
mMediaPlayer.setEventListener(mPlayerListener);
// Set up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(mSurfaceView);
vout.addCallback(this);
vout.attachViews();
// Create a new media object.
mCurrentMedia = new Media(mLibVLC, media);
// Enable the HW decoder.
mCurrentMedia.setHWDecoderEnabled(true,true);
// Set the media to the MediaPlayer.
mMediaPlayer.setMedia(mCurrentMedia);
// Begin playing the content.
mMediaPlayer.play();
Code: Select all
private MediaPlayer.EventListener mPlayerListener = new VLCPlayerListener(this);
private static class VLCPlayerListener implements MediaPlayer.EventListener {
/*
Master event listener for the VideoPlayer. Whenever an event occurs, we'll emit the signal
that corresponds to the respective action to take.
*/
private WeakReference<Player> mOwner;
public VLCPlayerListener(Player owner) {
mOwner = new WeakReference<>(owner);
}
@Override
public void onEvent(MediaPlayer.Event event) {
Player player = mOwner.get();
switch(event.type) {
case MediaPlayer.Event.EndReached:
Log.d(TAG, "EndReached------------------");
if(!player.haveLoggedPlaybackResults) {
player.reportPlaybackToDatabase(player.schedulePlaybackLength, player.actualPlaybackLength, "False");
player.releasePlayer();
player.createPlayer(player.TEST_FILE_PATH);
player.haveLoggedPlaybackResults = true;
}
break;