Custom MediaScanner libraries/MediaStore alternatives? - android

Are there any custom open-source libraries that don't rely on the default MediaStore (so that I don't reinvent the wheel)? Or do I have to write my own scanner? The problem:-
I've created a music player in Android that can also create playlists from local files. The details about the local media is obtained from Android's MediaStore. Everything works fine until I relocate my music files. When a media file is moved, the ID field in its entry in the Android MediaStore gets changed. Obviously that means any attempts to get to the file using the stored (stale) ID's will fail. How do I get around this? Thanks!

You are able to manually refresh the content of the Media library.
Read this related post - I think you will find it useful!

Related

File renamed successfully but MediaStore returns the same file name

I am building a simple video player application. I wanted to add a feature to rename video files from the app.
I am getting all the video files from MediaStore.Files.getContentUri("external") with a filter of MediaStore.Files.FileColumns.MIME_TYPE LIKE "video%" instead of MediaStore.Video.Media.EXTERNAL_CONTENT_URI directly because this skipped some of the files that I wanted to be there.
I got the following Java code that renames a file:
file.renameTo(File(file.parent, "video.mkv"))
It worked successfully and there was no problem with this.
How did I know that it was renamed?
I had another video player application so I checked if the file was renamed and the weird thing was, it was renamed there.
But when I again queried MediaStore it was not updated there, it gave the same file name again.
And after some browsing, I got to know that I need to update MediaStore too.
So if MediaStore is not updated, then how does that application know that the file was renamed?
Also, I don't know if this is important but just to mention here, it was not an in-built application so there is no chance of having any special permissions to access any "special" database.
So I don't think updating MediaStore is really necessary to rename a file.
Is there any other way of doing this?
Thanks

getting content uri of already downloaded video in android Q

i still don't understand the change made on access media files in android Q. My app downloads videos, but playing or retrieving the video gives error.
Noticed, for android Q, every media file outside of app specific folders need to be registered in the contentresolver. In which the content resolver gives a special id to that file in return. Am i right?
if so how do i register a media file in content resolver and at the same time get the uri of the media file
A good explanation on accessing, saving and opening media files on android Q will be appreciated for a better understanding
The file manipulation changes from android 9 (Q) are really confusing.
Have you read the basic documentation on data and file storage?
Basically consider your app can write and read files that it created inside internal storage or primary external storage on the folders that belongs to this app.
Reading from sdcard can be done but requires permission from the user.
Writing on sdcard can be done with limitations and is not so easy. It also requires user permission.
Media files can be handled by MediaStore api and if they are inside the folders from your app it is easier.
If you want to store Media file on other folders different from the default media folders, then it is a little more difficult.
Please, define better what are your app flows and requirements in order to be easier for someone to help.

how to access files in default package from native android code (Codename One)

Since I can't use Media objects for playing when the app is not running but I have to play media files in that state, I need a solution to access media files from native code and reference them for native media players (either via path or Inputstream). I still want to put the relevant files in that way that it won't become a burden to access them from native iOS code.
There are two options I was thinking about, but couldn't really manage in my implementation.
Put the relevant data files in the GuiBuilder's data section and access them over a Resources object (and call getData(id)). But when I try to create a Resources object over Resources.open("/theme"); from native code on Android I get the following exception: java.io.IOException: /theme not found.
Keep the relevant data files in the default package and access them over Class.getResourceAsStream or Class.getResource. But I don't know how to point at those files. I tried various paths but without any success.
If you copy the media files to FileSystemStorage, it should be fairly easy to access on the native side. You can just pass the path to your native interface.
That being said, I have developed a few CN1 apps with background audio without problem. On iOS you just need to supply the ios.background_modes=audio build hint so that the app will be allowed to run in the background.
If you use the Display.createBackgroundMedia() method to create the media, then Android will also use a background service for playing the media.

securing the mp3 in my android app

I have a android app which has a copyrighted mp3 track. I dont want users to see the mp3 that is stored in my app on music player.currently users are able to access the track using their default music player.
any lights on this issue?
Add a .nomedia file in the audio track directory of your app.This avoids the files being listed in music player.
There are multiple possibilities, based upon your needs, pick one, or a combination:
1) An easy solution: Put the .mp3 in your private folder. NOTE: Rooted users are still able to play/copy the mp3 file.
2) Another Easy way: rename the .mp3 to something weird, so it will not get picked up by music players. E.g. your_file.aaa ... NOTE: Rooted Users who know this file is actually an .mp3 can rename it and play/copy it
3) Or, a bit more work, encrypt/decrypt the file. This tutorial can get you started. This is an option if you absolutely want to prevent users from playing/copying the .mp3 outside your app.
Convert your file to binary refer this and the encrypt it using something like base64 while saving. while fetching do th reverse

Caching Layer in Android

I'm looking for a solution (possibly implementing it) that would allow me to create a cache on my SD card (say, 25G) which would be used by some "caching layer" to store media on demand. The issue being that all of my media doesnt fit on a 32G SD card, so I want to be able to transparently have my missing data downloaded (ie: I dont want to have to download using another app) while I am attempting to play it in the stock media player or the Gallery or whatever. Does anyone know of an existing solution like this? I'm already familiar with the various dedicated apps out there which do this for music, but I'm looking more for a generic cache which caches anything that passes through it on an LRU basis. I want my NAS at home (or on S3, dropbox, Ubuntu One, whatever) to be an extension of my Android device(s).
If one doesnt exist, is it possible to chain ContentProviders? Could I create a CacheProvider which keeps track of what is currently in my cache and what isnt, and use the URIs from the CacheProvider to populate the MediaStore? All examples I can find so far show that what comes out of the MediaStore is always a URI to a file, so I suspect its not currently possible.
After a little POC, it appears that this is not possible using ContentProviders alone. While it is possible to chain providers together if you override ContentProvider.openfile(), since the MediaProvider currently assumes that everything in _data points to a file or an HTTP stream, the Music app will fail to play any content which sticks another content URI into _data. If MediaProvider were changed to handle content URIs then this would be possible, but I think the only way to achieve that would be to copy/paste the MediaStore framework and rename it all, or to do the change in a mod (like CyanogenMod).

Categories

Resources