Android :: MediaPlayer Provides Wrong Duration On Audio Streaming
May 27, 2010
I am having the following problem: I am using Android's MediaPlayer to play an mp3 through an HTTP connection. The audio is played correctly, but the MediaPlayer returns an incorrect duration (calling mediaPlayer.getDuration() ). Depending on the mp3 the duration is either shorter or longer. The code that plays the audio is the following:
In my music app, i would like to play live streaming like radio broadcasting with mediaplayer as Mediaplayer mp = new Mediaplayer(); mp.setDataSource(LiveStreamingURL); mp.prepare(); mp.start(); but after playing for few seconds it is stopped. I dont know how to overcome it. Give me your suggestions for this.
I am developing a media player which will download the media content from network (Shoutcast) It works fine. Problem is a small gap between players (2 players) I am using two mediaplayers to play the data while a thread downloads and stores the data and stores in to 100Kb files continuously. on first players oncompletelistener() i started the second player wise versa. I think there is a problem with mp3 frames(header sync byte) while splitting 100kb files. how to resole the gap between players.
I'm trying to write a light-weight HTTP server in my app to feed dynamically generated MP3 data to the built-in Android MediaPlayer. I am not permitted to store my content on the SD card. My input data is essentially of an infinite length. I tell MediaPlayer that its data source should basically be something like "http://localhost/myfile.mp3". I've a simple server set up that waits for MediaPlayer to make this request. However, MediaPlayer isn't very cooperative. At first, it makes an HTTP GET and tries to grab the whole file. It times out if we try and simply dump data into the socket so we tried using the HTTP Range header to write data in chunks. MediaPlayer doesn't like this and doesn't keep requesting the subsequent chunks.
Has anyone had any success streaming data directly into MediaPlayer? Do I need to implement an RTSP or Shoutcast server instead? Am I simply missing a critical HTTP header? What strategy should I use here?.................
SDK level 8 (Froyo) has introduced the native capability for the MediaPlayer to connect to a streaming source, like Shoutcast. Previous SDK versions were able to do workarounds, such as run a local proxy on the device (see NPR). I took the same approach as NPR and am using a StreamProxy. However, NPR first checks if the currently running SDK is less than 8. If so, it uses the proxy. Otherwise, it connects directly. My StreamProxy requests metadata from the Shoutcast server, so it does not simply route the data from Shoutcast to my client. Instead, it parses out metadata and uses it accordingly, and only routes the music data.
When trying to use the StreamProxy at SDK level 8 or above, the MediaPlayer fails to prepare. My StreamProxy receives the connection and accepts it, but after successfully writing out the status line and headers to the client, the next write produces "java.net.SocketException: Connection reset by peer". This results in the client's mediaplayer throwing an "Error(1,-1007)". I am trying to figure out why the MediaPlayer is unable to connect to my local proxy. It should be the same as connecting to the original source without the metadata, which does work. I am forwarding on all headers from the external source, through my proxy, which includes content-type.
I have an app that streams mp3's from a server, works fine on 1.5 and lower. But on the droid, for certain songs the mediaplayer buffers to like over 50% but onPrepared() is never called. These same songs work fine on 1.5 or on a 2.0 emulator but for some reason they just hang on the actual droid phone. No mediaplayer errors are thrown but if i call stop or reset it while it is hanging like this, it throws this,
12-18 19:14:05.230: ERROR/MediaPlayer(15718): stop called in state 4 12-18 19:14:05.230: ERROR/MediaPlayer(15718): error (-38, 0) 12-18 19:14:05.238: ERROR/PlayerDriver(987): Command (6) was cancelled
it is only for certain files (yes they are all mp3s) and only on the droid. Anyone have any ideas why these songs would hang? I already checked the http headers and they are correct.
The company I work for is developing an Android App that plays a video file from a URL on web. The video URL is a parameter for a PHP script that encode it properly and redirects to the encoded video as shown below:
Where $output_video is the URL to the encoded video (it works if we use this URL in the browser) and $format is the video format. But when I try executing the MediaPlayerDemo_Video from the API Demos using the streaming mode, I get an error like this:
MediaPlayer Command PLAYER INIT completed with an error or info PVMFErrCorrupt MediaPlayer error (1. -10) MediaPlayer Error (1.-10)
If we hard-code the URL and format in the PHP script, it also does not work out, but with a different error:
MediaPlayer info/warning (1. 28) MediaPlayer Info (1 .28)
I am trying to create a small application for streaming radio broadcast that is in video/x-ms-asf format. the url has a .asx extension at the end. I have come to know that Android does not support this format currently, what other format for streaming broadcasts does it support so I can request that from the radio?
I am trying to make a very simple radio player for Android and I cannot get the audio streaming to work. In my latest attempt it plays for about 1 second and stops for some streams and it doesnt work at all for some other streams. Logcat doesn't give much useful information to me. I am testing on HTC Hero (Android 1.5).
If I hook the completion and buffer events I see the audio gets a complete event but it keeps buffering. Is there anything wrong with the code below? Should I be able to stream the the audio streams below? Is there a complete example somewhere of a working radio streaming?................
I want to create an Android application that is a client for an Internet radio station. And I want it look native to Android? But im confused with Android API logic and documentation. What i've got is that I need MediaPlayer and MediaController classes. Am I right, and is there any good example of AUDIO player for Android?
Especially, I'm very interested how to use MediaPlayer and MediaController classes together.
Finally I've got the code, that does exactly what I want:
I'm trying to create a way to adjust volume settings for each of the different streams (media, notification, ringtone, etc) and have a way to preview the output sound level of each stream. I believe I have the correct implementation, but when I set the output stream type, there is no sound that plays.
Here is the code that correctly plays the user's selected alarm sound:
That commented out line is what is causing me problems. I would like to hear the alarm sound at the volume levels of the different audio streams, but when I include that line for STREAM_ALARM or any other audio stream, no sound at all plays.
Some audio files return 0 from MediaPlayer.getDuration(), even though they're perfectly valid files that play ok and that players on Windows can find the duration of. There seem to be two different cases here: certain file types such as .wma and .wav always return 0 duration, and others only do so sometimes. I haven't been able to find any pattern in the latter case, but it does seem consistent per file. The music player displays 0:00 duration for these, so it's not just my code.
I have a activity which is called from another activity as an intent... This activity loads and starts playing a audio file. All is good - that much works. The activity also has a "stop" button and that stops the audio from playing - that is also fine.
But how do I stop the file from playing if the user uses the back button to leave the activity without clicking on the "Stop" button?
I'd like to be able to keep tabs on my dogs while I'm away. Ideally, I picture an app running on my PC that can stream audio to my cell, when I run an app on my cell. Any ideas around this? And there can be monkeys in the middle (PC to webpage to phone).
For my app, I need to record audio from MIC on an Android phone, and send it over TCP to the other android phone, where it needs to be played. I am using AudioRecord and AudioTrack class. This works great with a file - write audio to the file using DataOutputStream, and read from it using DataInputStream. However, if I obtain the same stream from a socket instead of a File, and try writing to it, I get an exception. I am at a loss to understand what could possibly be going wrong.
I have developed a streaming app for Android. My app is streaming AAC audio.The app works fine on 1.5, 1.6, and 2.1. I tested it on Froyo, the android 2.2 and it does not work there.I have try everthing - Streaming directly from server url - Download incrementaly the content, store in a temp file, start reading. - Download incrementaly the content, store in a ContentProvider and start reading.No luck, I always got errors : 06-23 02:47:02.257: ERROR/MediaPlayer(266): Unable to to create media player 06-23 02:47:02.257: INFO/System.out(266): setDataSourceFD failed.: status=0x80000000 Does Froyo support AAC? Anyone happens to stream AAC?
I am working on a music streaming application and cannot find APIs I can use for it (MediaPlayer supports files only local or HTTP). I have a few questions and would appreciate if someone can help me answering them.
Does Android SDK 1.5 support audio streaming (MP3 stream for example)? If does what API calls I can use? If doesn't what are the plans for future SDK releases that would support streaming? Are there any suggested work arounds until the streaming is supported (like temp files etc)?
I have installed the 2.1 update on my HTC Hero yesterday, and happy as a puppy I instaleld my streaming app... Just to discover that it won't stream decently... It has to stream an mp3 stream and it works on my ADP 1.6 device, on a Samsung Galaxy S test-device (with 2.1) and on the 2.1 emulator...
Logcat is gettign the follwoing errors :
06-30 10:14:18.360: INFO/AudioPolicyService(56): stopOutput(): before lock 06-30 10:14:21.259: DEBUG/dalvikvm(1906): GC freed 28 objects / 1944 bytes in 186ms 06-30 10:14:21.439: INFO/AudioHardwareMSM72XX(56): AudioHardware pcm playback is going to standby. 06-30 10:14:21.439: DEBUG/StreamProcess(56): OutputStreamProcess::ResetAOLC() 06-30 10:14:22.919: INFO/AudioPolicyService(56): startOutput(): before lock 06-30 10:14:22.987: INFO/AudioHardwareMSM72XX(56): AUDIO_START: start kernel pcm_out driver. 06-30 10:14:26.329: DEBUG/dalvikvm(287): GC freed 11 objects / 488 bytes in 268ms 06-30 10:14:47.789: INFO/AudioPolicyService(56): stopOutput(): before lock 06-30 10:14:50.879: INFO/AudioHardwareMSM72XX(56): AudioHardware pcm playback is going to standby. 06-30 10:14:50.879: DEBUG/StreamProcess(56): OutputStreamProcess::ResetAOLC() 06-30 10:14:53.911: INFO/AudioPolicyService(56): startOutput(): before lock 06-30 10:14:54.022: INFO/AudioHardwareMSM72XX(56): AUDIO_START: start kernel pcm_out driver.
The result is a playing player, which stops (pauzes) every 10 seconds, the restarts This will work for about 8-10 restarts and then will simply stop without ever thrwoing an exception or something like that Which makes it somewhat difficult (if not impossible) to catch for us developers So has anyone been experiencing the same problem ? Does anyone have a clue if in this update another OpenCore lib has been used ? Does anyone have any solution ?
When I pair my sprint htc hero to my car stereo, it always opens the default music player and starts playing a song. Can I prevent this from happening? I generally want to listen to pandora - and not my mp3's. Most annoying part is that the mp3's play simultaneously with pandora until I manually open that music app and pause the music.
There must be a way to either turn off the default action or to plug another program name into that defautl.
I'm planning on building an application where audio media is going to be streamed to the mobile phone for the user to listen.The targets are smartphones: iPhone/Blackberry/Android/(J2ME ?).I see that streaming on iPhone has to be done with HTTP Live streaming, but I don't see it supported by other platforms.Should I broadcast the streams via rstp ? http ? Is there any way to use a unified solution for all the different mobile platform ? If anyone already had to go through this, help would be greatly appreciated.
I am new in Android. I am using android os 2.2. I am trying to play streaming audio and video from url. I don't know what to do for that. after 3 days og googling i come to know that I have to use mediaPlayer and MediaController classes.I had use different differend combination of codes found on internet but not succeed.Can anybody guide me what to do for streaming audio/video playing. What about the UI if we use MediaPlayer or Controller class. is there any thing to related these in xml file of layout.if not then even please tell me what may be the code for that.please help me.