I am streaming from an mp3 stream using the MediaPlayer.
I set the datasource, call preparyAsync(), call start() on the onPrepared() callback.
Now I want to know the number of bytes downloaded by the mediaplayer when streaming a song.
Is there a way to track the number of bytes?
Its not going to be one song but instead an mp3 stream.
I understand you want to know the number of bytes of downloaded compressed data, not the number the bytes of uncompressed data inside MediaPlayer which is proportional to the lenght of audio played. (The compressed data may not be proportional in case of using VBR for example).
To get the number of bytes of downloaded compressed data you need to count the bytes of stream downloaded by MediaPlayer, but I believe the only way to have access to the stream downloaded is to implement a local streamproxy that feeds the MediaPlayer, or a second solution is to save the stream to a local file and open this file with MediaPlayer, but the later solution has some limitations as MediaPlayer locks the local file and data cannot be appended.
For the first solution see this solution on how to implement a proxy to feed MediaPlayer: MediaPlayer stutters at start of mp3 playback
Related
"Encoded PCM 16/8-bit" what does it mean?? lets say i have a mp3 music and i want to convert this to a encoded PCM so i could directly feed this to write() of AudioTrack object.
any tools by which i can convert??
and after conversion to PCM will it be playable in android.
(considering i am don't bother about quality)
Thank You!
PCM (pulse-code modulation) is a standard encoding scheme used in the WAV file format. It consists of 8- or 16-bit samples; there are a number of these per second of audio - that number is called the sample rate. AudioTrack is used to play back PCM data; this can be done in real-time while you write to its internal buffer (i.e. MODE_STREAM), or you can fill the buffer and then play back (MODE_STATIC). If you go with the streaming mode, it's important to continuously call write() to keep filling the buffer during playback, otherwise the AudioTrack will stop playing until it receives more data.
As for tools, a simple one is iTunes. Go to Preferences->General->Import Settings and choose "WAV encoder" from the drop-down menu. Now right-click a file you want to convert and select "Create WAV version". As you mentioned, you will lose a bit of quality, which is inevitable in conversion.
Alternatively to this method, consider using the MediaPlayer API, which will play MP3s natively.
I have a link that directly starts downloading of the song, but I want to stream that song in my app without downloading. Is it possible? Please help me through.
Link is: http://workintelligentonline.com/church/audio/1New Stories (Highway Blues).wma
For your application to play the song, the decoder has to read the data from memory. So the streaming data has to stored into a buffer or a page-cache implementation which is then fed to the decoder.
Once the song playback is completed, the MediaPlayer engine is closed which will release the allocated memory too. As long as your application doesn't write the contents of the memory into a file, you have technically played a streaming song without downloading.
I want create an app which records a sound into bytestream and it can be listened again. It will not save the recorded audio into a file, rather it will save it into a hardware memory. And a play option will be there by which the recorded file can be played. Recorded system will be like talking tom: record the audio and play it instantly
Can anyone provide me a sample code for this functions ?
Without saving the audio into a file, you can use the AudioRecord class which lets you read the recorded audio into a byte array.
An easier option to code and use would be the MediaRecorder, although it will come with a loss in performance as it does save the audio into a file every time.
I can receive a byte array from a Socket. I need to play audio from this byte array - the audio is encoded with AMR 8000Hz.
I found that I can play AMR audio with MediaPlayer. However, MediaPlayer can't play music from byte array, and I don't want to write them to file.
Is there a way to play AMR sound from byte array on android?
The Android framework allows you to play back audio data directly from memory using the AudioTrack class; the drawback is that the audio must already be decoded into PCM data. If you are lucky enough to target Android 4.1, there are new APIs that allow you to decode the data separately so it can be passed to AudioTrack (see MediaExtractor and MediaCodec). However, prior to that there were no exposed APIs for encoding/decoding beyond MediaRecorder and MediaPlayer.
If targeting a version of Android prior to 4.1 (which I imagine you probably are) you have two options:
Find a 3rd party decoder for the AMR data so you can pass it on to AudioTrack
Save your data to a file (even temporarily) so it can be handed to MediaPlayer
HTH
I'm using an Android MediaPlayer to play a bytestream that I receive externally.
Now I know it isn't possible to use a bytestream as input for my MediaPlayer (that would be perfect).
Therefor I want to create a file out of this stream and let the MediaPlayer just read that file.
But now I want to know exactly how far the MediaPlayer is in reading this file/stream, not in milliseconds but in bytes.
But is it possible to have some-sort of callback to know howmany bytes this MediaPlayer has read?