I am trying to autoplay youtube videos on android, which evry time i play video must press play button to play and that is a bad experince for the user, so i try many method but it dosnt work
so please guys help me ,thanks for advise
and this is a pieace of my code
#Override
public void onClick(View v) {
Intent intent = null;
intent=YouTubeStandalonePlayer.createVideoIntent(activity,DeveloperKey.DEVELOPER_KEY, VIDEO_ID);
activity.startActivity(intent);
}
autoplay = true;
lightboxMode = false;
intent = YouTubeStandalonePlayer.createVideoIntent(
this, YOUR_DEVELOPER_KEY, VIDEO_ID, startTimeMillis, autoplay, lightboxMode);
This works for me and can be found in youtube samples.
Documentation:
createVideoIntent(Activity activity, String developerKey, String videoId, int timeMillis, boolean autoplay, boolean lightboxMode)
Implementation example:
intent = YouTubeStandalonePlayer.createVideoIntent(this, DeveloperKey.DEVELOPER_KEY, VIDEO_ID, 0, true, false);
You need to pass true for autoplay parameter
Related
I am beginner in android and developing an app in which i am using YouTubePlayer API in order to show Youtube Videos of specific Playlist. I'm succeed in doing so. But what I want is that whenever the user selects any video from that playlist; the video should be played in Full Screen. Here is my code:
public class Main4Activity extends AppCompatActivity
{
Toolbar main_toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
main_toolbar=(Toolbar) findViewById(R.id.my_thirdtoolbar);
setSupportActionBar(main_toolbar);
getSupportActionBar().setTitle(R.string.my_tb_title);
getSupportActionBar().setIcon(R.drawable.tblogo);
OnClickButtonListener();
}
public void OnClickButtonListener()
{
Button youtubebtn = (Button) findViewById(R.id.button8);
youtubebtn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
String PLAYLIST_ID = "PLXRActLQ03oY_6AQb-5EMuKFYQA_fDE40";
Intent intent=YouTubeIntents.createOpenPlaylistIntent(Main4Activity.this,PLAYLIST_ID);
startActivity(intent);
}
}
);
}
}
You can use methods from YouTubeIntents. Here are some methods that you can use:
canResolvePlayVideoIntentWithOptions (Context context)
Checks if the YouTube application installed on the user's device supports the fullscreen and finishOnEnd optional parameters when resolving a play video intent.
If this method returns true, then your application can call the createPlayVideoIntentWithOptions(Context context, String videoId, boolean fullscreen, boolean finishOnEnd) method which creates an Intent that, when resolved, will start playing the video specified by videoId, within the YouTube application.
If this method returns false, then your application should call the createPlayVideoIntent(Context context, String videoId) method instead.
Additionally, please also check other implementations and try the suggested solutions in this SO post. Hope it helps!
I am using the following code to open the Equalizer in the App.
Intent intent = new Intent( );
intent.setAction("android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL");
if (intent.resolveActivity( getActivity().getPackageManager()) != null )
{
startActivityForResult( intent , 100 );
}
else
{
JBUtils.getInstance().showCustomToast( getActivity() , R.string.equalizer_notfound);
}
And added the permission
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
After user changes the Equalizer settings how to apply equalizer settings in the currently playing audio file.We are using the Exoplayer for playing the music file.
Thanks in Advance.
Please look at this issue (closed):
https://github.com/google/ExoPlayer/issues/252
There's an interesting example about using Equalizer in ExoPlayer.
I didn't try it yet but it seems an interesting starting point to integrate standard Equalizer in ExoPlayer.
Let me know if it works!
Here is the example I would start with:
audioRenderer = new MediaCodecAudioTrackRenderer(......){
private Equalizer equalizer;
#Override
public void onAudioSessionId ( int audioSessionId){
releaseEqualizer();
equalizer = new Equalizer(...,audioSessionId);
// Configure equalizer here.
equalizer.setEnabled(true);
}
#Override
public void onDisabled () {
releaseEqualizer();
}
private void releaseEqualizer () {
if (equalizer != null) {
equalizer.release();
equalizer = null;
}
}
};
Moreover there seems to be some issue with the equalizer. You can try to enable the workaround (disabled by default) in AudioTrack, setting the following flag to true:
public static boolean enablePreV21AudioSessionWorkaround = false;
You have to provide the your package name and current Media Player audio session id as extra before starting the activity. Add the below code before calling startActivityForResult.
intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, player.getAudioSessionId());
where player is an instance of MediaPlayer.
I have some YouTube links and I want to make a list like the playlist that exists in youtube such that a screen shot from the video automatically appear and when the user click on the link it opens the youtube app
How can I do it ?
thanks in advance
For the YouTube thumbnails, you can use the techniques outlined in this answer to grab the url of several auto-generated thumbnails, and using an image library like Picasso it is straightforward to load the image into an ImageView:
private static final String EXAMPLE_YOUTUBE_VIDEO_ID = fMOqfsBzqLU;
public static String getYouTubeThumbnailUrl(String videoId) {
return "http://img.youtube.com/vi/" + videoId + "/0.jpg";
}
//To use...
Picasso.with(context).load(getYouTubeThumbnailUrl(EXAMPLE_YOUTUBE_VIDEO_ID)).into(imageView);
Use a RecyclerView or ListView to display the images, and set an onClickListener() to the ImageView that links to the video on YouTube:
public static String getYouTubeVideoLink(String videoId) {
return "https://www.youtube.com/watch?v=" + videoId;
}
//To launch the video in the defaul browser...
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(getYouTubeVideoLink(EXAMPLE_YOUTUBE_VIDEO_ID)));
startActivity(i);
Edit: To open the video in the YouTube app, you can use try the examples in this post, or explore the YouTubePlayer API.
I have asked what is the code that sends a link from the application that I'm making to the vimeo application; it opens vimeo application but not the video specified in the link, does anybody knows how?
vimeo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try{
Intent browserIntent = null;
PackageManager pmi = getPackageManager();
browserIntent = pmi.getLaunchIntentForPackage("com.vimeo.android.videoapp");
browserIntent.setAction(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("http://player.vimeo.com/video/83178705"));
startActivity(browserIntent);
}
catch(Exception e){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://player.vimeo.com/video/83178705"));
startActivity(browserIntent);
}
}
});
I answered your other question with this solution. But I believe it will fix this issue as well since our vimeo-deeplink library accommodates opening our specific application.
You could include it with gradle:
compile 'com.vimeo.android.deeplink:vimeo-deeplink:1.0.0'
And then deeplink to your video with this method:
boolean handled = VimeoDeeplink.showVideoWithUri(Context context, String videoUri)
Where videoUri is equal to /videos/83178705.
By doing this below, it will reset all your app preference
Go to Settings->Apps, choose from menu Reset app preferences and confirm Reset apps.
After that,
choose it in Settings->Apps and press Clear defaults button for vimeo app
Now try to open that video link(vimeo link) again. Now it'll ask you to select which app to use. Then select your vimeo app as default
I have a simple button, and I wish to play an URL video buy clicking on this button but without a videoView.
So if I click on the button , the phone will ask which internal player I'll choose to play the video.
Here I was using a videoView that was playing the video inside the window of my application but I want it outside :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
video = (VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);
Uri chemin = Uri.parse("http://commonsware.com/misc/test2.3gp");
video.setVideoURI(chemin);
video.start();
Thank you,
so here's the code :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
boutonVideo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent in;
if (v.getId() == R.id.boutonVideo) {
in = new Intent(Intent.ACTION_VIEW, Uri
.parse(urlBandeAnnonce));
startActivity(in);
}
}
});
But it return me an error when I decide to stop the video and return to my activity.
Here is the AndroidRunTime Error :
java.lang.RuntimeException: Unable to start activity
ComponentInfo{Activity}: java.lang.NullPointerException
09-30 15:20:16.449: E/AndroidRuntime(2301):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
Solved
So I add finish(); and the error disappear.
Use an Intent with ACTION_VIEW along with the URI to the movie you want to play:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
startActivity(intent);
where movieUrl is a string containing the path to the movie.
This may or may not work with internet streams. Haven't tried it with those personally.
Have you looked to Android Api examples
if you have installed the samples on your pc it is located at (for windows systems)
C:\Program Files\Android\android-sdk\samples\android-16\ApiDemos\src\com\example\android\apis\media