[Android] Add LastPlaylist command

Sébastien Toque git at videolan.org
Thu Dec 6 19:48:29 CET 2012


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Wed Dec  5 20:00:20 2012 +0100| [729747db0b8c00e065912b927dfa401b34424740] | committer: Sébastien Toque

Add LastPlaylist command

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=729747db0b8c00e065912b927dfa401b34424740
---

 vlc-android/res/drawable-hdpi/ic_menu_revert.png   |  Bin 0 -> 1574 bytes
 vlc-android/res/drawable-ldpi/ic_menu_revert.png   |  Bin 0 -> 1299 bytes
 vlc-android/res/drawable-mdpi/ic_menu_revert.png   |  Bin 0 -> 1037 bytes
 vlc-android/res/drawable-xhdpi/ic_menu_revert.png  |  Bin 0 -> 2077 bytes
 vlc-android/res/menu/media_library.xml             |    5 +
 vlc-android/res/values-fr/strings.xml              |    1 +
 vlc-android/res/values/strings.xml                 |    1 +
 vlc-android/src/org/videolan/vlc/AudioService.java |  103 ++++++++++++++++++++
 .../src/org/videolan/vlc/gui/MainActivity.java     |    5 +
 9 files changed, 115 insertions(+)

diff --git a/vlc-android/res/drawable-hdpi/ic_menu_revert.png b/vlc-android/res/drawable-hdpi/ic_menu_revert.png
new file mode 100644
index 0000000..0b9cf2a
Binary files /dev/null and b/vlc-android/res/drawable-hdpi/ic_menu_revert.png differ
diff --git a/vlc-android/res/drawable-ldpi/ic_menu_revert.png b/vlc-android/res/drawable-ldpi/ic_menu_revert.png
new file mode 100644
index 0000000..b0f2c60
Binary files /dev/null and b/vlc-android/res/drawable-ldpi/ic_menu_revert.png differ
diff --git a/vlc-android/res/drawable-mdpi/ic_menu_revert.png b/vlc-android/res/drawable-mdpi/ic_menu_revert.png
new file mode 100644
index 0000000..7a45163
Binary files /dev/null and b/vlc-android/res/drawable-mdpi/ic_menu_revert.png differ
diff --git a/vlc-android/res/drawable-xhdpi/ic_menu_revert.png b/vlc-android/res/drawable-xhdpi/ic_menu_revert.png
new file mode 100644
index 0000000..19c580f
Binary files /dev/null and b/vlc-android/res/drawable-xhdpi/ic_menu_revert.png differ
diff --git a/vlc-android/res/menu/media_library.xml b/vlc-android/res/menu/media_library.xml
index 4b6a936..44ebb83 100644
--- a/vlc-android/res/menu/media_library.xml
+++ b/vlc-android/res/menu/media_library.xml
@@ -24,6 +24,11 @@
         </menu>
     </item>
     <item
+        android:id="@+id/ml_menu_last_playlist"
+        android:icon="@drawable/ic_menu_revert"
+        android:title="@string/last_playlist"
+        android:showAsAction="ifRoom" />
+    <item
         android:id="@+id/ml_menu_refresh"
         android:icon="@drawable/ic_menu_refresh"
         android:title="@string/refresh"
diff --git a/vlc-android/res/values-fr/strings.xml b/vlc-android/res/values-fr/strings.xml
index 75f0c93..9d7601a 100644
--- a/vlc-android/res/values-fr/strings.xml
+++ b/vlc-android/res/values-fr/strings.xml
@@ -21,6 +21,7 @@
     <string name="append">Lire à la suite</string>
     <string name="play_all">Lire tout</string>
     <string name="append_all">Lire tout à la suite</string>
+    <string name="last_playlist">Dernière liste de lecture</string>
     <string name="delete">Supprimer</string>
     <string name="set_song">Définir comme sonnerie</string>
     <string name="info">Information</string>
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 585633e..0db066a 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -25,6 +25,7 @@
     <string name="append">Append</string>
     <string name="play_all">Play all</string>
     <string name="append_all">Append all</string>
+    <string name="last_playlist">Last playlist</string>
     <string name="delete">Delete</string>
     <string name="set_song">Set as ringtone</string>
     <string name="info">Information</string>
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index c1894d9..6b1ae9a 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -20,6 +20,13 @@
 
 package org.videolan.vlc;
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -70,6 +77,7 @@ public class AudioService extends Service {
     public static final String ACTION_REMOTE_PAUSE = "org.videolan.vlc.remote.Pause";
     public static final String ACTION_REMOTE_STOP = "org.videolan.vlc.remote.Stop";
     public static final String ACTION_REMOTE_FORWARD = "org.videolan.vlc.remote.Forward";
+    public static final String ACTION_REMOTE_LAST_PLAYLIST = "org.videolan.vlc.remote.LastPlaylist";
     public static final String ACTION_WIDGET_UPDATE = "org.videolan.vlc.widget.UPDATE";
 
     public static final String WIDGET_PACKAGE = "org.videolan.vlc";
@@ -136,6 +144,7 @@ public class AudioService extends Service {
         filter.addAction(ACTION_REMOTE_PAUSE);
         filter.addAction(ACTION_REMOTE_STOP);
         filter.addAction(ACTION_REMOTE_FORWARD);
+        filter.addAction(ACTION_REMOTE_LAST_PLAYLIST);
         filter.addAction(Intent.ACTION_HEADSET_PLUG);
         filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
         registerReceiver(serviceReceiver, filter);
@@ -303,6 +312,8 @@ public class AudioService extends Service {
                 stop();
             } else if (action.equalsIgnoreCase(ACTION_REMOTE_FORWARD)) {
                 next();
+            } else if (action.equalsIgnoreCase(ACTION_REMOTE_LAST_PLAYLIST)) {
+                loadLastPlaylist();
             }
 
             /*
@@ -531,6 +542,7 @@ public class AudioService extends Service {
         showNotification();
         updateWidget(this);
         updateRemoteControlClientMetadata();
+        saveCurrentMedia();
     }
 
     @TargetApi(14)
@@ -573,12 +585,14 @@ public class AudioService extends Service {
         showNotification();
         updateWidget(this);
         updateRemoteControlClientMetadata();
+        saveCurrentMedia();
     }
 
     private void shuffle() {
         if (mShuffling)
             mPrevious.clear();
         mShuffling = !mShuffling;
+        saveCurrentMedia();
     }
 
     private void setRepeatType(int t) {
@@ -737,6 +751,8 @@ public class AudioService extends Service {
                 updateWidget(AudioService.this);
                 updateRemoteControlClientMetadata();
             }
+            AudioService.this.saveMediaList();
+            AudioService.this.saveCurrentMedia();
         }
 
         @Override
@@ -792,6 +808,7 @@ public class AudioService extends Service {
                 }
                 mMediaList.add(media);
             }
+            AudioService.this.saveMediaList();
         }
 
         @Override
@@ -892,4 +909,90 @@ public class AudioService extends Service {
 
         sendBroadcast(i);
     }
+
+    private synchronized void loadLastPlaylist() {
+        if (!Util.hasExternalStorage())
+            return;
+
+        String line;
+        FileInputStream input;
+        BufferedReader br;
+        int rowCount = 0;
+
+        int position = 0;
+        String currentMedia;
+        List<String> mediaPathList = new ArrayList<String>();
+
+        try {
+            // read CurrentMedia
+            input = new FileInputStream(AudioUtil.CACHE_DIR + "/" + "CurrentMedia.txt");
+            br = new BufferedReader(new InputStreamReader(input));
+            currentMedia = br.readLine();
+            mShuffling = "1".equals(br.readLine());
+            br.close();
+            input.close();
+
+            // read MediaList
+            input = new FileInputStream(AudioUtil.CACHE_DIR + "/" + "MediaList.txt");
+            br = new BufferedReader(new InputStreamReader(input));
+            while ((line = br.readLine()) != null) {
+                mediaPathList.add(line);
+                if (line.equals(currentMedia))
+                    position = rowCount;
+                rowCount++;
+            }
+            br.close();
+            input.close();
+
+            // load playlist
+            mInterface.load(mediaPathList, position, false);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (RemoteException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private synchronized void saveCurrentMedia() {
+        if (!Util.hasExternalStorage())
+            return;
+
+        FileOutputStream output;
+        BufferedWriter bw;
+
+        try {
+            output = new FileOutputStream(AudioUtil.CACHE_DIR + "/" + "CurrentMedia.txt");
+            bw = new BufferedWriter(new OutputStreamWriter(output));
+            bw.write(mCurrentMedia != null ? mCurrentMedia.getLocation() : "");
+            bw.write('\n');
+            bw.write(mShuffling ? "1" : "0");
+            bw.write('\n');
+            bw.close();
+            output.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private synchronized void saveMediaList() {
+        if (!Util.hasExternalStorage())
+            return;
+
+        FileOutputStream output;
+        BufferedWriter bw;
+
+        try {
+            output = new FileOutputStream(AudioUtil.CACHE_DIR + "/" + "MediaList.txt");
+            bw = new BufferedWriter(new OutputStreamWriter(output));
+            for (int i = 0; i < mMediaList.size(); i++) {
+                Media item = mMediaList.get(i);
+                bw.write(item.getLocation());
+                bw.write('\n');
+            }
+            bw.close();
+            output.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index a963e37..aa8c92f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -469,6 +469,11 @@ public class MainActivity extends SherlockFragmentActivity {
                 else
                     MediaLibrary.getInstance(this).loadMediaItems(this, true);
                 break;
+            // Restore last playlist
+            case R.id.ml_menu_last_playlist:
+                Intent i = new Intent(AudioService.ACTION_REMOTE_LAST_PLAYLIST);
+                sendBroadcast(i);
+                break;
             // Open MRL
             case R.id.ml_menu_open_mrl:
                 onOpenMRL();



More information about the Android mailing list