I am creating an own application for android that generates playlists. Application creates .m3u files in UTF-8 encoding format. Files exist and visible in file manager, but media players don't see the playlists and this is a problem. Playlists files are correct and work properly in build-in player in file manager.
Here is some part of the code, that gererates playlists:
File file = new File(Environment.getExternalStorageDirectory() + "/Music","Test.m3u");
PrintWriter writer = new PrintWriter(file, "UTF-8");
...
writer.println(PathToSong.toString()+"\r");
....
writer.flush();
writer.close();
I downloaded a program from Play Market that also creates playlists (.m3u) files. Playlists files that are built by the program have the same format as mine, but visible for media players. The most interesting thing is: ater launch the program from Play Market, playlists from my own program becomes visible for media players too.
Also my playlists become visible for the media players after restarting the phone. I develop and test my application using Android Studio 0.3.4.
I found the answer. It is needed to run media scanner so that mediafiles(photo, music, etc.) become visible in applications. Media Scanner runs automatically after phone restart.
To run Media Scanner manually you just need to paste and run this part of code:
UpdateMediaIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()));
sendBroadcast(UpdateMediaIntent);
Hope, it will be helpful for somebody else too.
Related
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
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
I'm recording/selecting video with media-capture plugin, convert it to mp4 with video-editor plugin and after the user confirms the selection I copy/move this file to app specific media dir (something like /storage/emulated/0/APPNAME/Video/).
Everything works fine, except that if the user tries to open the video file immediately, the native video player will open but there'll be a message like "Could not play video" (on android) and the console.log shows the error "File not found".
This happens on both iOS and Android.
I use this plugin to open video files in native players.
If I exit the app and reopen it, the issue dissapears. So the problem is, I think, that the system does not know about the existance of that new copied/moved file. Is there a way to refresh the filesystem?
I have checkd the file URI that I pass to the openfile plugin and it's the same when it works & when it doesn't.
I use HTML5 FileSystem to copy/move files.
I use promisses, I wait until files are copied/moved, so it's not this the issue.
I create an App which download a mp3 file and save it in app data directory and play it using android MediaPlayer class , the problem is, this code work on some device and not work on others, for example I noticed the device with SDK 10 and lower can't play it.
the code I use is very simple
mp = MediaPlayer.create(Sounds.this, Uri.fromFile(f));
mp.start();
I would appreciate any help.
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