diff --git a/android/app/build.gradle b/android/app/build.gradle index 506dd04d..069a1102 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "com.audiobookshelf.app" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 29 - versionName "0.9.13-beta" + versionCode 30 + versionName "0.9.14-beta" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt b/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt index a7ed975f..d51827f9 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt @@ -122,4 +122,9 @@ class MainActivity : BridgeActivity() { // Mandatory for Activity, but not for Fragment & ComponentActivity storageHelper.onRequestPermissionsResult(requestCode, permissions, grantResults) } + + override fun onUserInteraction() { + super.onUserInteraction() + Log.d(tag, "USER INTERACTION") + } } diff --git a/android/app/src/main/java/com/audiobookshelf/app/MyNativeAudio.kt b/android/app/src/main/java/com/audiobookshelf/app/MyNativeAudio.kt index 796db4c2..ac08489e 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/MyNativeAudio.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/MyNativeAudio.kt @@ -8,6 +8,8 @@ import androidx.core.content.ContextCompat import com.getcapacitor.* import com.getcapacitor.annotation.CapacitorPlugin import org.json.JSONObject +import java.util.* +import kotlin.concurrent.schedule @CapacitorPlugin(name = "MyNativeAudio") class MyNativeAudio : Plugin() { @@ -35,6 +37,9 @@ class MyNativeAudio : Plugin() { jsobj.put("playWhenReady", playWhenReady) notifyListeners("onPrepareMedia", jsobj) } + override fun onSleepTimerEnded() { + emit("onSleepTimerEnded", true) + } }) } mainActivity.pluginCallback = foregroundServiceReady @@ -201,4 +206,26 @@ class MyNativeAudio : Plugin() { Log.d(tag, "Setting Audiobooks ${audiobookObjs.size}") playerNotificationService.setAudiobooks(audiobookObjs) } + + @PluginMethod + fun setSleepTimer(call: PluginCall) { + var sleepTimeout:Long = call.getString("timeout", "360000")!!.toLong() + + playerNotificationService.setSleepTimer(sleepTimeout) + call.resolve() + } + + @PluginMethod + fun getSleepTimerTime(call: PluginCall) { + var time = playerNotificationService.getSleepTimerTime() + val ret = JSObject() + ret.put("value", time) + call.resolve(ret) + } + + @PluginMethod + fun cancelSleepTimer(call: PluginCall) { + playerNotificationService.cancelSleepTimer() + call.resolve() + } } diff --git a/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt b/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt index b4d7e1d7..1ea52118 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt @@ -51,6 +51,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { fun onPlayingUpdate(isPlaying: Boolean) fun onMetadata(metadata: JSObject) fun onPrepare(audiobookId:String, playWhenReady:Boolean) + fun onSleepTimerEnded() } private val tag = "PlayerService" @@ -84,6 +85,8 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { private var lastPauseTime: Long = 0 //ms private var onSeekBack: Boolean = false + private var sleepTimerTask:TimerTask? = null + fun setCustomObjectListener(mylistener: MyCustomObjectListener) { listener = mylistener } @@ -124,7 +127,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { } @RequiresApi(Build.VERSION_CODES.O) - private fun createNotificationChannel(channelId: String, channelName: String): String{ + private fun createNotificationChannel(channelId: String, channelName: String): String { val chan = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH) chan.lightColor = Color.DKGRAY @@ -718,5 +721,33 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { } } } + + fun setSleepTimer(timeout:Long) { + Log.d(tag, "Setting Sleep Timer for $timeout") + + sleepTimerTask?.cancel() + sleepTimerTask = Timer("SleepTimer",false).schedule(timeout) { + Log.d(tag, "Sleep Timer Done") + Handler(Looper.getMainLooper()).post() { + if (mPlayer.isPlaying) { + Log.d(tag, "Sleep Timer Pausing Player") + mPlayer.pause() + } + if (listener != null) listener.onSleepTimerEnded() + } + } + } + + fun getSleepTimerTime():Long? { + var time = sleepTimerTask?.scheduledExecutionTime() + Log.d(tag, "Sleep Timer execution time $time") + return time + } + + fun cancelSleepTimer() { + Log.d(tag, "Canceling Sleep Timer") + sleepTimerTask?.cancel() + sleepTimerTask = null + } } diff --git a/components/AudioPlayerMini.vue b/components/AudioPlayerMini.vue index b7d0e420..406cded2 100644 --- a/components/AudioPlayerMini.vue +++ b/components/AudioPlayerMini.vue @@ -27,6 +27,16 @@
+ +
+ + + +
+

{{ Math.ceil(sleepTimeoutCurrentTime / 1000 / 60) }}m

+
+
+
@@ -53,7 +63,9 @@ import MyNativeAudio from '@/plugins/my-native-audio' export default { props: { - loading: Boolean + loading: Boolean, + sleepTimerRunning: Boolean, + sleepTimeoutCurrentTime: Number }, data() { return { @@ -87,6 +99,9 @@ export default { } }, methods: { + showSleepTimerModal() { + this.$emit('showSleepTimer') + }, updatePlaybackRate() { this.currentPlaybackRate = this.playbackRate MyNativeAudio.setPlaybackSpeed({ speed: this.playbackRate }) @@ -333,8 +348,8 @@ export default { this.setFromObj() } - if ((this.stateName === 'ready_no_sync') || (this.stateName === 'buffering_no_sync')) this.noSyncUpdateTime = true - + if (this.stateName === 'ready_no_sync' || this.stateName === 'buffering_no_sync') this.noSyncUpdateTime = true + this.timeupdate() }, init() { diff --git a/components/app/StreamContainer.vue b/components/app/StreamContainer.vue index 6c1f22ac..832a4a06 100644 --- a/components/app/StreamContainer.vue +++ b/components/app/StreamContainer.vue @@ -15,15 +15,17 @@
- +
+
diff --git a/package.json b/package.json index 57a4cf63..d2a09f6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf-app", - "version": "v0.9.13-beta", + "version": "v0.9.14-beta", "author": "advplyr", "scripts": { "dev": "nuxt --hostname localhost --port 1337",