mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 04:43:07 +00:00
fix onAttach
This commit is contained in:
parent
b8bcd343d5
commit
fec8fa07d5
3 changed files with 41 additions and 22 deletions
|
@ -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 {
|
||||
|
|
|
@ -41,7 +41,7 @@ import de.nicidienase.chaosflix.fragments.OverlayFragment;
|
|||
*/
|
||||
|
||||
public class PlayerActivity extends AbstractServiceConnectedAcitivty
|
||||
implements OverlayFragment.PlaybackControlListener{
|
||||
implements OverlayFragment.PlaybackControlListener {
|
||||
|
||||
private static final String TAG = PlayerActivity.class.getSimpleName();
|
||||
@BindView(R.id.videoView)
|
||||
|
|
|
@ -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,7 +259,9 @@ public class OverlayFragment extends PlaybackFragment{
|
|||
.setActions(getAvailableActions(state))
|
||||
.setState(PlaybackState.STATE_PLAYING, currentPosition, 0);
|
||||
|
||||
mSession.setPlaybackState(stateBuilder.build());
|
||||
if(mSession != null){
|
||||
mSession.setPlaybackState(stateBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
private int getPlaybackState() {
|
||||
|
@ -297,29 +312,37 @@ public class OverlayFragment extends PlaybackFragment{
|
|||
}
|
||||
|
||||
private void play() {
|
||||
setPlaybackState(PlaybackState.STATE_PLAYING);
|
||||
setFadingEnabled(true);
|
||||
mCallback.play();
|
||||
if(mCallback != null){
|
||||
setPlaybackState(PlaybackState.STATE_PLAYING);
|
||||
setFadingEnabled(true);
|
||||
mCallback.play();
|
||||
}
|
||||
}
|
||||
|
||||
private void pause() {
|
||||
setPlaybackState(PlaybackState.STATE_PAUSED);
|
||||
setFadingEnabled(false);
|
||||
mCallback.pause();
|
||||
if(mCallback != null){
|
||||
setPlaybackState(PlaybackState.STATE_PAUSED);
|
||||
setFadingEnabled(false);
|
||||
mCallback.pause();
|
||||
}
|
||||
}
|
||||
|
||||
private void rewind() {
|
||||
int prevState = getPlaybackState();
|
||||
setPlaybackState(PlaybackState.STATE_FAST_FORWARDING);
|
||||
mCallback.skipBackward(30);
|
||||
setPlaybackState(prevState);
|
||||
if(mCallback != null){
|
||||
int prevState = getPlaybackState();
|
||||
setPlaybackState(PlaybackState.STATE_FAST_FORWARDING);
|
||||
mCallback.skipBackward(30);
|
||||
setPlaybackState(prevState);
|
||||
}
|
||||
}
|
||||
|
||||
private void fastForward() {
|
||||
int prevState = getPlaybackState();
|
||||
setPlaybackState(PlaybackState.STATE_FAST_FORWARDING);
|
||||
mCallback.skipForward(30);
|
||||
setPlaybackState(prevState);
|
||||
if(mCallback != null){
|
||||
int prevState = getPlaybackState();
|
||||
setPlaybackState(PlaybackState.STATE_FAST_FORWARDING);
|
||||
mCallback.skipForward(30);
|
||||
setPlaybackState(prevState);
|
||||
}
|
||||
}
|
||||
|
||||
private class ChaosflixSessionCallback extends MediaSession.Callback {
|
||||
|
|
Loading…
Reference in a new issue