我已经创建了一个Vimeo帐户来托管我的视频,我想从Vimeo中检索我的视频以在我的Android应用中的Exoplayer中显示。这是我的代码,但无法检索视频源。
class VideoPlayerActivity : Activity() {
private lateinit var player: SimpleExoPlayer
private lateinit var mediaDataSourceFactory: DataSource.Factory
private var trackSelector: DefaultTrackSelector? = null
private var lastSeenTrackGroupArray: TrackGroupArray? = null
private val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory()
private var currentWindow: Int = 0
private var playbackPosition: Long = 0
private val ivHideControllerButton: ImageView by lazy { findViewById<ImageView>(R.id.exo_controller) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_video_player)
}
private fun initializePlayer() {
trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
mediaDataSourceFactory = DefaultDataSourceFactory(this, Util.getUserAgent(this, "mediaPlayerSample"))
val mediaSource = ExtractorMediaSource.Factory(mediaDataSourceFactory)
.createMediaSource(Uri.parse("https://vimeo.com/354191291/e72a0cc122"))
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector)
with(player) {
prepare(mediaSource, false, false)
playWhenReady = true
}
playerView.setShutterBackgroundColor(Color.TRANSPARENT)
playerView.player = player
playerView.requestFocus()
ivHideControllerButton.setOnClickListener { playerView.hideController() }
lastSeenTrackGroupArray = null
}
private fun updateStartPosition() {
with(player) {
playbackPosition = currentPosition
currentWindow = currentWindowIndex
playWhenReady = playWhenReady
}
}
private fun releasePlayer() {
updateStartPosition()
player.release()
trackSelector = null
}
public override fun onStart() {
super.onStart()
if (Util.SDK_INT > 23) initializePlayer()
}
public override fun onResume() {
super.onResume()
if (Util.SDK_INT <= 23) initializePlayer()
}
public override fun onPause() {
super.onPause()
if (Util.SDK_INT <= 23) releasePlayer()
}
public override fun onStop() {
super.onStop()
if (Util.SDK_INT > 23) releasePlayer()
}
}
我试图为此行检索Vimeo val mediaSource = ExtractorMediaSource.Factory(mediaDataSourceFactory) .createMediaSource(Uri.parse(“ https://vimeo.com/354191291/e72a0cc122”)) 但这对我不起作用。
答案 0 :(得分:0)
在此网址“ http://player.vimeo.com/video/vimeo-video-id-here/config”上调用vimeo api 并在响应此呼叫后获得视频的URL,然后您可以在Exoplayer上播放