Commit 31f61415 authored by Duncan McNAMARA's avatar Duncan McNAMARA
Browse files

Medialibrary: move MediaWrapper to AMediaWrapper

parent 8ee5cd04
......@@ -99,6 +99,8 @@ dependencies {
api "androidx.core:core:$rootProject.ext.androidxCoreVersion"
api "androidx.fragment:fragment:$rootProject.ext.androidxVersion"
testImplementation "junit:junit:$rootProject.ext.junitVersion"
testImplementation "org.robolectric:robolectric:4.2"
}
apply from: '../publish.gradle'
......@@ -1736,23 +1736,23 @@ static JNINativeMethod methods[] = {
{"nativeRemoveDevice", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)removeDevice },
{"nativeBanFolder", "(Ljava/lang/String;)V", (void*)banFolder },
{"nativeUnbanFolder", "(Ljava/lang/String;)V", (void*)unbanFolder },
{"nativeLastMediaPlayed", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)lastMediaPLayed },
{"nativeLastStreamsPlayed", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)lastStreamsPlayed },
{"nativeLastMediaPlayed", "()[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)lastMediaPLayed },
{"nativeLastStreamsPlayed", "()[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)lastStreamsPlayed },
{"nativeAddToHistory", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)addToHistory },
{"nativeClearHistory", "()Z", (void*)clearHistory },
{"nativeGetVideos", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getVideos },
{"nativeGetSortedVideos", "(IZ)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getSortedVideos },
{"nativeGetSortedPagedVideos", "(IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getPagedVideos },
{"nativeGetRecentVideos", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getRecentVideos },
{"nativeGetAudio", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getAudio },
{"nativeGetSortedAudio", "(IZ)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getSortedAudio },
{"nativeGetSortedPagedAudio", "(IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getPagedAudio },
{"nativeGetRecentAudio", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getRecentAudio },
{"nativeGetVideos", "()[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getVideos },
{"nativeGetSortedVideos", "(IZ)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getSortedVideos },
{"nativeGetSortedPagedVideos", "(IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getPagedVideos },
{"nativeGetRecentVideos", "()[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getRecentVideos },
{"nativeGetAudio", "()[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getAudio },
{"nativeGetSortedAudio", "(IZ)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getSortedAudio },
{"nativeGetSortedPagedAudio", "(IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getPagedAudio },
{"nativeGetRecentAudio", "()[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getRecentAudio },
{"nativeSearch", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/SearchAggregate;", (void*)search},
{"nativeSearchMedia", "(Ljava/lang/String;)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchMedia},
{"nativeSearchPagedMedia", "(Ljava/lang/String;IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchPagedMedia},
{"nativeSearchPagedAudio", "(Ljava/lang/String;IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchPagedAudio},
{"nativeSearchPagedVideo", "(Ljava/lang/String;IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchPagedVideo},
{"nativeSearchMedia", "(Ljava/lang/String;)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchMedia},
{"nativeSearchPagedMedia", "(Ljava/lang/String;IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchPagedMedia},
{"nativeSearchPagedAudio", "(Ljava/lang/String;IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchPagedAudio},
{"nativeSearchPagedVideo", "(Ljava/lang/String;IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchPagedVideo},
{"nativeGetSearchVideoCount", "(Ljava/lang/String;)I", (void*)getSearchVideoCount },
{"nativeGetSearchAudioCount", "(Ljava/lang/String;)I", (void*)getSearchAudioCount },
{"nativeGetSearchMediaCount", "(Ljava/lang/String;)I", (void*)getSearchMediaCount },
......@@ -1768,11 +1768,11 @@ static JNINativeMethod methods[] = {
{"nativeSearchPlaylist", "(Ljava/lang/String;)[Lorg/videolan/medialibrary/media/Playlist;", (void*)searchPlaylist },
{"nativeSearchPagedPlaylist", "(Ljava/lang/String;IZII)[Lorg/videolan/medialibrary/media/Playlist;", (void*)searchPagedPlaylist },
{"nativeGetPlaylistSearchCount", "(Ljava/lang/String;)I", (void*)getPlaylistSearchCount },
{"nativeGetMedia", "(J)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getMedia },
{"nativeGetMediaFromMrl", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getMediaFromMrl },
{"nativeAddMedia", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)addMedia },
{"nativeGetMedia", "(J)Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getMedia },
{"nativeGetMediaFromMrl", "(Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getMediaFromMrl },
{"nativeAddMedia", "(Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)addMedia },
{"nativeRemoveExternalMedia", "(J)Z", (void*)removeExternalMedia },
{"nativeAddStream", "(Ljava/lang/String;Ljava/lang/String;)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)addStream },
{"nativeAddStream", "(Ljava/lang/String;Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)addStream },
{"nativeGetVideoCount", "()I", (void*)getVideoCount },
{"nativeGetAudioCount", "()I", (void*)getAudioCount },
{"nativeGetAlbums", "(IZ)[Lorg/videolan/medialibrary/media/Album;", (void*)getAlbums },
......@@ -1817,19 +1817,19 @@ static JNINativeMethod media_methods[] = {
};
static JNINativeMethod album_methods[] = {
{"nativeGetTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getTracksFromAlbum },
{"nativeGetPagedTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getPagedTracksFromAlbum },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchFromAlbum },
{"nativeGetTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getTracksFromAlbum },
{"nativeGetPagedTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getPagedTracksFromAlbum },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchFromAlbum },
{"nativeGetSearchCount", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;)I", (void*)getSearchFromAlbumCount },
{"nativeGetTracksCount", "(Lorg/videolan/medialibrary/Medialibrary;J)I", (void*)getTracksFromAlbumCount },
};
static JNINativeMethod artist_methods[] = {
{"nativeGetMedia", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getMediaFromArtist },
{"nativeGetMedia", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getMediaFromArtist },
{"nativeGetAlbums", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/media/Album;", (void*)getAlbumsFromArtist },
{"nativeGetPagedMedia", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getPagedMediaFromArtist },
{"nativeGetPagedMedia", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getPagedMediaFromArtist },
{"nativeGetPagedAlbums", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/Album;", (void*)getPagedAlbumsFromArtist },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchFromArtist },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchFromArtist },
{"nativeSearchAlbums", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/media/Album;", (void*)searchAlbumsFromArtist },
{"nativeGetTracksCount", "(Lorg/videolan/medialibrary/Medialibrary;J)I", (void*)getArtistTracksCount },
{"nativeGetAlbumsCount", "(Lorg/videolan/medialibrary/Medialibrary;J)I", (void*)getArtistAlbumsCount },
......@@ -1838,13 +1838,13 @@ static JNINativeMethod artist_methods[] = {
};
static JNINativeMethod genre_methods[] = {
{"nativeGetTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getMediaFromGenre },
{"nativeGetTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getMediaFromGenre },
{"nativeGetAlbums", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/media/Album;", (void*)getAlbumsFromGenre },
{"nativeGetArtists", "(Lorg/videolan/medialibrary/Medialibrary;JIZ)[Lorg/videolan/medialibrary/media/Artist;", (void*)getArtistsFromGenre },
{"nativeGetPagedTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getPagedMediaFromGenre },
{"nativeGetPagedTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getPagedMediaFromGenre },
{"nativeGetPagedAlbums", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/Album;", (void*)getPagedAlbumsFromGenre },
{"nativeGetPagedArtists", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/Artist;", (void*)getPagedArtistsFromGenre },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchMediaFromGenre },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchMediaFromGenre },
{"nativeSearchAlbums", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/media/Album;", (void*)searchAlbumsFromGenre },
{"nativeGetTracksCount", "(Lorg/videolan/medialibrary/Medialibrary;J)I", (void*)getGenreTracksCount },
{"nativeGetAlbumsCount", "(Lorg/videolan/medialibrary/Medialibrary;J)I", (void*)getGenreAlbumsCount },
......@@ -1854,19 +1854,19 @@ static JNINativeMethod genre_methods[] = {
};
static JNINativeMethod folder_methods[] = {
{"nativeMedia", "(Lorg/videolan/medialibrary/Medialibrary;JIIZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)mediaFromFolder },
{"nativeMedia", "(Lorg/videolan/medialibrary/Medialibrary;JIIZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)mediaFromFolder },
{"nativeSubfolders", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/Folder;", (void*)subFolders },
{"nativeMediaCount", "(Lorg/videolan/medialibrary/Medialibrary;JI)I", (void*)mediaFromFolderCount },
{"nativeSubfoldersCount", "(Lorg/videolan/medialibrary/Medialibrary;JI)I", (void*)subFoldersCount },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IIZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchMediaFromFolder },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IIZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchMediaFromFolder },
{"nativeGetSearchCount", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;I)I", (void*)getSearchMediaFromFolderCount },
};
static JNINativeMethod playlist_methods[] = {
{"nativeGetTracks", "(Lorg/videolan/medialibrary/Medialibrary;J)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getMediaFromPlaylist },
{"nativeGetPagedTracks", "(Lorg/videolan/medialibrary/Medialibrary;JII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getPagedMediaFromPlaylist },
{"nativeGetTracks", "(Lorg/videolan/medialibrary/Medialibrary;J)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getMediaFromPlaylist },
{"nativeGetPagedTracks", "(Lorg/videolan/medialibrary/Medialibrary;JII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)getPagedMediaFromPlaylist },
{"nativeGetTracksCount", "(Lorg/videolan/medialibrary/Medialibrary;J)I", (void*)getPlaylistTracksCount },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchFromPlaylist },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchFromPlaylist },
{"nativeGetSearchCount", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;)I", (void*)getSearchFromPlaylistCount },
{"nativePlaylistAppend", "(Lorg/videolan/medialibrary/Medialibrary;JJ)Z", (void*)playlistAppend },
{"nativePlaylistAppendGroup", "(Lorg/videolan/medialibrary/Medialibrary;J[J)Z", (void*)playlistAppendGroup },
......@@ -2008,7 +2008,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
GET_ID(GetMethodID,
ml_fields.SearchAggregate.initID,
ml_fields.SearchAggregate.clazz,
"<init>", "([Lorg/videolan/medialibrary/media/Album;[Lorg/videolan/medialibrary/media/Artist;[Lorg/videolan/medialibrary/media/Genre;[Lorg/videolan/medialibrary/media/MediaWrapper;[Lorg/videolan/medialibrary/media/MediaWrapper;[Lorg/videolan/medialibrary/media/Playlist;)V");
"<init>", "([Lorg/videolan/medialibrary/media/Album;[Lorg/videolan/medialibrary/media/Artist;[Lorg/videolan/medialibrary/media/Genre;[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;[Lorg/videolan/medialibrary/media/Playlist;)V");
GET_CLASS(ml_fields.Folder.clazz, "org/videolan/medialibrary/media/Folder", true);
......@@ -2025,11 +2025,11 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
GET_ID(GetMethodID,
ml_fields.MediaLibrary.onMediaAddedId,
ml_fields.MediaLibrary.clazz,
"onMediaAdded", "([Lorg/videolan/medialibrary/media/MediaWrapper;)V");
"onMediaAdded", "([Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;)V");
GET_ID(GetMethodID,
ml_fields.MediaLibrary.onMediaUpdatedId,
ml_fields.MediaLibrary.clazz,
"onMediaUpdated", "([Lorg/videolan/medialibrary/media/MediaWrapper;)V");
"onMediaUpdated", "([Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;)V");
GET_ID(GetMethodID,
ml_fields.MediaLibrary.onMediaDeletedId,
ml_fields.MediaLibrary.clazz,
......@@ -2129,7 +2129,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
GET_ID(GetMethodID,
ml_fields.MediaLibrary.onMediaThumbnailReadyId,
ml_fields.MediaLibrary.clazz,
"onMediaThumbnailReady", "(Lorg/videolan/medialibrary/media/MediaWrapper;Z)V");
"onMediaThumbnailReady", "(Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;Z)V");
#undef GET_CLASS
#undef GET_ID
......
......@@ -33,6 +33,7 @@ import android.util.Log;
import org.videolan.libvlc.LibVLC;
import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb;
import org.videolan.medialibrary.interfaces.EntryPointsEventsCb;
import org.videolan.medialibrary.interfaces.media.AMediaWrapper;
import org.videolan.medialibrary.media.Album;
import org.videolan.medialibrary.media.Artist;
import org.videolan.medialibrary.media.Folder;
......@@ -89,7 +90,7 @@ public class Medialibrary {
public static final String ACTION_IDLE = "action_idle";
public static final String STATE_IDLE = "state_idle";
public static final MediaWrapper[] EMPTY_COLLECTION = {};
public static final AMediaWrapper[] EMPTY_COLLECTION = {};
public static final String VLC_MEDIA_DB_NAME = "/vlc_media.db";
public static final String THUMBS_FOLDER_NAME = "/thumbs";
......@@ -214,47 +215,48 @@ public class Medialibrary {
@NonNull
public static Medialibrary getInstance() {
System.out.println("This is the real medialibrary");
return instance;
}
@WorkerThread
public MediaWrapper[] getVideos() {
return mIsInitiated ? nativeGetVideos() : new MediaWrapper[0];
public AMediaWrapper[] getVideos() {
return mIsInitiated ? nativeGetVideos() : new AMediaWrapper[0];
}
@WorkerThread
public MediaWrapper[] getPagedVideos(int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated ? nativeGetSortedPagedVideos(sort, desc, nbItems, offset) : new MediaWrapper[0];
public AMediaWrapper[] getPagedVideos(int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated ? nativeGetSortedPagedVideos(sort, desc, nbItems, offset) : new AMediaWrapper[0];
}
@WorkerThread
public MediaWrapper[] getVideos(int sort, boolean desc) {
return mIsInitiated ? nativeGetSortedVideos(sort, desc) : new MediaWrapper[0];
public AMediaWrapper[] getVideos(int sort, boolean desc) {
return mIsInitiated ? nativeGetSortedVideos(sort, desc) : new AMediaWrapper[0];
}
@WorkerThread
public MediaWrapper[] getRecentVideos() {
return mIsInitiated ? nativeGetRecentVideos() : new MediaWrapper[0];
public AMediaWrapper[] getRecentVideos() {
return mIsInitiated ? nativeGetRecentVideos() : new AMediaWrapper[0];
}
@WorkerThread
public MediaWrapper[] getAudio() {
return mIsInitiated ? nativeGetAudio() : new MediaWrapper[0];
public AMediaWrapper[] getAudio() {
return mIsInitiated ? nativeGetAudio() : new AMediaWrapper[0];
}
@WorkerThread
public MediaWrapper[] getAudio(int sort, boolean desc) {
return mIsInitiated ? nativeGetSortedAudio(sort, desc) : new MediaWrapper[0];
public AMediaWrapper[] getAudio(int sort, boolean desc) {
return mIsInitiated ? nativeGetSortedAudio(sort, desc) : new AMediaWrapper[0];
}
@WorkerThread
public MediaWrapper[] getPagedAudio(int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated ? nativeGetSortedPagedAudio(sort, desc, nbItems, offset) : new MediaWrapper[0];
public AMediaWrapper[] getPagedAudio(int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated ? nativeGetSortedPagedAudio(sort, desc, nbItems, offset) : new AMediaWrapper[0];
}
@WorkerThread
public MediaWrapper[] getRecentAudio() {
return mIsInitiated ? nativeGetRecentAudio() : new MediaWrapper[0];
public AMediaWrapper[] getRecentAudio() {
return mIsInitiated ? nativeGetRecentAudio() : new AMediaWrapper[0];
}
public int getVideoCount() {
......@@ -407,12 +409,12 @@ public class Medialibrary {
}
@WorkerThread
public MediaWrapper[] lastMediaPlayed() {
public AMediaWrapper[] lastMediaPlayed() {
return mIsInitiated ? nativeLastMediaPlayed() : EMPTY_COLLECTION;
}
@WorkerThread
public MediaWrapper[] lastStreamsPlayed() {
public AMediaWrapper[] lastStreamsPlayed() {
return mIsInitiated ? nativeLastStreamsPlayed() : EMPTY_COLLECTION;
}
......@@ -425,26 +427,26 @@ public class Medialibrary {
}
@Nullable
public MediaWrapper getMedia(long id) {
public AMediaWrapper getMedia(long id) {
return mIsInitiated ? nativeGetMedia(id) : null;
}
@Nullable
public MediaWrapper getMedia(Uri uri) {
public AMediaWrapper getMedia(Uri uri) {
if ("content".equals(uri.getScheme())) return null;
final String vlcMrl = Tools.encodeVLCMrl(uri.toString());
return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeGetMediaFromMrl(vlcMrl) : null;
}
@Nullable
public MediaWrapper getMedia(String mrl) {
public AMediaWrapper getMedia(String mrl) {
if (mrl != null && mrl.startsWith("content:")) return null;
final String vlcMrl = Tools.encodeVLCMrl(mrl);
return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeGetMediaFromMrl(vlcMrl) : null;
}
@Nullable
public MediaWrapper addMedia(String mrl) {
public AMediaWrapper addMedia(String mrl) {
final String vlcMrl = Tools.encodeVLCMrl(mrl);
return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeAddMedia(vlcMrl) : null;
}
......@@ -454,7 +456,7 @@ public class Medialibrary {
}
@Nullable
public MediaWrapper addStream(String mrl, String title) {
public AMediaWrapper addStream(String mrl, String title) {
final String vlcMrl = Tools.encodeVLCMrl(mrl);
final String vlcTitle = Tools.encodeVLCMrl(title);
return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeAddStream(vlcMrl, vlcTitle) : null;
......@@ -493,17 +495,17 @@ public class Medialibrary {
}
// If media is not in ML, find it with its path
public MediaWrapper findMedia(MediaWrapper mw) {
public AMediaWrapper findMedia(AMediaWrapper mw) {
if (mIsInitiated && mw != null && mw.getId() == 0L) {
final Uri uri = mw.getUri();
final MediaWrapper libraryMedia = getMedia(uri);
final AMediaWrapper libraryMedia = getMedia(uri);
if (libraryMedia != null) {
libraryMedia.addFlags(mw.getFlags());
return libraryMedia;
}
if (TextUtils.equals("file", uri.getScheme()) &&
uri.getPath() != null && uri.getPath().startsWith("/sdcard")) {
final MediaWrapper alternateMedia = getMedia(Tools.convertLocalUri(uri));
final AMediaWrapper alternateMedia = getMedia(Tools.convertLocalUri(uri));
if (alternateMedia != null) {
alternateMedia.addFlags(mw.getFlags());
return alternateMedia;
......@@ -514,14 +516,14 @@ public class Medialibrary {
}
@SuppressWarnings("unused")
public void onMediaAdded(MediaWrapper[] mediaList) {
public void onMediaAdded(AMediaWrapper[] mediaList) {
synchronized (mMediaCbs) {
for (MediaCb cb : mMediaCbs) cb.onMediaAdded();
}
}
@SuppressWarnings("unused")
public void onMediaUpdated(MediaWrapper[] mediaList) {
public void onMediaUpdated(AMediaWrapper[] mediaList) {
synchronized (mMediaCbs) {
for (MediaCb cb : mMediaCbs) cb.onMediaModified();
}
......@@ -731,9 +733,9 @@ public class Medialibrary {
}
}
public static LiveData<MediaWrapper> lastThumb = new SingleEvent<>();
public static LiveData<AMediaWrapper> lastThumb = new SingleEvent<>();
@SuppressWarnings({"unused", "unchecked"})
void onMediaThumbnailReady(MediaWrapper media, boolean success) {
void onMediaThumbnailReady(AMediaWrapper media, boolean success) {
if (success) ((MutableLiveData)lastThumb).postValue(media);
}
......@@ -819,11 +821,11 @@ public class Medialibrary {
return mIsInitiated && !TextUtils.isEmpty(query) ? nativeSearch(query) : null;
}
public MediaWrapper[] searchMedia(String query) {
public AMediaWrapper[] searchMedia(String query) {
return mIsInitiated && !TextUtils.isEmpty(query) ? nativeSearchMedia(query) : null;
}
public MediaWrapper[] searchMedia(String query, int sort, boolean desc, int nbItems, int offset) {
public AMediaWrapper[] searchMedia(String query, int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated && !TextUtils.isEmpty(query) ? nativeSearchPagedMedia(query, sort, desc, nbItems, offset) : null;
}
......@@ -831,7 +833,7 @@ public class Medialibrary {
return mIsInitiated ? nativeGetSearchMediaCount(query) : 0;
}
public MediaWrapper[] searchAudio(String query, int sort, boolean desc, int nbItems, int offset) {
public AMediaWrapper[] searchAudio(String query, int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated && !TextUtils.isEmpty(query) ? nativeSearchPagedAudio(query, sort, desc, nbItems, offset) : null;
}
......@@ -839,7 +841,7 @@ public class Medialibrary {
return mIsInitiated ? nativeGetSearchAudioCount(query) : 0;
}
public MediaWrapper[] searchVideo(String query, int sort, boolean desc, int nbItems, int offset) {
public AMediaWrapper[] searchVideo(String query, int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated && !TextUtils.isEmpty(query) ? nativeSearchPagedVideo(query, sort, desc, nbItems, offset) : null;
}
......@@ -980,23 +982,23 @@ public class Medialibrary {
private native void nativeRemoveEntryPoint(String path);
private native String[] nativeEntryPoints();
private native boolean nativeRemoveDevice(String uuid, String path);
private native MediaWrapper[] nativeLastMediaPlayed();
private native MediaWrapper[] nativeLastStreamsPlayed();
private native AMediaWrapper[] nativeLastMediaPlayed();
private native AMediaWrapper[] nativeLastStreamsPlayed();
private native boolean nativeAddToHistory(String mrl, String title);
private native boolean nativeClearHistory();
private native MediaWrapper nativeGetMedia(long id);
private native MediaWrapper nativeGetMediaFromMrl(String mrl);
private native MediaWrapper nativeAddMedia(String mrl);
private native AMediaWrapper nativeGetMedia(long id);
private native AMediaWrapper nativeGetMediaFromMrl(String mrl);
private native AMediaWrapper nativeAddMedia(String mrl);
private native boolean nativeRemoveExternalMedia(long id);
private native MediaWrapper nativeAddStream(String mrl, String title);
private native MediaWrapper[] nativeGetVideos();
private native MediaWrapper[] nativeGetSortedVideos(int sort, boolean desc);
private native MediaWrapper[] nativeGetRecentVideos();
private native MediaWrapper[] nativeGetAudio();
private native MediaWrapper[] nativeGetSortedAudio(int sort, boolean desc);
private native MediaWrapper[] nativeGetSortedPagedAudio(int sort, boolean desc, int nbItems, int offset);
private native MediaWrapper[] nativeGetSortedPagedVideos(int sort, boolean desc, int nbItems, int offset);
private native MediaWrapper[] nativeGetRecentAudio();
private native AMediaWrapper nativeAddStream(String mrl, String title);
private native AMediaWrapper[] nativeGetVideos();
private native AMediaWrapper[] nativeGetSortedVideos(int sort, boolean desc);
private native AMediaWrapper[] nativeGetRecentVideos();
private native AMediaWrapper[] nativeGetAudio();
private native AMediaWrapper[] nativeGetSortedAudio(int sort, boolean desc);
private native AMediaWrapper[] nativeGetSortedPagedAudio(int sort, boolean desc, int nbItems, int offset);
private native AMediaWrapper[] nativeGetSortedPagedVideos(int sort, boolean desc, int nbItems, int offset);
private native AMediaWrapper[] nativeGetRecentAudio();
private native int nativeGetVideoCount();
private native int nativeGetAudioCount();
private native Album[] nativeGetAlbums(int sort, boolean desc);
......@@ -1028,12 +1030,12 @@ public class Medialibrary {
private native void nativeSetMediaUpdatedCbFlag(int flags);
private native void nativeSetMediaAddedCbFlag(int flags);
private native SearchAggregate nativeSearch(String query);
private native MediaWrapper[] nativeSearchMedia(String query);
private native MediaWrapper[] nativeSearchPagedMedia(String query, int sort, boolean desc, int nbItems, int offset);
private native AMediaWrapper[] nativeSearchMedia(String query);
private native AMediaWrapper[] nativeSearchPagedMedia(String query, int sort, boolean desc, int nbItems, int offset);
private native int nativeGetSearchMediaCount(String query);
private native MediaWrapper[] nativeSearchPagedAudio(String query, int sort, boolean desc, int nbItems, int offset);
private native AMediaWrapper[] nativeSearchPagedAudio(String query, int sort, boolean desc, int nbItems, int offset);
private native int nativeGetSearchAudioCount(String query);
private native MediaWrapper[] nativeSearchPagedVideo(String query, int sort, boolean desc, int nbItems, int offset);
private native AMediaWrapper[] nativeSearchPagedVideo(String query, int sort, boolean desc, int nbItems, int offset);
private native int nativeGetSearchVideoCount(String query);
private native Artist[] nativeSearchArtist(String query);
private native Artist[] nativeSearchPagedArtist(String query, int sort, boolean desc, int nbItems, int offset);
......
package org.videolan.medialibrary;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Parcel;
import org.videolan.libvlc.Media;
import org.videolan.medialibrary.interfaces.media.AMediaWrapper;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.medialibrary.stubs.StubMediaWrapper;
public class ServiceLocator {
private static ServiceLocator mServiceLocator;
private static LocatorMode mMode = LocatorMode.VLC_ANDROID;
public static void setLocatorMode(LocatorMode mode) {
ServiceLocator.mMode = mode;
}
enum LocatorMode {
VLC_ANDROID,
TESTS,
}
public static ServiceLocator getInstance() {
return mServiceLocator;
}
// AMediaWrapper
public static AMediaWrapper getAMediaWrapper(long id, String mrl, long time, long length,
int type, String title, String filename,
String artist, String genre, String album,
String albumArtist, int width, int height,
String artworkURL, int audio, int spu,
int trackNumber, int discNumber, long lastModified,
long seen, boolean isThumbnailGenerated) {
if (mMode == LocatorMode.VLC_ANDROID) {
return new MediaWrapper(id, mrl, time, length, type, title,
filename, artist, genre, album, albumArtist, width, height, artworkURL,
audio, spu, trackNumber, discNumber, lastModified, seen, isThumbnailGenerated);
} else {
return new StubMediaWrapper(id, mrl, time, length, type, title,
filename, artist, genre, album, albumArtist, width, height, artworkURL,
audio, spu, trackNumber, discNumber, lastModified, seen, isThumbnailGenerated);
}
}
public static AMediaWrapper getAMediaWrapper(Uri uri, 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,
int discNumber, long lastModified, long seen) {
if (mMode == LocatorMode.VLC_ANDROID) {
return new MediaWrapper(uri, time, length, type, picture, title, artist, genre,
album, albumArtist, width, height, artworkURL, audio, spu, trackNumber,
discNumber, lastModified, seen);
} else {
return new StubMediaWrapper(uri, time, length, type, picture, title, artist, genre,
album, albumArtist, width, height, artworkURL, audio, spu, trackNumber,
discNumber, lastModified, seen);
}
}
public static AMediaWrapper getAMediaWrapper(Uri uri) {
if (mMode == LocatorMode.VLC_ANDROID) {
return new MediaWrapper(uri);
} else {
return new StubMediaWrapper(uri);
}
}
public static AMediaWrapper getAMediaWrapper(Media media) {
if (mMode == LocatorMode.VLC_ANDROID) {
return new MediaWrapper(media);
} else {
return new StubMediaWrapper(media);
}
}
public static AMediaWrapper getAMediaWrapper(Parcel in) {
if (mMode == LocatorMode.VLC_ANDROID) {
return new MediaWrapper(in);
} else {
return new StubMediaWrapper(in);
}
}
}
......@@ -5,8 +5,8 @@ import android.net.Uri;
import android.os.Environment;
import android.text.TextUtils;
import org.videolan.medialibrary.interfaces.media.AMediaWrapper;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import java.text.DecimalFormat;
import java.text.NumberFormat;
......@@ -36,7 +36,7 @@ public class Tools {
public static boolean isArrayEmpty(@Nullable Object[] array) {
return array == null || array.length == 0;
}
public static String getProgressText(MediaWrapper media) {
public static String getProgressText(AMediaWrapper media) {
long lastTime = media.getTime();
if (lastTime == 0L) return "";
return String.format("%s / %s",
......@@ -62,7 +62,7 @@ public class Tools {
return millisToString(millis, true, true);
}
public static String getResolution(MediaWrapper media) {
public static String getResolution(AMediaWrapper media) {
if (media.getWidth() > 0 && media.getHeight() > 0)
return String.format(Locale.US, "%dx%d", media.getWidth(), media.getHeight());
return "";
......@@ -70,8 +70,8 @@ public class Tools {
public static void setMediaDescription (MediaLibraryItem item) {
if (item.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
final MediaWrapper mw = (MediaWrapper) item;
if (mw.getType() == MediaWrapper.TYPE_VIDEO) {
final AMediaWrapper mw = (AMediaWrapper) item;
if (mw.getType() == AMediaWrapper.TYPE_VIDEO) {
final String progress = mw.getLength() == 0L ? null : mw.getTime() == 0L ? Tools.millisToString(mw.getLength()) : getProgressText(mw);
final String resolution = getResolution(mw);
boolean hasprogress = !TextUtils.isEmpty(progress), hasResolution = !TextUtils.isEmpty(resolution);
......@@ -80,7 +80,7 @@ public class Tools {
else if (hasprogress) sb.append(progress);
else sb.append(resolution);
item.setDescription(sb.toString());
} else if (mw.getType() == MediaWrapper.TYPE_AUDIO) {
} else if (mw.getType() == AMediaWrapper.TYPE_AUDIO) {