Skip to content

Instantly share code, notes, and snippets.

View nazmulidris's full-sized avatar
🤙
❯ Write Rust 🦀 for r3bl-open-core ❯ rec 📹 live code vids developerlife YT chan

Nazmul Idris nazmulidris

🤙
❯ Write Rust 🦀 for r3bl-open-core ❯ rec 📹 live code vids developerlife YT chan
View GitHub Profile
<com.google.android.exoplayer2.ui.PlayerView
...
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/exoplayerview_activity_video"
app:use_artwork="true"
app:default_artwork="@drawable/loading"
app:show_timeout="5000"
app:fastforward_increment="10000"
app:rewind_increment="10000"
app:controller_layout_id="@layout/custom_playback_control_minimal" />
val mediaMap = mapOf<SourceType, Uri>(
local_audio to Uri.parse("asset:///audio/file.mp3"),
local_video to Uri.parse("asset:///video/file.mp4"),
http_audio to Uri.parse("http://site...file.mp3"),
http_video to Uri.parse("http://site...file.mp4")
)
enum class SourceType {
local_audio, local_video, http_audio, http_video, playlist;
// Create player
player = ExoPlayerFactory.newSimpleInstance(
// Renders audio, video, text (subtitles) content
DefaultRenderersFactory(ctx),
// Choose best audio, video, text track from available sources,
// based on bandwidth, device capabilities, language, etc
DefaultTrackSelector(),
// Manage buffering and loading data over the network
DefaultLoadControl()
).apply { ... }
class PlayerHolder(...) : AnkoLogger {
...
fun start() {
// Load media.
player.prepare(...)
// Restore state (after onResume()/onStart())
with(playerState) {
// Start playback when media has buffered enough
// (whenReady is true by default).
player.playWhenReady = whenReady
data class PlayerState(var window: Int = 0,
var position: Long = 0,
var whenReady: Boolean = true,
var source: SourceType = local_audio)
class VideoActivity : AppCompatActivity() {
lateinit var playerHolder: PlayerHolder
val state = PlayerState()
override fun onCreate(savedInstanceState: Bundle?) {
...
playerHolder = PlayerHolder(this, exoplayerview_activity_video, state)
}
fun stop() {
player.stop(true)
info { "SimpleExoPlayer is stopped" }
}
fun release() {
player.release()
info { "SimpleExoPlayer is released" }
}
<com.google.android.exoplayer2.ui.PlayerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/exoplayerview_activity_video"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
enum class SourceType {
local_audio, local_video, http_audio, http_video, playlist;
}
data class PlayerState(var window: Int = 0,
var position: Long = 0,
var whenReady: Boolean = true,
var source: SourceType = local_audio)
class PlayerHolder(val context: Context,
public class MyService extends Service{
private void commandStart() {
if (!mServiceIsStarted) {
moveToStartedState();
return;
}
if (mExecutor == null) {