Android原生的vimeo视频播放

时间:2016-02-20 08:20:29

标签: android vimeo android-videoview vimeo-player vimeo-android

我正在开发原生android中的vimeo视频应用程序。但VideoView不支持此功能。我可以知道Android的任何示例或相关查询。我希望最终输出为.mp3 / .mp4格式。

我在Android iframe中尝试了WebView,它在Android WebView中运行良好,但我无法获得搜索栏。并且OnPause()无法暂停视频。 在这里,我可以获得暂停和播放按钮

enter image description here

示例:player.vimeo.com/video/49462103

我想在Android原生播放此视频

 <VideoView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/videoView"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

更新链接: Vimeo site Thread-1 Vimeo site Thread-2

enter image description here

我遇到了错误

3 个答案:

答案 0 :(得分:4)

Vimeo的嵌入代码应该在Android WebView中运行。 Vimeo仅为这些用户拥有的视频提供.mp4链接指向PRO用户。

另一种选择是使用official Deep Link library作为Android应用程序。这将允许您在Android应用中打开任何vimeo视频。

答案 1 :(得分:2)

您可以使用 Exoplayer 播放vimeo视频。 Exoplayer更可定制。您需要做的就是从视频配置链接中提取网址链接。您可以使用 retrofit 提取视频网址。

BASE_URL =“ https://player.vimeo.com/video/”

您将需要使用如下所示的get方法:

@GET("{id}/{config}")
Call<JsonObject>getVideoLink(@Path("id") String id, @Path("config") String config);

您将从视频链接获取ID。示例:“ https://vimeo.com/123456789/”,此处的ID为:123456789。

 JsonObject jsonObject = response.body();
            JsonObject req = jsonObject.getAsJsonObject("request");
            JsonObject file = req.getAsJsonObject("files");
            JsonArray arr = file.getAsJsonArray("progressive");
            String url = arr.get(0).getAsJsonObject().get("url").getAsString();

           // Build the media item.
            MediaItem mediaItem = MediaItem.fromUri(url);
            // Set the media item to be played.
            player.setMediaItem(mediaItem);
            // Prepare the player.
            player.prepare();
            // Start the playback.
            player.play();

别忘了先启动 Exoplayer

答案 2 :(得分:1)

我基于WebView为vimeo制作了本地播放器。支持公共和私人视频。

尝试:https://github.com/ct7ct7ct7/Android-VimeoPlayer

<com.ct7ct7ct7.androidvimeoplayer.view.VimeoPlayerView
    android:id="@+id/vimeoPlayer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>



VimeoPlayerView vimeoPlayer = findViewById(R.id.vimeoPlayer);
getLifecycle().addObserver(vimeoPlayer);

//public video
vimeoPlayer.initialize(59777392);

//If video is open. but limit playing at embedded.
vimeoPlayer.initialize({YourPrivateVideoId}, "SettingsEmbeddedUrl")

//If video is pirvate.
vimeoPlayer.initialize({YourPrivateVideoId},"VideoHashKey", "SettingsEmbeddedUrl")
相关问题