capacitor-plugin-playlist 0.4.2 → 0.6.0
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/README.md +29 -23
- package/android/build.gradle +5 -7
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +2 -1
- package/android/gradlew +8 -4
- package/android/src/main/java/org/dwbn/plugins/playlist/App.kt +0 -43
- package/android/src/main/java/org/dwbn/plugins/playlist/PlaylistPlugin.kt +217 -153
- package/android/src/main/java/org/dwbn/plugins/playlist/RmxAudioPlayer.java +4 -2
- package/android/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +8 -6
- package/android/src/main/java/org/dwbn/plugins/playlist/playlist/AudioApi.kt +20 -11
- package/android/src/main/java/org/dwbn/plugins/playlist/playlist/AudioPlaylistHandler.java +1 -46
- package/android/src/main/java/org/dwbn/plugins/playlist/playlist/BaseMediaApi.kt +4 -8
- package/android/src/main/java/org/dwbn/plugins/playlist/service/MediaService.kt +17 -0
- package/dist/docs.json +68 -489
- package/dist/esm/definitions.d.ts +1 -1
- package/package.json +8 -8
- 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/dependencies-accessors/gc.properties +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/fileChanges/last-build.bin +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/8.0.2/gc.properties +0 -0
- package/android/.gradle/8.2.1/checksums/checksums.lock +0 -0
- package/android/.gradle/8.2.1/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.2.1/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.2.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.2.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.2.1/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.2.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.2.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.2.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.2.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.2.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/config.properties +0 -2
- package/android/.gradle/file-system.probe +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -19
- package/android/.idea/kotlinc.xml +0 -6
- package/android/.idea/migrations.xml +0 -10
- package/android/.idea/misc.xml +0 -9
- package/android/.idea/vcs.xml +0 -6
- 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/dependencies-accessors/gc.properties +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/8.2.1/checksums/checksums.lock +0 -0
- package/android/bin/.gradle/8.2.1/checksums/md5-checksums.bin +0 -0
- package/android/bin/.gradle/8.2.1/checksums/sha1-checksums.bin +0 -0
- package/android/bin/.gradle/8.2.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/bin/.gradle/8.2.1/dependencies-accessors/gc.properties +0 -0
- package/android/bin/.gradle/8.2.1/executionHistory/executionHistory.bin +0 -0
- package/android/bin/.gradle/8.2.1/executionHistory/executionHistory.lock +0 -0
- package/android/bin/.gradle/8.2.1/fileChanges/last-build.bin +0 -0
- package/android/bin/.gradle/8.2.1/fileHashes/fileHashes.bin +0 -0
- package/android/bin/.gradle/8.2.1/fileHashes/fileHashes.lock +0 -0
- package/android/bin/.gradle/8.2.1/gc.properties +0 -0
- package/android/bin/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/bin/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/bin/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/bin/.gradle/config.properties +0 -2
- 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 +0 -6
- package/android/bin/.idea/gradle.xml +0 -19
- package/android/bin/.idea/kotlinc.xml +0 -6
- package/android/bin/.idea/migrations.xml +0 -10
- package/android/bin/.idea/misc.xml +0 -9
- package/android/bin/.idea/vcs.xml +0 -6
- package/android/bin/.project +0 -34
- package/android/bin/build.gradle +0 -79
- package/android/bin/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/bin/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/android/bin/gradle.properties +0 -22
- package/android/bin/gradlew +0 -244
- package/android/bin/gradlew.bat +0 -92
- package/android/bin/local.properties +0 -8
- package/android/bin/proguard-rules.pro +0 -21
- package/android/bin/settings.gradle +0 -2
- package/android/bin/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.class +0 -0
- package/android/bin/src/main/AndroidManifest.xml +0 -4
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/App.kt +0 -61
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/FakeR.kt +0 -39
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/OnStatusCallback.kt +0 -34
- 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 +0 -403
- 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 +0 -94
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/manager/MediaControlsListener.kt +0 -13
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/manager/Options.kt +0 -77
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +0 -286
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/notification/PlaylistNotificationProvider.kt +0 -26
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/playlist/AudioApi.kt +0 -101
- 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 +0 -40
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/service/MediaImageProvider.kt +0 -79
- package/android/bin/src/main/java/org/dwbn/plugins/playlist/service/MediaService.kt +0 -54
- package/android/bin/src/main/res/.gitkeep +0 -0
- package/android/bin/src/main/res/drawable/ic_closed_caption_white_24dp.xml +0 -9
- package/android/bin/src/main/res/drawable/ic_demo_icon_adaptive.xml +0 -15
- package/android/bin/src/main/res/drawable/ic_launcher_background.xml +0 -48
- package/android/bin/src/main/res/drawable/ic_launcher_foreground.xml +0 -22
- package/android/bin/src/main/res/drawable/ic_notification_icon.png +0 -0
- package/android/bin/src/main/res/layout/bridge_layout_main.xml +0 -15
- package/android/bin/src/main/res/values/colors.xml +0 -3
- package/android/bin/src/main/res/values/strings.xml +0 -3
- package/android/bin/src/main/res/values/styles.xml +0 -3
- package/android/bin/src/test/java/com/getcapacitor/ExampleUnitTest.class +0 -0
- package/android/local.properties +0 -8
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# capacitor-plugin-playlist
|
|
2
|
+
|
|
2
3
|
Will probably be published as @dwbn/capacitor-playlist
|
|
3
4
|
|
|
4
5
|
A capacitor 3. 0 plugin for Android, iOS and Web with native support for audio playlists, background support, and lock screen controls
|
|
@@ -21,12 +22,13 @@ cordova, and here we wanna give back to the community our outcome, any help is a
|
|
|
21
22
|
|
|
22
23
|
## 2. Notes
|
|
23
24
|
|
|
24
|
-
### On
|
|
25
|
+
### On _Android_, utilizes a wrapper over ExoPlayer called [ExoMedia](https://github.com/brianwernick/ExoMedia). ExoPlayer is a powerful, high-quality player for Android provided by Google
|
|
26
|
+
|
|
25
27
|
### On iOS, utilizes a customized AVQueuePlayer in order to provide feedback about track changes, buffering, etc.; given that AVQueuePlayer can keep the audio session running between songs.
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
- This plugin is not designed to play mixable, rapid-fire, low-latency audio, as you would use in a game. A more appropriate cordova plugin for that use case is [cordova-plugin-nativeaudio](https://github.com/floatinghotpot/cordova-plugin-nativeaudio)
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
- Cannot mix audio; again the NativeAudio plugin is probably more appropriate. This is due to supporting the lock screen and command center controls: only an app in command of audio can do this, otherwise the controls have no meaning. I would like to add an option to do this, it should be fairly straightforward; at the cost of not supporting the OS-level controls for that invokation.
|
|
30
32
|
|
|
31
33
|
## 3. Installation
|
|
32
34
|
|
|
@@ -36,10 +38,13 @@ As with most capacitor plugins...
|
|
|
36
38
|
npm i capacitor-plugin-playlist
|
|
37
39
|
npx cap sync
|
|
38
40
|
```
|
|
41
|
+
|
|
39
42
|
### For web
|
|
40
|
-
include hlsjs in your build
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
include hlsjs in your build
|
|
45
|
+
|
|
46
|
+
#### E.G. for Angular 2+:
|
|
47
|
+
|
|
43
48
|
```
|
|
44
49
|
npm i hls.js
|
|
45
50
|
```
|
|
@@ -55,16 +60,8 @@ architect => build => options:
|
|
|
55
60
|
]
|
|
56
61
|
```
|
|
57
62
|
|
|
58
|
-
### On Android:
|
|
59
|
-
|
|
60
|
-
##### Add to your build.gradle
|
|
61
|
-
```
|
|
62
|
-
ext {
|
|
63
|
-
exoPlayerVersion = "2.9.6"
|
|
64
|
-
supportLibVersion = "28.0.0"
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
63
|
##### AndroidManifest.xml:
|
|
64
|
+
|
|
68
65
|
```
|
|
69
66
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
70
67
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
@@ -78,7 +75,9 @@ ext {
|
|
|
78
75
|
```
|
|
79
76
|
|
|
80
77
|
##### Glide image loading for notifiction center
|
|
78
|
+
|
|
81
79
|
To be able to use glide you need to create a file MyAppGlideModule.java:
|
|
80
|
+
|
|
82
81
|
```
|
|
83
82
|
package org.your.package.namespace;
|
|
84
83
|
|
|
@@ -88,10 +87,13 @@ import com.bumptech.glide.module.AppGlideModule;
|
|
|
88
87
|
@GlideModule
|
|
89
88
|
public final class MyAppGlideModule extends AppGlideModule {}
|
|
90
89
|
```
|
|
90
|
+
|
|
91
91
|
also see https://guides.codepath.com/android/Displaying-Images-with-the-Glide-Library
|
|
92
92
|
|
|
93
93
|
### iOS
|
|
94
|
+
|
|
94
95
|
##### inside Info.plist:
|
|
96
|
+
|
|
95
97
|
```
|
|
96
98
|
<key>UIBackgroundModes</key>
|
|
97
99
|
<array>
|
|
@@ -105,6 +107,7 @@ Android normally will give you ~2-3 minutes of background playback before killin
|
|
|
105
107
|
iOS will immediately stop playback when the app goes into the background if you do not include the `audio` `UIBackgroundMode`. iOS has an additional requirement that audio playback must never stop; when it does, the audio session will be terminated and playback cannot continue without user interaction.
|
|
106
108
|
|
|
107
109
|
### Android notification icon
|
|
110
|
+
|
|
108
111
|
To show a better notification icon in Android Lollipop (API 21) and above, create a transparent (silhouette) icon and name the file e.g. as "ic_notification.png".
|
|
109
112
|
Then you can use the options like:
|
|
110
113
|
|
|
@@ -124,8 +127,10 @@ Just drop into your project and go.
|
|
|
124
127
|
Should be quite obvious howto adapt this for other frameworks, or just vanillaJS
|
|
125
128
|
|
|
126
129
|
### API
|
|
130
|
+
|
|
127
131
|
Example:
|
|
128
132
|
@see definition.ts
|
|
133
|
+
|
|
129
134
|
```
|
|
130
135
|
import {Playlist, AudioTrack} from 'capacitor-plugin-playlist'
|
|
131
136
|
|
|
@@ -147,20 +152,21 @@ Its a meant as a drop in replacement
|
|
|
147
152
|
|
|
148
153
|
in the best case you only change your import. :D
|
|
149
154
|
|
|
150
|
-
|
|
151
155
|
## 5. Todo
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
|
|
157
|
+
- [iOS] Utilize [AudioPlayer](https://github.com/delannoyk/AudioPlayer) instead of directly implementing AVQueuePlayer. `AudioPlayer` includes some smart network recovery features
|
|
158
|
+
- [iOS, Android] Add a full example
|
|
154
159
|
|
|
155
160
|
## 6. Credits
|
|
156
161
|
|
|
157
162
|
There are several plugins that are similar to this one, but all are focused on aspects of the media management experience. This plugin takes inspiration from:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
163
|
+
|
|
164
|
+
- [cordova-plugin-playlist](https://github.com/Rolamix/cordova-plugin-playlist)
|
|
165
|
+
- [cordova-plugin-media](https://github.com/apache/cordova-plugin-media)
|
|
166
|
+
- [ExoMedia](https://github.com/brianwernick/ExoMedia)
|
|
167
|
+
- [PlaylistCore](https://github.com/brianwernick/PlaylistCore) (provides player controls on top of ExoMedia)
|
|
168
|
+
- [Bi-Directional AVQueuePlayer proof of concept](https://github.com/jrtaal/AVBidirectionalQueuePlayer)
|
|
169
|
+
- [cordova-music-controls-plugin](https://github.com/homerours/cordova-music-controls-plugin)
|
|
164
170
|
|
|
165
171
|
## 7. License
|
|
166
172
|
|
package/android/build.gradle
CHANGED
|
@@ -2,17 +2,16 @@ ext {
|
|
|
2
2
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
3
|
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
4
4
|
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
5
|
-
exoPlayerVersion = project.hasProperty('exoPlayerVersion') ? rootProject.ext.exoPlayerVersion : "2.9.6"
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
buildscript {
|
|
9
|
-
ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.
|
|
8
|
+
ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.10'
|
|
10
9
|
repositories {
|
|
11
10
|
google()
|
|
12
11
|
mavenCentral()
|
|
13
12
|
}
|
|
14
13
|
dependencies {
|
|
15
|
-
classpath 'com.android.tools.build:gradle:8.
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
|
16
15
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -22,10 +21,10 @@ apply plugin: 'kotlin-android'
|
|
|
22
21
|
|
|
23
22
|
android {
|
|
24
23
|
namespace "org.dwbn.plugins.playlist"
|
|
25
|
-
|
|
24
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
26
25
|
defaultConfig {
|
|
27
26
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
28
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
27
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
29
28
|
versionCode 1
|
|
30
29
|
versionName "1.0"
|
|
31
30
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
@@ -65,8 +64,7 @@ dependencies {
|
|
|
65
64
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
66
65
|
|
|
67
66
|
// Image Exomedia
|
|
68
|
-
implementation 'com.devbrackets.android:exomedia:
|
|
69
|
-
implementation "com.google.android.exoplayer:extension-okhttp:$exoPlayerVersion"
|
|
67
|
+
implementation 'com.devbrackets.android:exomedia:5.1.0'
|
|
70
68
|
|
|
71
69
|
// Image Loading
|
|
72
70
|
implementation 'com.github.bumptech.glide:glide:4.6.1'
|
|
Binary file
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
|
|
4
4
|
networkTimeout=10000
|
|
5
|
+
validateDistributionUrl=true
|
|
5
6
|
zipStoreBase=GRADLE_USER_HOME
|
|
6
7
|
zipStorePath=wrapper/dists
|
package/android/gradlew
CHANGED
|
@@ -85,9 +85,6 @@ done
|
|
|
85
85
|
APP_BASE_NAME=${0##*/}
|
|
86
86
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
|
87
87
|
|
|
88
|
-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
89
|
-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
90
|
-
|
|
91
88
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
92
89
|
MAX_FD=maximum
|
|
93
90
|
|
|
@@ -133,10 +130,13 @@ location of your Java installation."
|
|
|
133
130
|
fi
|
|
134
131
|
else
|
|
135
132
|
JAVACMD=java
|
|
136
|
-
|
|
133
|
+
if ! command -v java >/dev/null 2>&1
|
|
134
|
+
then
|
|
135
|
+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
137
136
|
|
|
138
137
|
Please set the JAVA_HOME variable in your environment to match the
|
|
139
138
|
location of your Java installation."
|
|
139
|
+
fi
|
|
140
140
|
fi
|
|
141
141
|
|
|
142
142
|
# Increase the maximum file descriptors if we can.
|
|
@@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
|
|
|
197
197
|
done
|
|
198
198
|
fi
|
|
199
199
|
|
|
200
|
+
|
|
201
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
202
|
+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
203
|
+
|
|
200
204
|
# Collect all arguments for the java command;
|
|
201
205
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
|
202
206
|
# shell script including quotes and variable substitutions, so put them in
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
package org.dwbn.plugins.playlist
|
|
2
2
|
|
|
3
3
|
import android.app.Application
|
|
4
|
-
import com.devbrackets.android.exomedia.ExoMedia
|
|
5
4
|
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
5
|
|
|
16
6
|
class App : Application() {
|
|
17
7
|
private lateinit var _playlistManager: PlaylistManager;
|
|
@@ -25,38 +15,5 @@ class App : Application() {
|
|
|
25
15
|
resetPlaylistManager()
|
|
26
16
|
super.onCreate()
|
|
27
17
|
|
|
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
18
|
}
|
|
62
19
|
}
|