运行YoutubeAndroidAPIDemo应用程序时出现问题

时间:2014-08-19 10:55:36

标签: android api

我检查了stackoverflow是否有类似的问题,但没有发现任何问题。 所以这是我的问题,我正在构建一个Android应用程序,我需要使用YouTube API。 我按照这个指南: https://developers.google.com/youtube/android/player/

但我似乎无法运行演示应用程序。 整个项目都充满了错误,我无法理解为什么, 所有“R.id.blabla”项目都有错误说: “blabla无法解决或不是一个领域”

我查看了这些问题 - Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties

和:YouTubeAndroidAPIDemo does not run

尝试了一切,没有多大帮助。 我很确定我错过了什么,但我不知道是什么。 之前还有其他人遇到过这样的事吗? PLZ帮助:D

2 个答案:

答案 0 :(得分:0)

试试这个:

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() {

            }
        };


}

希望这可以帮到你!

答案 1 :(得分:-1)

我遇到了类似的问题,请尝试删除:import R.java行,如果有的话。