Provider "MediaProvider" is in use - android

My current task involves fixing an Android music player that sucks too much RAM. By taking a look at the "Apps" section of the system settings, I found a mysterious (for me) process called Media. Here is a screenshot:
I would like to know more about this process and about the reason why it appears every time a song is played and disappears every time the playback stops. The only reference I have been able to find in the official documentation is this one.
What does the MediaProvider class do?
Do you have any clue about what may be causing that process to be kept alive during the playback?

I solved it myself. Turned out that a Cursor was being left open (I don't know whether accidentally or willfully), thus causing the Media process to appear.
Still, it is weird that, neither in the official SDK documentation nor on the Net, there is no mention about any MediaProvider-ish thing.

Related

MediaPlayer starts throwing unknown errors after some time

I have an app with lots of short videos being played all over. Some of them using VideoView, some just a TextureView with a MediaPlayer. This works fine, except after a while, any new attempt to play a video using either of those methods fails with MEDIA_ERROR_UNKNOWN and a seemingly random value for extra. It seems to happen a lot earlier on lower-end devices too. It starts working again after killing the app.
Some more info that might be useful:
Most of the videos are set to loop
There can sometimes be more than one video loaded at a time, though it still breaks even if I avoid those situations
I call release() on the MediaPlayers I use when the activity or fragment they're in is destroyed, so I'd assume it's not a problem with leaking resources or something like that
All the videos being played are in the app's local storage
On some devices, I sometimes get an IOException saying setDataSourceFD failed instead, though I couldn't get it to happen to post the exact message here
My min sdk is 21 and target is 29
From the googling I've done so far, the only thing that seemed remotely related I found was that the video is in an unsupported format, but that can't be the case here, as it sometimes fails on videos that were played just fine before, sometimes even on the same run.
There's also this similar question, though that seems to be specific to a device, whereas I see this on anything I try it on, from emulators, through low-ends to high-ends, with the time it takes to break generally being longer the higher-end the device is.
This has been eluding me for a few days now, so any help would be much appreciated. Thanks.

Android MediaRecorder delay and method of fixing it

I am developing an app that allows you to record many clips and stitches them back together before uploading. Whilst developing for Android 5 and up I think this is prevalent problem on all the platforms. Not sure if anyone came up with an usable solution. I seem not to be able to record 1s video as the MediaRecorder takes ~500ms to .start() and on different devices this time changes.
The only method that I found to be more or less accurate is to set up a file observer on media file at the moment when I start() and stop observing when I finish I tend to wait for the first 256bytes to be written before I measure the clip time.
Now then CAN ANYONE tell me whether this is the only thing I can do? Or is there a better method of measuring the delay? Or if you know of an approach I could take to write a recording app that will have immediate start and stop I will greatly appreciate that.
If not maybe point me in the direction of a different approach? Bear in mind I am an absolute beginner so answers like "use MediaCodec API" really not going to help me a lot. I searched for days an appropriate solution can't seem to find anything useful anywhere. Setting thread with a delayedPost is also not an answer.

how to avoid Activity / Service restart on "Copying File asset ... to make it aligned"

I have a music streaming app which holds a PARTIAL_WAKE_LOCK to avoid that the CPU goes to sleep while playing music in the background. It works fine, but sometimes Android still kills and restarts my service instantly.
Here's what I found in the logs in the moment when this happened:
Copying FileAsset 0x65ccb2f8 (zip:/data/app/com.my.app.apk:/resources.arsc) to buffer size 143364 to make it aligned.
I know that Android can always kill / restart my Activity and even service and that the lifecycle methods are to be used to deal with it. However, in this case the music stops while the user is listening and restarting the stream at the exact position is very hard in my case.
So, what is happening here? Why does Android need to copy the app resources? And can anything be done so Android does not see the need to do it or can do it without killing the app?
We had the same problem before, but it disappear after we build APK by Eclipse->File->Export->Export Android Application. The reason should be related to the tool - \android-sdk-windows\tools\zipalign.exe, it is only used when Export.

Anybody experiencing ANR when using MediaPlayer as service?

Hi I'm getting ANR (Application Not Responding) errors but I can't understand why. If I click "Wait" everything works perfectly and the ANR doesn't come back anymore.
Now, I do know that when using MediaPlayer as a service is good practice using .prepareAsync and the onPrepared() method rather than simple .prepare() and .start(). It doesn't lock the UI thread and works great.
The problem is that all my ANRs are not happening when opening files (you would guess higher processor there), but randomly when they are playing and when the cpu is at few % at most. As I mentioned earlier NOTHING is remotely close to being unresponsive and there is little left on the UI thread.
The only clue is that I don't get ANRs the first time I play a track, but only after it has been changed. I thought that the prepareAsync threads were colliding and I added a lock myself. no change.
I tried to release the media player each time before starting a new track. no change
I tried to reset, stop etc in many sequences. no change.
Has anybody experienced the same thing?
As a workaround, is there any way to automatically dismiss the ANR? I know it's not the answer but I can't find any options. I am on a rooted tablet (I compiled the ROM) and it is only for myself - no distribution
thanks
A standard Service actually runs on the main Thread, if you are seeing ANRs perhaps you should move the entire MediaPlayer to another Thread. To quote the documentation
Most confusion about the Service class actually revolves around what it is not:
A Service is not a separate process.
A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).
You are already using prepareAsync(), but as you stated the error occurs while the MediaPlayer is running, not preparing. Without more detail on what exactly causes the ANR, I believe switching to a HandlerThread is your best option.

android playback suddenly stopping

I have an app that is streaming audio content and sometimes it just
stops all of the suddent.
the logcat windows shows --
AudioHardware pcm playback is going to standby
and that's it.
I saw on another thread (pun intended) that someone was saying it was
because he was using too many threads. Could that really be causing
this? Could i give the audio thread higher priority?
Anyway to prevent the audio hardware pcm from going to standby?
I too am having this problem, and have nearly exhausted all my resources trying to find a workaround. I found an article on how to prevent this with AudioRecord, and maybe the same principles he talks about there will apply to you as well:
http://hificorder.blogspot.com/
In my case, I am having lockups using SoundPool. Increasing the number of max streams allowed prevented this from happening in most cases, but it still happens in other situations. I really wish there was better information about how to handled this correctly, because as it is, this is a show stopping bug in my app which may force me to abandon it all together.
Be sure to post back if you have any findings to add.

Categories

Resources