use of com.brightcove.player.event.EventListener in project android-player-samples by BrightcoveOS.
the class MainActivityTest method testPlay.
/**
* Test for pre, mid, and post rolls.
*/
public void testPlay() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
Log.v(TAG, "testPlay");
eventEmitter.on(EventType.AD_STARTED, new EventListener() {
@Override
public void processEvent(Event event) {
assertTrue("Should not have started an ad: " + state, state != State.STARTED_AD);
switch(state) {
case STARTING_CONTENT:
numPrerollsPlayed++;
break;
case STARTED_CONTENT:
numMidrollsPlayed++;
break;
case COMPLETED_CONTENT:
numPostrollsPlayed++;
break;
default:
Log.e(TAG, "Unexpected state: " + state);
}
state = State.STARTED_AD;
}
});
eventEmitter.on(EventType.AD_COMPLETED, new EventListener() {
@Override
public void processEvent(Event event) {
assertTrue("Should have started an ad: " + state, state == State.STARTED_AD);
state = State.COMPLETED_AD;
}
});
eventEmitter.on(EventType.WILL_CHANGE_VIDEO, new EventListener() {
@Override
public void processEvent(Event event) {
state = State.STARTING_CONTENT;
if (eventEmitter != null) {
eventEmitter.once(EventType.PROGRESS, new EventListener() {
@Override
public void processEvent(Event event) {
assertTrue("Should have played a preroll: " + state, state == State.COMPLETED_AD);
state = State.STARTED_CONTENT;
}
});
}
}
});
eventEmitter.on(EventType.COMPLETED, new EventListener() {
@Override
public void processEvent(Event event) {
if (event.properties.containsKey(Event.SKIP_CUE_POINTS)) {
latch.countDown();
} else {
state = State.COMPLETED_CONTENT;
}
}
});
assertTrue("Timeout occurred.", latch.await(3, TimeUnit.MINUTES));
brightcoveVideoView.stopPlayback();
assertEquals("Should have played 2 prerolls.", 2, numPrerollsPlayed);
assertEquals("Should have played 2 midrolls.", 2, numMidrollsPlayed);
assertEquals("Should have played 2 postrolls.", 2, numPostrollsPlayed);
}
use of com.brightcove.player.event.EventListener in project android-player-samples by BrightcoveOS.
the class GoogleCastComponentTest method testCastMediaToRemoteDeviceAndBackFromPaused.
/**
* Test the successful local to remote playback and then remote to local
* with the media starting in the PAUSE state on the local device.
*
* @throws InterruptedException
*/
public void testCastMediaToRemoteDeviceAndBackFromPaused() throws InterruptedException {
Log.v(TAG, "testCastMediaToRemoteDeviceAndBackFromPaused");
final CountDownLatch countDownLatch = new CountDownLatch(2);
brightcoveVideoView.pause();
solo.sleep(3000);
eventEmitter.once(EventType.DID_STOP, new EventListener() {
@Override
public void processEvent(Event event) {
assertFalse("BrightVideoVideo is not playing.", brightcoveVideoView.isPlaying());
countDownLatch.countDown();
}
});
solo.clickOnActionBarItem(R.id.media_router_menu_item);
solo.clickInList(0);
solo.sleep(6000);
brightcoveVideoView.start();
assertFalse("BrightcoveVideoView playback did not start.", brightcoveVideoView.isPlaying());
solo.waitForActivity(VideoCastControllerActivity.class);
solo.sleep(10000);
solo.assertCurrentActivity("VideoCastControllerActivity is displayed", VideoCastControllerActivity.class);
List<View> views = solo.getCurrentViews();
for (View v : views) {
if (v instanceof android.support.v7.app.MediaRouteButton) {
solo.clickOnView(v);
}
}
solo.sleep(3000);
solo.clickOnButton("Disconnect");
solo.sleep(3000);
countDownLatch.countDown();
assertTrue("Timeout occurred.", countDownLatch.await(3, TimeUnit.MINUTES));
}
use of com.brightcove.player.event.EventListener in project android-player-samples by BrightcoveOS.
the class GoogleCastComponentTest method testCastMediaToRemoteDeviceAndBackFromPlaying.
/**
* Test the successful local to remote playback and then remote to local
* with the media starting in the PLAY state on the local device.
* @throws InterruptedException
*/
public void testCastMediaToRemoteDeviceAndBackFromPlaying() throws InterruptedException {
Log.v(TAG, "testCastMediaToRemoteDeviceAndBackFromPlaying");
final CountDownLatch countDownLatch = new CountDownLatch(2);
solo.clickOnActionBarItem(R.id.media_router_menu_item);
solo.clickInList(0);
eventEmitter.once(EventType.DID_PAUSE, new EventListener() {
@Override
public void processEvent(Event event) {
assertFalse("BrightVideoVideo is paused.", brightcoveVideoView.isPlaying());
countDownLatch.countDown();
}
});
solo.waitForActivity(VideoCastControllerActivity.class);
solo.sleep(10000);
solo.assertCurrentActivity("VideoCastControllerActivity is displayed", VideoCastControllerActivity.class);
List<View> views = solo.getCurrentViews();
for (View v : views) {
if (v instanceof android.support.v7.app.MediaRouteButton) {
solo.clickOnView(v);
}
}
solo.sleep(3000);
solo.clickOnButton("Disconnect");
solo.sleep(3000);
countDownLatch.countDown();
assertTrue("Timeout occurred.", countDownLatch.await(3, TimeUnit.MINUTES));
}
use of com.brightcove.player.event.EventListener in project android-player-samples by BrightcoveOS.
the class MainActivity method setupGoogleIMA.
/**
* Setup the Brightcove IMA Plugin.
*/
private void setupGoogleIMA() {
// Establish the Google IMA SDK factory instance.
final ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
// Enable logging up ad start.
eventEmitter.on(EventType.AD_STARTED, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Enable logging any failed attempts to play an ad.
eventEmitter.on(GoogleIMAEventType.DID_FAIL_TO_PLAY_AD, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Enable Logging upon ad completion.
eventEmitter.on(EventType.AD_COMPLETED, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Set up a listener for initializing AdsRequests. The Google
// IMA plugin emits an ad request event as a result of
// initializeAdsRequests() being called.
eventEmitter.on(GoogleIMAEventType.ADS_REQUEST_FOR_VIDEO, new EventListener() {
@Override
public void processEvent(Event event) {
// Create a container object for the ads to be presented.
AdDisplayContainer container = sdkFactory.createAdDisplayContainer();
container.setPlayer(googleIMAComponent.getVideoAdPlayer());
container.setAdContainer(brightcoveVideoView);
// Build an ads request object and point it to the ad
// display container created above.
AdsRequest adsRequest = sdkFactory.createAdsRequest();
adsRequest.setAdTagUrl(adRulesURL);
adsRequest.setAdDisplayContainer(container);
ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(1);
adsRequests.add(adsRequest);
// Respond to the event with the new ad requests.
event.properties.put(GoogleIMAComponent.ADS_REQUESTS, adsRequests);
eventEmitter.respond(event);
}
});
// Create the Brightcove IMA Plugin and pass in the event
// emitter so that the plugin can integrate with the SDK.
googleIMAComponent = new GoogleIMAComponent(brightcoveVideoView, eventEmitter, true);
// Calling GoogleIMAComponent.initializeAdsRequests() is no longer necessary.
}
use of com.brightcove.player.event.EventListener in project android-player-samples by BrightcoveOS.
the class MainActivity method setupGoogleIMA.
/**
* Setup the Brightcove IMA Plugin.
*/
private void setupGoogleIMA() {
// Establish the Google IMA SDK factory instance.
final ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
// Enable logging up ad start.
eventEmitter.on(EventType.AD_STARTED, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Enable logging any failed attempts to play an ad.
eventEmitter.on(GoogleIMAEventType.DID_FAIL_TO_PLAY_AD, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Enable Logging upon ad completion.
eventEmitter.on(EventType.AD_COMPLETED, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Set up a listener for initializing AdsRequests. The Google
// IMA plugin emits an ad request event as a result of
// initializeAdsRequests() being called.
eventEmitter.on(GoogleIMAEventType.ADS_REQUEST_FOR_VIDEO, new EventListener() {
@Override
public void processEvent(Event event) {
// Create a container object for the ads to be presented.
AdDisplayContainer container = sdkFactory.createAdDisplayContainer();
container.setPlayer(googleIMAComponent.getVideoAdPlayer());
container.setAdContainer(brightcoveVideoView);
// Build an ads request object and point it to the ad
// display container created above.
AdsRequest adsRequest = sdkFactory.createAdsRequest();
adsRequest.setAdTagUrl(adRulesURL);
adsRequest.setAdDisplayContainer(container);
ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(1);
adsRequests.add(adsRequest);
// Respond to the event with the new ad requests.
event.properties.put(GoogleIMAComponent.ADS_REQUESTS, adsRequests);
eventEmitter.respond(event);
}
});
// Create the Brightcove IMA Plugin and pass in the event
// emitter so that the plugin can integrate with the SDK.
googleIMAComponent = new GoogleIMAComponent(brightcoveVideoView, eventEmitter, true);
// Calling GoogleIMAComponent.initializeAdsRequests() is no longer necessary.
}
Aggregations