У меня плеер работает, но его нет в панели уведомлений. Из того, что мне сказали, мне нужно создать службу, которая добавила бы медиаплеер в раздел уведомлений пользователя.
package com.exaple.mediatest
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ui.PlayerView
class MainActivity : AppCompatActivity() {
private val player: SimpleExoPlayer by lazy { SimpleExoPlayer.Builder(this).build()}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val playerView = findViewById<PlayerView>(R.id.mediaplayer)
playerView.setPlayer(player);
val mediaItem: MediaItem = MediaItem.fromUri("https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4")
player.setMediaItem(mediaItem)
player.prepare()
player.play()
}
}
Как видите, это очень простой видеоплеер.
Мой main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/mediaplayer"
android:layout_width="match_parent"
android:layout_height="match_parent"
></com.google.android.exoplayer2.ui.PlayerView>
</androidx.constraintlayout.widget.ConstraintLayout>