This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.kt
81 lines (71 loc) · 2.78 KB
/
MainActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.example.myapplication
import android.app.Activity
import android.os.Bundle
import android.os.Looper
import android.util.Log
import androidx.media3.common.DeviceInfo
import androidx.media3.common.Player
import androidx.media3.common.SimpleBasePlayer
import androidx.media3.session.MediaSession
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val player = MediaSessionPlayer()
MediaSession.Builder(this, player)
.setId("Playback")
.build()
}
}
class MediaSessionPlayer : SimpleBasePlayer(Looper.getMainLooper()) {
private var state = State.Builder()
.setAvailableCommands(
Player.Commands.Builder()
.addAll(
Player.COMMAND_PLAY_PAUSE,
Player.COMMAND_STOP,
Player.COMMAND_GET_DEVICE_VOLUME,
// Player.COMMAND_SET_DEVICE_VOLUME,
// Player.COMMAND_ADJUST_DEVICE_VOLUME,
Player.COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS,
Player.COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS,
)
.build()
)
.setDeviceInfo(
DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE)
.setMinVolume(0)
.setMaxVolume(20)
.build()
)
.setPlaylist(listOf(MediaItemData.Builder("placeholder").build()))
.setCurrentMediaItemIndex(0)
.setPlaybackState(Player.STATE_READY)
.setPlayWhenReady(true, PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST)
.setDeviceVolume(1)
.setIsDeviceMuted(false)
.build()
override fun getState(): State {
return this.state
}
override fun handleSetDeviceVolume(deviceVolume: Int, flags: Int): ListenableFuture<*> {
Log.d(LOG_TAG, "handleSetDeviceVolume: deviceVolume=$deviceVolume, flags=$flags")
return Futures.immediateVoidFuture()
}
override fun handleIncreaseDeviceVolume(flags: Int): ListenableFuture<*> {
Log.d(LOG_TAG, "handleIncreaseDeviceVolume: flags=$flags")
return Futures.immediateVoidFuture()
}
override fun handleDecreaseDeviceVolume(flags: Int): ListenableFuture<*> {
Log.d(LOG_TAG, "handleDecreaseDeviceVolume: flags=$flags")
return Futures.immediateVoidFuture()
}
override fun handleSetDeviceMuted(muted: Boolean, flags: Int): ListenableFuture<*> {
Log.d(LOG_TAG, "handleSetDeviceMuted: muted=$muted, flags=$flags")
return Futures.immediateVoidFuture()
}
companion object {
private const val LOG_TAG = "MediaSessionPlayer"
}
}