Question

i am trying to embed a youtube api for android, everything for good except the fact, that video play for a one second only and then stop automaticly. but when i am going to the fullScreenMode, the video playing as expected.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_show);

    ivThumbnail = (ImageView) findViewById(R.id.ivThumbnail);
    tv = (ImageView) findViewById(R.id.tv);

    Intent i = getIntent();
    screenCase = i.getIntExtra("screenCase", -1);

    selectedVideoId = Splash.playlists[screenCase].getItems().get(0).getVideo().getId();

    setProperTvImage();
    createButtons();

    ivThumbnail.setImageBitmap(Splash.playlists[screenCase]
            .thumbnails[0]);

    youtubeLV = (ListView)findViewById(R.id.lvPlaylist);
    adapter = new MyYoutubeListAdapter(this, Splash.playlists[screenCase].getItems(), screenCase);

    youtubeLV.setAdapter(adapter);
    youtubeLV.setOnItemClickListener(this);

    youtubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_view); 
    youtubePlayerView.initialize(DeveloperKey.DEVELOPER_KEY, this); //init Player

}

onInitializationSuccess

public void onInitializationSuccess(Provider arg0, YouTubePlayer _player,
        boolean wasRestored) {

    this.player = _player;
    //player.setPlayerStyle(PlayerStyle.CHROMELESS);

    if(!wasRestored){
        playVideoAtSelection();
    }

}

and finally playVideAtSelection methode

private void playVideoAtSelection() {

    if(player != null){
        Log.e("player ", "not null");
        player.cueVideo(selectedVideoId);
    }else{
        Log.e("player ", "null");
    }

}

Any suggestions?

Was it helpful?

Solution

Well, its a bit late for answer, but someone might stumble on this post and might get an insight.

I was facing the same issue and 1st option below solved my problem.

After a lot of search regarding the similar issue, I came across two things.

1) Check if your YoutubePlayerView (in activity XML) has padding option. Remove the padding if its there.

2) As per youtube Api documentation, the minimum size specified is 200 x 110 dp for YoutubePlayerView. Make suitable changes in size if that is the case.

Hope it helps somebody.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top