In my app would like user to click on a button on actionbar. This action to invoke default mediaplayer, so that user can select any music as they like. Need ability to return to the app while the music is played in the background.
Any help is appreciated.
Following code works as intended...
Intent intent = new Intent();
intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
Intent.CATEGORY_APP_MUSIC);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Min SDK 15
startActivity(intent);
Related
I have an application which opens different videos using Intent chooser. So you can imagine user clicks on the list item which contains many elements with name of the video.
Now, the thing is working fine with this,
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uriPath, "video/mp4");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
but when the user again clicks on the same item, the intent chooser is shown. Selecting any video player in the device resumes the video.
So the question is, Is there any flag or some way in which the video can be started from the beginning ?
This thing not only happens with video but with pdf's. If an pdf was open and scrolled to the last page, then again opening the pdf again from my application opens it with the last page.
hi hardikI had a similar application to be developed where different
videos should be played when select different items from a list view.
I tried to test my application for the behavior that the video resumes
from last played frame if launch again from the app.
For me it always starts from the beginning. I have tested this on 4.2.2
and 4.4 versions only
The code to start the video was something like this:
Intent in = new Intent(Intent.ACTION_VIEW);
in.setDataAndType(uripath, "video/*");
startActivity(in);
This question is answered here already Android play video intent with start position, particularly in this comment from CommonsWare
Even if there were, they would be on a per-app basis.
If you need this level of control over the video playback,
handle the video playback yourself within your own app
(e.g., VideoView), rather than pass control to third party apps
See http://developer.android.com/reference/android/widget/VideoView.html#seekTo(int) and Playing a video in VideoView in Android
When you delegate to another application with an intent, you get what you get. You should control this within your app using the video player, and if you probably need a library for a pdf view widget. Something like http://code.google.com/p/apv/.
As you use an intent to play the video, it is really up to the acting application how to interpret and handle the intent. Unless the acting application (the one handling the intent you're firing) accepts extra parameters to choose between start-from-beginning and resume, there is really not much you can do.
For full control, use your own video player.
Use VideoView to resolve your problem.
private VideoView myVideoView;
VideoView has an inbuilt method start() which will start your video from the beginning like this:
#Override
public void onStart(){
super.onStart();
myVideoView.start();
}
You can also use the myVideoView.start() on onResume method as well.
Hope this would help. :)
I am completely unsure of this. I also agree on the other views that it is the responsibility of the called Application to handle the intent as it wishes.
However, a wild guess would be to change the uri:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
uriPath.buildUpon()
.appendQueryParameter("t", String.valueOf(System.currentTimeMillis()))
.build(),
"video/mp4"
);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Note: I did not have the problem that you are mentioning. The video always restarted.
Intent intent = new Intent();
ComponentName comp = new ComponentName("com.android.music","com.android.music.MediaPlaybackActivity");
intent.setComponent(comp);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "audio/*");
startActivity(intent);
This is the code that i am using to open samsung player in other phones except galaxy S3. Regarding galaxy S3 this package is replaced with
ComponentName comp2 = new ComponentName("com.sec.android.app.music","com.sec.android.app.music.AudioPreview");
But in this case it is working only as audio preview but on pause it gets finished But i wanted play exactly like the one in the above as a music player . So for that i replaced ComponentName with this to open the musicplayer
ComponentName comp2 = new ComponentName("com.sec.android.app.music",
"com.sec.android.app.music.MusicActionTabActivity");
But in the case the player won't plays the url that i have passed. It just open's the default music player in S3. I need to play file with the android default music player.
Look Android is using AudioPlaybackPreview or someother named activity, to handle the song playback from fileManager or any other place .
Actually you want to use the default Playing activity ,which is used to show all the controls and all .Dear it's not possible to use that Activity , since it had been linked to someother service having data of all the songs and all paths. This playing Activity has control of next atnd previous and all , that is linked with one playback service.
Third thing is that , as far as i know that S3 is almost providing the same layout for playing the song from filemanager or for plaaying from any other activity. But the problem with that is that when u go back from there , it will stop the playing song.
Refer to android music player source code , u will understand why it's not possible to launch that activity.
I am looking for a way to pause Spotify playback. I have tried searching, and using the AudioManager, but I believe that only works if it is part of your activity. Does anyone know a way to pause Spotify playback?
How to stop or pause Pandora and Spotify
That issue is similar and shows how to pause and stop most media players.
I found that this works best:
Intent pauseSpotify = new Intent("com.spotify.mobile.android.ui.widget.PLAY");
pauseSpotify.setPackage("com.spotify.music");
sendBroadcast(pauseSpotify);
Essentially, what you are doing is, creating a new intent which action is the built in "PLAY" action from the spotify app. Next you set the package and finally call the intent.
I got the idea from an article and applied it to normal android.
//play
Intent intent = new
Intent("com.spotify.mobile.android.ui.widget.PLAY");
intent.putExtra("paused",true);
intent.setPackage("com.spotify.music");
sendBroadcast(intent);
//pause
Intent intent = new
Intent("com.spotify.mobile.android.ui.widget.PLAY");
intent.putExtra("paused",false);
intent.setPackage("com.spotify.music");
sendBroadcast(intent);
I've analyzed Spotify's apk file and found the command file.
This would work perfectly on version 8.4.77
You can skip song by replacing "PLAY" to "NEXT".
I tried "PREVIOUS" but it didn't work, guessing it as spotify's default design.
In my small Android application I am calling the inbuilt voice recorder using
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent, REQUEST_CODE_RECORD_SOUND);
and I don't want the list button in the voice recorder. I tried a lot but am not able to hide it.
Also I want to ask that can my activity sense the actions taken on voice recorder like Record, start, stop, pause.
I am trying to pick a song using an Activity which will give meta-information about the songs. I want to do this instead of a simple file browser . I have the following code but it unfortunately also plays the song once clicked. I simply want the user to be able to select a song from their MediaStore and act upon it later without playing.
public class Main extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_PICK);
intent.setData(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivity(intent);
}
}
As far as I can tell, the 'picker' you're seeing is a 'preview' type of design (looking at it on my phone).
It's a bit like 'picking' a ringtone, for example...
You see a list and can select each one in turn to get a 'preview'. When you decide on the ringtone you want, you click OK and that returns the selection. Clicking Cancel simply leaves things as they were (existing ringtone selection is kept).
I can't see any way of overriding this behaviour of the picker and haven't found any alternative way (Intent parameters, for example) to achieve what you want to do.
In other words, as I understand it, you simply want the user to silently pick a piece of music and it to return to your Activity but the (preview) picker doesn't work that way.
You can find out what the user previewed/selected when they click OK in the picker however, if you use...
startActivityForResult(intent, 1234);
Note, 1234 is just an arbitrary code.
If you check the Intent returned to onActivityResult() it will have the content Uri of the piece of music the user selected before they pressed OK.