0

I'm working on a small app using YouTube API & webview to load the channel's chat, now there is no errors everything loads fine I can see the video I can see the chat fine but when I try to interact with the chat it doesn't seems to work, I have tried many things but nothing seems to work and I was wondering if anybody could give me a hand solving this issue.

LiveTube.java

package com.live.tube;

import com.live.tube.R;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;

import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class LiveTube extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
private YouTubePlayer YPlayer;
private static final String YoutubeDeveloperKey = "AIzaSyBMwV1heA9q55LybRCK5dXXTJWADRbmDh4";
private static final int RECOVERY_DIALOG_REQUEST = 1;

//Live Channel//";
public static final String VIDEO_ID = "eTWrGNka-ik";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_live_tube);



YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(YoutubeDeveloperKey, this);


}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
    YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
    errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
} else {
    String errorMessage = String.format(
            "There was an error initializing the YouTubePlayer",
            errorReason.toString());
    Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
}

@Override
public void onInitializationSuccess(Provider provider,
    YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
    YPlayer = player;
//loadVideId
    YPlayer.loadVideo(VIDEO_ID);
}

        WebView myWebView = (WebView) findViewById(R.id.webview);
        myWebView.setWebViewClient(new WebViewClient());
        myWebView.setWebChromeClient(new WebChromeClient());
        myWebView.setWebViewClient(new WebViewClient());
        myWebView.clearCache(true);
        myWebView.clearHistory();
        myWebView.getSettings().setDomStorageEnabled(true);
        myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        myWebView.loadUrl("https://www.youtube.com/live_chat?v=h98Psy5NZPo");
    }
}

activity_live_tube.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/container"
     android:layout_width="match_parent"
     android:layout_height="match_parent">

         <WebView
         android:id="@+id/webview"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />

         <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtube_view"
        android:layout_width="fill_parent"
        android:layout_height="180dp" />

</FrameLayout>
rijotech
  • 356
  • 3
  • 17
  • What seems to be the error? Can you share the error logs? Also here is the document for [liveChat](https://developers.google.com/youtube/v3/live/docs/liveChatMessages) and [sample implementation](http://stackoverflow.com/questions/26229728/how-to-obtain-a-feed-of-comments-entered-through-the-chat-box-during-a-youtube) – Mr.Rebot Jul 22 '16 at 15:36
  • There is no error, when I click to input text It doesn't work. – rijotech Jul 22 '16 at 16:48

0 Answers0