Skip to content

Commit

Permalink
VE-93 - add reset player API (kaltura#188)
Browse files Browse the repository at this point in the history
* add reset API to player so app can reset player state before change media

* add reset to player API
so  app that wants to change media can call reset before so player state will be in the initial state

* codacy

* change API to be called stop
add stopped event to this operation
  • Loading branch information
giladna authored Mar 29, 2017
1 parent 6e6d44a commit 6b363de
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public void destroy() {

}

@Override
public void stop() {
// stop player
}

@Override
public void play() {
isPlaying = true;
Expand Down
6 changes: 6 additions & 0 deletions playkit/src/main/java/com/kaltura/playkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public interface Player {
* Should be called when you want to destroy the player.
*/
void destroy();

/**
* stop player and back to initial playback state.
*/
void stop();

/**
* Start playback of the media.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public void destroy() {
player.destroy();
}

@Override
public void stop() {
player.stop();
}

@Override
public PlayerView getView() {
return player.getView();
Expand Down
3 changes: 2 additions & 1 deletion playkit/src/main/java/com/kaltura/playkit/PlayerEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public enum Type {
TRACKS_AVAILABLE, // Sent when track info is available.
REPLAY, //Sent when replay happened.
PLAYBACK_PARAMS_UPDATED, // Sent event that notify about changes in the playback parameters. When bitrate of the video or audio track changes or new media loaded. Holds the PlaybackParamsInfo.java object with relevant data.
VOLUME_CHANGED // Sent when volume is changed.
VOLUME_CHANGED, // Sent when volume is changed.
STOPPED // sent when stop player api is called
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,16 @@ public PlayerEvent.ExceptionInfo getCurrentException() {
return new PlayerEvent.ExceptionInfo(currentException, sameErrorOccurrenceCounter);
}

@Override
public void stop() {
if (player != null) {
player.setPlayWhenReady(false);
player.seekTo(0);
player.stop();
sendDistinctEvent(PlayerEvent.Type.STOPPED);
}
}

void savePlayerPosition() {
if (player == null) {
log.e("Attempt to invoke 'savePlayerPosition()' on null instance of the exoplayer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ public PlayerEvent.ExceptionInfo getCurrentException() {
return null;
}

@Override
public void stop() {
if (player != null) {
player.pause();
player.seekTo(0);
player.reset();
sendDistinctEvent(PlayerEvent.Type.STOPPED);
}
}

public static String getWidevineAssetPlaybackUri(String assetUri) {
String assetUriForPlayback = assetUri;
if (assetUri.startsWith("file:")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public void destroy() {
eventListener = null;
}

@Override
public void stop() {
player.stop();
}

private void startPlaybackFrom(long startPosition) {
if (player == null) {
log.e("Attempt to invoke 'startPlaybackFrom()' on null instance of the player engine");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,11 @@ interface PlayerEngine {
* @return - the last {@link PlayerEvent.ExceptionInfo} that happened.
*/
PlayerEvent.ExceptionInfo getCurrentException();


/**
* Stop player executing the {@link PlayerEngine} implementation.
* stop the player and seek to start position.
*/
void stop();
}

0 comments on commit 6b363de

Please sign in to comment.