[Android] Audio player: switch to the previous and next media by scrolling
Adrien Maglo
git at videolan.org
Tue Jan 14 18:53:49 CET 2014
vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Tue Jan 14 18:53:40 2014 +0100| [17dafe835edc8011fe08e97da09e4bdd7420ff03] | committer: Adrien Maglo
Audio player: switch to the previous and next media by scrolling
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=17dafe835edc8011fe08e97da09e4bdd7420ff03
---
.../videolan/vlc/widget/AudioMediaSwitcher.java | 72 +++++++++++++++++++-
.../org/videolan/vlc/widget/AudioMiniPlayer.java | 31 +++++++++
2 files changed, 102 insertions(+), 1 deletion(-)
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java b/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
index a100a93..dc21210 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
@@ -34,8 +34,15 @@ import android.widget.TextView;
public class AudioMediaSwitcher extends FlingViewGroup {
+ private AudioMediaSwitcherListener mAudioMediaSwitcherListener;
+
+ private boolean hasPrevious;
+ private int previousPosition;
+
public AudioMediaSwitcher(Context context, AttributeSet attrs) {
super(context, attrs);
+
+ setOnViewSwitchedListener(mViewSwitchListener);
}
public void updateMedia() {
@@ -45,12 +52,17 @@ public class AudioMediaSwitcher extends FlingViewGroup {
removeAllViews();
+ hasPrevious = false;
+ previousPosition = 0;
+
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- if (audioController.hasPrevious())
+ if (audioController.hasPrevious()) {
addMediaView(inflater,
audioController.getTitlePrev(),
audioController.getArtistPrev(),
audioController.getCoverPrev());
+ hasPrevious = true;
+ }
if (audioController.hasMedia())
addMediaView(inflater,
audioController.getTitle(),
@@ -63,6 +75,7 @@ public class AudioMediaSwitcher extends FlingViewGroup {
audioController.getCoverNext());
if (audioController.hasPrevious() && audioController.hasMedia()) {
+ previousPosition = 1;
scrollTo(1);
}
}
@@ -84,4 +97,61 @@ public class AudioMediaSwitcher extends FlingViewGroup {
addView(v);
}
+
+ private final ViewSwitchListener mViewSwitchListener = new ViewSwitchListener() {
+
+ @Override
+ public void onSwitching(float progress) {
+ if (mAudioMediaSwitcherListener != null)
+ mAudioMediaSwitcherListener.onMediaSwitching();
+ }
+
+ @Override
+ public void onSwitched(int position) {
+ if (mAudioMediaSwitcherListener != null)
+ {
+ if (previousPosition != position) {
+ if (position == 0 && hasPrevious)
+ mAudioMediaSwitcherListener.onMediaSwitched(AudioMediaSwitcherListener.PREVIOUS_MEDIA);
+ if (position == 1 && !hasPrevious)
+ mAudioMediaSwitcherListener.onMediaSwitched(AudioMediaSwitcherListener.NEXT_MEDIA);
+ else if (position == 2)
+ mAudioMediaSwitcherListener.onMediaSwitched(AudioMediaSwitcherListener.NEXT_MEDIA);
+ previousPosition = position;
+ }
+ else
+ mAudioMediaSwitcherListener.onMediaSwitched(AudioMediaSwitcherListener.CURRENT_MEDIA);
+ }
+ }
+
+ @Override
+ public void onTouchDown() {
+ if (mAudioMediaSwitcherListener != null)
+ mAudioMediaSwitcherListener.onTouchDown();
+ }
+
+ @Override
+ public void onTouchUp() {
+ if (mAudioMediaSwitcherListener != null)
+ mAudioMediaSwitcherListener.onTouchUp();
+ }
+ };
+
+ public void setAudioMediaSwitcherListener(AudioMediaSwitcherListener l) {
+ mAudioMediaSwitcherListener = l;
+ }
+
+ public static interface AudioMediaSwitcherListener {
+ public final static int PREVIOUS_MEDIA = 1;
+ public final static int CURRENT_MEDIA = 2;
+ public final static int NEXT_MEDIA = 3;
+
+ void onMediaSwitching();
+
+ void onMediaSwitched(int position);
+
+ void onTouchDown();
+
+ void onTouchUp();
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
index 16f445d..d359cd1 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
@@ -36,6 +36,7 @@ import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.CommonDialogs.MenuType;
import org.videolan.vlc.gui.audio.AudioListAdapter;
import org.videolan.vlc.interfaces.IAudioPlayer;
+import org.videolan.vlc.widget.AudioMediaSwitcher.AudioMediaSwitcherListener;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -93,6 +94,8 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
View v = inflater.inflate(R.layout.audio_player, container, false);
mAudioMediaSwitcher = (AudioMediaSwitcher) v.findViewById(R.id.audio_media_switcher);
+ mAudioMediaSwitcher.setAudioMediaSwitcherListener(mAudioMediaSwitcherListener);
+
mBigCover = (AnimatedCoverView) v.findViewById(R.id.big_cover);
mTime = (TextView) v.findViewById(R.id.time);
mLength = (TextView) v.findViewById(R.id.length);
@@ -228,6 +231,8 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
mBigCover.setImageBitmap(cover);
mAudioMediaSwitcher.updateMedia();
+ mAdvFunc.setVisibility(ImageButton.VISIBLE);
+ mPlaylistSwitch.setVisibility(ImageButton.VISIBLE);
if (mAudioController.isPlaying()) {
mPlayPause.setImageResource(R.drawable.ic_pause);
@@ -396,4 +401,30 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
MainActivity activity = (MainActivity)getActivity();
activity.hideMiniPlayer();
}
+
+ private final AudioMediaSwitcherListener mAudioMediaSwitcherListener = new AudioMediaSwitcherListener() {
+
+ @Override
+ public void onMediaSwitching() {}
+
+ @Override
+ public void onMediaSwitched(int position) {
+ if (position == AudioMediaSwitcherListener.PREVIOUS_MEDIA)
+ mAudioController.previous();
+ else if (position == AudioMediaSwitcherListener.NEXT_MEDIA)
+ mAudioController.next();
+ }
+
+ @Override
+ public void onTouchDown() {
+ mAdvFunc.setVisibility(ImageButton.GONE);
+ mPlaylistSwitch.setVisibility(ImageButton.GONE);
+ }
+
+ @Override
+ public void onTouchUp() {
+ mAdvFunc.setVisibility(ImageButton.VISIBLE);
+ mPlaylistSwitch.setVisibility(ImageButton.VISIBLE);
+ }
+ };
}
More information about the Android
mailing list