Play a video without sound using an Intent with ACTION_VIEW - android

So I have this very usual piece of code in my widget, which plays a video on click.
Intent nextintent = new Intent(Intent.ACTION_VIEW);
nextintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
nextintent.setDataAndType(pathToVideo, "video/*");
context.startActivity(nextintent);
I somewhere also have a property that says wether this video should be played with sound or muted.
Now, just how do I tell my intent to abide by that property ? None of the flags or action types (as far as I've seen) specify that. Any clues ?
Thanks in advance.

Here's a possibility I used :
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, true);
Now I'm not sure it works for now, because I have other MediaPlayer problems and can't test it. Plus the volume probably won't be set back to its original level once the video is done playing (which is what I'd ideally want).

Related

How to automatically play Playlist in Spotify Android app

I'm trying to play a known playlist in the Spotify app. The best I've got is to load the playlist, but not play it.
Two things I've tried. Firstly to play from search:
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setComponent(new ComponentName("com.spotify.music",
"com.spotify.music.MainActivity"));
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,
MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE);
intent.putExtra(MediaStore.EXTRA_MEDIA_PLAYLIST, <PLAYLIST>);
intent.putExtra(SearchManager.QUERY, <PLAYLIST>);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I've tried replacing PLAYLIST with the name of a known playlist. Also tried things like "4Rj0zQ0Ux47upeqVSIuBx9", "spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9" etc. All these do is a failed search for these strings.
Second attempt is the View intent:
String uri = "https://play.spotify.com/user/11158272501/playlist/4Rj0zQ0Ux47upeqVSIuBx9";
Intent intent= new Intent( Intent.ACTION_VIEW, Uri.parse(uri) );
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
This loads the playlist, but does not play. If I then use one of the many ways to send a KEYCODE_MEDIA_PLAY key, it just resumes the currently playing list, not this newly loaded list.
Any help from anyone (including Spotify devs)?
BTW I don't want to use the Spotify SDK to implement my own Spotify Player - it seems a shame to have to do this when a perfectly good player is already installed on a user's device.
I found the answer from this blog. What I was missing was the playlist URI as a data Uri in the intent. So not using the proper Android way of Play from search.
So, using the first method from the question, you end up with this:
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setData(Uri.parse(
"spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
3 things to note:
the Uri can't be the https://play.spotify... but has to be the colon seperated type.
the Spotify account must be premium, otherwise the playlist opens but does not play.
this does not work if the screen is off, or lock screen is showing. The spotify activity needs to display on the screen before it loads and plays!
This final point means it isn't actually usable for me... so not accepting answer yet.
Just add :play to Spotify Intent URI
spotify:album:3avifwTCXoRzRxxGM1O0eN:play

Google Glass Video Capture Intent ignores limit and size extras

I'm trying to limit the length of a video captured on Google Glass via the follow code:
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 10485760); // 10mb in bytes
startActivityForResult(intent, Constants.TAKE_VIDEO_REQUEST);
It appears Glass ignores these extras though. The user still has the option to tap extend and the file size never stops the video either.
Are these extras used in Glass or is this a bug?
EDIT: Filed a feature request: https://code.google.com/p/google-glass-api/issues/detail?id=469
Those Intent Extras are not actually used by the ACTION_VIDEO_CAPTURE action. Please file a feature request on our issues tracker to track this.
Alain,
this is happening to me as well.
I submitted Issue 651 for that.

Extend Video recording time in Google Glass

Is there a way we can extend the default video recording time on glass. The current recording time is only 10 seconds and we have to extend it manually by pressing the camera key for one second or by tapping and choosing Extend Video option. So i was wondering whether there is a flag that we can set when requesting the camera to start recording which will cause the camera to record an extended video.
I was also wondering how can we set the maximum time limit of video recording and what is the default time limit of video recording in glass ?
I am using the code below for starting the glass camera for video recording
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent, CAPTURE_VIDEO_REQUEST_CODE);
Also if there isn't a possible way can anyone guide me on the alternatives. Is there any open source camera available which works for glass or should i have to write my own camera [any links that would help me get started] ?
Hope you get him idea from it:
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra("android.intent.extra.durationLimit", 60);
startActivityForResult(intent, CAPTURE_VIDEO_REQUEST_CODE);
This above code video duration is one minute,if u want to extend the video time then do it like that,and now the video duration is 2 minutes:
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra("android.intent.extra.durationLimit", 120);
startActivityForResult(intent, CAPTURE_VIDEO_REQUEST_CODE);
You can access the camera directly and record the video yourself. See the official Android documentation for more information: http://developer.android.com/guide/topics/media/camera.html#capture-video

Play multiple songs with Android intent

In my application, I need to launch the Android Music Player. And, for now, it works perfectly :
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
File file = new File(file_path);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(Intent.createChooser(intent, "..."));
But the user can't use the "next" and "prev" buttons to switch music. That's why I try to launch multiple songs at once (a playlist). And I don't really know how to do this!
Give an array to the intent ?
As far I know there is no way to launch multiple tracks. But you can implement your player, using the MediaPlayer class. Which also doesn't supports multiple tracks. So you also have to make a service, use OnCompletionListener to listen when tracks finish, to start the next track.
This thread will help:
How do Android mediaplayers continuing playing songs when app is closed?
Also this one:
Start default music player with music playing by default
yes their is no direct way to get multiple songs using intent . but you can fetch selected songs. play one by one by your code.using media player.
set songs in queue .
For your purpose you had to make your own media player.
using this code for picking multiple songs sourcetopickmultiplesongs;
store the selected song array.
play one after other using this piece of code .
MediaPlayer mp1=MediaPlayer.create(getBaseContext(), R.raw.sound1);
MediaPlayer mp2=MediaPlayer.create(getBaseContext(), R.raw.sound2);
mp1.prepare();
mp2.prepare();
mp1.start();
mp1.setNextMediaPlayer(mp2);
hope this helps .

Play audio files with default player

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

Categories

Resources