android - Can a videoview play a video stored on internal storage? -


I am trying to give my users the ability to use external or internal storage, both images and video ( Of a scientific nature). When the media is stored on the SD card, it's all right. But when I store the media internally, only images will be displayed; Anything that I do not try, I get various errors in trying to load and display the archived media under Application Contex .getFilesDir () I am

Is there such a trick to set the content of VideoView in such a file?

Can a Content Resolver Help Me?

On the related note, is it believed that external storage exists?

Thanks in advance,

Sid

Below is a version that fails with "Video can not be played", Sorry, this video is not Can be played. "But I have many other methods of failure, I can copy the internal video to temporary storage (external) and run it, so internally it is actually making a valid movie. Only then fails when I directly internal it I try to run from memory.

  video file = new file (this.getFilesDir (+). File separator + "test.mp4"); InputStream data = res.openRawResource (R .raw.moviegood) Try {OutputStream myOutputStream = New FileOutputStream (videoFile); Byte [] Buffer = New Byte [8192]; Integer Length; While ((Length = Data. Read (Buffer)) gt; {myOutputStream.write ( Buffer;} close my / myOutputStream.flush (); myOutputStream.close (); data.close ();} hold (FileNotFoundException e) {// TODO auto generated blocking block e.printStackTrace ();} hold (IOException E) {// TODO Auto-Generated Catch Block e.printStac KTrace (); } Vview.setKeepScreenOn (true); Vview.setVideoPath (videoFile.getAbsolutePath ()); Vview.start ();  

The media player requires that the files being world-readable are permissible. You can see the permission of the file in the ADB shell with the following command:

  ls -al /data/data/com.mypackage/myfile  

Perhaps "-Rai ------" will see, which means that only the owner (your app, not the media player) has given permission to read / write.

Note: Your phone must be in order to use the ls command (in internal memory) without specifying the file.

If your phone is rooted, you can add universal read permission to ADB shell with the following command:

  chmod o + r / data / data / Com.mypackage / myfile  

If you need to modify these permissions in a programmatic way (Routed phone is required!), You can use the following command in your app code :

  runtime.gettime (). Exec ("chmod o + r /data/data/com.mypackage/myfile");  

Basically see more on a Linux command Chmod.

Edit: Get a more straightforward approach (useful for those without root phones). Since this file is the owner of the file, it can create a file descriptor and it's a media player. Setdata can be sent to the source ():

  FileInputStream fileInputStream = New FileInputStream ("/ data / data / com.mypackage / myfile"); MediaPlayer.setDataSource (fileInputStream.getFD ());  

This approach avoids the permission problem completely.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -