0

I checked stackoverflow for similiar problems and didn't found anything. so here's my problem, I'm building an android app and I need to use YouTube API. I followed this guide: https://developers.google.com/youtube/android/player/

but I can't seem to run the Demo App. the entire project is full of errors and I can't understand why, all of the "R.id.blabla" items are having an error saying: "blabla cannot be resolved or is not a field"

I checked those Questions - Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties

and : YouTubeAndroidAPIDemo does not run

tried everything there, didn't helped much. I'm pretty sure I am missing something but I have no idea what. anyone else encountered something like this before? plz help :D

Community
  • 1
  • 1
JozeRi
  • 3,219
  • 6
  • 27
  • 45

2 Answers2

0

Try this:

layoutfile.xml

      <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtube_player"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/teacherName"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="10dp"

                android:background="#fff"
                android:padding="5dp" />
 <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/date"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="115dp" 
            android:visibility="gone"
            />

        <TextView
            android:id="@+id/progressBarText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/progressBar1"
            android:layout_centerHorizontal="true"
            android:maxLines="3"
            android:visibility="gone"
            android:text="Video Loading..." />

TutorialVideoView.java

public class TutorialVideoView  extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener
{

    private VideoView videoView;
    private MediaController mController;
    private Uri uriYouTube;


    ProgressBar progressBar1;
    TextView progressBarText;

     String v_title,v_date,v_id,v_url,v_teacher;

        public static final String API_KEY = "Your API key";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tutorialvideo_view);


        progressBar1 = (ProgressBar)findViewById(R.id.progressBar1);
        progressBarText=(TextView)findViewById(R.id.progressBarText);

        v_id="Your YouTube Video ID";

        YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
        youTubePlayerView.setVisibility(View.VISIBLE);
        youTubePlayerView.initialize(API_KEY, this);


    }
      @Override
        public void onInitializationFailure(Provider provider, YouTubeInitializationResult result) {
            Toast.makeText(this, "Failured to Initialize!", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {

            /** add listeners to YouTubePlayer instance **/
            player.setPlayerStateChangeListener(playerStateChangeListener);
            player.setPlaybackEventListener(playbackEventListener);

            /** Start buffering **/
            if (!wasRestored) {
                player.cueVideo(v_id);
            }
        }

        private PlaybackEventListener playbackEventListener = new PlaybackEventListener() {

            @Override
            public void onBuffering(boolean arg0) {

            }

            @Override
            public void onPaused() {

            }

            @Override
            public void onPlaying() {

            }

            @Override
            public void onSeekTo(int arg0) {

            }

            @Override
            public void onStopped() {

            }

        };

        private PlayerStateChangeListener playerStateChangeListener = new PlayerStateChangeListener() {

            @Override
            public void onAdStarted() {

            }

            @Override
            public void onError(ErrorReason arg0) {

            }

            @Override
            public void onLoaded(String arg0) {

            }

            @Override
            public void onLoading() {
            }

            @Override
            public void onVideoEnded() {

            }

            @Override
            public void onVideoStarted() {

            }
        };


}

Hope this may help you!

Krupa Patel
  • 3,309
  • 3
  • 23
  • 28
  • Hi there, thanks for your answer, even if it didn't help me that much. I really appriciate it ! – JozeRi Aug 19 '14 at 13:04
-1

I had a similar problem, try deleting the: import R.java line, if it's there.

tamasJozsa
  • 86
  • 1
  • 12