WebView에서 YouTube 동영상이 재생되지 않음 - Android

웹뷰에서 유튜브 동영상을 재생하려고 하는데, 웹뷰에서 재생 버튼으로 동영상의 첫 화면이 표시되는데, 재생 버튼을 클릭하면 진행률 표시줄이 시작되고 2~3초 후 진행률 표시줄이 멈추고 검은색으로 화면이 비어 있습니다.

이미지1: 재생 버튼이 있는 동영상 첫 화면

Image2: 재생 버튼을 클릭한 후 화면이 비어 있습니다.

제발! 비디오가 시작되지 않는 이유를 도와주세요.

IMAGE:1

IMAGE:2

이것은 웹 뷰에서 YouTubeVideo를 재생하는 소스 코드입니다 ... 제발 도와주세요 ...

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    WebView wv = (WebView) findViewById(R.id.webView1);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setPluginsEnabled(true);
    final String mimeType = "text/html";
    final String encoding = "UTF-8";
    String html = getHTML();
    wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
}

public String getHTML() {
    String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"http://www.youtube.com/embed/"
            + "J2fB5XWj6IE"
            + "?fs=0\" frameborder=\"0\">\n"
            + "</iframe>\n";
    return html;
}
질문에 대한 의견 (7)
해결책

웹뷰에 HTML 콘텐츠를 로드하기 전에 이 줄을 추가합니다.

wv.setWebChromeClient(new WebChromeClient() {
});

문서에서 가져옵니다:

애플리케이션에서 인라인 HTML5 비디오를 지원하려면 하드웨어 가속을 켜고 웹크롬클라이언트를 설정해야 합니다. 전체 화면 지원을 위해서는 onShowCustomView(View, WebChromeClient.CustomViewCallback) 및 onHideCustomView()의 구현이 필요하며, getVideoLoadingProgressView()는 선택 사항입니다.

해설 (5)

다음의 코드는 비디오 플레이어를 통해 필요한 핵심 표시하십시오 시작됨인 웹 프레임워크이다. 전체 흐름을 데 있어 가장 중요한 것은 비데로비에프 통과하면 백됩니다 웹크롬클리나 첨부하려면 데이터베이스에구성원을 보기 보기 계층에 있는 합니다.

  • I have it 어셈블된 검토하든 통해 소스 코드를 브라우저에 AOSP.* 일환으로 사용 가능

이 코드는 참조입니다 않을 수 있는 4 뷰 명백하네. 보기입니다 계층 구조가:

프라메라리우스 마콘텐트비에프 (루트) '-'

  • '웹보기 마웹비에프' (child of 마콘텐트비에프)
  • '프라메라리우스 마커스트롬비스콘타이너' (child of 마콘텐트비에프)
  • 마커스트롬비에프 '보기' (child of 마커스트롬비스콘타이너)

뷰 구성했는지 설정 작업의 일환으로 컨테이너입니다 활동까지입니다.







언크리치 활동 '에':

    mContentView = (FrameLayout) findViewById(R.id.main_content);
    mWebView = (WebView) findViewById(R.id.webView);
    mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);

등록 '을 (를)' '웹크롬클리나 마웹비에프'. 그 다음 2 - 4 메서드을 클라이언트입니다 재지정하지 합니다.

void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
{
    // if a view already exists then immediately terminate the new one
    if (mCustomView != null)
    {
        callback.onCustomViewHidden();
        return;
    }

    // Add the custom view to its container.
    mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
    mCustomView = view;
    mCustomViewCallback = callback;

    // hide main browser view
    mContentView.setVisibility(View.GONE);

    // Finally show the custom view container.
    mCustomViewContainer.setVisibility(View.VISIBLE);
    mCustomViewContainer.bringToFront();
}

void onHideCustomView()
{
    if (mCustomView == null)
        return;

    // Hide the custom view.
    mCustomView.setVisibility(View.GONE);
    // Remove the custom view from its container.
    mCustomViewContainer.removeView(mCustomView);
    mCustomView = null;
    mCustomViewContainer.setVisibility(View.GONE);
    mCustomViewCallback.onCustomViewHidden();

    // Show the content view.
    mContentView.setVisibility(View.VISIBLE);
}

public Bitmap getDefaultVideoPoster()
{
    if (mDefaultVideoPoster == null)
    {
        mDefaultVideoPoster = BitmapFactory.decodeResource(getResources(), R.drawable.default_video_poster);
    }
    return mDefaultVideoPoster;
}

public View getVideoLoadingProgressView()
{
    if (mVideoProgressView == null)
    {
        LayoutInflater inflater = LayoutInflater.from(this);
        mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
    }
    return mVideoProgressView;
}

다음과 같은 활동 주기 때문에 추가할 수도 있습니다.

@Override
protected void onStop()
{
    super.onStop();
    if (mCustomView != null)
    {
        if (mCustomViewCallback != null)
            mCustomViewCallback.onCustomViewHidden();
        mCustomView = null;
    }
}

@Override
public void onBackPressed()
{
    if (mCustomView != null)
    {
        onHideCustomView();
    } else
    {
        finish();
    }
}

데이터베이스에구성원을 활동 할 수 있는 비디오 숨기십시오 활동이 다시 버튼을 누를 때 중지되었거나.

해설 (3)

추가 (새 웹크롬클리나 (), '와' 웨브리웨인세웹크롬클리나 활성하하려면 플러그인 비디오에 대한 추가

if (Build.VERSION.SDK_INT < 8) {
            webview.getSettings().setPluginsEnabled(true);
        } else {
            webview.getSettings().setPluginState(PluginState.ON);
        }

스나크스

해설 (2)

모바일 기기에서 스트리밍되는 유튜브 동영상에 문제가 있습니다. 웹 보기에서 URL을 직접 로드하고 실행하려고 하면 동영상이 재생되지 않습니다. 이 문제를 해결하는 어려운 방법 중 하나는 비디오 보기에서 비디오를 스트리밍하는 것입니다. 이 방법을 시도해 보지는 않았지만 시도해 볼 수 있습니다. 유튜브 동영상을 재생하는 다른 방법으로는 웹 보기 설정에서 사용자 에이전트를 모바일 기기에서 데스크톱으로 변경하는 것이 더 쉬운 방법이라고 할 수 있습니다. 사용자 에이전트는 유튜브 동영상이 실행될 기기 유형을 나타내며 그에 따라 해당 종류의 웹 페이지가 서버에서 전송됩니다. 이렇게 하면 유튜브 동영상을 스트리밍하고 재생할 수 있습니다. 이를 수행하는 방법은 다음과 같습니다;

public static final int USER_MOBILE  = 0;
public static final int USER_DESKTOP = 1;
wv.getSettings().setUserAgent(USER_DESKTOP);   // 1 is for the desktop
해설 (2)

내가 이 복사됨 아스케르 코드와 가져다줄래요 통했다. 와-u 지불인 플래시할 설치할 필요가 있다고 생각한다. 디 와-u?? 그래서 와-u 추가 인터넷 사용 권한???

내 코드를 브트와 여기 있습니다.

package com.example.youtube;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.util.Log;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebChromeClient;
import android.webkit.WebViewClient;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AbsoluteLayout;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.TextView;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
public class MainActivity extends Activity{

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().requestFeature(Window.FEATURE_PROGRESS);

            setContentView(R.layout.activity_main);

final ProgressBar Pbar;

Pbar = (ProgressBar) findViewById(R.id.pB4);
WebView wv = (WebView) findViewById(R.id.webVie1);
//wv.setWebViewClient(new Callback());
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(true);
//wv.setBackgroundColor(0x919191);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = getHTML();
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");

final Activity activity = this;

wv.setWebChromeClient(new WebChromeClient() {
       public void onProgressChanged(WebView view, int progress) {
         // Activities and WebViews measure progress with different scales.
         // The progress meter will automatically disappear when we reach 100%

         activity.setProgress(progress * 100);
         {
             if(progress < 100 && Pbar.getVisibility() == ProgressBar.GONE){
                 Pbar.setVisibility(ProgressBar.VISIBLE);

             }
             Pbar.setProgress(progress);
             if(progress == 100) {
                 Pbar.setVisibility(ProgressBar.GONE);

             }
          }
       }
     });
     wv.setWebViewClient(new WebViewClient() {
       public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
         Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_LONG).show();
       }
     });
     wv.setDownloadListener(new DownloadListener()
     {

        public void onDownloadStart(String url, String userAgent,String contentDisposition, String mimetype,long contentLength)
         {
             Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

             startActivity(intent);   
         }

     });

}

    private String getHTML() {
        // TODO Auto-generated method stub
        String html1 = "\n"
                + "\n";
        return html1;
    }

  /*  public void onPause()
    {
        super.onPause();
        System.exit(0);
    }*/

}

레이아웃 파일

<?xml version="1.0" encoding="utf-8"?>








 />
해설 (0)

하지만 내 웹보기 javascript 활성화됨 제거 작업을 하고 있던 비디오

        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
해설 (0)

웹뷰에서 유튜브 동영상을 재생하려는 이유는 무엇인가요? 다음 의도를 사용하여 재생할 수 있습니다.

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(stringUrl)));

그렇지 않으면 웹뷰에서 재생하려면 다음 링크를 따르세요.

https://stackoverflow.com/questions/9565533/android-how-to-play-youtube-video-in-webview?rq=1

해설 (0)

이 번호요 시도하시겠습니까

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(stringUrl)));
해설 (0)