简体   繁体   中英

Android default video player closes when video is done

I'm using the ACTION_VIEW to stream/play a remote video file. When the video is done playing the video player closes automatically. How do I stop the video player from closing? Thanks.

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);

MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getMimeTypeFromExtension(MimeTypeMap
            .getFileExtensionFromUrl(scFile.getFileUrl()));

intent.setDataAndType(Uri.parse(scFile.getFileUrl()), type);
startActivity(intent);

In order to do this there would need to be a way to pass a "don't close" flag in the intent's data. I'm not aware that such a flag exists, so if you really need this behavior I think you will need to use the MediaPlayer class instead.

I found the solution in another question.

call a new video intent like this:

Intent intent = new Intent (Intent.ACTION_VIEW);

intent.setDataAndType (uri,"video/mp4");
intent.putExtra (MediaStore.EXTRA_FINISH_ON_COMPLETION, false);

activity.startActivity (intent);

link to original question: Returning to Android app after external video player closes

Hi you can use it like this.

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("add video url");
intent.setDataAndType(data, "video/mp4");
intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION,false);
startActivity(intent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM