I'm trying to play sound from URI Using MediaPlayer Class but when i tried this my app crashed then i noticed that mediaplayer.create() function returns null what can i do to solve this problem?`
mediaplayer=MediaPlayer.create(this,Uri.parse("http://example.com/files/music.mp3"));
if (mediaplayer==null){
Toast.makeText(this,"media player is null",Toast.LENGTH_LONG).show();
}
else
mediaplayer.start();
now when i run my app it shows Toast message "media player is null"
I experienced similar problem with MediaPlayer
the create() method sometimes return null
Some of the file types I have tried are mp3, wav, and m4a
I know they aren't corrupt because I can play them in winamp/itunes
While the documentation does say that it supports those file type, it turns out that it actually doesn't
I noticed that when the audio file (regardless of file type) is 10Mb or more then the MediaPlayer will return null. It made me conclude that MediaPlayer can't play file above certain bitrates. big size = better quality.
So my solution is: Convert everything into .mp3 with 128kbps bitrate
EDIT:
It looks like the problem is with my emulator, when I used a real Android device, everything works perfectly. Make sure that you test on real Android Device. Or in my case, I created another AVD profile with better spec and it works
Related
I am creating a video using an Android app and after this mp4 Video File is created it does not play back properly. The audio will play over a still frame from the video and then once the timer reaches the end then the video will play several moving frames.
This issue is only occurring when I create the video on a Samsung Galaxy S7 and not on any other phones.
I am not experienced in video file encoding so I do not even know where to start with debugging what is wrong with the file. If someone could explain what causes something like this That would be amazing
The first video sample decode time in your file is 1506981408/90000 - which is giant - about 4.5 hours into the stream.
So the entry is obviously bogus.
Hard to say where is bogus decode time is coming from - may uninitialized memory of some sort.
See 'stts' box offset 1052223 - first array entry.
I corrected your video and put a copy here: https://drive.google.com/open?id=0B1K1m-YmE28DMXdFemZKbXg0WFk
For video view in Android, I have added some media player listener such as onPreparedListener, onCompletionListener etc.
But when video get completed then onCompletionListener is not getting called.
Also we observe that something onCompletionListener get called and sometime not.
This issue occurs only for Samsung Galaxy tablet
OS version 4.1.2.
And the same code had worked properly on another Samsung device such as S2, S3, S4 etc.
Does anyone have ideas?
Two comments.
To check whether the VideoView causes the issue. because the OnCompletionListener interface of VideoView is just a wrap for the MediaPlayer's OnCompletionListener interface, you can use a MediaPlayer directly to play the video file and check whether its OnCompletionListener works every time.
-if the same thing happens, means MediaPlayer can't play the video file correctly, maybe you need check the onError() callback thoroughly.
check whether the video file or Uri points to a corrupted video file, you can use the tools like mp4dump to dump the file information.
Hope it helps.
I'm not sure but Just a trick which might solve your problem:
find the total length of video and check if current position reached. if condition satisfies, copy code of onCompletion here.
I'm streaming the audio file (.mp3) from internet with Android Media Player.
It works quite well except Samsung Devices. As far as I see, it doesn't stream the audio but tries to download. It sometimes pushes Media Player Error (1 -1004). Nothing is getting played.
I also tried to redirect the Application to the Media Player with URL of audio file, it goes to Music Player application, indicating "Preparing..." for a while, but then It shows the message "sorry, player does not support this type of audio" with Toast.
Anybody else had the same error before ? Any advise to find a solution ?
Thanks.
There are some bugs in native sound libraries on Samsung Galaxy S2 for instance (look here). I had those problems (random crashes / freezes) and solved it by using OpenSL library for that specific case.
I want to stream an audio mp3 file and then play it through android media player plus I also want to cache this file, so that mediaplayer don't have to stream for recently played tracks.
I have tried using prepareAsync method but it doesn't give me access to buffer content, so I have decided to stream the audio file myself and then pass it to the media player for playing. I have achieved this by following this article here but this approach has a problem i.e. while transferring the file to media player it goes into error mode which causes my player to behave inconsistently.
When media player enters its error mode it doesn't come out of it automatically so I am forced to create a new media player and then re-provide it the downloaded file, this workaround causes the user to experience an undesired pause in the song playing.
So, does any one have improved an version of code given in above link? or do they know a better solution to this problem or is there is actually a library for streaming an audio file in android?
Thanks
The link you provided looks like a less than ideal solution (not to mention outdated). What you probably want is a local proxy server that gives you access to byte data before the MediaPlayer gets it. See my answer here for a little more explanation.
I'm developing android application using Mediaplayer class that plays a song using a url. The problem is that the returned value after calling
mp.getDuration()
is larger than the actual duration of the song.
for example the song has a duration of 4.3 but in my application it gives that it equals 4.6
Can you give more details about your working environment (android version, file format, ...)?
The MediaPlayer is quite buggy. Surely you are experiencing one bug regarding some specific format. Have a look to the open issues in this topic.