Skip to content

Commit

Permalink
correct deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Aug 14, 2020
1 parent 37ffcfc commit 9ddbcb2
Showing 1 changed file with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.exoplayer2.DefaultLoadControl
import com.google.android.exoplayer2.DefaultRenderersFactory
import com.google.android.exoplayer2.ExoPlayerFactory
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.source.ExtractorMediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.util.Util
Expand All @@ -24,12 +22,12 @@ import java.io.File
class VideoPlayerActivity : AppCompatActivity() {

private lateinit var exoPlayer: SimpleExoPlayer
private lateinit var uri: String
private var uri = ""

companion object {
fun start(activity: Activity, uri: String) {
val intent = Intent(activity, VideoPlayerActivity::class.java)
intent.putExtra("uri", uri)
.putExtra("uri", uri)
activity.startActivity(intent)
}
}
Expand All @@ -38,32 +36,29 @@ class VideoPlayerActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_video_player)

if (intent != null) {
val bundle: Bundle = intent.extras!!
uri = bundle.getString("uri", "")
intent?.extras?.let {
uri = it.getString("uri", "")
}

initializePlayer()

}

private fun initializePlayer() {

val trackSelector = DefaultTrackSelector()
val trackSelector = DefaultTrackSelector(this)
val loadControl = DefaultLoadControl()
val rendererFactory = DefaultRenderersFactory(this)

exoPlayer = ExoPlayerFactory.newSimpleInstance(
rendererFactory, trackSelector, loadControl
)
exoPlayer = SimpleExoPlayer.Builder(this, rendererFactory)
.setLoadControl(loadControl)
.setTrackSelector(trackSelector)
.build()
}

private fun play(uri: Uri) {

val userAgent = Util.getUserAgent(this, getString(R.string.app_name))
val mediaSource = ExtractorMediaSource
val mediaSource = ProgressiveMediaSource
.Factory(DefaultDataSourceFactory(this, userAgent))
.setExtractorsFactory(DefaultExtractorsFactory())
.createMediaSource(uri)

ep_video_view.player = exoPlayer
Expand All @@ -88,5 +83,4 @@ class VideoPlayerActivity : AppCompatActivity() {
exoPlayer.stop()
exoPlayer.release()
}

}

0 comments on commit 9ddbcb2

Please sign in to comment.