Skip to content

Commit

Permalink
Merge pull request #96 from TeamAmaze/feature
Browse files Browse the repository at this point in the history
Implement playlists in media player; add shuffle button; add play next button; add fab options; other bugfixes
  • Loading branch information
VishalNehra committed Dec 28, 2022
2 parents 3ccff7c + dd6a5a6 commit b8f7748
Show file tree
Hide file tree
Showing 83 changed files with 6,085 additions and 3,030 deletions.
45 changes: 23 additions & 22 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ plugins {
id 'kotlin-kapt'
id("com.github.triplet.play") version "3.7.0"
id 'com.starter.easylauncher'
id 'com.mikepenz.aboutlibraries.plugin'
}

android {
Expand Down Expand Up @@ -57,8 +58,8 @@ android {
applicationId "com.amaze.fileutilities"
minSdk 19
targetSdk 31
versionCode 72
versionName "1.72"
versionCode 74
versionName "1.74"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -129,8 +130,8 @@ android {
buildTypes {
debug {
applicationIdSuffix ".debug"
minifyEnabled true
shrinkResources true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
if (appProps != null &&
appProps.containsKey('OPENSUBTITLES_API_KEY_DEBUG')) {
Expand Down Expand Up @@ -171,18 +172,31 @@ android {
flavorDimensions 'static'

productFlavors {
fdroid {
register("fdroid") {
dimension 'static'
buildConfigField "boolean", "IS_VERSION_FDROID", "true"
}

play {
register("play") {
dimension 'static'
buildConfigField "boolean", "IS_VERSION_FDROID", "false"
signingConfig signingConfigs.config
}
}

playConfigs {
register("play") {
serviceAccountCredentials.set(file("service_account_config.json"))
defaultToAppBundles.set(true)

// track.set("internal")
track.set("production")
userFraction.set(1.0d)
updatePriority.set(3)
releaseStatus.set(com.github.triplet.gradle.androidpublisher.ReleaseStatus.COMPLETED)
}
}

splits {
abi {
enable true
Expand Down Expand Up @@ -210,17 +224,6 @@ android {
}
}

play {
serviceAccountCredentials.set(file("service_account_config.json"))
defaultToAppBundles.set(true)

// track.set("internal")
track.set("production")
userFraction.set(1.0d)
updatePriority.set(5)
releaseStatus.set(com.github.triplet.gradle.androidpublisher.ReleaseStatus.COMPLETED)
}

dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
Expand All @@ -241,8 +244,8 @@ dependencies {
implementation 'androidx.webkit:webkit:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
implementation "androidx.fragment:fragment-ktx:$fragment_version"
// implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
Expand All @@ -264,9 +267,7 @@ dependencies {
implementation 'com.github.massoudss:waveformSeekBar:5.0.1'
implementation 'com.github.lincollincol:amplituda:2.1.6'
//Simple library show
implementation('com.mikepenz:aboutlibraries:6.1.1@aar') {
transitive = true
}
implementation 'com.mikepenz:aboutlibraries:10.0.0'
implementation 'com.quickbirdstudios:opencv:4.5.3.0'
// https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j
// implementation 'com.rmtheis:tess-two:9.1.0'
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.amaze.fileutilities">

<uses-sdk tools:overrideLibrary="com.folioreader, linc.com.amplituda, me.zhanghai.android.fastscroll, org.opencv" />
<uses-sdk tools:overrideLibrary="com.folioreader, linc.com.amplituda,
me.zhanghai.android.fastscroll, org.opencv, com.mikepenz.aboutlibraries" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand Down Expand Up @@ -263,6 +264,9 @@
android:launchMode="singleInstance"
android:exported="true"
/>
<activity
android:name="com.mikepenz.aboutlibraries.ui.LibsActivity"
android:theme="@style/CustomAboutLibrariesStyle" />

<service
android:name=".audio_player.AudioPlayerService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.amaze.fileutilities.audio_player

import android.content.ComponentName
import android.content.ServiceConnection
import android.net.Uri
import android.os.IBinder
import com.amaze.fileutilities.utilis.ObtainableServiceBinder
import com.google.android.exoplayer2.PlaybackParameters
Expand All @@ -48,6 +49,10 @@ class AudioPlaybackServiceConnection(private val activityRef: WeakReference<OnPl
activityRef.get()?.serviceDisconnected()
specificService?.getPlaybackInfoUpdateCallback(null)
}

fun getAudioServiceInstance(): ServiceOperationCallback? {
return specificService
}
}

interface ServiceOperationCallback {
Expand All @@ -64,4 +69,5 @@ interface ServiceOperationCallback {
fun getRepeat(): Int
fun invokePlaybackProperties(playbackSpeed: Float, pitch: Float): Unit
fun getPlaybackParameters(): PlaybackParameters?
fun insertPlayNextSong(uri: Uri)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AudioPlayerInterfaceHandlerViewModel : ViewModel() {
private var localAudioModelList: ArrayList<LocalAudioModel>? = null
// var uriList: ArrayList<Uri>? = null
// approx value if player is playing
var isPlaying: Boolean = true
var isPlaying: Boolean = false
var forceShowSeekbar = false

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,20 @@ class AudioPlayerService : Service(), ServiceOperationCallback, OnPlayerRepeatin
return exoPlayer?.playbackParameters
}

override fun insertPlayNextSong(uri: Uri) {
val tempUriList = mutableListOf<Uri>()
uriList?.forEach {
if (it != uri) {
tempUriList.add(it)
}
if (it == currentUri) {
tempUriList.add(uri)
}
}
uriList = tempUriList
audioProgressHandler?.calculatePlayingIndex()
}

override fun invokeSeekPlayer(position: Long) {
seekPlayer(position)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ data class AudioProgressHandler(
return playingIndex
}

private fun calculatePlayingIndex(): Int {
fun calculatePlayingIndex(): Int {
if (uriList != null) {
var index = 0
for (uri in uriList!!) {
Expand Down
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;
}
}
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;
}
}
}

0 comments on commit b8f7748

Please sign in to comment.