Delay control hiding when button pressed

This commit is contained in:
Martin Fietz 2016-02-18 08:38:57 +01:00
parent acff2ba0d6
commit 8f3f0c30c6
4 changed files with 82 additions and 37 deletions

View File

@ -763,8 +763,7 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
if (butRev != null) { if (butRev != null) {
butRev.setOnClickListener(v -> { butRev.setOnClickListener(v -> {
int curr = controller.getPosition(); onRewind();
controller.seekTo(curr - UserPreferences.getRewindSecs() * 1000);
}); });
butRev.setOnLongClickListener(new View.OnLongClickListener() { butRev.setOnLongClickListener(new View.OnLongClickListener() {
@ -800,12 +799,13 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
}); });
} }
butPlay.setOnClickListener(controller.newOnPlayButtonClickListener()); butPlay.setOnClickListener(v -> {
onPlayPause();
});
if (butFF != null) { if (butFF != null) {
butFF.setOnClickListener(v -> { butFF.setOnClickListener(v -> {
int curr = controller.getPosition(); onFastForward();
controller.seekTo(curr + UserPreferences.getFastFowardSecs() * 1000);
}); });
butFF.setOnLongClickListener(new View.OnLongClickListener() { butFF.setOnLongClickListener(new View.OnLongClickListener() {
@ -848,6 +848,29 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
} }
} }
protected void onRewind() {
if (controller == null) {
return;
}
int curr = controller.getPosition();
controller.seekTo(curr - UserPreferences.getRewindSecs() * 1000);
}
protected void onPlayPause() {
if(controller == null) {
return;
}
controller.playPause();
}
protected void onFastForward() {
if (controller == null) {
return;
}
int curr = controller.getPosition();
controller.seekTo(curr + UserPreferences.getFastFowardSecs() * 1000);
}
protected abstract int getContentViewResourceId(); protected abstract int getContentViewResourceId();
void handleError(int errorCode) { void handleError(int errorCode) {

View File

@ -202,6 +202,24 @@ public class VideoplayerActivity extends MediaplayerActivity {
videoControlsShowing = !videoControlsShowing; videoControlsShowing = !videoControlsShowing;
} }
@Override
protected void onRewind() {
super.onRewind();
setupVideoControlsToggler();
}
@Override
protected void onPlayPause() {
super.onPlayPause();
setupVideoControlsToggler();
}
@Override
protected void onFastForward() {
super.onFastForward();
setupVideoControlsToggler();
}
private final SurfaceHolder.Callback surfaceHolderCallback = new SurfaceHolder.Callback() { private final SurfaceHolder.Callback surfaceHolderCallback = new SurfaceHolder.Callback() {
@Override @Override

View File

@ -72,7 +72,11 @@ public class ExternalPlayerFragment extends Fragment {
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
controller = setupPlaybackController(); controller = setupPlaybackController();
butPlay.setOnClickListener(controller.newOnPlayButtonClickListener()); butPlay.setOnClickListener(v -> {
if(controller != null) {
controller.playPause();
}
});
} }
private PlaybackController setupPlaybackController() { private PlaybackController setupPlaybackController() {
@ -88,7 +92,6 @@ public class ExternalPlayerFragment extends Fragment {
return butPlay; return butPlay;
} }
@Override @Override
public boolean loadMediaInfo() { public boolean loadMediaInfo() {
ExternalPlayerFragment fragment = ExternalPlayerFragment.this; ExternalPlayerFragment fragment = ExternalPlayerFragment.this;
@ -145,8 +148,11 @@ public class ExternalPlayerFragment extends Fragment {
} }
controller = setupPlaybackController(); controller = setupPlaybackController();
if (butPlay != null) { if (butPlay != null) {
butPlay.setOnClickListener(controller butPlay.setOnClickListener(v -> {
.newOnPlayButtonClickListener()); if(controller != null) {
controller.playPause();
}
});
} }
controller.init(); controller.init();
} }

View File

@ -574,34 +574,32 @@ public abstract class PlaybackController {
} }
public OnClickListener newOnPlayButtonClickListener() { public void playPause() {
return v -> { if (playbackService == null) {
if (playbackService == null) { Log.w(TAG, "Play/Pause button was pressed, but playbackservice was null!");
Log.w(TAG, "Play/Pause button was pressed, but playbackservice was null!"); return;
return; }
} switch (status) {
switch (status) { case PLAYING:
case PLAYING: playbackService.pause(true, reinitOnPause);
playbackService.pause(true, reinitOnPause); break;
break; case PAUSED:
case PAUSED: case PREPARED:
case PREPARED: playbackService.resume();
playbackService.resume(); break;
break; case PREPARING:
case PREPARING: playbackService.setStartWhenPrepared(!playbackService
playbackService.setStartWhenPrepared(!playbackService .isStartWhenPrepared());
.isStartWhenPrepared()); if (reinitOnPause
if (reinitOnPause && playbackService.isStartWhenPrepared() == false) {
&& playbackService.isStartWhenPrepared() == false) { playbackService.reinit();
playbackService.reinit(); }
} break;
break; case INITIALIZED:
case INITIALIZED: playbackService.setStartWhenPrepared(true);
playbackService.setStartWhenPrepared(true); playbackService.prepare();
playbackService.prepare(); break;
break; }
}
};
} }
public boolean serviceAvailable() { public boolean serviceAvailable() {