Initial commit
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// android/app/src/main/kotlin/pt/ruifpb/openvinyl/MainActivity.kt
|
||||
//
|
||||
// MethodChannel pt.ruifpb.openvinyl/media_control
|
||||
// hasPermission() → Boolean
|
||||
// requestPermission() → Unit
|
||||
// getCurrentMedia() → Map?
|
||||
// playPause() → Unit ← NEW: sends play/pause to active MediaSession
|
||||
|
||||
package pt.ruifpb.openvinyl
|
||||
|
||||
import android.content.Intent
|
||||
import android.provider.Settings
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.EventChannel
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
|
||||
private val methodChannelName = "pt.ruifpb.openvinyl/media_control"
|
||||
private val eventChannelName = "pt.ruifpb.openvinyl/media_events"
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, methodChannelName)
|
||||
.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"hasPermission" -> result.success(MediaListenerService.isEnabled(this))
|
||||
"requestPermission" -> {
|
||||
startActivity(
|
||||
Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
)
|
||||
result.success(null)
|
||||
}
|
||||
"getCurrentMedia" -> result.success(MediaListenerService.lastMediaMap)
|
||||
"playPause" -> {
|
||||
MediaListenerService.sendPlayPause()
|
||||
result.success(null)
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
EventChannel(flutterEngine.dartExecutor.binaryMessenger, eventChannelName)
|
||||
.setStreamHandler(object : EventChannel.StreamHandler {
|
||||
override fun onListen(args: Any?, sink: EventChannel.EventSink) {
|
||||
MediaListenerService.eventSink = sink
|
||||
}
|
||||
override fun onCancel(args: Any?) {
|
||||
MediaListenerService.eventSink = null
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user