diff --git a/musicus_player/android/src/main/kotlin/de/johrpan/musicus_player/MusicusPlayerPlugin.kt b/musicus_player/android/src/main/kotlin/de/johrpan/musicus_player/MusicusPlayerPlugin.kt index be3f0cc..ac3d782 100644 --- a/musicus_player/android/src/main/kotlin/de/johrpan/musicus_player/MusicusPlayerPlugin.kt +++ b/musicus_player/android/src/main/kotlin/de/johrpan/musicus_player/MusicusPlayerPlugin.kt @@ -40,10 +40,13 @@ public class MusicusPlayerPlugin: FlutterPlugin, MethodCallHandler { channel.invokeMethod("onComplete", null) } - result.success(null) + result.success(mediaPlayer?.getDuration()) } else if (call.method == "play") { mediaPlayer?.start() result.success(null) + } else if (call.method == "getPosition") { + // TODO: Check, if mediaPlayer is in a valid state. + result.success(mediaPlayer?.getCurrentPosition()) } else if (call.method == "pause") { mediaPlayer?.pause() result.success(null) diff --git a/musicus_player/lib/musicus_player.dart b/musicus_player/lib/musicus_player.dart index 65ad497..7a0bdc3 100644 --- a/musicus_player/lib/musicus_player.dart +++ b/musicus_player/lib/musicus_player.dart @@ -1,7 +1,7 @@ import 'package:flutter/services.dart'; /// A simple music player. -/// +/// /// Give it an URI using [setUri] and it will start playing. class MusicusPlayer { /// Called, when the player reaches the end of the audio file. @@ -10,10 +10,12 @@ class MusicusPlayer { final _channel = MethodChannel('de.johrpan.musicus_player/platform'); /// Create a new player. - /// + /// /// This will do nothing, until [setUri] was called. If the player reaches /// the end of the current audio file, [onComplete] will be called. - MusicusPlayer({this.onComplete}) { + MusicusPlayer({ + this.onComplete, + }) { _channel.setMethodCallHandler(_handleMethodCall); } @@ -24,11 +26,12 @@ class MusicusPlayer { } /// Set URI of the audio file to play. - /// - /// If the player will always stop doing, what it did before, and start - /// playing from the provided URI if possible. - Future setUri(String uri) async { - await _channel.invokeMethod('setUri', {'uri': uri}); + /// + /// The player will always stop doing, what it did before, and start + /// playing from the provided URI if possible. The return value is the + /// duration of the new track in milliseconds. + Future setUri(String uri) async { + return await _channel.invokeMethod('setUri', {'uri': uri}); } /// Play from the current URI and resume playback if previously paused. @@ -36,6 +39,11 @@ class MusicusPlayer { await _channel.invokeMethod('play'); } + /// Get the current playback position in milliseconds. + Future getPosition() async { + return await _channel.invokeMethod('getPosition'); + } + /// Pause playback. Future pause() async { await _channel.invokeMethod('pause');