-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI for customizing playback params #63
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d581d43
basic player menu xml
daytime-em 03b8023
# This is a combination of 37 commits.
daytime-em ba7045c
squashed changes
daytime-em b9b89dc
Renaming
daytime-em de2c617
theemes
daytime-em d79c339
remove invalid menu items
daytime-em 5af251d
update label
daytime-em File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
187 changes: 187 additions & 0 deletions
187
app/src/main/java/com/mux/player/media3/examples/ConfigurablePlayerActivity.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 |
---|---|---|
@@ -0,0 +1,187 @@ | ||
package com.mux.player.media3.examples | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import android.widget.Toast | ||
import androidx.annotation.OptIn | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.media3.common.MediaItem | ||
import androidx.media3.common.MediaMetadata | ||
import androidx.media3.common.PlaybackException | ||
import androidx.media3.common.Player | ||
import androidx.media3.common.util.UnstableApi | ||
import com.mux.stats.sdk.core.model.CustomData | ||
import com.mux.stats.sdk.core.model.CustomerData | ||
import com.mux.stats.sdk.core.model.CustomerVideoData | ||
import com.mux.stats.sdk.core.model.CustomerViewData | ||
import com.mux.stats.sdk.core.util.UUID | ||
import com.mux.player.MuxPlayer | ||
import com.mux.player.media3.R | ||
import com.mux.player.media3.databinding.ActivityConfigurablePlayerBinding | ||
|
||
/** | ||
* A configurable example that uses the normal media3 player UI to play a video in the foreground from | ||
* Mux Video, using a Playback ID | ||
* | ||
* You can configure the Activity via the UI | ||
*/ | ||
class ConfigurablePlayerActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityConfigurablePlayerBinding | ||
private val playerView get() = binding.player | ||
|
||
private val playbackParamsHelper = PlaybackParamsHelper() | ||
|
||
private var player: MuxPlayer? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityConfigurablePlayerBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
if (savedInstanceState != null) { | ||
playbackParamsHelper.restoreInstanceState(savedInstanceState) | ||
} | ||
|
||
binding.configurablePlayerPlaybackIdIn.hint = playbackParamsHelper.playbackIdOrDefault() | ||
|
||
binding.configurablePlayerUpdateMediaItem.setOnClickListener { | ||
playbackParamsHelper.playbackId = binding.configurablePlayerPlaybackIdIn.text?.trim()?.toString() | ||
playbackParamsHelper.playbackToken = | ||
binding.configurablePlayerPlaybackTokenIn.text?.trim()?.toString() | ||
playbackParamsHelper.drmToken = binding.configurablePlayerDrmTokenIn.text?.trim()?.toString() | ||
playbackParamsHelper.customDomain = binding.configurablePlayerDomainIn.text?.trim()?.toString() | ||
|
||
maybePlayMediaItem(playbackParamsHelper.createMediaItem()) | ||
} | ||
binding.configurablePlaybackIdClear.setOnClickListener { | ||
binding.configurablePlayerPlaybackIdIn.text = null | ||
playbackParamsHelper.playbackId = null | ||
} | ||
binding.configurablePlayerDrmTokenClear.setOnClickListener { | ||
binding.configurablePlayerDrmTokenIn.text = null | ||
playbackParamsHelper.drmToken = null | ||
} | ||
binding.configurablePlayerPlaybackTokenClear.setOnClickListener { | ||
binding.configurablePlayerPlaybackTokenIn.text = null | ||
playbackParamsHelper.playbackToken = null | ||
} | ||
binding.configurablePlayerDomainClear.setOnClickListener { | ||
binding.configurablePlayerDomainIn.text = null | ||
playbackParamsHelper.customDomain = null | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
|
||
val mediaItem = playbackParamsHelper.createMediaItem() | ||
|
||
maybePlayMediaItem(mediaItem) | ||
} | ||
|
||
override fun onStop() { | ||
tearDownPlayer() | ||
|
||
super.onStop() | ||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
playbackParamsHelper.saveInstanceState(outState) | ||
|
||
super.onSaveInstanceState(outState) | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||
menuInflater.inflate(R.menu.basic_player_menu, menu) | ||
return true | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
val helperHandled = playbackParamsHelper.handleMenuClick(item) | ||
if (helperHandled) { | ||
val newMediaItem = playbackParamsHelper.createMediaItem() | ||
maybePlayMediaItem(newMediaItem) | ||
return true | ||
} else { | ||
return super.onOptionsItemSelected(item) | ||
} | ||
} | ||
|
||
private fun maybePlayMediaItem(mediaItem: MediaItem) { | ||
val item = mediaItem.buildUpon().setMediaMetadata(createMediaMetadata()).build() | ||
if (item != player?.currentMediaItem) { | ||
playSomething(item) | ||
} | ||
} | ||
|
||
private fun createMediaMetadata(): MediaMetadata { | ||
return MediaMetadata.Builder() | ||
.setTitle("Mux Player Example") | ||
.build() | ||
} | ||
|
||
private fun tearDownPlayer() { | ||
playerView.player = null | ||
player?.release() | ||
} | ||
|
||
private fun playSomething(mediaItem: MediaItem) { | ||
val player = createPlayer(this) | ||
player.setMediaItem(mediaItem) | ||
player.prepare() | ||
player.playWhenReady = true | ||
|
||
this.playerView.player = player | ||
this.player = player | ||
} | ||
|
||
@OptIn(UnstableApi::class) | ||
private fun createPlayer(context: Context): MuxPlayer { | ||
val out: MuxPlayer = MuxPlayer.Builder(context) | ||
.addMonitoringData( | ||
CustomerData().apply { | ||
customerViewData = CustomerViewData().apply { | ||
viewSessionId = UUID.generateUUID() | ||
} | ||
customerVideoData = CustomerVideoData().apply { | ||
videoSeries = "My Series" | ||
videoId = "abc1234zyxw" | ||
} | ||
customData = CustomData().apply { | ||
customData1 = "my custom metadata field" | ||
customData2 = "another custom metadata field" | ||
customData10 = "up to 10 custom fields" | ||
} | ||
} | ||
) | ||
.applyExoConfig { | ||
// Call ExoPlayer.Builder methods here | ||
setHandleAudioBecomingNoisy(true) | ||
setSeekBackIncrementMs(10_000) | ||
setSeekForwardIncrementMs(30_000) | ||
} | ||
.build() | ||
|
||
out.addListener(object : Player.Listener { | ||
override fun onPlayerError(error: PlaybackException) { | ||
// todo - better error info than this, inline in ui | ||
Log.e(TAG, "player error!", error) | ||
Toast.makeText( | ||
this@ConfigurablePlayerActivity, | ||
"Playback error! ${error.localizedMessage}", | ||
Toast.LENGTH_LONG | ||
).show() | ||
} | ||
}) | ||
|
||
return out | ||
} | ||
|
||
companion object { | ||
val TAG = ConfigurablePlayerActivity::class.simpleName | ||
} | ||
} |
115 changes: 0 additions & 115 deletions
115
app/src/main/java/com/mux/player/media3/examples/DrmPlaybackActivity.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. and soon a URL