-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from TeamAmaze/feature
Implement playlists in media player; add shuffle button; add play next button; add fab options; other bugfixes
- Loading branch information
Showing
83 changed files
with
6,085 additions
and
3,030 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/amaze/fileutilities/audio_player/playlist/M3UWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2021-2022 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>, | ||
* Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors. | ||
* | ||
* This file is part of Amaze File Utilities. | ||
* | ||
* Amaze File Utilities is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.amaze.fileutilities.audio_player.playlist; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import com.amaze.fileutilities.home_page.ui.files.MediaFileInfo; | ||
|
||
public class M3UWriter { | ||
|
||
private static final String EXTENSION = "m3u"; | ||
private static final String HEADER = "#EXTM3U"; | ||
private static final String ENTRY = "#EXTINF:"; | ||
private static final String DURATION_SEPARATOR = ","; | ||
|
||
public static File write(File dir, MediaFileInfo.Playlist playlist, List<MediaFileInfo> songs) | ||
throws IOException { | ||
if (!dir.exists()) // noinspection ResultOfMethodCallIgnored | ||
dir.mkdirs(); | ||
File file = new File(dir, playlist.getName().concat("." + EXTENSION)); | ||
|
||
if (songs.size() > 0) { | ||
BufferedWriter bw = new BufferedWriter(new FileWriter(file)); | ||
|
||
bw.write(HEADER); | ||
for (MediaFileInfo song : songs) { | ||
if (song.getExtraInfo() != null && song.getExtraInfo().getAudioMetaData() != null) { | ||
MediaFileInfo.AudioMetaData metaData = song.getExtraInfo().getAudioMetaData(); | ||
bw.newLine(); | ||
bw.write( | ||
ENTRY | ||
+ metaData.getDuration() | ||
+ DURATION_SEPARATOR | ||
+ metaData.getArtistName() | ||
+ " - " | ||
+ song.getTitle()); | ||
bw.newLine(); | ||
bw.write(song.getPath()); | ||
} | ||
} | ||
|
||
bw.close(); | ||
} | ||
|
||
return file; | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
app/src/main/java/com/amaze/fileutilities/audio_player/playlist/PlaylistLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (C) 2021-2022 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>, | ||
* Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors. | ||
* | ||
* This file is part of Amaze File Utilities. | ||
* | ||
* Amaze File Utilities is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.amaze.fileutilities.audio_player.playlist; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.amaze.fileutilities.home_page.ui.files.MediaFileInfo; | ||
|
||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.provider.BaseColumns; | ||
import android.provider.MediaStore; | ||
import android.provider.MediaStore.Audio.PlaylistsColumns; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class PlaylistLoader { | ||
|
||
@NonNull | ||
public static List<MediaFileInfo.Playlist> getAllPlaylists(@NonNull final Context context) { | ||
return getAllPlaylists(makePlaylistCursor(context, null, null)); | ||
} | ||
|
||
@NonNull | ||
public static MediaFileInfo.Playlist getPlaylist( | ||
@NonNull final Context context, final long playlistId) { | ||
return getPlaylist( | ||
makePlaylistCursor( | ||
context, BaseColumns._ID + "=?", new String[] {String.valueOf(playlistId)})); | ||
} | ||
|
||
@NonNull | ||
public static MediaFileInfo.Playlist getPlaylist( | ||
@NonNull final Context context, final String playlistName) { | ||
return getPlaylist( | ||
makePlaylistCursor(context, PlaylistsColumns.NAME + "=?", new String[] {playlistName})); | ||
} | ||
|
||
@NonNull | ||
public static MediaFileInfo.Playlist getPlaylist(@Nullable final Cursor cursor) { | ||
MediaFileInfo.Playlist playlist = new MediaFileInfo.Playlist(-1, ""); | ||
|
||
if (cursor != null && cursor.moveToFirst()) { | ||
playlist = getPlaylistFromCursorImpl(cursor); | ||
} | ||
if (cursor != null) cursor.close(); | ||
return playlist; | ||
} | ||
|
||
@NonNull | ||
public static List<MediaFileInfo.Playlist> getAllPlaylists(@Nullable final Cursor cursor) { | ||
List<MediaFileInfo.Playlist> playlists = new ArrayList<>(); | ||
|
||
if (cursor != null && cursor.moveToFirst()) { | ||
do { | ||
playlists.add(getPlaylistFromCursorImpl(cursor)); | ||
} while (cursor.moveToNext()); | ||
} | ||
if (cursor != null) cursor.close(); | ||
return playlists; | ||
} | ||
|
||
@NonNull | ||
private static MediaFileInfo.Playlist getPlaylistFromCursorImpl(@NonNull final Cursor cursor) { | ||
final long id = cursor.getLong(0); | ||
final String name = cursor.getString(1); | ||
return new MediaFileInfo.Playlist(id, name); | ||
} | ||
|
||
@Nullable | ||
public static Cursor makePlaylistCursor( | ||
@NonNull final Context context, final String selection, final String[] values) { | ||
try { | ||
return context | ||
.getContentResolver() | ||
.query( | ||
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, | ||
new String[] { | ||
/* 0 */ | ||
BaseColumns._ID, | ||
/* 1 */ | ||
PlaylistsColumns.NAME | ||
}, | ||
selection, | ||
values, | ||
MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER); | ||
} catch (SecurityException e) { | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.