How to properly use MediaPlayer as notification? - android

Actually i'm developing an app for an Android Device with a barcode scanner and i'm trying to set a .wav sound that should be played every time i've read the same barcode.
on my scan method i'm simply trying to do the following:
MediaPlayer mpFound = MediaPlayer.create(OrdiniActivity.this, R.raw.exist);
mpFound.start();
this sound can be stuck with another that i start every time the scanner scanned a barcode that exist in a history list but the issue is that if i read multiple barcodes (so the code above is run more and more times) the sound just die and doesn't sound any sound anymore.

Related

Background Audio Recording with Media Recorder in Android Studio with Java

I am trying to record audio and save it in a temporary file every 30 seconds the app is running and send it to firebase.
I am able to get this working but the problem is when the app goes to background, I can't create a new instance of the Media Recorder and it crashes the app.
I have a foreground service which works well.
Please how can I fix this?
I am expecting that every 30 seconds, a new temporary file will be created and saved, the next 30 seconds a new audio file will be set for saving the next audio even while the app is running in background.

Media recorder stopped notification

I need help setting up a notification everytime the media recorder is stopped for a certain amount of time. My program starts and stops media recorder often but its usually instant so I need the code to say everytime media recorder is null for say 10 seconds call notification method.

Phonegap - continuous audio playback not working when the app is in background mode

I have built an audio streaming application for iOS and Android using Phonegap. I have used HTML5 Audio API to play audio files. The audio is being streamed from a PHP server.
When i try to play a song, it is playing fine when the application is in foreground and background/locked.
When i try to play a list of songs, the current song is playing till the end but the next song is not playing. This is working fine when the app is in foreground and not working when the app is in background/locked state.
Detailed Scenario:
Select a song from the playlist. The song is being played.
Push the application to background/lock the device. The current song is still playing till it ends.
While the app is in background, once the current song ends the next song is retrieved from the server. But it is not playing.
Now when i bring the app to the foreground, it immediately starts playing without even buffering. This is because that the song is already served from the server and buffered when it was in background.
Platforms and the issue: iOS (background & locked) & Android (background mode only. works fine in locked state)
I have done my research on this problem and all i could find was few solutions for native audio players. Have anyone solved this?

how to know when audio is started playing in android

In my application I want to get start time of music player when user started and end time when it stops.I don't want to start any music player in my app. I just want to track user activity in device. So i want my application to get any notification when user started the music .
Do I get any intent for music player started and it stopped.Or do I get any intent for when user opens music files.
Is there any other method other than intent to capture the start time and and time when user starts music player.
Well you can implement the interface 'AudioManager.OnAudioFocusChangeListener' in which there is a method 'onAudioFocusChange' which lets you know if audio focus has been changed, and it can also tell if focus was gained or lost.
See this link, it explains the Audio Focus in detail. An application must gain audio focus through a request, and you can implement the 'AudioManager.OnAudioFocusChangeListener' and if there is focus gain, you can detect if the media player is running, (because some other application such as you tube may gain focus to play its audio), see this to see how to detect which application or service is currently running. You can find if audio has started to play, and if it was the media player or not.
Hope this helps. It was interesting question and I have learned some new things while searching for the answer!

Is there any Listener for Media Recorder?

Actually i am creating an application which starts recording when user start speaking and
stop recording automatically when user stop speaking.
so is there any way to find if user is speaking or not?
is there any listener for Media Recorder for this?
No, AFAIK there are no listeners or intents that would notify your app that sound level has gone above some threshold (e.g. user started talking).
You could use AudioRecord class to record the microphone audio and then analyze it to see the volume. However this would require your app to run at that time.

Categories

Resources