private void next() { int index = mMediaList.indexOf(mCurrentMedia); mPrevious.push(mCurrentMedia); if (mRepeating == RepeatType.Once) mCurrentMedia = mMediaList.get(index); else if (mShuffling && mPrevious.size() < mMediaList.size()) { while (mPrevious.contains( mCurrentMedia = mMediaList.get((int) (Math.random() * mMediaList.size())))) ; } else if (!mShuffling && index < mMediaList.size() - 1) { mCurrentMedia = mMediaList.get(index + 1); } else { if (mRepeating == RepeatType.All && mMediaList.size() > 0) mCurrentMedia = mMediaList.get(0); else { stop(); return; } } if (mLibVLCPlaylistActive) { if (mRepeating == RepeatType.None) mLibVLC.next(); else if (mRepeating == RepeatType.Once) mLibVLC.playIndex(index); else mLibVLC.playIndex(mMediaList.indexOf(mCurrentMedia)); } else { mLibVLC.readMedia(mCurrentMedia.getLocation(), true); } mHandler.sendEmptyMessage(SHOW_PROGRESS); setUpRemoteControlClient(); showNotification(); updateWidget(this); updateRemoteControlClientMetadata(); saveCurrentMedia(); }
@Override public void onDestroy() { super.onDestroy(); stop(); if (mWakeLock.isHeld()) mWakeLock.release(); unregisterReceiver(serviceReceiver); if (mRemoteControlClientReceiver != null) { unregisterReceiver(mRemoteControlClientReceiver); mRemoteControlClientReceiver = null; } }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); int state = intent.getIntExtra("state", 0); if (mLibVLC == null) { Log.w(TAG, "Intent received, but VLC is not loaded, skipping."); return; } // skip all headsets events if there is a call TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if (telManager != null && telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) return; /* * Launch the activity if needed */ if (action.startsWith(ACTION_REMOTE_GENERIC) && !mLibVLC.isPlaying() && mCurrentMedia == null) { Intent iVlc = new Intent(context, MainActivity.class); iVlc.putExtra(START_FROM_NOTIFICATION, true); iVlc.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); context.startActivity(iVlc); } /* * Remote / headset control events */ if (action.equalsIgnoreCase(ACTION_REMOTE_PLAYPAUSE)) { if (mLibVLC.isPlaying() && mCurrentMedia != null) pause(); else if (!mLibVLC.isPlaying() && mCurrentMedia != null) play(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_PLAY)) { if (!mLibVLC.isPlaying() && mCurrentMedia != null) play(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_PAUSE)) { if (mLibVLC.isPlaying() && mCurrentMedia != null) pause(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_BACKWARD)) { previous(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_STOP)) { stop(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_FORWARD)) { next(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_LAST_PLAYLIST)) { loadLastPlaylist(); } /* * headset plug events */ if (mDetectHeadset) { if (action.equalsIgnoreCase(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { Log.i(TAG, "Headset Removed."); if (mLibVLC.isPlaying() && mCurrentMedia != null) pause(); } else if (action.equalsIgnoreCase(Intent.ACTION_HEADSET_PLUG) && state != 0) { Log.i(TAG, "Headset Inserted."); if (!mLibVLC.isPlaying() && mCurrentMedia != null) play(); } } /* * Sleep */ if (action.equalsIgnoreCase(VLCApplication.SLEEP_INTENT)) { stop(); } }