Can we change the extension of video and play it? - android

Currently I am downloading a ".mp4" video and saving it in a folder. I want to hide it from gallery. I know how to hide a folder. Currently I am saving it in a different extension for ex. like ".sss" and it is saving properly. Now how can I play that video in my application.
I tried to change the extension and in file and try to play it, but it is not working, here is my code
File extStore = Environment.getExternalStorageDirectory()+"/"+"downloadFolder"+"/"+"video1.sss".replace(".sss",".mp4");
JCVideoPlayer mJcVideoPlayerStandard = (JCVideoPlayerStandard) findViewById(R.id.videoplayer);
mJcVideoPlayerStandard.setUp(extStore.getPath(),JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "Normal");
mJcVideoPlayerStandard.showContextMenu();
I am using this path to play the video,and I am usign JcVideo player lib for playing the video, here is the gradle for it
compile 'fm.jiecao:jiecaovideoplayer:5.4'
When I am saving the file in ".mp4" format I am able to play the video. But when I use different format,I am not able to play it. Any help will be preferable

I think what you are trying to do is to rename the file to mp4 before you play it?
If so the code above is replacing the the '.sss' with '.mp4' in the search string rather than renaming it in the file system.
In other words the line:
File extStore = Environment.getExternalStorageDirectory()+"/"+"downloadFolder"+"/"+"video1.sss".replace(".sss",".mp4");
simply translates to:
File extStore = Environment.getExternalStorageDirectory()+"/"+"downloadFolder"+"/"+"video1.mp4";
As your actual file is still video1.sss you get an error when you try to play a file named video1.mp4 as it can't be found.
If you do want to rename a file you can do it like this:
File file1 = new File("Path of file");
File file2 = new File("Path with new name for the file");
boolean ok = file1.renameTo(file2);

I think you simply can't do it! by changing the extension of a video file you can't play it. because no matter what its extension is, the Audio and Video format coding format won't change by changing extension name. If a player can't play such extension, it is not in its supported video codec.
The Audio and Video format define how a video file is build byte to byte. check this Wikipedia page.

Related

Create VideoView from a video file that is inside of a Zip File - Android

I have successfully downloaded a .Zip file from my server, which is then stored on my tablet.
However, I now want to set VideoView.setUri() to one of the files in the .zip.
I have DownloadManager.getUriForDownloadedFile(referenceId) showing me that the zip's Uri is: content://downloads/my_downloads/305.
What I want to do now is take that Uri and feed it into the VideoView, without extracting it (if possible).
I have found that you can reference a zip's file via the extension:
"zip_path_zip_name" + "!/" + filename.ext".
So you could call:
VideoView.setVideoURI(Uri.parse("zipPathAndTitle" + "!/" + "test.mp4""));
But I'm stuck from the Uri of: content://downloads/my_downloads/305 getting that as a file I can reference, to then set as the VideoView's Uri.
Any help is greatly received.
First, extract the zip file to a specific folder in your storage. You can't use file inside this zip file unless you extract it. Get the path of the extracted file you want in this folder then set it to your VideoView.

Playing .mp4 file on zip without extracting zip

On the SD-card I have a zip file containing one video file (.mp4). I need to play that video file via a VideoView without extracting the zip.
So far I have tried :
ZipFile zipFile = new ZipFile(new File("/sdcard/checking.zip"));
ZipEntry zipEntry = zipFile.getEntry("checking.mp4");
InputStream inStream = zipFile.getInputStream(zipEntry);
But I don't find any API that plays video from InputStream. zipEntry.getSize() does return the value.
I tried videoView.setVideoURI(Uri.parse("//sdcard/checking.zip!/checking.mp4")); from HERE
But it shows "Can't play video".
So how do I do that (mentioned in the title) on android.
With the VideoView or MediaPlayer you can't do that
To be honest I am having the same problem. But in the Expansion Files documentation it says you need to zip the file in a particular way in order to read straight from the zip folder. You shouldn't apply any compression to the media inside.
Hope this helps...
I just don't really know how to zip like that.

Playing sound files from expansion file

I have an expansion file with a series of sound files. The longer ones are .mp3 files while the shorter sound effects are .wav files. I pack them in a .zip file with no compression. I use the Zip File reader and downloader library provided by Google.
I'm opening the sound files like so:
MediaPlayer mPlayer;
...
AssetFileDescript asd = expansionFile.getAssFileDescriptor(fileName);
FileDescriptor soundFile = asd.getFileDescriptor();
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(soundFile);
mPlayer.prepare();
mPlayer.start();
The odd thing is that it plays the same sound file every single time. It seems to be whatever it finds first. The byte size for asd.getDeclaredLength() and asd.getLength() is exactly what it should be. This means the file descriptor is at least finding the file, but for some reason the MediaPlayer plays whatever random file it decides.
What exactly am I missing here? Any help would be greatly appreciated.
Thanks.
The first approximation is correct, except for when the zip file contains more than one file, then you should use:
mPlayer.setDataSource(asd.getFileDescriptor(), asd.getStartOffset(), asd.getLength());
You can get more information from this other question:
Play audio file from the assets directory
Please, also remember to close the AssetFileDescriptor just after setDataSource to media player:
asd.close();
http://developer.android.com/reference/android/media/MediaPlayer.html#setDataSource%28java.io.FileDescriptor,%20long,%20long%29

Android path to resource inside package

I tried to add a video path to an Android sample project - MediaPlayerDemo
I can playback the video when it stored in sdcard, the path is
"file:///sdcard/dcim/a.m4v"
But I can't playback the video when it stored in res/drawable. the path is
"android.resource://" +this.getPackageName () + "/" + R.drawable.a
I can read the id of the video in debug mode, but just can't replay the video.
How to solve it?
UPDATES
Thank you for the reply, so far i have tried:
put the video in assets, set path to "file:///android_asset/a.m4v".
put the video in raw, set path to
("android.resource://" +this.getPackageName () + "/" + R.raw.a) or ("android.resource://" +this.getPackageName () + "/raw/a)
but none of them can playback video.
My video is 1.8Mb, does it matter?
Create a new folder with name raw in res folder, if already created let it be. Copy your playable video file (e.g., myvideo.mp4) to raw folder. Use below code in your app.
String uriPath = "android.resource://"+getPackageName()+"/raw/myvideo";
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
I tested, its working for me. If the video is playable from sdcard then only it will play from raw folder, otherwise it will show a dialog box says Cannot play video.
try it and let me know what happened.
FYI, drawable is to store icons, images, drawables for the application. So You can put the same video either in assets or in raw folder.
I have found the solution, but not a straight forward way.
First, the file not found problem is not the path problem, it is because the permission problem.
To solve that, many people suggest copy the file into FileInputStream. But still got file not found problem.
But the File can be written to Inputstream. However, setDataSource() of Mediaplayer class does not acccept InpuStream. Therefore need to write the Inputstream to a temp File by BufferedOutputStream.
finally, setDataSource(tempfile_path) without error.
This question is quite old and still not answered well so here I will answer.
First of all, do not put videos in the assets folder. It is a bad practice. Create another folder (Preferably one named raw).
The second thing is that please do not use m4v format. Use a mp4 video.
Here is the code to insert video:
//Here it is assumed here that the file name of video in raw folder is demo
VideoView video = (VideoView) findViewById(R.id.videoView);
video.setVideoPath("android.resource//" + getPackageName() + "/" + R.raw.demo);
video.start();
Hope this clarifies your doubt!

Playing Video from app cache inside a directory

I am working on Android 3.1 ,
My problem is that the downloaded video from link to my applications cache directory does not working,
but Working the same downloaded video from the Cache?
The video is being downloaded and I am saving it into memory application like the following senarios
// Works
File file = new File(getCacheDir(), "sample.mp4");
// Does not work
String RootDir = getCacheDir() + File.separator + "FirstData";
File RootFile = new File(RootDir);
RootFile.mkdirs();
File file = new File(RootFile.getAbsolutePath(), "sample.mp4");
If I attempt to play the video and set the path like .
videoview.setVideoPath(file.getAbsolutePath());
and trying to "stream" the video to my VideoView, it is showing sorry can not play the video
and showing the errors like
03-22 12:43:39.898: E/MediaPlayer(1335): error (1, -2147483648)
and also i sets the file permissions like
file.setReadable(true,false);
even it showing the same.
but its working fine when the location of video is getCacheDir(), Only the problem with inside cache one more directory i have created and trying to play then the problem is coming.
So Can anyone explain this behavior?

Categories

Resources