【问题标题】:How to Play Youtube Playlist Intent Videos in Full Screen如何全屏播放 Youtube 播放列表意图视频
【发布时间】:2016-10-18 14:29:14
【问题描述】:

我是 android 的初学者,正在开发一个应用程序,我在其中使用 YouTubePlayer API 来显示特定播放列表的 Youtube 视频。我这样做是成功的。但我想要的是,每当用户从该播放列表中选择任何视频时;视频应该全屏播放。这是我的代码:

public class Main4Activity extends AppCompatActivity
{
    Toolbar main_toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        main_toolbar=(Toolbar) findViewById(R.id.my_thirdtoolbar);
        setSupportActionBar(main_toolbar);
        getSupportActionBar().setTitle(R.string.my_tb_title);
        getSupportActionBar().setIcon(R.drawable.tblogo);
        OnClickButtonListener();
    }

    public void OnClickButtonListener()
    {
        Button youtubebtn = (Button) findViewById(R.id.button8);
        youtubebtn.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                String PLAYLIST_ID = "PLXRActLQ03oY_6AQb-5EMuKFYQA_fDE40";
                Intent intent=YouTubeIntents.createOpenPlaylistIntent(Main4Activity.this,PLAYLIST_ID);
                startActivity(intent);

            }
        }
        );
    }
}

【问题讨论】:

    标签: android android-studio youtube-api


    【解决方案1】:

    您可以使用来自YouTubeIntents 的方法。以下是您可以使用的一些方法:

    • canResolvePlayVideoIntentWithOptions (Context context)

      在解析播放视频意图时检查安装在用户设备上的 YouTube 应用程序是否支持 fullscreenfinishOnEnd 可选参数。

      • 如果此方法返回true,那么您的应用程序可以调用createPlayVideoIntentWithOptions(Context context, String videoId, boolean fullscreen, boolean finishOnEnd) 方法,该方法会创建一个Intent,在解决该Intent 后,将开始在YouTube 应用程序中播放videoId 指定的视频。
      • 如果此方法返回false,那么您的应用程序应改为调用createPlayVideoIntent(Context context, String videoId) 方法。

    此外,还请检查其他实现并尝试此SO post 中建议的解决方案。希望对您有所帮助!

    【讨论】:

    • 我使用了 createPlayVideoIntent 方法。它显示播放列表,但我希望当用户点击该播放列表中的任何视频时,它将全屏播放
    • 你也用过canResolvePlayVideoIntentWithOptions()的方法吗?
    • 我已经发布了上面的代码。我只使用了一种方法来显示特定的播放列表视频。
    • 正如我提供的文档中所述,在发送意图之前使用canResolve 方法,以确保用户的设备具有支持给定意图的 YouTube 应用程序版本。跨度>
    猜你喜欢
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2012-12-26
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多