New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use Java to load playlist with PierfrancescoSoffritti / android-youtube-player 12.1.0? #1099
Comments
|
@billdzl Thank you so much for your respond. I have already Tried that but I am not sure if I miss anything I meanAlthough I am able to play Youtube Video but when I use your suggestion still I can't play Youtube Playlist. I have 2 questions from you which if you could reply I would highly appreciate it:
I use following code but it can not still play Youtube PlayLists?
All the Best, |
Thanks again, but as you know honestly the code sample you have provided is for Kotlin , and i have written my application with Java. I have test it by the following Youtube Playlist (PL22201173A69F18EA) which is Free Youtube playlist of Stanford University. could anyone please help me with what change to the my last comment I should do for java support for the Youtube playlist? I guess I have to initialize iFramePlayerOptions but as you know unfortunately the sample code and example is written in Kotlin , not Java. |
Here you go: package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.playlistExample;
import android.os.Bundle;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.options.IFramePlayerOptions;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;
import com.pierfrancescosoffritti.aytplayersample.R;
public class PlaylistExampleActivity extends AppCompatActivity {
private static final String PLAYLIST_ID = "PLEpEmEcrrKJUhZkyIAgQ17Oxyd3fx_y1j";
private YouTubePlayerView youTubePlayerView;
private YouTubePlayer youTubePlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_playlist_example);
youTubePlayerView = findViewById(R.id.youtube_player_view);
IFramePlayerOptions iFramePlayerOptions = new IFramePlayerOptions.Builder()
.controls(1)
.listType("playlist")
.list(PLAYLIST_ID)
.build();
getLifecycle().addObserver(youTubePlayerView);
youTubePlayerView.initialize(youtubePlayerListener, true, iFramePlayerOptions);
Button nextVideoButton = findViewById(R.id.next_video_button);
nextVideoButton.setOnClickListener(v -> {
if (youTubePlayer != null) {
youTubePlayer.nextVideo();
}
});
Button previousVideoButton = findViewById(R.id.previous_video_button);
previousVideoButton.setOnClickListener(v -> {
if (youTubePlayer != null) {
youTubePlayer.previousVideo();
}
});
Button playSecondVideoButton = findViewById(R.id.play_second_video_button);
playSecondVideoButton.setOnClickListener(v -> {
if (youTubePlayer != null) {
youTubePlayer.playVideoAt(1);
}
});
Button shuffleButton = findViewById(R.id.shuffle_button);
shuffleButton.setOnClickListener(v -> {
if (youTubePlayer != null) {
youTubePlayer.setShuffle(true);
}
});
Button loopButton = findViewById(R.id.loop_button);
loopButton.setOnClickListener(v -> {
if (youTubePlayer != null) {
youTubePlayer.setLoop(true);
}
});
}
private final AbstractYouTubePlayerListener youtubePlayerListener = new AbstractYouTubePlayerListener() {
@Override
public void onReady(YouTubePlayer youTubePlayer) {
PlaylistExampleActivity.this.youTubePlayer = youTubePlayer;
}
};
} |
@PierfrancescoSoffritti |
please refer to https://github.com/PierfrancescoSoffritti/android-youtube-player/tree/master/core-sample-app , @PierfrancescoSoffritti ,I guess it's possible that the monkey invited it |
@PierfrancescoSoffritti @billdizl |
First of all thanks for your great works, I have managed to use [PierfrancescoSoffritti 12.1.0 to load Youtube video. I saw that you have supported Playlist Videos as well, I saw your GitHub homepage you have written the following code in Katlin for supporting Playlist , I was wondering what is the equivalent code in Java in regard of supporting playlist ? I mean what is the equivalent of following:
This is the code I have used but as mentioned earlier only support Youtube Video not playlist . how should I set that the listType would be "playlist" in java , Please kindly help me to fix it to work with Playlist too. Thanks in advance.
here is the code that I need your assistant to kindly help me to fix it :
Kindest Regards,
Sincerely
Pooya
The text was updated successfully, but these errors were encountered: