在不使用 Android Youtube API 的情况下在 Android 应用程序中播放 Youtube 视频 [英] Play Youtube Video inside an Android App without using Android Youtube API

查看:32
本文介绍了在不使用 Android Youtube API 的情况下在 Android 应用程序中播放 Youtube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有另一种方法可以在不使用 Android Youtube API 的情况下在 Android 应用程序中播放 Youtube 视频?我们已经使用上述 API 实现了一个解决方案,但在某些设备上,它需要降级 Youtube 应用程序版本才能播放视频.我已经在 Github 中搜索了我可以使用的可能的库,但大多数都依赖于 Android Youtube API.还尝试使用 WebView 嵌入,但有时会崩溃.

Is there another way to play Youtube videos inside an Android App without using Android Youtube API? We already implemented a solution using the said API, but on some device it requires to downgrade the Youtube app version to play the video. I already searched in Github for possible library that I can use, but most it are dependent to Android Youtube API. Also tried to embed using WebView, but sometimes it crashes.

我正在通过解析来自 http://www.youtube 的结果来实施另一种解决方案.com/get_video_info?&video_id=p3ND_O6YYg4 并获取dashmpd"的值,然后加载dashmpd"的值,结果可以是在 Android 的 VideoView 中用作源,但它没有音频.我注意到视频和音频的来源不同.

I'm implementing another solution by parsing a result from http://www.youtube.com/get_video_info?&video_id=p3ND_O6YYg4 and get the value for "dashmpd", then load the value of "dashmpd" and the result can be used as a source in Android's VideoView, but it has no audio. I noticed that video and audio have different sources.

提前致谢!

推荐答案

我在使用 YouTube Player API 时也遇到了问题,因此我决定基于 Webview 构建自己的播放器库.它现已在 GitHub 上开源,您可以在此处找到它.

I also had problems with the YouTube Player API so I decided to build my own player library, based on Webview. It is now opensource on GitHub, you can find it here.

要开始,您只需要将库添加到您的依赖项中:

To get started you just need to add the library to your dependencies:

dependencies {
  implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:*last-version*'
}

将视图添加到您的布局:

Add the View to your layout:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.pierfrancescosoffritti.androidyoutubeplayer.player.YouTubePlayerView
        android:id="@+id/youtube_player_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

并初始化它:

YouTubePlayerView youtubePlayerView = findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youtubePlayerView);

youtubePlayerView.initialize(new YouTubePlayerInitListener() {
    @Override
    public void onInitSuccess(@NonNull final YouTubePlayer initializedYouTubePlayer) {
        initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() {
            @Override
            public void onReady() {
                String videoId = "6JYIGclVQdw";
                initializedYouTubePlayer.loadVideo(videoId, 0);
            }
        });
    }
}, true);

这篇关于在不使用 Android Youtube API 的情况下在 Android 应用程序中播放 Youtube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆