How to play a segment of a video in Android? - 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.

Related

How to check if external media player is playing in android?

I want to stop my media player if external media player is playing.
I've implemented following code but it is called even when my app media player is playing.
if (audioManager.isMusicActive()) {
return;
}
How to distinguish between in-app media player and external media player?
Any help would be appreciated.
Two or more Android apps can play audio to the same output stream
simultaneously. The system mixes everything together. While this is
technically impressive, it can be very aggravating to a user. To avoid
every music app playing at the same time, Android introduces the idea
of audio focus. Only one app can hold audio focus at a time.
Further,
A well-behaved audio app should manage audio focus according to these
general guidelines:
Call requestAudioFocus() immediately before starting to play and
verify that the call returns AUDIOFOCUS_REQUEST_GRANTED. If you design
your app as we describe in this guide, the call to requestAudioFocus()
should be made in the onPlay() callback of your media session. When
another app gains audio focus, stop or pause playing, or duck the
volume down. When playback stops, abandon audio focus. Audio focus is
handled differently depending on the the version of Android that is
running:
You can check the more detail from developer link.

Stream an audio from server to my app

I want to stream an audio from the server to Android App. I found some solutions but my scenario is quite different.
I have an audio file which is uploaded to the server, I want to run that audio on a specific time and must be stop after audio complete.
Now let say a user opens his android app to listen an audio after one minute from the start time of that audio than he must listen audio from after one minute of audio running and could not listen that audio from back and forward.
Please guide me the to do it and which technologies should I use?
Would it be better you use Google Firebase or any Realtime server? or simple hosting will be a nice option ?
Thanks

Access data stream as it is received

I've seen mention with the previous SDK as well as the current SDK that it is possible for Spotify songs to stream to the device at 1.5 times faster than their playback length. I am currently overriding the SPTAudioController and can access the audio frames as they are played back through it. My hope was that by overriding - (NSInteger)attemptToDeliverAudioFrames:(const void *)audioFrames ofCount:(NSInteger)frameCount streamDescription:(AudioStreamBasicDescription)audioDescription and returning the same count of frames that are passed in, I would immediately receive the next set of frames. This is not the case however, the frames are only delivered as fast as the song is playing, ie. I receive frames the entire time the song is playing.
How can the current Spotify SDK be used to access the audio data as soon as it is received from Spotify?
Note: although the method above is from the iOS SDK, I am interested in answers for both the Android and iOS versions.
I'm afraid the answer to this is that you aren't allowed to do so, our licenses only allows you to get the data at ~realtime speed.
Same goes for all our SDK's.

Background Audio for a Call in Progress - Possible?

I am writing a android app which is supposed to play back a audio file when a call is in progress coming from a specific number .. I tried many approaches.. but all went in vein
Separate Thread
Listener on Telephone service
starting a service in parallel
can any one please help me how to proceed regarding this ?
Update :
I am able to play a mp3 file on call recieve and i am able to play it load on speaker.. but how ever loud i play the calling party is not able to listen to it.... is there anyway i can push the speaker stream to call stream
From the api doc here
Note: You can play back the audio data only to the standard output
device. Currently, that is the mobile device speaker or a Bluetooth
headset. You cannot play sound files in the conversation audio during
a call.
So from this and lots of other so answers we can conclude that we can not play an audio during a call process.
But a long time ago from a personal experience with a handset I got a result where the audiotrack was playing while there was a call established and both the voices were heard at the same time. So I think this depends on handsets if it allows it then you can play.
You can try another thing experimentally. play the audio using a different route ( speakerphone or bluetooth).
Another option is to build your custom android build

SetLooping(boolean) function won't work in android

I created a sample audio player application in android. In my application I used Play, Pause and Stop functions. Now I wish to add Loop functionality in my application. i.e., when I click the Loop button, recently played audio will play continuously, when I click Stop button the audio file will be stop. I go through the android developer site, I got a function setLooping(boolean). I set this my media player nothing will happen, how can I use this, in my code I used like this,
MediaPlayer mPlayer= new MediaPlayer();
mPlayer.setLooping(false);
you are setting the setLooping to false ,if you want to be repeted you must set it to true .You want it to be playing again and again right?
Use:
mPlayer.setLooping(true)

Categories

Resources