mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
player: Keep playback state after URI change
This commit is contained in:
parent
4c0bcb9d26
commit
c8bf158985
1 changed files with 8 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ public class MusicusPlayerPlugin: FlutterPlugin, MethodCallHandler {
|
||||||
private lateinit var channel: MethodChannel
|
private lateinit var channel: MethodChannel
|
||||||
private lateinit var context: Context
|
private lateinit var context: Context
|
||||||
|
|
||||||
|
private var playing = false
|
||||||
private var uri: Uri? = null
|
private var uri: Uri? = null
|
||||||
private var mediaPlayer: MediaPlayer? = null
|
private var mediaPlayer: MediaPlayer? = null
|
||||||
|
|
||||||
|
|
@ -40,8 +41,13 @@ public class MusicusPlayerPlugin: FlutterPlugin, MethodCallHandler {
|
||||||
channel.invokeMethod("onComplete", null)
|
channel.invokeMethod("onComplete", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (playing) {
|
||||||
|
mediaPlayer?.start()
|
||||||
|
}
|
||||||
|
|
||||||
result.success(mediaPlayer?.getDuration())
|
result.success(mediaPlayer?.getDuration())
|
||||||
} else if (call.method == "play") {
|
} else if (call.method == "play") {
|
||||||
|
playing = true
|
||||||
mediaPlayer?.start()
|
mediaPlayer?.start()
|
||||||
result.success(null)
|
result.success(null)
|
||||||
} else if (call.method == "getPosition") {
|
} else if (call.method == "getPosition") {
|
||||||
|
|
@ -52,9 +58,11 @@ public class MusicusPlayerPlugin: FlutterPlugin, MethodCallHandler {
|
||||||
mediaPlayer?.seekTo(call.argument("positionMs")!!)
|
mediaPlayer?.seekTo(call.argument("positionMs")!!)
|
||||||
result.success(null)
|
result.success(null)
|
||||||
} else if (call.method == "pause") {
|
} else if (call.method == "pause") {
|
||||||
|
playing = false
|
||||||
mediaPlayer?.pause()
|
mediaPlayer?.pause()
|
||||||
result.success(null)
|
result.success(null)
|
||||||
} else if (call.method == "stop") {
|
} else if (call.method == "stop") {
|
||||||
|
playing = false
|
||||||
uri = null
|
uri = null
|
||||||
mediaPlayer?.release()
|
mediaPlayer?.release()
|
||||||
mediaPlayer = null
|
mediaPlayer = null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue