简体   繁体   中英

When starting a new Activity for video player, how to force android video player to not exit after the video is played

I am using the following intent to play a video with the android default Video Player.

        File file = new File(galleryList.get(getAbsoluteAdapterPosition()).getPath());
        Intent i = new Intent(Intent.ACTION_VIEW);
        if (GalleryMediaHelper.isVideoFile(galleryList.get(getAbsoluteAdapterPosition()).getPath())) {
            i.setDataAndType(FileProvider.getUriForFile(context, AUTHORITY, file), "video/*");
        }
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION);
        if (i.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(i);
      

So far so good. The video player starts playing the video. The problem is that, when the video is played the video player is closed and the user returns to the my app. -> NOK

How can I force video player to not close and either play on repeat the video or just wait for user to press back to exit video player?

The problem is that, when the video is played the video player is closed and the user returns to the my app

That behavior will depend on the video player app. There are hundreds, if not thousands, of possible video player apps that might handle your Intent , based on pre-installed and user-installed video player apps.

How can I force video player to not close and either play on repeat the video or just wait for user to press back so that he can do whatever he/she wants with the video player (pause, stop, replay etc)?

That is not possible. The behavior of a video player app is up to the developers of that app.

If you need that level of control over the user experience, implement your own video player, such as by integrating ExoPlayer.

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