VideoView cannot play video from internal storage

All your problems with Audio, Video and Images.

VideoView cannot play video from internal storage

Postby mathias.lin » Wed Aug 04, 2010 6:26 pm

I have an application with a lot of media data (images and videos) that were previously stored on the sdcard. With that, images and videos are displayed fine in my app.

Now, in order to secure the content more, I wanted to move the content to the internal storage / data dir of the app, which I did. I copied all media with a routine within my app to the data folder (/data/data/com.myapp/some/folders/video.mp4) and adjusted the path in my app so that it would look for the media in the internal storage data directory and not the sdcard anymore.

Everything works fine, images are being displayed (decoded) properly, but videos don't play. They files do exist though - I do not get a FileNotFound exception. But an IOException:
java.io.IOException: Prepare failed.: status=0xFFFFFFFC

Why is that? Everything is handled within my one app and the videos have been copied with the same routine as the images, thus having the same permission settings. Looking at the stack trace, it all runs in process id 18060).

Why I cannot playback the video from internal storage? Or how can I?


Code: Select all
V/MediaPlayer(18060): message received msg=100, ext1=-4, ext2=-4
E/MediaPlayer(18060): SISO TEST MEDIA_ERROR
E/MediaPlayer(18060): error (-4, -4)
V/MediaPlayer(18060): signal application thread
V/MediaPlayer(18060): callback application
V/MediaPlayer(18060): back from callback
V/MediaPlayer(18060): prepare complete - status=-4
E/MyApp(18060): vp Exception in btnVideoPause prep
E/MyApp(18060): java.io.IOException: Prepare failed.: status=0xFFFFFFFC
E/MyApp(18060):   at android.media.MediaPlayer.prepare(Native Method)
E/MyApp(18060):   at com.myapp.android.activity.videoplayer.VideoPlayer.playVideo(VideoPlayer.java:302)
E/MyApp(18060):   at com.myapp.android.activity.videoplayer.VideoPlayer.surfaceCreated(VideoPlayer.java:432)

E/MyApp(18060):   at android.view.SurfaceView.updateWindow(SurfaceView.java:532)
E/MyApp(18060):   at android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
E/MyApp(18060):   at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
E/MyApp(18060):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
E/MyApp(18060):   at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
E/MyApp(18060):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
E/MyApp(18060):   at android.view.View.draw(View.java:6796)
E/MyApp(18060):   at android.widget.FrameLayout.draw(FrameLayout.java:352)
E/MyApp(18060):   at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
E/MyApp(18060):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
E/MyApp(18060):   at android.view.View.draw(View.java:6796)
E/MyApp(18060):   at android.widget.FrameLayout.draw(FrameLayout.java:352)
E/MyApp(18060):   at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1901)
E/MyApp(18060):   at android.view.ViewRoot.draw(ViewRoot.java:1407)
E/MyApp(18060):   at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
E/MyApp(18060):   at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
E/MyApp(18060):   at android.os.Handler.dispatchMessage(Handler.java:99)
E/MyApp(18060):   at android.os.Looper.loop(Looper.java:123)
E/MyApp(18060):   at android.app.ActivityThread.main(ActivityThread.java:4627)
E/MyApp(18060):   at java.lang.reflect.Method.invokeNative(Native Method)
E/MyApp(18060):   at java.lang.reflect.Method.invoke(Method.java:521)
E/MyApp(18060):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
E/MyApp(18060):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
E/MyApp(18060):   at dalvik.system.NativeStart.main(Native Method)
I/MediaPlayer(18060): Info (1,26)
User avatar
mathias.lin
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Tue Aug 11, 2009 4:21 am
Location: Guangzhou, China

Top

Re: VideoView cannot play video from internal storage

Postby blundell » Thu Aug 05, 2010 1:32 pm

No clue sorry, interesting that you can open the pictures and not the video's :-/

Just out of interest, your phone would need to be rooted to move something into this directory, correct?
Why not package the media with the apk? Or do you download it from the net to your SD card then move it to your IS?
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: VideoView cannot play video from internal storage

Postby mathias.lin » Thu Aug 05, 2010 1:51 pm

No, the phone doesn't need to be rooted. Although I cannot move the files under /data/ as a user, the app needs to do that. Which is why I wrote a routine in the app that copies the 1.5GB of data to the /data/ directory (internal storage) and then removes the data from sdcard. Actually I don't want to give the regular user access to the /data/ dir, this is the whole point why I'm doing that: I want to protect the media data, so that only the app can display it or the data can be cleared/deleted, but not copied off the device.
(For better understanding: In my case, it's not a public app for the market,but I bundle the device with my app and rent it out).

I found a workaround now that whenever I want to play a video, I copy one video to sdcard (always under the same name), and then remove it after it's finished. It's not the best solution, but at least I get it working and the media is a little better protected than before.

> package the media with the apk ?

I'm not sure whether that would make a difference. It would mean I need to place the videos into the assets folder of the app. But that's also internal storage - I haven't tried that but it should not make much difference... but maybe.... I might try that later.

> Or do you download it from the net

Yes, the media gets updated via a CMS on the web, then eventually download it (zip file) and update the app with the new media files once in a while.
User avatar
mathias.lin
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Tue Aug 11, 2009 4:21 am
Location: Guangzhou, China

Re: VideoView cannot play video from internal storage

Postby jonbonazza » Thu Aug 05, 2010 2:22 pm

A phone needs root access for anything (person or app) to access the /data/ directory. That is why apps like rootExplorer exist and are only useable by rooted phones.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: VideoView cannot play video from internal storage

Postby blundell » Thu Aug 05, 2010 2:32 pm

Ah interesting I didn't realised the app had access here when non rooted.

Yeah I've seen Video working when packaged in the res of the apk, that's why I though I'd mention it, but obviously if you want to update them you would have to release a new apk.

Good idea copying it over and playing it, not the best solution but at least it works.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: VideoView cannot play video from internal storage

Postby mathias.lin » Thu Aug 05, 2010 4:27 pm

Wondering though if larger files ~5-6 MB can handled from the raw/assets folder well.

btw: found some related discussions at
http://stackoverflow.com/questions/2860 ... ets-folder
http://stackoverflow.com/questions/3028 ... raw-folder
User avatar
mathias.lin
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Tue Aug 11, 2009 4:21 am
Location: Guangzhou, China

Top

Re: VideoView cannot play video from internal storage

Postby blundell » Thu Aug 12, 2010 8:16 pm

Hey mathias have you looked into zipping the files and putting them in the raw dir then decompress to the internal storage / data , just playing with it now
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: VideoView cannot play video from internal storage

Postby mathias.lin » Fri Aug 13, 2010 12:41 am

Haven't tried it, is it working for you? So you play the video from the raw dir or also from the data dir? If I understood correctly, it would also be attempted to play from the data dir, right? Is it working?
User avatar
mathias.lin
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Tue Aug 11, 2009 4:21 am
Location: Guangzhou, China

Re: VideoView cannot play video from internal storage

Postby blundell » Sat Aug 14, 2010 7:13 pm

Hey bit busy this weekend with other things,

but I've got it zipped in the DIR and I can uncompress it to the Internal Storage directory , I'm just trying to figure out how to create a URI of it's location once i've done this .. update you mon-tues. This will save me about 1-2meg per video let's just hope they play!
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: VideoView cannot play video from internal storage

Postby mathias.lin » Sat Aug 14, 2010 7:23 pm

What do you mean 'how to create an URI' ? You cannot just path the absolute path of the file to the video view? It should be /data/data/com.yourAppPackage/files or something like that, not?
User avatar
mathias.lin
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Tue Aug 11, 2009 4:21 am
Location: Guangzhou, China

Re: VideoView cannot play video from internal storage

Postby blundell » Sat Aug 14, 2010 7:38 pm

Well that's what I'm looking for documentation for, not just "something like that" :-)
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: VideoView cannot play video from internal storage

Postby mathias.lin » Sun Aug 15, 2010 3:10 am

But you can define the path whatever you like it to be.
/data/data/com.yourAppPackage/files or /data/data/com.yourAppPackage/anotherfolder or /data/data/com.yourAppPackage/subfolder/subfolder2 and then you set the videoPath to that.
See my reply at http://stackoverflow.com/questions/3474 ... 78#3474878 and also http://stackoverflow.com/questions/3458 ... 04#3458104
Use getFilesDir() (standard method of the SDK) to get the base directory /data/data/com.yourAppPackage/files.
User avatar
mathias.lin
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Tue Aug 11, 2009 4:21 am
Location: Guangzhou, China

Re: VideoView cannot play video from internal storage

Postby blundell » Mon Aug 16, 2010 4:53 pm

Yeah I've ended up at the same place as you mathias, getting a prepare failed status0x1 error :-(

Looking at the google example they give a little hint that it won't work:
Code: Select all
path = "";
                    if (path == "") {
                        // Tell the user to provide a media file URL.
                        Toast
                                .makeText(
                                        MediaPlayerDemo_Video.this,
                                        "Please edit MediaPlayerDemo_Video Activity, "
                                                + "and set the path variable to your media file path."
                                                + " Your media file must be stored on sdcard.",
                                        Toast.LENGTH_LONG).show();

                    }


"Your media file must be stored on sdcard." so guess where f*cked,

I don't think copying to the SD card is a viable option for me, would cause to much lag, I'll keep looking
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: VideoView cannot play video from internal storage

Postby blundell » Mon Aug 16, 2010 5:47 pm

I am 'DA BOMB'

Change your code to use a File Descriptor and you can use the internal storage Mathias :-)

so I basically did this:
Code: Select all
player.setDataSource(myObject.getVideoPath(this));

public FileDescriptor getVideoPath(Context context) {
      Log.i(TAG,"Returning FileDescriptor");
      try {
                       // This is the same as your "/data/data/com.package" string
         File tempFile = context.getFileStreamPath(videoResName).getAbsoluteFile();
         FileInputStream fis = new FileInputStream(tempFile);
         return fis.getFD();
      } catch (IOException e) {
         Log.e(TAG,"Bad Bad Times, Failed to get File Descriptor");
      }
      return null;
   }


Found here : http://stackoverflow.com/questions/1972 ... -from-byte :-)
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: VideoView cannot play video from internal storage

Postby blundell » Wed Aug 18, 2010 7:41 pm

Just converted it to use external storage as well , so I can confirm VideoView work's where-ever you put your files as long as you call it with a FileDescriptor :-)
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top
Next

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot] and 14 guests