How to play Video from application cache in android - android

I want to play video file from android cache folder using the following code :
String cacheDir = getApplicationContext().getCacheDir().getAbsolutePath();
File outFile = new File(cacheDir, "intro.mp4");
vvIntro.setVideoPath(cacheDir+"/intro");
vvIntro.start();
But I got error :
07-05 20:14:21.896: E/MediaPlayer(1251): error (1, -2147483648)
07-05 20:14:21.928: I/Choreographer(1251): Skipped 79 frames! The application may be doing too much work on its main thread.
07-05 20:14:22.186: D/gralloc_goldfish(1251): Emulator without GPU emulation detected.
07-05 20:14:22.496: E/MediaPlayer(1251): Error (1,-2147483648)
07-05 20:14:22.496: D/VideoView(1251): Error: 1,-2147483648
where the file is already exists and the required persimmon as show below :

You create a File object pointing to your MP4 file, then totally ignore that File object and provide an invalid path to vvIntro. Instead, try:
File outFile = new File(getCacheDir(), "yourVideoName.mp4");
vvIntro.setVideoPath(outFile.getAbsolutePath());
vvIntro.start();
and see if that helps.

You can just use my simple library AndroidVideoCache. It allows stream and cache video simultaneously.

you can set Uri :
Uri uri = Uri.parse(getApplicationContext().getCacheDir()+"/video.mp4") ;
videoView.setVideoURI(uri);
videoView.start();

Related

New getExternalFilesDir in Android R crashes in emulator because SD card is missing?

I'm trying to use non-deprecated methods for storing an image. However, the suggested context.getExternalFilesDir crashes in the emulator on the first line in the following.
val albumFolder = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!
i { "Writing file to ${albumFolder.absolutePath} "}
albumFolder.mkdirs()
check(albumFolder.exists() && albumFolder.canWrite()) { "Missing or non-writable folder: ${albumFolder.absolutePath}"}
It throws 2 errors, then dies on a NPE for the first line.
E/vold: Failed to find mounted volume for /storage/emulated/0/Android/data/MYAPP/files/Pictures/
W/ContextImpl: Failed to ensure /storage/emulated/0/Android/data/MYAPP/files/Pictures: android.os.ServiceSpecificException: (code -22)

Android media player can't play ogg files

I'm using MediaPlayer library to stream some audio files from my server. The problem is when I want to play ogg audio file with media player in android version 4.2.2 and it's ok when I play it in android nougat. It gives me this error while preparing ogg audio file:
E/Tag: Prepare failed.: status=0x106
E/MediaPlayer: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)
E/MediaPlayer: stop called in state 0
Is there any alternative way to stream ogg format in all devices?
by the way there is no problem with playing mp3 files in all android versions I'v tested.
Thank you ...
First you should add <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Then set data source, maybe:
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_RING); will help;
And of course prepare file before start:
mp.prepare();
mp.start();

How to post audio file to server in android

I need to post Audio file(picking from Audio/* intent) to server.here i got Uri, but the posting param type is File. I Used below code but it shows /directory/.. is not a absolute path and getting FileNotFoundException. Any one suggest me..
Code :
Uri uri=data.getData();
File f=new File(uri.getPath());
Log:
09-26 21:20:19.735: I/System.out(920): java.io.FileNotFoundException: /document/audio:5257: open failed: ENOENT (No such file or directory)
(this is a duplicate)
See here:
Convert file: Uri to File in Android
Don't use Uri::ToString() and use Uri::getPath() instead.

Android API-Demo MediaPlayer not playing videos from SD-Card

I installed the ApiDemos project, which can be found in <your-sdk-path>/sdk/samples (provided you installed samples with SDK manager). I tried the one for api17. I pushed a video file onto the sd card of my device (I tried a samsung tablet and a LG P990) with DDMS and set the Path of the video to:
path = Environment.getExternalStorageDirectory().getPath() + "/myvideo.mp4";
(That is the only part where I edited the ApiDemos example)
I checked that this path returns the actual path to the sdcard where I pushed to file to and it is, the video however is not played.
When I run the whole thing in a genymotion device, the video is played without a problem. Does anyone has an Idea whats wrong here?
Log
These are the lines that are logged when the video is tried to be loaded by the ApiDemo:
11-05 16:03:42.830 2305-2334/? E/Trace﹕ error opening trace file: No such file or directory (2)
11-05 16:03:42.838 2305-10023/? E/OMXCodec﹕ [LEGO] else flags = 0
11-05 16:03:42.955 2305-10023/? E/OMXCodec﹕ set buffer size variable to : 1572864
11-05 16:03:44.970 2305-10034/? E/OMXCodec﹕ [OMX.TI.DUCATI1.VIDEO.DECODER] ERROR(0x80001000, 0)
11-05 16:03:45.189 385-456/? E/WifiStateMachine﹕ set default RSSI: -200
11-05 16:03:46.986 2305-10023/? A/OMXCodec﹕ frameworks/av/media/libstagefright/OMXCodec.cpp:1821 CHECK_EQ( err,(status_t)OK) failed: -110 vs. 0
11-05 16:03:46.986 2305-10023/? A/libc﹕ Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 10023 (TimedEventQueue)
If your Video is in the root of your sd Card then try:
videoView.setVideoPath("/sdcard/myvideo.mp4");
or try if you have a Directory named e.g "my_Videos"
path = Environment.getExternalStorageDirectory() + "//my_Videos//";
path += "myvideo.mp4";

Failed to unmount /mnt/secure/staging

android Unable to access files in SD card ####Android无法访问SD卡中的文件
I am working on application where it create text files in the SD card.
I have a receiver which will execute logic to create files in SD card from that point I will keep on store some data into that .
So far it is working properly , but suddenly I stopped working.
I checked logcat output , I found some logs related to SD card mounting.
But do not have an idea to how to resolve this issue.
below are the log statements:
1.464 W/Vold ( 2357): Failed to unmount /mnt/secure/staging (Device or resource busy, retries 3, action 0)
08-23 07:26:31.783 E/ProcessKiller( 2357): Process logcat (3344) has open file /mnt/secure/staging/abc1.txt
08-23 07:26:31.783 E/ProcessKiller( 2357): Process logcat (3345) has open file /mnt/secure/staging/abc2.txt
08-23 07:26:32.845 W/Vold ( 2357): Failed to unmount /mnt/secure/staging (Device or resource busy, retries 2, action 1)
08-23 07:26:33.173 E/ProcessKiller( 2357): Process logcat (3344) has open file /mnt/secure/staging/abc1.txt
I have added permission android.permission.WRITE_EXTERNAL_STORAGE
I think it's just because you're use multiple thread to access file. So, try to use synchronized in your open file function.
synchronized void openFile(String filePath) {
// Code to open file
}
before writing the text file into SD-card you must always check the media state
if(Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED))
{
// read or write file logic here //
}

Categories

Resources