@Test
public void testEventMediaSessionTerminated() throws InterruptedException,
ClientProtocolException, IOException {
final PlayerEndpoint player = pipeline.newPlayerEndpoint(URL_SMALL)
.build();
HttpGetEndpoint httpEP = pipeline.newHttpGetEndpoint().terminateOnEOS()
.build();
player.connect(httpEP);
httpEP.addMediaSessionStartedListener(new MediaEventListener<MediaSessionStartedEvent>() {
@Override
public void onEvent(MediaSessionStartedEvent event) {
player.play();
}
});
final BlockingQueue<MediaSessionTerminatedEvent> events = new ArrayBlockingQueue<>(
1);
httpEP.addMediaSessionTerminatedListener(new MediaEventListener<MediaSessionTerminatedEvent>() {
@Override
public void onEvent(MediaSessionTerminatedEvent event) {
events.add(event);
}
});
try (CloseableHttpClient httpclient = HttpClientBuilder.create()
.build()) {
// This should trigger MediaSessionStartedEvent
httpclient.execute(new HttpGet(httpEP.getUrl()));
}
Assert.assertNotNull("MediaSessionTerminatedEvent not sent in 20s",
events.poll(20, SECONDS));
httpEP.release();
player.release();
}