Commit 4b9863f5 authored by Edward Wang's avatar Edward Wang Committed by Sébastien Toque
Browse files

Add loop one, all and none feature

parent e34af1d6
......@@ -37,11 +37,11 @@ public interface AudioPlayer {
void shuffle();
void repeat();
boolean isShuffling();
boolean isRepeating();
void setRepeatType(RepeatType t);
RepeatType getRepeatType();
}
}
......@@ -116,10 +116,17 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
} else {
mShuffle.setImageResource(R.drawable.ic_shuffle);
}
if (mAudioController.isRepeating()) {
mRepeat.setImageResource(R.drawable.ic_repeat_glow);
} else {
switch(mAudioController.getRepeatType()) {
case None:
mRepeat.setImageResource(R.drawable.ic_repeat);
break;
case Once:
mRepeat.setImageResource(R.drawable.ic_repeat_one);
break;
default:
case All:
mRepeat.setImageResource(R.drawable.ic_repeat_glow);
break;
}
if (mAudioController.hasNext())
mNext.setVisibility(ImageButton.VISIBLE);
......@@ -182,7 +189,18 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
}
public void onRepeatClick(View view) {
mAudioController.repeat();
switch (mAudioController.getRepeatType()) {
case None:
mAudioController.setRepeatType(RepeatType.All);
break;
case All:
mAudioController.setRepeatType(RepeatType.Once);
break;
default:
case Once:
mAudioController.setRepeatType(RepeatType.None);
break;
}
update();
}
......
......@@ -35,7 +35,7 @@ public class AudioService extends Service {
private EventManager mEventManager;
private Notification mNotification;
private boolean mShuffling = false;
private boolean mRepeating = false;
private RepeatType mRepeating = RepeatType.None;
@Override
public void onStart(Intent intent, int startId) {
......@@ -168,7 +168,7 @@ public class AudioService extends Service {
private void next() {
int index = mMediaList.indexOf(mCurrentMedia);
mPrevious.push(mCurrentMedia);
if (mRepeating)
if (mRepeating == RepeatType.Once)
mCurrentMedia = mMediaList.get(index);
else if (mShuffling && mPlayedMedia.size() < mMediaList.size()) {
while (mPlayedMedia.contains(mCurrentMedia = mMediaList
......@@ -177,8 +177,12 @@ public class AudioService extends Service {
} else if (index < mMediaList.size() - 1) {
mCurrentMedia = mMediaList.get(index + 1);
} else {
stop();
return;
if (mRepeating == RepeatType.All)
mCurrentMedia = mMediaList.get(0);
else {
stop();
return;
}
}
mLibVLC.readMedia(mCurrentMedia.getPath());
showNotification();
......@@ -202,8 +206,8 @@ public class AudioService extends Service {
mShuffling = !mShuffling;
}
private void repeat() {
mRepeating = !mRepeating;
private void setRepeatType(int t) {
mRepeating = RepeatType.values()[t];
}
private IAudioService.Stub mInterface = new IAudioService.Stub() {
......@@ -239,8 +243,8 @@ public class AudioService extends Service {
}
@Override
public boolean isRepeating() {
return mRepeating;
public int getRepeatType() {
return mRepeating.ordinal();
}
@Override
......@@ -372,8 +376,8 @@ public class AudioService extends Service {
}
@Override
public void repeat() throws RemoteException {
AudioService.this.repeat();
public void setRepeatType(int t) throws RemoteException {
AudioService.this.setRepeatType(t);
}
@Override
......@@ -383,7 +387,7 @@ public class AudioService extends Service {
@Override
public boolean hasNext() throws RemoteException {
if (mRepeating)
if (mRepeating == RepeatType.Once)
return false;
int index = mMediaList.indexOf(mCurrentMedia);
if (mShuffling && mPlayedMedia.size() < mMediaList.size() ||
......@@ -395,7 +399,7 @@ public class AudioService extends Service {
@Override
public boolean hasPrevious() throws RemoteException {
if (mRepeating)
if (mRepeating == RepeatType.Once)
return false;
int index = mMediaList.indexOf(mCurrentMedia);
if (mPrevious.size() > 0 || index > 0)
......
......@@ -331,9 +331,9 @@ public class AudioServiceController implements AudioPlayerControl {
}
@Override
public void repeat() {
public void setRepeatType(RepeatType t) {
try {
mAudioServiceBinder.repeat();
mAudioServiceBinder.setRepeatType(t.ordinal());
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: repeat()");
}
......@@ -350,12 +350,12 @@ public class AudioServiceController implements AudioPlayerControl {
}
@Override
public boolean isRepeating() {
public RepeatType getRepeatType() {
try {
return mAudioServiceBinder.isRepeating();
return RepeatType.values()[mAudioServiceBinder.getRepeatType()];
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: isRepeating()");
return false;
return RepeatType.None;
}
}
}
......@@ -8,13 +8,13 @@ interface IAudioService {
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();
int getRepeatType();
void setRepeatType(int t);
boolean hasMedia();
boolean hasNext();
boolean hasPrevious();
......
package org.videolan.vlc.android;
public enum RepeatType {
None,
Once,
All
}
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