使用iframe自动播放暂停视频的Android webview

时间:2018-03-15 10:08:55

标签: android youtube-iframe-api

我正在使用这个库在android tv上播放YouTube视频。视频播放正常。但是,当任何用户触摸或点击视频时,它会暂停并在另一次点击时再次播放。我试图让它不可点击: mWebView.setOnTouchListener(new View.OnTouchListener(){     @override     public boolean onTouch(View v,MotionEvent event){         返回false;     } }); mWebView.setClickable(假); mWebView.setEnabled(假); mWebView.setFocusableInTouchMode(假); mWebView.setFocusable(假); 但这不起作用。

1 个答案:

答案 0 :(得分:0)

  1. 布局文件main_activity.xml
  2. <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:fitsSystemWindows="true"
        tools:context="it.tranvantung.stackoverflow.MainActivity">
        <fr.bmartel.youtubetv.YoutubeTvView
            android:id="@+id/youtube_video"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:yt_autoplay="true"
            app:yt_videoId="kjkTvbYvglQ" />
    </LinearLayout>

    1. 我的活动:您可以从WebView获取YoutubeTvView并停用触摸功能。
    2.     YoutubeTvView youtubeTvView;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              youtubeTvView = findViewById(R.id.youtube_video);
              WebView youtubeWebview = youtubeTvView.findViewById(R.id.youtube_view);
              youtubeWebview.setOnTouchListener(new View.OnTouchListener() {
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                      return true;
                  }
              });
          }

      1. 清单文件:添加android:hardwareAccelerated="true"
      2. <activity android:name=".MainActivity"
                    android:hardwareAccelerated="true">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
        </activity>
        4. build.gradle

        compile 'fr.bmartel:youtubetv:1.2'

相关问题