-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add output switcher button to player screen on Android
- Loading branch information
1 parent
8ac5dcf
commit bfa9027
Showing
6 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 50 additions & 2 deletions
52
android/app/src/main/kotlin/com/unicornsonlsd/finamp/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,54 @@ | ||
package com.unicornsonlsd.finamp | ||
|
||
import androidx.annotation.NonNull | ||
import androidx.mediarouter.app.SystemOutputSwitcherDialogController | ||
import androidx.mediarouter.media.MediaRouter | ||
import com.ryanheise.audioservice.AudioServiceActivity | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
class MainActivity: FlutterActivity() { | ||
} | ||
class MainActivity: AudioServiceActivity() { | ||
private val CHANNEL = "com.unicornsonlsd.finamp/output_switcher" | ||
|
||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result -> | ||
println("calling method: '${call.method}'") | ||
if (call.method == "showOutputSwitcherDialog") { | ||
showOutputSwitcherDialog() | ||
result.success(null) | ||
} else if (call.method == "getRoutes") { | ||
val router = MediaRouter.getInstance(this) | ||
val routes = router.routes | ||
routes.forEach { route -> | ||
println("Route: ${route.name}, connection state: ${route.connectionState}, system route: ${route.isSystemRoute}, default: ${route.isDefault}, device speaker: ${route.isDeviceSpeaker}, bluetooth: ${route.isBluetooth}, volume: ${route.volume}, provider: ${route.provider.packageName}") | ||
} | ||
} else if (call.method == "setOutputToDeviceSpeaker") { | ||
val router = MediaRouter.getInstance(this) | ||
val routes = router.getRoutes() | ||
routes.forEach { route -> | ||
println("Route: ${route.name}, connection state: ${route.connectionState}, system route: ${route.isSystemRoute}, default: ${route.isDefault}, device speaker: ${route.isDeviceSpeaker}, bluetooth: ${route.isBluetooth}, volume: ${route.volume}, provider: ${route.provider.packageName}") | ||
} | ||
val deviceSpeakerRoute = routes.first { route -> route.isDeviceSpeaker } | ||
router.selectRoute(deviceSpeakerRoute) | ||
} else if (call.method == "setOutputToBluetoothDevice") { | ||
val router = MediaRouter.getInstance(this) | ||
val routes = router.getRoutes() | ||
routes.forEach { route -> | ||
println("Route: ${route.name}, connection state: ${route.connectionState}, system route: ${route.isSystemRoute}, default: ${route.isDefault}, device speaker: ${route.isDeviceSpeaker}, bluetooth: ${route.isBluetooth}, volume: ${route.volume}, provider: ${route.provider.packageName}") | ||
} | ||
val bluetoothRoute = routes.first { route -> route.isBluetooth } | ||
router.selectRoute(bluetoothRoute) | ||
} | ||
else { | ||
println("Method not found: '${call.method}'") | ||
result.notImplemented() | ||
} | ||
} | ||
} | ||
|
||
private fun showOutputSwitcherDialog() { | ||
SystemOutputSwitcherDialogController.showDialog(this) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters