Stop app from pausing music (from Spotify etc.) on launch? - java

I'm busy making a template for a general UI which I can use in multiple apps, and I discovered that my app pauses music playing in the background whenever it is launched - most likely due to it having its own start-up sound in the form of a .mp4 that is played as a splash screen.
Is there a way of preventing my app prioritizing its own volume above others or making it mute its own volume when sound is already being played by the device?
PS: If using .mp4 is not general practice for splash screens, I admit, I'm learning as I go - if anyone can correct me on the proper or most optimized solution for making a sound + video happen while not interfering with external apps' sound, that would be much appreciated. Thanks :)

The only way that I know of is disabling the sound for the app that is causing the issue. Most apps have a setting to turn off sound. I don't think you can disable this for every app at once, otherwise when someone calls, you would have to manually turn off the music before answering, "hello".
You can also go into your app settings and "stop notifications" which might help.

I've been using Spotify on my s10 for some times. I also faced the same issue. I found a post why Spotify keeps stopping, and I cleared cache and turned off power saving mode on my device. You can try logging out from other devices which is also helpful

Related

Android App based on a service stop after some time in background

I've created an app, based on this link https://www.geeksforgeeks.org/services-in-android-with-example/, for playing an audio file than have 10 hours in background. But, after block or minimize, unfortunately, the sound stops after some time.
Do someone have an idea why this happening? Is there a way that keeps the app playing the sound after block or minimize, just like Spotify does?
I have made a repo for that app. For now, I have not added features to add controls when the app is running but will be coming soon. But, for now, when the app goes in background, the audio starts playing with the following controls:
Start
Pause
Reset
You can find the repo over here.

How do I stop hogging the microphone

TL;DR: My app is hogging the user's microphone. Can I turn it off automatically whenever another app needs to use the mic?
I have an Android app that has some really cool microphone functionality, similar to Amazon Alexa, that stays on all the time in a background service. The problem is, my app hogs the users' microphone, making it unusable:
However, this is terrible application behavior on my behalf, and I want to do my best to avoid it. Is it possible to be notified when another application requests to use the microphone, so that I can automatically stop my service?
PS: I am using the Pocketsphinx library for continuous background voice recognition.
This is tricky, as I'm not a ware of any API for this. This surely will require system-level APIs to work like an "Ok Google" type of thing.
A viable option would be (from https://stackoverflow.com/a/43623308/603270) to run a Job at regular intervals, checking for foreground apps using android.permission.PACKAGE_USAGE_STATS.
This might suffice. But you could also add things regarding phone calls (how to detect phone call broadcast receiver in android) using android.intent.action.PHONE_STATE or media playback (via Receiver or maybe even MediaPlayer directly).
If you're really wanting to get this thing working, an alternative would be to get an array list of all installed apps on the system and which ones require permission to use the mic or not, then use an accessibility service to monitor the users screen if an app the user just opened requires the mic (which you'll know from the array you just grabbed). From there, disable the mic in your app if their app needs the mic. The background service can then check in intervals of, say, two minutes, to see if the app that required the mic is still open. This is really inefficient. But if you don't care, then this might be a good option.
There is no standard way to inform another app that you want access to the microphone (so that they release the resources and let you access it). You could however send a broadcast to all other apps ("requesting the microphone"), but the other apps would have to implement this feature (and very few or zero developers will do this).
I would recommend you to simply inform the user that the microphone is currently not available, because you can't do anything else.

mediaRecoder.reset() while recording a video CAMERA2 API

Can we reset all the values that hold in mediaRecorder while recording video?
I've tried just using mediaRecorder.reset() while recording video. But it won't work. I don't know is it possible or not. If it is possible please any references will appreciate.
I've read this and also google developers, mediaRecorder in developers. But any of references didn't mention my issue.
EDIT :
What I want is while recording a video set mediaRecorder.reset() and mediaRecorder.start(). The problem occurs when I'm doing this. I need to chunk of video clips while recording the same video. Need those process in parallel. While I'm trying to stop and restart the camera capturing methods it will miss many frames. Bcoz handling camera is somewhat cost for the processor. I tried this and it occurs some errors that telling session configuration failed. Now I'm stuck in here. Need help!
Thank you for your valuable time.
Edit in response to clarifications:
Ok, so you want to split the video file into multiple separate files.
You'll need to use the lower-level APIs (MediaCodec, MediaMuxer) to implement this yourself; the higher-level MediaRecorder does not support this without losing frames.
Original:
So you're trying to pause the video recording temporarily.
Unfortunately, there's no support for this before API level 24, which added MediaRecorder.pause(). You can't call MediaRecorder.reset() mid-video and have it work.
All you can really do is to record the full video and then post-process it to crop sections you don't want.

Ideas for my app that runs in the background

I'm developing an app that runs in the background that essentially snaps a front facing photo every time the phone is successfully/unsuccessfully unlocked. This isn't an original idea, but I'm developing it as a final project for my college android programming course, with no intent to sell this app. I have a general idea how I am going to go about this via some research but I keep running across a problem.
I know that it is hard and bad practice to run an app continuously in the background, so the idea is you put the app to sleep and set an alarm. My problem is that if the would be phone-snooper were to get really lucky, they could access the phone in between the alarms, and the owner of the phone would never know. I talked with my professor, and he proposed a couple ideas, but we could not come up with a definite solution, so I'm asking opinions here. Any idea how to subvert this dilemma? Thanks a ton.
Your approach is probably not appropriate for the problem. You can't "time" unpredictable events (like someone attempting to unlock a phone). Or else it's not clear how you are setting the alarm.
You should change the approach to an event-based approach.
Either provide a service for a lock-screen app so that it can use your code to capture a pic by sending login attempt events to it. You write that and provide an SDK/API.
Or else create your own lock screen app with your feature:
https://stackoverflow.com/questions/10864300/create-a-lock-screen-of-my-own

Voice command for screen unlock android

I want to use voice command to screen unlock an android phone.
I have tried the voice recognition sample code from android, but how do i integrate it to achieve this feature?
I have some doubts,
1) would i have to use service for this feature?
2) when the phone screen is locked, can it have access to internet? (because google voice is using internet)
3) I have looked through PowerManager class, but using which method can i invoke my voiceReconigtion activity when i pressed the Power button? (phone is in sleep,locked mode)
Any guide or solution/feedback is much appreciated!
Thank You
I am almost positive you'll have to run this in a service, as it seems that it would be destroyed as soon as it's out of focus and the GC needs allocations...
As far as the waking from sleep, I believe this is the right direction.
Best of luck.

Categories