mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Rename top level directories
This commit is contained in:
parent
256bda1b72
commit
674ce19414
90 changed files with 0 additions and 0 deletions
31
player/.gitignore
vendored
Normal file
31
player/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# VS Code related
|
||||
.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
**/*.g.dart
|
||||
**/doc/api/
|
||||
.dart_tool/
|
||||
pubspec.lock
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
.packages
|
||||
.pub-cache/
|
||||
.pub/
|
||||
/build/
|
||||
8
player/android/.gitignore
vendored
Normal file
8
player/android/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
gradle-wrapper.jar
|
||||
/.gradle
|
||||
/gradle
|
||||
/captures/
|
||||
/gradlew
|
||||
/gradlew.bat
|
||||
/local.properties
|
||||
GeneratedPluginRegistrant.java
|
||||
43
player/android/build.gradle
Normal file
43
player/android/build.gradle
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
group 'de.johrpan.musicus_player'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.50'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
}
|
||||
lintOptions {
|
||||
disable 'InvalidPackage'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
||||
4
player/android/gradle.properties
Normal file
4
player/android/gradle.properties
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
org.gradle.jvmargs=-Xmx1536M
|
||||
android.enableR8=true
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
1
player/android/settings.gradle
Normal file
1
player/android/settings.gradle
Normal file
|
|
@ -0,0 +1 @@
|
|||
rootProject.name = 'musicus_player'
|
||||
3
player/android/src/main/AndroidManifest.xml
Normal file
3
player/android/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.johrpan.musicus_player">
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package de.johrpan.musicus_player
|
||||
|
||||
import android.content.Context
|
||||
import android.media.MediaPlayer
|
||||
import android.net.Uri
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||
import io.flutter.plugin.common.MethodChannel.Result
|
||||
import io.flutter.plugin.common.PluginRegistry.Registrar
|
||||
|
||||
public class MusicusPlayerPlugin: FlutterPlugin, MethodCallHandler {
|
||||
private lateinit var channel: MethodChannel
|
||||
private lateinit var context: Context
|
||||
|
||||
private var playing = false
|
||||
private var uri: Uri? = null
|
||||
private var mediaPlayer: MediaPlayer? = null
|
||||
|
||||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel = MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "de.johrpan.musicus_player/platform")
|
||||
channel.setMethodCallHandler(this)
|
||||
context = flutterPluginBinding.getApplicationContext()
|
||||
}
|
||||
|
||||
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
|
||||
if (call.method == "setUri") {
|
||||
val newUri = Uri.parse(call.argument<String>("uri"))
|
||||
uri = newUri
|
||||
|
||||
if (mediaPlayer != null) {
|
||||
mediaPlayer?.release()
|
||||
}
|
||||
|
||||
mediaPlayer = MediaPlayer.create(context, uri)
|
||||
mediaPlayer?.setOnCompletionListener {
|
||||
channel.invokeMethod("onComplete", null)
|
||||
}
|
||||
|
||||
if (playing) {
|
||||
mediaPlayer?.start()
|
||||
}
|
||||
|
||||
result.success(mediaPlayer?.getDuration())
|
||||
} else if (call.method == "play") {
|
||||
playing = true
|
||||
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 == "seekTo") {
|
||||
// TODO: Check, if mediaPlayer is in a valid state.
|
||||
mediaPlayer?.seekTo(call.argument("positionMs")!!)
|
||||
result.success(null)
|
||||
} else if (call.method == "pause") {
|
||||
playing = false
|
||||
mediaPlayer?.pause()
|
||||
result.success(null)
|
||||
} else if (call.method == "stop") {
|
||||
playing = false
|
||||
uri = null
|
||||
mediaPlayer?.release()
|
||||
mediaPlayer = null
|
||||
result.success(null)
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel.setMethodCallHandler(null)
|
||||
}
|
||||
}
|
||||
61
player/lib/musicus_player.dart
Normal file
61
player/lib/musicus_player.dart
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
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.
|
||||
final void Function() onComplete;
|
||||
|
||||
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,
|
||||
}) {
|
||||
_channel.setMethodCallHandler(_handleMethodCall);
|
||||
}
|
||||
|
||||
Future<void> _handleMethodCall(MethodCall call) async {
|
||||
if (call.method == 'onComplete' && onComplete != null) {
|
||||
onComplete();
|
||||
}
|
||||
}
|
||||
|
||||
/// Set URI of the audio file to play.
|
||||
///
|
||||
/// 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<int> setUri(String uri) async {
|
||||
return await _channel.invokeMethod('setUri', {'uri': uri});
|
||||
}
|
||||
|
||||
/// Play from the current URI and resume playback if previously paused.
|
||||
Future<void> play() async {
|
||||
await _channel.invokeMethod('play');
|
||||
}
|
||||
|
||||
/// Get the current playback position in milliseconds.
|
||||
Future<int> getPosition() async {
|
||||
return await _channel.invokeMethod('getPosition');
|
||||
}
|
||||
|
||||
/// Seek to a new position, which should be provided in milliseconds.
|
||||
Future<void> seekTo(int positionMs) async {
|
||||
await _channel.invokeMethod('seekTo', {'positionMs': positionMs});
|
||||
}
|
||||
|
||||
/// Pause playback.
|
||||
Future<void> pause() async {
|
||||
await _channel.invokeMethod('pause');
|
||||
}
|
||||
|
||||
/// Stop the player.
|
||||
Future<void> stop() async {
|
||||
await _channel.invokeMethod('stop');
|
||||
}
|
||||
}
|
||||
17
player/pubspec.yaml
Normal file
17
player/pubspec.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
name: musicus_player
|
||||
description: A simple music player for Musicus.
|
||||
version: 0.0.1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.3.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
flutter:
|
||||
plugin:
|
||||
platforms:
|
||||
android:
|
||||
package: de.johrpan.musicus_player
|
||||
pluginClass: MusicusPlayerPlugin
|
||||
Loading…
Add table
Add a link
Reference in a new issue