3

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.

Hardik4560
  • 3,097
  • 1
  • 16
  • 29

5 Answers5

2
 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);
amIT
  • 638
  • 13
  • 27
1

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/.

Community
  • 1
  • 1
Eric Woodruff
  • 5,907
  • 3
  • 31
  • 32
  • 1
    It looks like you're answering a completely different question. OP _wants_ the video to start from the beginning on every launch - not resume. OP also mentions the case with `PDF` files. Do you think the OP should write an app that handles the viewing of all file types? Quite an undertaking, don't you think? – user3264740 Feb 13 '14 at 20:21
  • On the contrary, the seekTo demonstrates the only means to have control of the video position, whether the position is somewhere in the middle or at the beginning. If you read my answer, there is no intent protocol for specifying a video position by delegating to another app. To be fair, the pdf aspect was only anecdotal to the question. If handling each mime type within the app is how the OS was designed then that is what OP will have to do. The quote in my answer speaks for itself. – Eric Woodruff Feb 13 '14 at 20:31
  • Thanks @EricWoodruff, I do want my application to launch another video player(proving multiple choice to the user) from my application which I successfully achieved by using ACTION_VIEW and the mime type. About the pdf, its not an anecdotal but tested and checked with multiple pdf readers like adobe reader, moon+, foxit, etc. I don't want the control but mere a "play from start" flexibility when the 3rd party player is launched. – Hardik4560 Feb 14 '14 at 04:01
  • I appreciate your expectations, but that is not a standard intent extra for VIEW. Did you try FLAG_ACTIVITY_CLEAR_TASK instead? – Eric Woodruff Feb 14 '14 at 04:37
  • Yes I used it, also tried with FLAG_ACTIVITY_NEW_TASK. – Hardik4560 Feb 14 '14 at 05:03
  • See my comment, no matter what you do it is the activity handling the intent that decides what to do with it. – DKIT Feb 20 '14 at 14:03
0

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.

DKIT
  • 3,401
  • 2
  • 18
  • 22
  • 1
    I started to write an answer but this is more or less what I was planing to write. Try setting extra parameters to start position but as it's mentioned it's up to the application handling intent to do what it wants and read or ignore those. – Igor Čordaš Feb 19 '14 at 13:08
-1

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. :)

Pihu
  • 1,025
  • 11
  • 32
  • 1
    I know this already, if videoview was the solution I would have copleted this and won't have asked the question. My question is more towards some launching the video in other player while starting it from beginning. I also know about surfaceView. That all can be achieved and I also have used them in other projects. – Hardik4560 Feb 19 '14 at 13:01
-1

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.

Sherif elKhatib
  • 44,650
  • 15
  • 84
  • 105