How can I Encrypt and Decry-pt Video playing any Video Player? - android

I working on media application, On app user able to watch video on any video player. all media file is stored in Internal Storage which is .mp4 formate in particular folder called LearningVideo.
My question is I want to encrypt that video so a user won't able access that and also decrypt that video when app play that.
So how can I achieve this task, please help me.
I tried com.google.android.exoplayer:exoplayer:2.6.0

Use CipherOutputStream and CipherInputStream for encryption and decryption of file in android.
There are two ways through which you can achieve your goal
Download a file and encrypt it, when you want to play that file decrypt it in a temporary file and play it.
if you want to play the encrypted file on the fly (not decrypting it in a temp file) then you can use Libmedia library. It streams encrypted file on localhost and plays it from there

Try to write Files inside FilesDir may be this solved your issue
File rootpath = getApplicationContext().getFilesDir();
File path = new File(rootpath.getAbsolutePath() + "/LearningVideo");
You can store your files inside /data/user/0/<packageName>/files

Related

try to hide downloaded videos of video streaming App

I'm trying to create an AWS video streaming App on Android. but I have to download the video for offline streaming. but thing is that I want to hide the video files, like youtube or NetFlix.so if anyone can explain how to hide downloaded files....pleasse help me . Thank you :)
You can use app-specific files directory, no one can see files...
You can access files directory via,
in Kotlin
val file = File(context.filesDir, filename)
in Java
File file = new File(context.getFilesDir(), filename);
for more details https://developer.android.com/training/data-storage/app-specific

How to stream encrypted file using exoplayer (sample)?

I am trying to stream encrypted audio file (.mp3),but I do not know how to achieve this. I am requesting a sample, or some form of direction to do that?. There is an issue here https://github.com/google/ExoPlayer/issues/2467
but it is discussing play local encrypted file.
Thanks for help.

Android - Video Playback from internal memory

I have a requirement to be able to save and play videos from the internal memory. The files have a mix of .mp4 and .3gp formats. My question has two parts - saving files and playback.
SAVING FILES
I know of two ways to save video into the internal memory:
1. FileOutputStream f = context.openFileOutput(videoName, MODE_WORLD_READABLE);
2. FileOutputStream f = new FileOutputStream(internalFilePath+File.separator+videoName);
where internalFilePath is obtained separately by using getFilesDir() function.
Question: I can only play videos which were saved using #1 and not #2 above. Why? I get errors saying like:
"This video can't be played"
Is it because files stored by #2 are not readable by video playback apps because they are private to my app? But then how can I make my files private and playable at the same time? This is where the second part of the question fits I guess.
PLAYBACK
I know of three ways to play videos in my app:
Building an intent with ACTION_VIEW, setting the data type to the appropriate mime type, startActivity(intent) and letting installed apps take care of the playback.
Using a VideoView. Although I personally don't like this approach because of the amount of coding involved.
Using MediaPlayer class.
Question: Considering that I store my files in the internal memory, which of these methods is the best for playback?
When you are saving a video to your internal storage, that video is accessible to that application only and no other app can use that video. In your case, you have shown two methods to save videos to your file.
FileOutputStream f = context.openFileOutput(videoName, MODE_WORLD_READABLE);
This way you are able to play your file because you have set mode as MODE_WORLD_READABLE. MODE_PRIVATE makes it private for your app. This is why you are able to use the video file from other app by this way as your mode is mode_world_readable and when you are saving the file the second way, it doesn't play because the file is again private to your application only.
For playing videos that have been saved from the second approach, you can try the following code:
FileInputStream fileInputStream = new FileInputStream(filePath);
mediaPlayer.setDataSource(fileInputStream.getFD());
I guess this should work.
Edit: Please change the above code snippet variables as per your project needs.
Source: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

How do you make internal files world readable on Honeycomb?

I am trying to load video files from my internal storage to a VideoView. I download these video files from a server and then store them locally using this code:
FileOutputStream out = openFileOutput(filename, Context.MODE_WORLD_READABLE);
The documentation here: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal made me believe that these files would be created as world readable, but I don't think that is true.
Here is the code I use to load the file into the ViewView:
videoView.setVideoPath(getFilesDir() +"/"+ filename);
And here is the output I get from DDMS:
ERROR/MediaPlayer(4264): error (1, -2147483648)
ERROR/MediaPlayer(4264): Error (1,-2147483648)
DEBUG/VideoView(4264): Error: 1,-2147483648
If I change the code to load the same video from my raw resources directory, everything runs fine. However, I need to be able to download these videos and play them locally.
Are my only options to use external data or is there a way to make internal data public to something like a VideoView?
CommonsWare solution in the comments is repeated below, as it is the one I ended up using:
Note that you can always use MediaPlayer and SurfaceView if you don't like the interface of VideoView. Or, implement a simple ContentProvider with openFile() to return the FileDescriptor and use the content:// Uri with VideoView. - CommonsWare

How can I encrypt a file (video/audio/image), save to SDCard, then decrypt that same file and play it via VideoView?

I am trying to create an app that would download a file from a remote server and save it to the SD card. The file is quite confidential so I need an encryption for this. I would like it to be saved as encrypted. When I want to play the file, it should only be played on my media player which has the decrypt code. No other player can play that file. How is this possible? Thanks for any suggestions you may have.
If you don't want to be bothered with a delay by decrypting the entire file before to be able to start the playing, you should consider a streaming architecture. A typical design involves the javax.crypto.CipherInputStream class and a local http instance. For an example of that kind of design, look at something like LocalSingleHttpServer.

Categories

Resources