[Android] Audio player: create a separate player update function to update only the progress bars
Adrien Maglo
git at videolan.org
Thu Jan 9 13:41:32 CET 2014
vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Wed Jan 8 14:38:46 2014 +0100| [8c7aa761a779e6a781fbfdc1b2e4adce7cf3098b] | committer: Adrien Maglo
Audio player: create a separate player update function to update only the progress bars
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8c7aa761a779e6a781fbfdc1b2e4adce7cf3098b
---
vlc-android/src/org/videolan/vlc/AudioService.java | 20 +++++++++++++++++++-
.../org/videolan/vlc/AudioServiceController.java | 13 +++++++++++++
.../vlc/gui/audio/AudioPlayerFragment.java | 17 +++++++++++------
.../org/videolan/vlc/interfaces/IAudioPlayer.java | 1 +
.../vlc/interfaces/IAudioServiceCallback.aidl | 1 +
.../org/videolan/vlc/widget/AudioMiniPlayer.java | 13 +++++++------
6 files changed, 52 insertions(+), 13 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 9343955..4f064b3 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -395,6 +395,7 @@ public class AudioService extends Service {
case EventHandler.MediaPlayerPlaying:
Log.i(TAG, "MediaPlayerPlaying");
service.executeUpdate();
+ service.executeUpdateProgress();
String location = service.mLibVLC.getMediaList().getMRL(service.mCurrentIndex);
long length = service.mLibVLC.getLength();
@@ -423,6 +424,7 @@ public class AudioService extends Service {
case EventHandler.MediaPlayerPaused:
Log.i(TAG, "MediaPlayerPaused");
service.executeUpdate();
+ service.executeUpdateProgress();
service.showNotification();
service.setRemoteControlClientPlaybackState(EventHandler.MediaPlayerPaused);
if (service.mWakeLock.isHeld())
@@ -431,6 +433,7 @@ public class AudioService extends Service {
case EventHandler.MediaPlayerStopped:
Log.i(TAG, "MediaPlayerStopped");
service.executeUpdate();
+ service.executeUpdateProgress();
service.setRemoteControlClientPlaybackState(EventHandler.MediaPlayerStopped);
if (service.mWakeLock.isHeld())
service.mWakeLock.release();
@@ -438,6 +441,7 @@ public class AudioService extends Service {
case EventHandler.MediaPlayerEndReached:
Log.i(TAG, "MediaPlayerEndReached");
service.executeUpdate();
+ service.executeUpdateProgress();
service.next();
if (service.mWakeLock.isHeld())
service.mWakeLock.release();
@@ -457,6 +461,7 @@ public class AudioService extends Service {
service.mLibVLC.getMediaList().getMRL(
service.mCurrentIndex)), Toast.LENGTH_SHORT);
service.executeUpdate();
+ service.executeUpdateProgress();
service.next();
if (service.mWakeLock.isHeld())
service.mWakeLock.release();
@@ -542,6 +547,16 @@ public class AudioService extends Service {
updateWidget(this);
}
+ private void executeUpdateProgress() {
+ for (IAudioServiceCallback callback : mCallback.keySet()) {
+ try {
+ callback.updateProgress();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
/**
* Alias for mMetadataCache.get(mCurrentIndex)
*
@@ -576,7 +591,7 @@ public class AudioService extends Service {
case SHOW_PROGRESS:
if (service.mCallback.size() > 0) {
removeMessages(SHOW_PROGRESS);
- service.executeUpdate(false);
+ service.executeUpdateProgress();
sendEmptyMessageDelayed(SHOW_PROGRESS, 1000);
}
break;
@@ -714,6 +729,7 @@ public class AudioService extends Service {
mHandler.removeMessages(SHOW_PROGRESS);
hideNotification();
executeUpdate();
+ executeUpdateProgress();
changeAudioFocus(false);
}
@@ -729,6 +745,7 @@ public class AudioService extends Service {
@Override
public void run() {
service.executeUpdate();
+ service.executeUpdateProgress();
}
}, 1000);
} else {
@@ -1054,6 +1071,7 @@ public class AudioService extends Service {
mHandler.sendEmptyMessage(SHOW_PROGRESS);
showNotification();
executeUpdate();
+ executeUpdateProgress();
}
/**
diff --git a/vlc-android/src/org/videolan/vlc/AudioServiceController.java b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
index 7cb0281..27f23e7 100644
--- a/vlc-android/src/org/videolan/vlc/AudioServiceController.java
+++ b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
@@ -54,6 +54,11 @@ public class AudioServiceController implements IAudioPlayerControl {
public void update() throws RemoteException {
updateAudioPlayer();
}
+
+ @Override
+ public void updateProgress() throws RemoteException {
+ updateProgressAudioPlayer();
+ }
};
private AudioServiceController() {
@@ -170,6 +175,14 @@ public class AudioServiceController implements IAudioPlayerControl {
}
/**
+ * Update the progress of all AudioPlayers
+ */
+ private void updateProgressAudioPlayer() {
+ for (IAudioPlayer player : mAudioPlayer)
+ player.updateProgress();
+ }
+
+ /**
* This is a handy utility function to call remote procedure calls from mAudioServiceBinder
* to reduce code duplication across methods of AudioServiceController.
*
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
index c0b657e..6dda292 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
@@ -253,12 +253,7 @@ public class AudioPlayerFragment extends SherlockFragment implements IAudioPlaye
lastTitle = title;
mTitle.setText(lastTitle);
mArtist.setText(mAudioController.getArtist());
- int time = mAudioController.getTime();
- int length = mAudioController.getLength();
- mTime.setText(Util.millisToString(mShowRemainingTime ? time-length : time));
- mLength.setText(Util.millisToString(length));
- mTimeline.setMax(length);
- mTimeline.setProgress(time);
+
if (mAudioController.isPlaying()) {
mPlayPause.setImageResource(R.drawable.ic_pause);
mPlayPause.setContentDescription(getString(R.string.pause));
@@ -296,6 +291,16 @@ public class AudioPlayerFragment extends SherlockFragment implements IAudioPlaye
updateList();
}
+ @Override
+ public synchronized void updateProgress() {
+ int time = mAudioController.getTime();
+ int length = mAudioController.getLength();
+ mTime.setText(Util.millisToString(mShowRemainingTime ? time-length : time));
+ mLength.setText(Util.millisToString(length));
+ mTimeline.setMax(length);
+ mTimeline.setProgress(time);
+ }
+
private void updateList() {
ArrayList<Media> audioList = new ArrayList<Media>();
String currentItem = null;
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IAudioPlayer.java b/vlc-android/src/org/videolan/vlc/interfaces/IAudioPlayer.java
index 0b017cf..c3db49f 100644
--- a/vlc-android/src/org/videolan/vlc/interfaces/IAudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IAudioPlayer.java
@@ -23,5 +23,6 @@ package org.videolan.vlc.interfaces;
public interface IAudioPlayer {
public void update();
+ public void updateProgress();
}
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IAudioServiceCallback.aidl b/vlc-android/src/org/videolan/vlc/interfaces/IAudioServiceCallback.aidl
index 26d2134..3e91745 100644
--- a/vlc-android/src/org/videolan/vlc/interfaces/IAudioServiceCallback.aidl
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IAudioServiceCallback.aidl
@@ -22,4 +22,5 @@ package org.videolan.vlc.interfaces;
interface IAudioServiceCallback {
void update();
+ void updateProgress();
}
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
index c3320e2..39e74b4 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
@@ -211,14 +211,15 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
mBackward.setVisibility(ImageButton.VISIBLE);
else
mBackward.setVisibility(ImageButton.INVISIBLE);
- int time = mAudioPlayerControl.getTime();
- int length = mAudioPlayerControl.getLength();
- // Update all view elements
-
- mProgressBar.setMax(length);
- mProgressBar.setProgress(time);
}
+ }
+ @Override
+ public synchronized void updateProgress() {
+ int time = mAudioPlayerControl.getTime();
+ int length = mAudioPlayerControl.getLength();
+ mProgressBar.setMax(length);
+ mProgressBar.setProgress(time);
}
public void show() {
More information about the Android
mailing list