简体   繁体   English

使用Intent Chooser时视频会自动恢复

[英]Video automatically resumed when using Intent Chooser

I have an application which opens different videos using Intent chooser. 我有一个应用程序,使用Intent选择器打开不同的视频。 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. 这件事不仅发生在视频上,而且发生在pdf上。 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. 如果pdf已打开并滚动到最后一页,那么再次从我的应用程序再次打开pdf将打开它与最后一页。

 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 我仅在4.2.2和4.4版本上测试了这个

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 这个问题在这里已经回答了Android播放视频意图的起始位置 ,特别是在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 请参阅http://developer.android.com/reference/android/widget/VideoView.html#seekTo(int)在Android中的VideoView中播放视频

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. 你应该使用视频播放器在你的应用程序中控制它,如果你可能需要一个用于pdf视图小部件的库。 Something like http://code.google.com/p/apv/ . 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. 使用VideoView解决您的问题。

private VideoView myVideoView;

VideoView has an inbuilt method start() which will start your video from the beginning like this: VideoView有一个内置方法start(),它将从头开始你的视频,如下所示:

 @Override
    public void onStart(){
        super.onStart();
        myVideoView.start();
    }

You can also use the myVideoView.start() on onResume method as well. 您也可以在onResume方法上使用myVideoView.start()。

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: 然而,一个疯狂的猜测是改变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. 视频总是重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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