[Android] AudioService: dynamically update audio file lengths
Edward Wang
git at videolan.org
Sun Dec 9 04:30:01 CET 2012
vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sat Dec 8 22:10:23 2012 -0500| [a78daebbb358fa036b012daef80f78fa927bb65e] | committer: Edward Wang
AudioService: dynamically update audio file lengths
Some files (notably OGG) don't have track info until they are played, so dynamically fill them in when playing.
This is also about as close as you can get for the length sort issue without having playing everything during the media scan.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=a78daebbb358fa036b012daef80f78fa927bb65e
---
vlc-android/src/org/videolan/vlc/AudioService.java | 20 ++++++++++++++++++++
.../src/org/videolan/vlc/DatabaseManager.java | 4 ++++
2 files changed, 24 insertions(+)
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 2f6d6c9..696f1d3 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -352,6 +352,26 @@ public class AudioService extends Service {
switch (msg.getData().getInt("event")) {
case EventManager.MediaPlayerPlaying:
Log.i(TAG, "MediaPlayerPlaying");
+
+ String location = service.mCurrentMedia.getLocation();
+ long length = service.mLibVLC.getLength();
+ DatabaseManager dbManager = DatabaseManager
+ .getInstance(VLCApplication.getAppContext());
+ Media m = dbManager.getMedia(VLCApplication.getAppContext(),
+ location);
+ /**
+ * 1) There is a media to update
+ * 2) It has a length of 0
+ * (dynamic track loading - most notably the OGG container)
+ * 3) We were able to get a length even after parsing
+ * (don't want to replace a 0 with a 0)
+ */
+ if(m != null && m.getLength() == 0 && length > 0) {
+ Log.d(TAG, "Updating audio file length");
+ dbManager.updateMedia(location,
+ DatabaseManager.mediaColumn.MEDIA_LENGTH, length);
+ }
+
service.changeAudioFocus(true);
service.setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
if (!service.mWakeLock.isHeld())
diff --git a/vlc-android/src/org/videolan/vlc/DatabaseManager.java b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
index 1a3a806..115b000 100644
--- a/vlc-android/src/org/videolan/vlc/DatabaseManager.java
+++ b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
@@ -507,6 +507,10 @@ public class DatabaseManager {
if (object != null)
values.put(MEDIA_SPUTRACK, (Integer)object);
break;
+ case MEDIA_LENGTH:
+ if (object != null)
+ values.put(MEDIA_LENGTH, (Long)object);
+ break;
default:
return;
}
More information about the Android
mailing list