How to allow VideoView to continue playing when using Share? Android - android

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.

Related

set intent's display size and position it if it is possible

I'm new to android so I appreciate all the comments you have.
I want to call a new Intent from a BroadcastReceiver.
Is it possible to set the displayed size of the new intent and position it?
Precisely, I would like to place a custom picture on top of the incoming
call screen and still be able to answer or reject the call.
I could do it with toast, but it disappears after I while and I don't want that
to happen.
Thanks in advance!
I want to call a new Intent from a BroadcastReceiver
You do not "call a new Intent" in Android.
Is it possible to set the displayed size of the new intent and position it?
I am assuming that by "call a new Intent" you mean "start an activity", and by "set the displayed size of the new Intent" you mean "set the displayed size of the activity".
In that case, the code that is starting the activity has no control over the rendering of that activity. The implementer of the activity is the one that controls the rendering. It is possible for an activity to not fill the screen and have control over its size. I presume that it is possible for the activity to control where it is on the screen, though I haven't looked into that.
I would like to place a custom picture on top of the incoming call screen and still be able to answer or reject the call
That is both impossible and impractical.
It is impossible because only the foreground activity gets user input. Your activity that will "place a custom picture" will receive all input; the incoming-call screen will not receive input, and so the user cannot accept or reject the call.
It is impractical because across thousands of Android device models there are dozens, if not hundreds, of incoming-call screen implementations, none of which have to look the same. As a result, you have no way of knowing whether your "custom picture" will visually overlay important things in the incoming-call screen, such as the buttons to accept or reject the call.

proper way to present a cardScrollActivity before a live card for google glass

What is the proper way to present a card scroll activity before presenting a service? For example, if I wanted to allow the user to select a song in a scroll view before playing the song in a live card.
For this case I would still have the service be the entry point and use the following to start the scroll activity from the service (depending on the use case);
Intent intent = new Intent(getBaseContext(), CardScrollActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(intent);
Then after making your selection and before finishing your activity, using a service interface method publish your live card from the service or use a broadcast receiver to notify the service to publish.

Video automatically resumed when using Intent Chooser

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.

Initiate Camera Intent with the Gallery Icon

I am working on an app that accesses the camera and returns an uri, which I pass to another activity and display the extracted bitmap in an ImageView. Everything seems to work fine. Here is the code that I use to initiate the camera intent.
mCameraButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCameraUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraUri);
mtimeCameraAcessed = System.currentTimeMillis();
startActivityForResult(cameraIntent, RECEIVE_CAMERA_PICTURE);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
});
But, I have noticed a discrepancy. When my application access the camera, the gallery icon at the bottom of the screen seems to be missing (the icon appears when you access the camera application on any android phone). I have attached a couple of screenshots to illustrate this.
I want the user to access the camera while being able to change his/her mind and then access the gallery on the same screen (by tapping the gallery icon). Now, I do know how to initiate a gallery intent via 'Intent.ACTION_PICK'. I have also looked at the this question, but I don't completely agree that I need a custom camera layout to achieve what I intend to do: Single intent to let user take picture OR pick image from gallery in Android
The reason I say this is because, I have seen apps such as QuickPic that access the camera application with the gallery icon at the bottom. Can anyone please throw some light on this?
After going through some thorough research, I have come to a conclusion that this is infact impossible. However, a custom layout combined with the camera api would be the ideal solution if something like this is desired. But then, I have observed that using the camera api has certain problems such as skewed appearance of the camera screen.
QuickPic takes the user to the camera screen (with the gallery icon) but drops him/her out of the app while doing so. At that point, the user is basically using the stock camera app on Android and not the Quickpic app itself.

Android - Picking a song to play using Intent

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.

Categories

Resources