Created
June 29, 2016 22:16
-
-
Save technoplato/298f5c2f19eab29bf4ad3a82d8187b02 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.mlustig.bctcttest; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import com.brightcove.player.edge.Catalog; | |
import com.brightcove.player.edge.VideoListener; | |
import com.brightcove.player.event.Event; | |
import com.brightcove.player.event.EventEmitter; | |
import com.brightcove.player.event.EventListener; | |
import com.brightcove.player.event.EventType; | |
import com.brightcove.player.model.Video; | |
import com.brightcove.player.view.BrightcoveExoPlayerVideoView; | |
import com.brightcove.player.view.BrightcovePlayer; | |
/** | |
* This app illustrates how to use the FreeWheel and Widevine plugins | |
* together with the Brightcove Player for Android. | |
* | |
* @author Billy Hnath | |
*/ | |
public class MainActivity extends BrightcovePlayer { | |
private final String TAG = this.getClass().getSimpleName(); | |
private EventEmitter eventEmitter; | |
private int startPosition = 0; | |
private Catalog catalog; | |
private String [] videoList; | |
private int counter = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
// When extending the BrightcovePlayer, we must assign the BrightcoveExoPlayerVideoView | |
// before entering the superclass. This allows for some stock video player lifecycle | |
// management. | |
setContentView(R.layout.activity_main); | |
brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view); | |
super.onCreate(savedInstanceState); | |
videoList = new String[3]; | |
videoList[0] = "liveAnd1_flv300hlsAll"; | |
videoList[1] = "liveAnd2_flv300hlsAll"; | |
videoList[2] = "liveAnd3_flv300hlsAll"; | |
eventEmitter = brightcoveVideoView.getEventEmitter(); | |
catalog = new Catalog(eventEmitter, "1997976452001", "BCpkADawqM2STgKtyt3YKeaM6X1w6enZpbKytDA016jqDEMkg7BFA0HeV0Tf6kteluBe4wzcXVrX0gu3jfkkMvHXxX3C7brSPbcqX0ZWseDrVW6sSWUTOM-n8J1MNcLkSO80gJKtCnjU9AYD"); | |
catalog.findVideoByReferenceID("liveAnd1_flv300hlsAll", new VideoListener() { | |
// Add the video found to the queue with add(). | |
// Start playback of the video with start(). | |
@Override | |
public void onVideo(Video video) { | |
Log.v(TAG, "onVideo: video = " + video); | |
brightcoveVideoView.add(video); | |
brightcoveVideoView.start(); | |
// Hide the player until it is ready to playback. | |
brightcoveVideoView.setVisibility(View.INVISIBLE); | |
} | |
}); | |
eventEmitter.on(EventType.DID_PLAY, new EventListener() { | |
@Override | |
public void processEvent(Event event) { | |
// Show the player until it is ready to playback. | |
brightcoveVideoView.setVisibility(View.VISIBLE); | |
} | |
}); | |
eventEmitter.on(EventType.PROGRESS, new EventListener() { | |
@Override | |
public void processEvent(Event event) { | |
event.preventDefault(); | |
Log.d(TAG, "*** PROGRESS *** " + event.properties.get("playheadPosition")); | |
startPosition++; | |
if (startPosition > 15) { | |
startPosition = 0; | |
if (counter == 0) { | |
catalog.findVideoByID("5006308559001", new VideoListener() { | |
@Override | |
public void onVideo(final Video video) { | |
eventEmitter.once(EventType.DID_CHANGE_LIST, new EventListener() { | |
@Override | |
public void processEvent(Event event) { | |
brightcoveVideoView.add(video); | |
brightcoveVideoView.start(); | |
// Hide the player until it is ready to playback. | |
brightcoveVideoView.setVisibility(View.INVISIBLE); | |
} | |
}); | |
brightcoveVideoView.stopPlayback(); | |
brightcoveVideoView.clear(); | |
} | |
}); | |
} else { | |
catalog.findVideoByReferenceID(videoList[counter], new VideoListener() { | |
@Override | |
public void onVideo(final Video video) { | |
eventEmitter.once(EventType.DID_CHANGE_LIST, new EventListener() { | |
@Override | |
public void processEvent(Event event) { | |
brightcoveVideoView.add(video); | |
brightcoveVideoView.start(); | |
// Hide the player until it is ready to playback. | |
brightcoveVideoView.setVisibility(View.INVISIBLE); | |
} | |
}); | |
brightcoveVideoView.stopPlayback(); | |
brightcoveVideoView.clear(); | |
} | |
}); | |
} | |
counter++; | |
if (counter >= 3) counter = 0; | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment