Hi, I know I post similar question already, but I decided to go with simpler version of playing videos.I have most of the code, but the crucial thing is missing.The thing that I want to accomplish is to play video by clicking on the listview items.I'll explain what kind of app I am making. It's about Metallica band, and I have Fragment that shows Albums, and when you click on of the albums, it opens a new Activity with Tracks inside of said activity.And when you click on of the songs, I want to open yt_video of that song. That's it.My main problem is yt_Activity, cause in TracksActivity I know I have to use Intent.Almost forgot, all my data is stored on Firebase, so in Tracks there is id, title and url of every song in particular.I would be grateful to anyone who could tell me how to solve my problem.
public class YT_activity extends YouTubeFailureRecoveryActivity {
@BindView(R.id.youtube_view) YouTubePlayerView youtube_view;
@BindView(R.id.lvTracks) ListView lvTracks;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_yt);
ButterKnife.bind(this);
youtube_view.initialize(Youtube_key.getAPI_KEY(),this);
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerView) findViewById(R.id.youtube_view);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
if (!wasRestored){
}
}
}
public abstract class YouTubeFailureRecoveryActivity extends YouTubeBaseActivity
implements YouTubePlayer.OnInitializedListener{
private static final int RECOVERY_DIALOG_REQUEST = 1;
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
} else {
String errorMessage = String.format(getString(R.string.error_player), errorReason.toString());
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RECOVERY_DIALOG_REQUEST) {
getYouTubePlayerProvider().initialize(Youtube_key.getAPI_KEY(), this);
}
}
protected abstract YouTubePlayer.Provider getYouTubePlayerProvider();
}
This is some of the code from TracksActivity:
private List<Track> mapTracks(HashMap<String, HashMap> m) {
List<Track> r = new ArrayList<>();
Set<String> keys = m.keySet();
for (String key : keys) {
HashMap<String, Object> album = m.get(key);
String id = (String) album.get("id");
String title = (String) album.get("title");
final String url = (String) album.get("url");
Track t = new Track(id, title, url);
r.add(t);
lvTracks.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getApplicationContext(),YT_activity.class);
intent.putExtra("position", position);
intent.putExtra("url",url);
startActivity(intent);
}
});
}
return r;
}
}
What I have tried:
I've tryied to find soulution using Google.