Background Audio Recording with Media Recorder in Android Studio with Java - android

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.

Related

Android 9 : How to get Audio in Background from Call made by phone in my app

I have heard a lot about blocking the call recording in android 9. I want to understand is it possible to get audio stream in a background service. Every time a user make a Call. If anyone can help me here what are approach to achieve this like giving notification/asking permission to user for this or building a system app or a plugin or a service. For me Audio stream are required to convert it into speech to text.
i got reference from android documentation for incallService,building a calling App and implementing real time text. I have no idea how to connect these three together to get Audio Stream in background service

How to properly use MediaPlayer as notification?

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.

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.

android how to get the statue of phone whether it is playing a sound file

A user make a new task A and set the alarm, then he make another new task B in the same time and also set the alarm.
When the alarm for task A come up,the user doesn't dismiss the alarm on time,the alarm for task B just come after it.Well,now it's duet.
I want some help for judge the statue if the phone is playing any music sounds or how to prevent the alarm to show duet.
My project must depend on API 7.
To get the statue of phone whether it is playing a sound file, you can refer this document.
Before your app starts playing any audio, it should hold the audio focus for the stream it will be using. This is done with a call to requestAudioFocus() which returns AUDIOFOCUS_REQUEST_GRANTED if your request is successful.

How to play a segment of a video in Android?

I am writing an android project, and just want to play a specified part of a video(eg: 10s-15s), So how to get the data(which I use it and can play from 10s to 15s without the original video file, of course the data contains the video's 10s-15s data)?
Unfortunately there is no Media Extractor available on android from the SDK to extract the data. You will have to do this offline on a PC using PC tools.
But you can however implement what you want to do in Android, as follows ..
Create a instance of MediaPlayer and set the source to the file you want to play.
Prepare the mediaplayer
seek to the 10th second.
Start the playback using the play
Keep querying the mediaplayer for the current time of the playback, when it hits 15 seconds, call stop on the media player.
Or you can write a delayed message for your handler and stop the playback when you get the delayed message.

Categories

Resources