capacitor-plugin-playlist 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/8.0.2/checksums/checksums.lock +0 -0
- package/android/.gradle/8.0.2/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.0.2/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.0.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.0.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.0.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.0.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.0.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.0.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/config.properties +2 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +8 -3
- package/android/.idea/kotlinc.xml +6 -0
- package/android/.idea/migrations.xml +10 -0
- package/android/.idea/misc.xml +2 -2
- package/android/.project +34 -0
- package/android/bin/.gradle/8.0.2/checksums/checksums.lock +0 -0
- package/android/bin/.gradle/8.0.2/checksums/md5-checksums.bin +0 -0
- package/android/bin/.gradle/8.0.2/checksums/sha1-checksums.bin +0 -0
- package/android/bin/.gradle/8.0.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/bin/.gradle/8.0.2/executionHistory/executionHistory.bin +0 -0
- package/android/bin/.gradle/8.0.2/executionHistory/executionHistory.lock +0 -0
- package/android/bin/.gradle/8.0.2/fileChanges/last-build.bin +0 -0
- package/android/bin/.gradle/8.0.2/fileHashes/fileHashes.bin +0 -0
- package/android/bin/.gradle/8.0.2/fileHashes/fileHashes.lock +0 -0
- package/android/bin/.gradle/8.0.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/bin/.gradle/8.0.2/gc.properties +0 -0
- package/android/bin/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/bin/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/bin/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/bin/.gradle/config.properties +2 -0
- package/android/bin/.gradle/file-system.probe +0 -0
- package/android/bin/.gradle/vcs-1/gc.properties +0 -0
- package/android/bin/.idea/compiler.xml +6 -0
- package/android/bin/.idea/gradle.xml +19 -0
- package/android/bin/.idea/kotlinc.xml +6 -0
- package/android/bin/.idea/migrations.xml +10 -0
- package/android/bin/.idea/misc.xml +9 -0
- package/android/bin/.idea/vcs.xml +6 -0
- package/android/bin/.project +34 -0
- package/android/bin/.settings/org.eclipse.buildship.core.prefs +13 -0
- package/android/bin/build.gradle +79 -0
- package/android/bin/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/bin/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/android/bin/gradle.properties +22 -0
- package/android/bin/gradlew +244 -0
- package/android/bin/gradlew.bat +92 -0
- package/android/bin/local.properties +8 -0
- package/android/bin/proguard-rules.pro +21 -0
- package/android/bin/settings.gradle +2 -0
- package/android/bin/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.class +0 -0
- package/android/bin/src/main/AndroidManifest.xml +4 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/App.kt +62 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/FakeR.kt +39 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/OnStatusCallback.kt +34 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/OnStatusReportListener.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/PlaylistItemOptions.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/PlaylistPlugin.kt +356 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/RmxAudioErrorType.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/RmxAudioPlayer.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/RmxAudioStatusMessage.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/RmxConstants.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/TrackRemovalItem.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/data/AudioTrack.kt +94 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/manager/MediaControlsListener.kt +13 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/manager/Options.kt +77 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +286 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/notification/PlaylistNotificationProvider.kt +26 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/playlist/AudioApi.kt +101 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/playlist/AudioPlaylistHandler$Builder.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/playlist/AudioPlaylistHandler.class +0 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/playlist/BaseMediaApi.kt +40 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/service/MediaImageProvider.kt +79 -0
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/service/MediaService.kt +53 -0
- package/android/bin/src/main/res/.gitkeep +0 -0
- package/android/bin/src/main/res/drawable/ic_closed_caption_white_24dp.xml +9 -0
- package/android/bin/src/main/res/drawable/ic_demo_icon_adaptive.xml +15 -0
- package/android/bin/src/main/res/drawable/ic_launcher_background.xml +48 -0
- package/android/bin/src/main/res/drawable/ic_launcher_foreground.xml +22 -0
- package/android/bin/src/main/res/drawable/ic_notification_icon.png +0 -0
- package/android/bin/src/main/res/layout/bridge_layout_main.xml +15 -0
- package/android/bin/src/main/res/values/colors.xml +3 -0
- package/android/bin/src/main/res/values/strings.xml +3 -0
- package/android/bin/src/main/res/values/styles.xml +3 -0
- package/android/bin/src/test/java/com/getcapacitor/ExampleUnitTest.class +0 -0
- package/android/build.gradle +0 -4
- package/android/local.properties +1 -1
- package/android/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +2 -1
- package/dist/docs.json +1357 -3
- package/dist/esm/web.js +1 -6
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +1 -6
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -6
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.idea/modules/android.iml +0 -18
- package/android/.idea/modules.xml +0 -8
- /package/android/{.gradle/configuration-cache → bin/.gradle/8.0.2/dependencies-accessors}/gc.properties +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
@rem
|
|
2
|
+
@rem Copyright 2015 the original author or authors.
|
|
3
|
+
@rem
|
|
4
|
+
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
@rem you may not use this file except in compliance with the License.
|
|
6
|
+
@rem You may obtain a copy of the License at
|
|
7
|
+
@rem
|
|
8
|
+
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
@rem
|
|
10
|
+
@rem Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
@rem See the License for the specific language governing permissions and
|
|
14
|
+
@rem limitations under the License.
|
|
15
|
+
@rem
|
|
16
|
+
|
|
17
|
+
@if "%DEBUG%"=="" @echo off
|
|
18
|
+
@rem ##########################################################################
|
|
19
|
+
@rem
|
|
20
|
+
@rem Gradle startup script for Windows
|
|
21
|
+
@rem
|
|
22
|
+
@rem ##########################################################################
|
|
23
|
+
|
|
24
|
+
@rem Set local scope for the variables with windows NT shell
|
|
25
|
+
if "%OS%"=="Windows_NT" setlocal
|
|
26
|
+
|
|
27
|
+
set DIRNAME=%~dp0
|
|
28
|
+
if "%DIRNAME%"=="" set DIRNAME=.
|
|
29
|
+
@rem This is normally unused
|
|
30
|
+
set APP_BASE_NAME=%~n0
|
|
31
|
+
set APP_HOME=%DIRNAME%
|
|
32
|
+
|
|
33
|
+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
34
|
+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
35
|
+
|
|
36
|
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
37
|
+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
38
|
+
|
|
39
|
+
@rem Find java.exe
|
|
40
|
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
41
|
+
|
|
42
|
+
set JAVA_EXE=java.exe
|
|
43
|
+
%JAVA_EXE% -version >NUL 2>&1
|
|
44
|
+
if %ERRORLEVEL% equ 0 goto execute
|
|
45
|
+
|
|
46
|
+
echo.
|
|
47
|
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
48
|
+
echo.
|
|
49
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
50
|
+
echo location of your Java installation.
|
|
51
|
+
|
|
52
|
+
goto fail
|
|
53
|
+
|
|
54
|
+
:findJavaFromJavaHome
|
|
55
|
+
set JAVA_HOME=%JAVA_HOME:"=%
|
|
56
|
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
57
|
+
|
|
58
|
+
if exist "%JAVA_EXE%" goto execute
|
|
59
|
+
|
|
60
|
+
echo.
|
|
61
|
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
62
|
+
echo.
|
|
63
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
64
|
+
echo location of your Java installation.
|
|
65
|
+
|
|
66
|
+
goto fail
|
|
67
|
+
|
|
68
|
+
:execute
|
|
69
|
+
@rem Setup the command line
|
|
70
|
+
|
|
71
|
+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@rem Execute Gradle
|
|
75
|
+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
76
|
+
|
|
77
|
+
:end
|
|
78
|
+
@rem End local scope for the variables with windows NT shell
|
|
79
|
+
if %ERRORLEVEL% equ 0 goto mainEnd
|
|
80
|
+
|
|
81
|
+
:fail
|
|
82
|
+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
83
|
+
rem the _cmd.exe /c_ return code!
|
|
84
|
+
set EXIT_CODE=%ERRORLEVEL%
|
|
85
|
+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
|
86
|
+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
|
87
|
+
exit /b %EXIT_CODE%
|
|
88
|
+
|
|
89
|
+
:mainEnd
|
|
90
|
+
if "%OS%"=="Windows_NT" endlocal
|
|
91
|
+
|
|
92
|
+
:omega
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
## This file must *NOT* be checked into Version Control Systems,
|
|
2
|
+
# as it contains information specific to your local configuration.
|
|
3
|
+
#
|
|
4
|
+
# Location of the SDK. This is only used by Gradle.
|
|
5
|
+
# For customization when using a Version Control System, please read the
|
|
6
|
+
# header note.
|
|
7
|
+
#Sat Jul 13 01:10:53 CEST 2024
|
|
8
|
+
sdk.dir=/Users/philippmohrenweiser/Library/Android/sdk
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Add project specific ProGuard rules here.
|
|
2
|
+
# You can control the set of applied configuration files using the
|
|
3
|
+
# proguardFiles setting in build.gradle.
|
|
4
|
+
#
|
|
5
|
+
# For more details, see
|
|
6
|
+
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
7
|
+
|
|
8
|
+
# If your project uses WebView with JS, uncomment the following
|
|
9
|
+
# and specify the fully qualified class name to the JavaScript interface
|
|
10
|
+
# class:
|
|
11
|
+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
12
|
+
# public *;
|
|
13
|
+
#}
|
|
14
|
+
|
|
15
|
+
# Uncomment this to preserve the line number information for
|
|
16
|
+
# debugging stack traces.
|
|
17
|
+
#-keepattributes SourceFile,LineNumberTable
|
|
18
|
+
|
|
19
|
+
# If you keep the line number information, uncomment this to
|
|
20
|
+
# hide the original source file name.
|
|
21
|
+
#-renamesourcefileattribute SourceFile
|
package/android/bin/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.class
ADDED
|
Binary file
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
package org.dwbn.plugins.playlist
|
|
2
|
+
|
|
3
|
+
import android.app.Application
|
|
4
|
+
import com.devbrackets.android.exomedia.ExoMedia
|
|
5
|
+
import org.dwbn.plugins.playlist.manager.PlaylistManager
|
|
6
|
+
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory
|
|
7
|
+
import com.google.android.exoplayer2.upstream.DataSource
|
|
8
|
+
import com.google.android.exoplayer2.upstream.TransferListener
|
|
9
|
+
import com.google.android.exoplayer2.upstream.cache.CacheDataSource
|
|
10
|
+
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory
|
|
11
|
+
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
|
|
12
|
+
import com.google.android.exoplayer2.upstream.cache.SimpleCache
|
|
13
|
+
import okhttp3.OkHttpClient
|
|
14
|
+
import java.io.File
|
|
15
|
+
|
|
16
|
+
class App : Application() {
|
|
17
|
+
private lateinit var _playlistManager: PlaylistManager;
|
|
18
|
+
val playlistManager get() = _playlistManager
|
|
19
|
+
|
|
20
|
+
fun resetPlaylistManager() {
|
|
21
|
+
_playlistManager = PlaylistManager(this)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun onCreate() {
|
|
25
|
+
resetPlaylistManager()
|
|
26
|
+
super.onCreate()
|
|
27
|
+
|
|
28
|
+
configureExoMedia()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private fun configureExoMedia() {
|
|
32
|
+
// Registers the media sources to use the OkHttp client instead of the standard Apache one
|
|
33
|
+
// Note: the OkHttpDataSourceFactory can be found in the ExoPlayer extension library `extension-okhttp`
|
|
34
|
+
ExoMedia.setDataSourceFactoryProvider(object : ExoMedia.DataSourceFactoryProvider {
|
|
35
|
+
private var instance: CacheDataSourceFactory? = null
|
|
36
|
+
|
|
37
|
+
override fun provide(
|
|
38
|
+
userAgent: String,
|
|
39
|
+
listener: TransferListener?
|
|
40
|
+
): DataSource.Factory {
|
|
41
|
+
if (instance == null) {
|
|
42
|
+
// Updates the network data source to use the OKHttp implementation
|
|
43
|
+
val upstreamFactory =
|
|
44
|
+
OkHttpDataSourceFactory(OkHttpClient(), userAgent, listener)
|
|
45
|
+
|
|
46
|
+
// Adds a cache around the upstreamFactory
|
|
47
|
+
val cache = SimpleCache(
|
|
48
|
+
File(cacheDir, "ExoMediaCache"),
|
|
49
|
+
LeastRecentlyUsedCacheEvictor((50 * 1024 * 1024).toLong())
|
|
50
|
+
)
|
|
51
|
+
instance = CacheDataSourceFactory(
|
|
52
|
+
cache,
|
|
53
|
+
upstreamFactory,
|
|
54
|
+
CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return instance!!
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package org.dwbn.plugins.playlist
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Context
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* R replacement for PhoneGap Build.
|
|
8
|
+
* Code adopted from https://github.com/EddyVerbruggen/barcodescanner-lib-aar
|
|
9
|
+
*
|
|
10
|
+
* ([^.\w])R\.(\w+)\.(\w+)
|
|
11
|
+
* $1fakeR("$2", "$3")
|
|
12
|
+
*
|
|
13
|
+
* @author Maciej Nux Jaros
|
|
14
|
+
*/
|
|
15
|
+
class FakeR {
|
|
16
|
+
var context: Context
|
|
17
|
+
private set
|
|
18
|
+
private var packageName: String
|
|
19
|
+
|
|
20
|
+
constructor(activity: Activity) {
|
|
21
|
+
context = activity.applicationContext
|
|
22
|
+
packageName = context.packageName
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
constructor(context: Context) {
|
|
26
|
+
this.context = context
|
|
27
|
+
packageName = context.packageName
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun getId(group: String?, key: String?): Int {
|
|
31
|
+
return context.resources.getIdentifier(key, group, packageName)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
companion object {
|
|
35
|
+
fun getId(context: Context, group: String?, key: String?): Int {
|
|
36
|
+
return context.resources.getIdentifier(key, group, context.packageName)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package org.dwbn.plugins.playlist
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.getcapacitor.JSObject
|
|
5
|
+
import org.json.JSONException
|
|
6
|
+
import org.json.JSONObject
|
|
7
|
+
|
|
8
|
+
class OnStatusCallback internal constructor(private val plugin: PlaylistPlugin) {
|
|
9
|
+
fun onStatus(what: RmxAudioStatusMessage, trackId: String?, param: JSONObject?) {
|
|
10
|
+
val data = JSObject()
|
|
11
|
+
val detail = JSObject()
|
|
12
|
+
detail.put("msgType", what.value)
|
|
13
|
+
detail.put("trackId", trackId)
|
|
14
|
+
detail.put("value", param)
|
|
15
|
+
data.put("action", "status")
|
|
16
|
+
data.put("status", detail)
|
|
17
|
+
Log.v(TAG, "statusChanged:$data")
|
|
18
|
+
plugin.emit("status", data)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
companion object {
|
|
22
|
+
private const val TAG = "PlaylistStatusCallback"
|
|
23
|
+
fun createErrorWithCode(code: RmxAudioErrorType?, message: String?): JSONObject {
|
|
24
|
+
val error = JSONObject()
|
|
25
|
+
try {
|
|
26
|
+
error.put("code", code)
|
|
27
|
+
error.put("message", message ?: "")
|
|
28
|
+
} catch (e: JSONException) {
|
|
29
|
+
Log.e(TAG, "Exception while raising onStatus: ", e)
|
|
30
|
+
}
|
|
31
|
+
return error
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
package org.dwbn.plugins.playlist
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.devbrackets.android.playlistcore.data.MediaProgress
|
|
5
|
+
import com.getcapacitor.*
|
|
6
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
7
|
+
import org.dwbn.plugins.playlist.data.AudioTrack
|
|
8
|
+
import org.json.JSONArray
|
|
9
|
+
import org.json.JSONObject
|
|
10
|
+
import java.util.*
|
|
11
|
+
|
|
12
|
+
@CapacitorPlugin(name = "Playlist")
|
|
13
|
+
class PlaylistPlugin : Plugin(), OnStatusReportListener {
|
|
14
|
+
var TAG = "PlaylistPlugin"
|
|
15
|
+
private var statusCallback: OnStatusCallback? = null
|
|
16
|
+
private var audioPlayerImpl: RmxAudioPlayer? = null
|
|
17
|
+
private var resetStreamOnPause = true
|
|
18
|
+
|
|
19
|
+
override fun load() {
|
|
20
|
+
audioPlayerImpl = RmxAudioPlayer(this, (this.context.applicationContext as App))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@PluginMethod
|
|
24
|
+
fun initialize(call: PluginCall) {
|
|
25
|
+
statusCallback = OnStatusCallback(this)
|
|
26
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_REGISTER, "INIT", null)
|
|
27
|
+
Log.i(TAG, "Initialized...")
|
|
28
|
+
audioPlayerImpl!!.resume()
|
|
29
|
+
call.resolve()
|
|
30
|
+
}
|
|
31
|
+
@PluginMethod
|
|
32
|
+
fun setOptions(call: PluginCall) {
|
|
33
|
+
val options: JSObject = call.getObject("options") ?: JSObject()
|
|
34
|
+
resetStreamOnPause = options.optBoolean("resetStreamOnPause", this.resetStreamOnPause)
|
|
35
|
+
Log.i("AudioPlayerOptions", options.toString())
|
|
36
|
+
audioPlayerImpl!!.resetStreamOnPause = resetStreamOnPause
|
|
37
|
+
audioPlayerImpl!!.setOptions(options)
|
|
38
|
+
call.resolve()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@PluginMethod
|
|
42
|
+
fun release(call: PluginCall) {
|
|
43
|
+
destroyResources()
|
|
44
|
+
call.resolve()
|
|
45
|
+
Log.i(TAG,"released")
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@PluginMethod
|
|
49
|
+
fun setLoop(call: PluginCall) {
|
|
50
|
+
val loop: Boolean = call.getBoolean("loop", audioPlayerImpl!!.playlistManager.loop)!!
|
|
51
|
+
audioPlayerImpl!!.playlistManager.loop = loop
|
|
52
|
+
call.resolve()
|
|
53
|
+
Log.i(TAG,"setLoop: " + (if (loop) "TRUE" else "FALSE"))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@PluginMethod
|
|
57
|
+
fun setPlaylistItems(call: PluginCall) {
|
|
58
|
+
val items: JSArray = call.getArray("items")
|
|
59
|
+
val optionsArgs: JSONObject = call.getObject("options")
|
|
60
|
+
val options = PlaylistItemOptions(optionsArgs)
|
|
61
|
+
|
|
62
|
+
val trackItems: ArrayList<AudioTrack> = getTrackItems(items)
|
|
63
|
+
audioPlayerImpl!!.playlistManager.setAllItems(trackItems, options)
|
|
64
|
+
for (playerItem in trackItems) {
|
|
65
|
+
if (playerItem.trackId != null) {
|
|
66
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_ITEM_ADDED, playerItem.trackId, playerItem.toDict())
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
call.resolve()
|
|
71
|
+
|
|
72
|
+
Log.i(TAG,"setPlaylistItems" + items.length().toString())
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@PluginMethod
|
|
76
|
+
fun addItem(call: PluginCall) {
|
|
77
|
+
val item: JSONObject = call.getObject("item")
|
|
78
|
+
val playerItem: AudioTrack? = getTrackItem(item)
|
|
79
|
+
audioPlayerImpl!!.getPlaylistManager().addItem(playerItem)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if (playerItem?.trackId != null) {
|
|
83
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_ITEM_ADDED, playerItem.trackId, playerItem.toDict())
|
|
84
|
+
}
|
|
85
|
+
call.resolve()
|
|
86
|
+
Log.i(TAG,"addItem")
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@PluginMethod
|
|
90
|
+
fun addAllItems(call: PluginCall) {
|
|
91
|
+
val items: JSONArray = call.getArray("items")
|
|
92
|
+
val trackItems = getTrackItems(items)
|
|
93
|
+
audioPlayerImpl!!.playlistManager.addAllItems(trackItems)
|
|
94
|
+
|
|
95
|
+
for (playerItem in trackItems) {
|
|
96
|
+
if (playerItem.trackId != null) {
|
|
97
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_ITEM_ADDED, playerItem.trackId, playerItem.toDict())
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
call.resolve()
|
|
101
|
+
Log.i(TAG,"addAllItems")
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@PluginMethod
|
|
105
|
+
fun removeItem(call: PluginCall) {
|
|
106
|
+
val trackIndex: Int = call.getInt("index", -1)!!
|
|
107
|
+
val trackId: String = call.getString("id", "")!!
|
|
108
|
+
Log.i(TAG,"removeItem trackIn" )
|
|
109
|
+
val item = audioPlayerImpl!!.playlistManager.removeItem(trackIndex, trackId)
|
|
110
|
+
|
|
111
|
+
if (item != null) {
|
|
112
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_ITEM_REMOVED, item.trackId, item.toDict())
|
|
113
|
+
call.resolve()
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
call.reject("Could not find item!")
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@PluginMethod
|
|
121
|
+
fun removeItems(call: PluginCall) {
|
|
122
|
+
val items: JSONArray = call.getArray("items")
|
|
123
|
+
var removed = 0
|
|
124
|
+
|
|
125
|
+
val removals = ArrayList<TrackRemovalItem>()
|
|
126
|
+
for (index in 0 until items.length()) {
|
|
127
|
+
val entry = items.optJSONObject(index) ?: continue
|
|
128
|
+
val trackIndex = entry.optInt("trackIndex", -1)
|
|
129
|
+
val trackId = entry.optString("trackId", "")
|
|
130
|
+
removals.add(TrackRemovalItem(trackIndex, trackId))
|
|
131
|
+
val removedTracks = audioPlayerImpl!!.playlistManager.removeAllItems(removals)
|
|
132
|
+
if (removedTracks.size > 0) {
|
|
133
|
+
for (removedItem in removedTracks) {
|
|
134
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_ITEM_REMOVED, removedItem.trackId, removedItem.toDict())
|
|
135
|
+
}
|
|
136
|
+
removed = removedTracks.size
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
val result = JSObject()
|
|
141
|
+
result.put("removed", removed)
|
|
142
|
+
call.resolve(result)
|
|
143
|
+
|
|
144
|
+
Log.i(TAG,"removeItems")
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@PluginMethod
|
|
148
|
+
fun clearAllItems(call: PluginCall) {
|
|
149
|
+
audioPlayerImpl!!.playlistManager.clearItems()
|
|
150
|
+
|
|
151
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_PLAYLIST_CLEARED, "INVALID", null)
|
|
152
|
+
call.resolve()
|
|
153
|
+
|
|
154
|
+
Log.i(TAG,"clearAllItems")
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@PluginMethod
|
|
158
|
+
fun play(call: PluginCall) {
|
|
159
|
+
if (audioPlayerImpl!!.playlistManager.playlistHandler != null) {
|
|
160
|
+
val isPlaying = (audioPlayerImpl!!.playlistManager.playlistHandler?.currentMediaPlayer != null
|
|
161
|
+
&& audioPlayerImpl!!.playlistManager.playlistHandler?.currentMediaPlayer?.isPlaying!!)
|
|
162
|
+
// There's a bug in the threaded repeater that it stacks up the repeat calls instead of ignoring
|
|
163
|
+
// additional ones or starting a new one. E.g. every time this is called, you'd get a new repeat cycle,
|
|
164
|
+
// meaning you get N updates per second. Ew.
|
|
165
|
+
if (!isPlaying) {
|
|
166
|
+
audioPlayerImpl!!.playlistManager.playlistHandler?.play()
|
|
167
|
+
//audioPlayerImpl.getPlaylistManager().playlistHandler.seek(position)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
call.resolve()
|
|
172
|
+
|
|
173
|
+
Log.i(TAG,"play")
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@PluginMethod
|
|
177
|
+
fun playTrackByIndex(call: PluginCall) {
|
|
178
|
+
val index: Int = call.getInt("index", audioPlayerImpl!!.playlistManager.currentPosition)!!
|
|
179
|
+
val seekPosition = (call.getInt("position", 0)!! * 1000.0).toLong()
|
|
180
|
+
|
|
181
|
+
audioPlayerImpl!!.playlistManager.currentPosition = index
|
|
182
|
+
audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, false)
|
|
183
|
+
|
|
184
|
+
call.resolve()
|
|
185
|
+
|
|
186
|
+
Log.i(TAG,"playTrackByIndex")
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@PluginMethod
|
|
190
|
+
fun playTrackById(call: PluginCall) {
|
|
191
|
+
val id: String = call.getString("id")!!
|
|
192
|
+
if ("" != id) {
|
|
193
|
+
// alternatively we could search for the item and set the current index to that item.
|
|
194
|
+
val code = id.hashCode()
|
|
195
|
+
val seekPosition = (call.getInt("position", 0)!! * 1000.0).toLong()
|
|
196
|
+
audioPlayerImpl!!.playlistManager.setCurrentItem(code.toLong())
|
|
197
|
+
audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, false)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
call.resolve()
|
|
201
|
+
|
|
202
|
+
Log.i(TAG,"playTrackById")
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
@PluginMethod
|
|
206
|
+
fun selectTrackByIndex(call: PluginCall) {
|
|
207
|
+
val index: Int = call.getInt("index", audioPlayerImpl!!.playlistManager.currentPosition)!!
|
|
208
|
+
|
|
209
|
+
audioPlayerImpl!!.playlistManager.currentPosition = index
|
|
210
|
+
|
|
211
|
+
val seekPosition = (call.getInt("position", 0)!! * 1000.0).toLong()
|
|
212
|
+
|
|
213
|
+
audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, true)
|
|
214
|
+
|
|
215
|
+
call.resolve()
|
|
216
|
+
|
|
217
|
+
Log.i(TAG,"selectTrackByIndex")
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@PluginMethod
|
|
222
|
+
fun selectTrackById(call: PluginCall) {
|
|
223
|
+
val id: String = call.getString("id")!!
|
|
224
|
+
if ("" != id) {
|
|
225
|
+
// alternatively we could search for the item and set the current index to that item.
|
|
226
|
+
val code = id.hashCode()
|
|
227
|
+
audioPlayerImpl!!.playlistManager.setCurrentItem(code.toLong())
|
|
228
|
+
|
|
229
|
+
val seekPosition = (call.getInt("position", 0)!! * 1000.0).toLong()
|
|
230
|
+
|
|
231
|
+
audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, true)
|
|
232
|
+
}
|
|
233
|
+
call.resolve()
|
|
234
|
+
|
|
235
|
+
Log.i(TAG,"selectTrackById")
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@PluginMethod
|
|
239
|
+
fun pause(call: PluginCall) {
|
|
240
|
+
audioPlayerImpl!!.playlistManager.invokePausePlay()
|
|
241
|
+
|
|
242
|
+
call.resolve()
|
|
243
|
+
|
|
244
|
+
Log.i(TAG,"pause")
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
@PluginMethod
|
|
248
|
+
fun skipForward(call: PluginCall) {
|
|
249
|
+
audioPlayerImpl!!.playlistManager.invokeNext()
|
|
250
|
+
|
|
251
|
+
call.resolve()
|
|
252
|
+
|
|
253
|
+
Log.i(TAG,"skipForward")
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@PluginMethod
|
|
257
|
+
fun skipBack(call: PluginCall) {
|
|
258
|
+
audioPlayerImpl!!.playlistManager.invokePrevious()
|
|
259
|
+
|
|
260
|
+
call.resolve()
|
|
261
|
+
|
|
262
|
+
Log.i(TAG,"skipBack")
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
@PluginMethod
|
|
266
|
+
fun seekTo(call: PluginCall) {
|
|
267
|
+
var position: Long = 0
|
|
268
|
+
val progress: MediaProgress? = audioPlayerImpl!!.playlistManager.currentProgress
|
|
269
|
+
if (progress != null) {
|
|
270
|
+
position = progress.position
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
val seekPosition = (call.getInt("position", (position / 1000.0f).toInt())!! * 1000.0).toLong()
|
|
274
|
+
|
|
275
|
+
val isPlaying: Boolean? = audioPlayerImpl!!.playlistManager.playlistHandler?.currentMediaPlayer?.isPlaying
|
|
276
|
+
audioPlayerImpl!!.playlistManager.playlistHandler?.seek(seekPosition)
|
|
277
|
+
if (isPlaying === null || !isPlaying) {
|
|
278
|
+
audioPlayerImpl!!.playlistManager.playlistHandler?.pause(false)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
call.resolve()
|
|
282
|
+
|
|
283
|
+
Log.i(TAG,"seekTo")
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
@PluginMethod
|
|
287
|
+
fun setPlaybackRate(call: PluginCall) {
|
|
288
|
+
val speed = call.getFloat("rate", audioPlayerImpl!!.playlistManager.getPlaybackSpeed())!!
|
|
289
|
+
audioPlayerImpl!!.playlistManager.setPlaybackSpeed(speed)
|
|
290
|
+
|
|
291
|
+
call.resolve()
|
|
292
|
+
|
|
293
|
+
Log.i(TAG,"setPlaybackRate")
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
@PluginMethod
|
|
297
|
+
fun setVolume(call: PluginCall) {
|
|
298
|
+
val volume = call.getFloat("volume", audioPlayerImpl!!.volume)!!
|
|
299
|
+
audioPlayerImpl!!.volume = volume
|
|
300
|
+
|
|
301
|
+
call.resolve()
|
|
302
|
+
|
|
303
|
+
Log.i(TAG,"addItem")
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
override fun handleOnDestroy() {
|
|
307
|
+
Log.d(TAG, "Plugin destroy")
|
|
308
|
+
super.handleOnDestroy()
|
|
309
|
+
destroyResources()
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
override fun onError(errorCode: RmxAudioErrorType?, trackId: String?, message: String?) {
|
|
313
|
+
if (statusCallback == null) {
|
|
314
|
+
return
|
|
315
|
+
}
|
|
316
|
+
val errorObj = OnStatusCallback.createErrorWithCode(errorCode, message)
|
|
317
|
+
onStatus(RmxAudioStatusMessage.RMXSTATUS_ERROR, trackId, errorObj)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
override fun onStatus(what: RmxAudioStatusMessage, trackId: String?, param: JSONObject?) {
|
|
321
|
+
if (statusCallback == null) {
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
statusCallback!!.onStatus(what, trackId, param)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private fun destroyResources() {
|
|
328
|
+
statusCallback = null
|
|
329
|
+
audioPlayerImpl!!.playlistManager.clearItems()
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private fun getTrackItem(item: JSONObject?): AudioTrack? {
|
|
333
|
+
if (item != null) {
|
|
334
|
+
val track = AudioTrack(item)
|
|
335
|
+
return if (track.trackId != null) {
|
|
336
|
+
track
|
|
337
|
+
} else null
|
|
338
|
+
}
|
|
339
|
+
return null
|
|
340
|
+
}
|
|
341
|
+
private fun getTrackItems(items: JSONArray?): ArrayList<AudioTrack> {
|
|
342
|
+
val trackItems = ArrayList<AudioTrack>()
|
|
343
|
+
if (items != null && items.length() > 0) {
|
|
344
|
+
for (index in 0 until items.length()) {
|
|
345
|
+
val obj = items.optJSONObject(index)
|
|
346
|
+
val track: AudioTrack = getTrackItem(obj) ?: continue
|
|
347
|
+
trackItems.add(track)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return trackItems
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
fun emit(name: String, data: JSObject) {
|
|
354
|
+
this.notifyListeners(name, data, true)
|
|
355
|
+
}
|
|
356
|
+
}
|
|
Binary file
|
|
Binary file
|