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.
Related
I have a video playing full screen in the Android application. I've added a button to allow the user to bring up the "Share" dialog to share to social media, texting, or e-mail. However, when the user selects, for example Facebook, the video will stop playback. Is it possible to force the video to continue playing/rendering in the background with sound ON while the user is performing the share?
The code to Share is below:
public static void share(Activity activity, String subject, String body, String title)
{
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
activity.startActivity(Intent.createChooser(shareIntent, title));
}
VideoView is extremely finicky when it comes to lifecycle, and it stops the video the moment the activity hosting it is paused. Showing an intent chooser dialog effectively pauses your activity.
The preferred method (for both user experience and to handle your issue) would be to use ShareActionProvider to allow the user to select the sharing destination. This is a pop-up list, typically anchored to the action bar, which is a more modern method of showing these options. As an added benefit, the pop-up won't cause your activity to pause, so the video should not stop.
If you must still use the external dialog method, you will have to move away from VideoView and implement the video surface yourself with MediaPlayer. This isn't as scary as it sounds, you can see from the source code that most of VideoView is just wiring it up to MediaPlayer callbacks and attempting to manage state when the surface is created or destroyed.
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);
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.
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.
I have an intent that launches an Audio Player Intent, and plays an Audio File. The Audio Player offcourse is external to my application. When the user presses the back button, my activity is again displayed to the user. I want the Audio Player to close when the user presses the back button. How can i control this.
There are two options to achieve your requirement
call "finish()" after startActivity() which is used to start audioplayer. finish() function will close your application and when user press back button from audioplayer, Android will display previous activity most probably home screen.
User CLEAR_TOP flag when you start the activity. Clear top flag will clear all top activity so when user press back from audio player, Android OS will display Home Screen.
Intent i = new Intent(......);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Thank You
I placed this code on the OnResume() of my calling activity and it works like a GEM.
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
AudioManager mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
if (mAudioManager.isMusicActive())
{
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
this.sendBroadcast(i);
}