I am trying to play youtube url play n no of times on button click
I stumbled on the following code on the net:
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.youtube.com/watch?v=Ux_kvgL570A"));
startActivity(browserIntent);
but this code plays youtube url only once,how to modify this code if i want to
play youtube url multiple times
Currently, you're using a browser to display the video, but for it, you need use the Youtube API.
This thread: Youtube data API : Get access to media stream and play (JAVA) can explain you a little more about the youtube implementation on android using a media player.
But to repeat a video, you can add the follow lines:
videoView.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
And this is the reference for the YouTube API: https://developers.google.com/youtube/android/player/sample-applications
Related
Hey everyone, i would like to get the link of an selected video in an "Youtube Intent"
I've this actually ;
Intent intent = YouTubeIntents.createChannelIntent (SelectDocFragment.this.getActivity(), "PitbullVEVO");
startActivity(intent);
I would like an startActivityForResult, and the result should be "https://www.youtube.com/watch?v=ODh6hSZBJqY" which is the youtube that i selected in my YoutubeIntent.
i've tried to achieve this with an Youtube Player Api, and load my channel :
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cuePlaylist("PLRX442jA-zGKxR-wAfC_xUvpZX1Rh0usm");
I'm able to get the current Video with :
public void onLoaded(String mVideoId) {
String url = "http://www.youtube.com/watch?v=" + mVideoId;
}
But, youTubePlayer.cuePlaylist or youTubePlayer.loadVideo are not able to load an channel where i could selected any videos.
Similarly to this topic : Is it possible to integrate youtube channel in android?
It is possible to get this with YoutubeIntent ?
EDIT :
I would like this in my android APP, and here i choose the video that i will display after, i just want the link of the video selected by the user.
As said Yupi : Get selected video in Youtube Intent or Youtube Player
We have to request the Youtube APi to get a JSON and then parse it.
To do this, i've found a very useful tutorial here :
https://www.codeproject.com/Articles/1214971/Youtube-channel-integration-in-Android-using
For anyone who want to do the same :)
Here is a demo :
https://www.youtube.com/watch?v=GJMdgwvrR_Y
I am trying to play youtube videos using StandAlonePlayer. Which is working fine. But I want to close the player after completion of video. How to do this? Any help will be appreciated.
here is my code to play video using standalone player.
Intent intent = YouTubeStandalonePlayer.createVideoIntent(context, Consts.DEVELOPER_KEY, VIDEO_ID,0,true,false);
startActivityForResult(intent);
On activity result I can handle the error state. But I want close the player once video completes.
If the video is in a VideoView,so you can call setOnCompletionListener to it so you will be notified that the video is done playing.
videoView.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
//write your code after complete video play
}
});
im trying to play a video in VideoView on an android application.
the question is how do i fetch the correct link to the video from youtube and not just the webpage?
setContentView(R.layout.videopopup);
VideoView vv = (VideoView)findViewById(R.id.videoElem);
MediaController mc = new MediaController(this);
mc.setEnabled(true);
mc.show(0);
vv.setMediaController(mc);
vv.setVideoURI(Uri.parse("http://www.youtube.com/v/oFL2rszPmmU?version=3&feature=player_detailpage"));
vv.requestFocus();
vv.showContextMenu();
vv.start();
in this link: Video View not playing youtube video
Evgeny Nacu explains which link it should be, but not how to retrieve it from a given youtube page.
Simple way to play video using default youtube app:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(your youtube url);
Youtube app will do everything. You need not do anything.
and if that doesn't solve, use webview instead of videoview in your code
here is a link!
This link has Video and i want to display only video in my Android app. I think this website haven't provided any xml service so that we can use it, Is there any way to show only Video from this link to android app.
Thanks
hii ali you want to play video in your android app it can be do by two ways .
you can use your default youtube app to play the video or you can play it in your browser by following way.
if (isAppInstalled("com.google.android.youtube")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
.parse("vnd.youtube://" + b.getString("video")));
startActivity(intent);
finish();
} else {
// Toast.makeText(this,
// "To view this Video you must install the youtube application in your device..",
// Toast.LENGTH_SHORT).show();
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("http://m.youtube.com/watch?v="
+ b.getString("video"))));
finish();
}
It worked for me
If it worked please vote
I want to play an MP3 file using the default Android player. I managed to get the file playing but it plays in the background. I want to have all the nice controls for pausing, playing, etc.
My code now is something like:
String link = "http://www.example.com/file.mp3";
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(link);
mp.prepare();
mp.start();
How can I do it that when this file begins to play to go to another screen with the player and all the nice controls?
The MediaPlayer class should be used when you want to implement your own media player. If you want to use an existing player, you'll have to launch the appropriate intent, for example:
Uri uri = Uri.parse("http://www.site.com/file.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
If the particular Action doesn't work, take a look here: http://developer.android.com/reference/android/content/Intent.html