fix onAttach

This commit is contained in:
Felix 2017-04-04 02:36:17 +02:00
parent b8bcd343d5
commit fec8fa07d5
3 changed files with 41 additions and 22 deletions

View file

@ -239,8 +239,6 @@ public class PlaybackHelper extends PlaybackControlGlue {
if(getCurrentSpeedId() == speed){
return;
}
// setFadingEnabled(true);
// fragment.setFadingEnabled(true);
if(mTransportControls != null){
mTransportControls.play();
} else {
@ -250,8 +248,6 @@ public class PlaybackHelper extends PlaybackControlGlue {
@Override
protected void pausePlayback() {
// setFadingEnabled(false);
// fragment.setFadingEnabled(false);
if(mTransportControls != null){
mTransportControls.pause();
} else {

View file

@ -140,6 +140,9 @@ public class OverlayFragment extends PlaybackFragment{
mMediaControler = getActivity().getMediaController();
if(mMediaControler != null){
mMediaControler.registerCallback(mMediaControllerCallback);
} else {
Log.d(TAG, "MediaController is null");
getActivity().finish();
}
ClassPresenterSelector ps = new ClassPresenterSelector();
ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
@ -214,10 +217,21 @@ public class OverlayFragment extends PlaybackFragment{
mHelper.onStop();
}
@SuppressWarnings("WrongConstant")
@Override
public void onAttach(Context context) {
super.onAttach(context);
setupMediaSession(context);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
setupMediaSession(activity);
}
@SuppressWarnings("WrongConstant")
private void setupMediaSession(Context context) {
Log.d(TAG,"OnAttach");
if(context instanceof PlaybackControlListener){
mCallback = (PlaybackControlListener) context;
@ -232,7 +246,6 @@ public class OverlayFragment extends PlaybackFragment{
mSession.setActive(true);
setPlaybackState(PlaybackState.STATE_NONE);
// mSession.setPlaybackState(state);
getActivity().setMediaController(
new MediaController(getActivity(),mSession.getSessionToken()));
@ -246,8 +259,10 @@ public class OverlayFragment extends PlaybackFragment{
.setActions(getAvailableActions(state))
.setState(PlaybackState.STATE_PLAYING, currentPosition, 0);
if(mSession != null){
mSession.setPlaybackState(stateBuilder.build());
}
}
private int getPlaybackState() {
Activity activity = getActivity();
@ -297,30 +312,38 @@ public class OverlayFragment extends PlaybackFragment{
}
private void play() {
if(mCallback != null){
setPlaybackState(PlaybackState.STATE_PLAYING);
setFadingEnabled(true);
mCallback.play();
}
}
private void pause() {
if(mCallback != null){
setPlaybackState(PlaybackState.STATE_PAUSED);
setFadingEnabled(false);
mCallback.pause();
}
}
private void rewind() {
if(mCallback != null){
int prevState = getPlaybackState();
setPlaybackState(PlaybackState.STATE_FAST_FORWARDING);
mCallback.skipBackward(30);
setPlaybackState(prevState);
}
}
private void fastForward() {
if(mCallback != null){
int prevState = getPlaybackState();
setPlaybackState(PlaybackState.STATE_FAST_FORWARDING);
mCallback.skipForward(30);
setPlaybackState(prevState);
}
}
private class ChaosflixSessionCallback extends MediaSession.Callback {
@Override