如何从 vimeo 帐户检索视频源以在 exoplayer android 中播放?

Posted

技术标签:

【中文标题】如何从 vimeo 帐户检索视频源以在 exoplayer android 中播放?【英文标题】:How to retrieve video source from vimeo account to play in exoplayer android? 【发布时间】:2019-12-22 18:16:07 【问题描述】:

我创建了 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")) 但它对我不起作用。

【问题讨论】:

【参考方案1】:

在此网址“http://player.vimeo.com/video/vimeo-video-id-here/config”上调用 vimeo Api 并响应此调用获取视频的 URL,然后您可以在 Exoplayer 上播放它

【讨论】:

以上是关于如何从 vimeo 帐户检索视频源以在 exoplayer android 中播放?的主要内容,如果未能解决你的问题,请参考以下文章

通过表单直接上传到 Vimeo

从 vimeo 获取视频缩略图

视频从 Dropbox 上传到 vimeo 服务器

如何在颤振中播放来自vimeo的私人视频

如何让 wordpress 用户直接上传到 youtube 或 vimeo?

如何从 vimeo 和 facebook 在 vi​​tamio 播放器中播放视频?