[Android] [PATCH 1/3] libvlc/Media: implements Parcelable

Thomas Guillem thomas at gllm.fr
Mon Jan 5 16:17:17 CET 2015


---
 libvlc/src/org/videolan/libvlc/Media.aidl | 23 ++++++++++
 libvlc/src/org/videolan/libvlc/Media.java | 72 ++++++++++++++++++++++++++++---
 2 files changed, 90 insertions(+), 5 deletions(-)
 create mode 100644 libvlc/src/org/videolan/libvlc/Media.aidl

diff --git a/libvlc/src/org/videolan/libvlc/Media.aidl b/libvlc/src/org/videolan/libvlc/Media.aidl
new file mode 100644
index 0000000..9b30419
--- /dev/null
+++ b/libvlc/src/org/videolan/libvlc/Media.aidl
@@ -0,0 +1,23 @@
+/*****************************************************************************
+ * Media.aidl
+ *****************************************************************************
+ * Copyright © 2015 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+package org.videolan.libvlc;
+
+parcelable Media;
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index 2db08db..e4cf411 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -24,10 +24,12 @@ import java.util.HashSet;
 import java.util.Locale;
 
 import android.graphics.Bitmap;
+import android.os.Parcel;
+import android.os.Parcelable;
 import android.text.TextUtils;
 import android.util.Log;
 
-public class Media {
+public class Media implements Parcelable {
     public final static String TAG = "VLC/LibVLC/Media";
 
     public final static HashSet<String> VIDEO_EXTENSIONS;
@@ -192,10 +194,9 @@ public class Media {
         }
     }
 
-    public Media(String location, long time, long length, int type,
-            Bitmap picture, String title, String artist, String genre, String album, String albumArtist,
-            int width, int height, String artworkURL, int audio, int spu, int trackNumber) {
-        mLocation = location;
+    private void init(long time, long length, int type,
+                      Bitmap picture, String title, String artist, String genre, String album, String albumArtist,
+                      int width, int height, String artworkURL, int audio, int spu, int trackNumber) {
         mFilename = null;
         mTime = time;
         mAudioTrack = audio;
@@ -215,6 +216,33 @@ public class Media {
         mTrackNumber = trackNumber;
     }
 
+    public Media(String location, long time, long length, int type,
+                 Bitmap picture, String title, String artist, String genre, String album, String albumArtist,
+                 int width, int height, String artworkURL, int audio, int spu, int trackNumber) {
+        mLocation = location;
+        init(time, length, type, picture, title, artist, genre, album, albumArtist,
+             width, height, artworkURL, audio, spu, trackNumber);
+    }
+
+    public Media(Parcel in) {
+        mLocation = in.readString();
+        init(in.readLong(),
+             in.readLong(),
+             in.readInt(),
+             (Bitmap) in.readParcelable(Bitmap.class.getClassLoader()),
+             in.readString(),
+             in.readString(),
+             in.readString(),
+             in.readString(),
+             in.readString(),
+             in.readInt(),
+             in.readInt(),
+             in.readString(),
+             in.readInt(),
+             in.readInt(),
+             in.readInt());
+    }
+
     public String getLocation() {
         return mLocation;
     }
@@ -407,4 +435,38 @@ public class Media {
     public int getFlags() {
         return mFlags;
     }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeValue(getLocation());
+        dest.writeLong(getTime());
+        dest.writeLong(getLength());
+        dest.writeInt(getType());
+        dest.writeParcelable(getPicture(), flags);
+        dest.writeValue(getTitle());
+        dest.writeValue(getArtist());
+        dest.writeValue(getGenre());
+        dest.writeValue(getAlbum());
+        dest.writeValue(getAlbumArtist());
+        dest.writeInt(getWidth());
+        dest.writeInt(getHeight());
+        dest.writeValue(getArtworkURL());
+        dest.writeInt(getAudioTrack());
+        dest.writeInt(getSpuTrack());
+        dest.writeInt(getTrackNumber());
+    }
+
+    public static final Parcelable.Creator<Media> CREATOR = new Parcelable.Creator<Media>() {
+        public Media createFromParcel(Parcel in) {
+            return new Media(in);
+        }
+        public Media[] newArray(int size) {
+            return new Media[size];
+        }
+    };
 }
-- 
2.1.3



More information about the Android mailing list