Commit ae0047a9 authored by John Mooring's avatar John Mooring Committed by Sébastien Toque

Implemented repeat and shuffle.

Signed-off-by: Sébastien Toque's avatarSébastien Toque <xilasz@gmail.com>
parent 74e49bf4
......@@ -34,6 +34,14 @@ public interface AudioPlayer {
void next();
void previous();
void shuffle();
void repeat();
boolean isShuffling();
boolean isRepeating();
}
}
......@@ -85,6 +85,16 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
} else {
mPlayPause.setBackgroundResource(R.drawable.ic_play);
}
if (mAudioController.isShuffling()) {
mShuffle.setImageResource(R.drawable.ic_shuffle_glow);
} else {
mShuffle.setImageResource(R.drawable.ic_shuffle);
}
if (mAudioController.isRepeating()) {
mRepeat.setImageResource(R.drawable.ic_repeat_glow);
} else {
mRepeat.setImageResource(R.drawable.ic_repeat);
}
if (mAudioController.hasNext())
mNext.setVisibility(ImageButton.VISIBLE);
else
......@@ -137,13 +147,13 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
}
public void onRepeatClick(View view) {
// mAudioController.repeat();
Util.toaster(R.string.notavailable);
mAudioController.repeat();
update();
}
public void onShuffleClick(View view) {
// mAudioController.shuffle();
Util.toaster(R.string.notavailable);
mAudioController.shuffle();
update();
}
@Override
......
......@@ -2,6 +2,7 @@ package org.videolan.vlc.android;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import android.app.Notification;
import android.app.PendingIntent;
......@@ -20,10 +21,14 @@ public class AudioService extends Service {
private LibVLC mLibVLC;
private ArrayList<Media> mMediaList;
private ArrayList<Media> mPlayedMedia;
private Stack<Media> mPrevious;
private Media mCurrentMedia;
private ArrayList<IAudioServiceCallback> mCallback;
private EventManager mEventManager;
private Notification mNotification;
private boolean mShuffling = false;
private boolean mRepeating = false;
@Override
public void onStart(Intent intent, int startId) {
......@@ -38,6 +43,8 @@ public class AudioService extends Service {
mCallback = new ArrayList<IAudioServiceCallback>();
mMediaList = new ArrayList<Media>();
mPlayedMedia = new ArrayList<Media>();
mPrevious = new Stack<Media>();
mEventManager = EventManager.getIntance();
}
......@@ -144,6 +151,8 @@ public class AudioService extends Service {
mLibVLC.stop();
mCurrentMedia = null;
mMediaList.clear();
mPlayedMedia.clear();
mPrevious.clear();
mHandler.removeMessages(SHOW_PROGRESS);
hideNotification();
executeUpdate();
......@@ -151,23 +160,43 @@ public class AudioService extends Service {
private void next() {
int index = mMediaList.indexOf(mCurrentMedia);
if (index < mMediaList.size() - 1) {
mPrevious.push(mCurrentMedia);
if (mRepeating)
mCurrentMedia = mMediaList.get(index);
else if (mShuffling && mPlayedMedia.size() < mMediaList.size()) {
while (mPlayedMedia.contains(mCurrentMedia = mMediaList
.get((int) (Math.random() * mMediaList.size()))))
;
} else if (index < mMediaList.size() - 1) {
mCurrentMedia = mMediaList.get(index + 1);
mLibVLC.readMedia(mCurrentMedia.getPath());
showNotification();
} else {
stop();
return;
}
mLibVLC.readMedia(mCurrentMedia.getPath());
showNotification();
}
private void previous() {
int index = mMediaList.indexOf(mCurrentMedia);
if (index > 0) {
if (mPrevious.size() > 0)
mCurrentMedia = mPrevious.pop();
else if (index > 0)
mCurrentMedia = mMediaList.get(index - 1);
mLibVLC.readMedia(mCurrentMedia.getPath());
showNotification();
}
else
return;
mLibVLC.readMedia(mCurrentMedia.getPath());
showNotification();
}
private void shuffle() {
if (mShuffling)
mPlayedMedia.clear();
mShuffling = !mShuffling;
}
private void repeat() {
mRepeating = !mRepeating;
}
private IAudioService.Stub mInterface = new IAudioService.Stub() {
......@@ -197,6 +226,16 @@ public class AudioService extends Service {
return mLibVLC.isPlaying();
}
@Override
public boolean isShuffling() {
return mShuffling;
}
@Override
public boolean isRepeating() {
return mRepeating;
}
@Override
public boolean hasMedia() throws RemoteException {
return mMediaList.size() != 0;
......@@ -257,7 +296,8 @@ public class AudioService extends Service {
throws RemoteException {
mEventManager.addHandler(mEventHandler);
mMediaList.clear();
mPlayedMedia.clear();
mPrevious.clear();
DatabaseManager db = DatabaseManager.getInstance();
for (int i = 0; i < mediaPathList.size(); i++) {
String path = mediaPathList.get(i);
......@@ -285,6 +325,15 @@ public class AudioService extends Service {
AudioService.this.previous();
}
public void shuffle() throws RemoteException {
AudioService.this.shuffle();
}
@Override
public void repeat() throws RemoteException {
AudioService.this.repeat();
}
@Override
public void setTime(long time) throws RemoteException {
mLibVLC.setTime(time);
......@@ -292,8 +341,11 @@ public class AudioService extends Service {
@Override
public boolean hasNext() throws RemoteException {
if (mRepeating)
return false;
int index = mMediaList.indexOf(mCurrentMedia);
if (index < mMediaList.size() - 1)
if (mShuffling && mPlayedMedia.size() < mMediaList.size() ||
index < mMediaList.size() - 1)
return true;
else
return false;
......@@ -301,8 +353,10 @@ public class AudioService extends Service {
@Override
public boolean hasPrevious() throws RemoteException {
if (mRepeating)
return false;
int index = mMediaList.indexOf(mCurrentMedia);
if (index > 0)
if (mPrevious.size() > 0 || index > 0)
return true;
else
return false;
......
......@@ -301,4 +301,41 @@ public class AudioServiceController implements AudioPlayerControl {
return false;
}
@Override
public void shuffle() {
try {
mAudioServiceBinder.shuffle();
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: shuffle()");
}
}
@Override
public void repeat() {
try {
mAudioServiceBinder.repeat();
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: repeat()");
}
}
@Override
public boolean isShuffling() {
try {
return mAudioServiceBinder.isShuffling();
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: isShuffling()");
return false;
}
}
@Override
public boolean isRepeating() {
try {
return mAudioServiceBinder.isRepeating();
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: isRepeating()");
return false;
}
}
}
......@@ -7,10 +7,14 @@ interface IAudioService {
void stop();
void next();
void previous();
void shuffle();
void repeat();
void setTime(long time);
String getCurrentMediaPath();
void load(in List<String> mediaPathList, int position);
boolean isPlaying();
boolean isShuffling();
boolean isRepeating();
boolean hasMedia();
boolean hasNext();
boolean hasPrevious();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment