1

I am trying to play a youtube clip in a WebView inside aFragment.

It is lodiong fine however when I try and play it I only hear the youtube clip and the video doesn't play. Also I see a blue screen over the webview when I press play. see image: enter image description here

Also here is my Fragment:

public class WebViewerFragment extends Fragment{
private WebView mWebView;
private String mWebURL;

private ProgressBar mProgressBar;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    if (container == null)
    {
        return null;
    }


    View view = inflater.inflate(R.layout.utube_viewer_layout, container, false);
    mWebView = (WebView) view.findViewById(R.id.utube_wv);
    mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar_YouTube);

    return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState)
{

    super.onActivityCreated(savedInstanceState);

    mWebView.setWebViewClient(new myWebClient());

    WebSettings ws = mWebView.getSettings();
    ws.setBuiltInZoomControls(true);
    ws.setJavaScriptEnabled(true);
    ws.setPluginState(PluginState.ON);
    ws.setPluginsEnabled(true);
    mWebView.loadUrl("http://www.youtube.com/watch?v=LD-67jlsY9I");

}



public class myWebClient extends WebViewClient
{
        @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        mWebView.setWebViewClient(new myWebClient());
        return false;
    }
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon)
    {
         view.setVisibility(View.GONE);
         mProgressBar.setVisibility(view.VISIBLE);
    }

    @Override
    public void onPageFinished(WebView view, String url)
    {
        view.setVisibility(View.VISIBLE);
        mProgressBar.setVisibility(view.GONE);
    }

}}
user1163234
  • 2,407
  • 6
  • 35
  • 63
  • alternatively you could use the YouTube Android Player that should give an all together better user experience: https://developers.google.com/youtube/android/player/ – Budius Mar 04 '14 at 12:55
  • I tried that but I need to invoke from Fragment doesnt seem like this is supported... – user1163234 Mar 04 '14 at 12:56
  • the player is just a normal `ViewGroup` in android: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerView I used before in a `ViewPager` with a `FragmentPagerAdapter` and that gave me some life-cycle issues, but if you're not using ViewPager it works fine. – Budius Mar 04 '14 at 12:58

0 Answers0