Android streaming sound - android

I am doing a streamed musicplayer for android.
I have tried with MediaPlayer
mp.setDataSource("http://www.myServerPage.com/songUrl.mp3");
mp.prepare();
mp.start();
and it works but not good.
The prepare state is very slow and often the application is freezing.
I have searched a lot on forums and tutorials and as far as I can see this is the common way of doing it.
Do anyone know is it is another way of opening up a stream to play music from a server or have any good advices, maybe in NDK or by some other inputstream?
Thanks for the help.
/micke

The Media Playback article is pretty clear about how to deal with remote media sources: call prepareAsync() and set a listener to get notified when the source is ready for playing.
The reason for this is exactly what you're experiencing:
(...) the call to prepare() can take a long time to execute, because it
might involve fetching and decoding media data. So, as is the case
with any method that may take long to execute, you should never call
it from your application's UI thread. Doing that will cause the UI
to hang until the method returns, which is a very bad user experience
and can cause an ANR (Application Not Responding) error.
I suggest you go over the mentioned article for some more information and pointers that may help you with further development.

Related

Create mediaplayer alternate for live stream android

In reference to my question at:
Android Lollipop prepareAsync() takes a long time to return
I would like to go to a lower level. Does anyone know of a way to set up and play a live stream WITHOUT using a MediaPlayer object? Nothing fancy, just connect and play. No retrieval of song info or anything else.
Please see my other question (still unanswered) for details.

Playing game sounds

I need to play sound effects in my game such as jump, failed, shot etc.
So for this purpose I have selected SoundPool class. But there were some times when it lagged.
So I wonder what is correct way to use this class. I have tried to use play method in new thread, it seems work better but I don't know if I am correct.
Please advice how to use object of this class correctly for better performance.
Best way to implement Sound / Music into your game is by using Service component. Read this answer here for an example.

Android Media Player Async Prepare the file

I was looking at the Media Player application found in the Android 2.1 platform samples. I gave a link of the URL for the media file i wanted to play. Now it played fine, but the app gave a "taking too long" warning dialog, meaning too much work was been done on the UI. Is there a better approach to prepare the file async, when streaming from the internet, so as not to bug the UI thread more then needed.
Thanks.
PrepareAsync() is performed on another thread (hence the name). I don't think the problem is here.
I use Service to for player. It doesn't require UI so you can be sure it's not blocking ui and it's not killed when you leave activity.

Quick minor explanation of Android services?

I apologize up-front if this is a really obvious question since I'm pretty sure I'm over-thinking it.
Anyway, I'm building a music player in Android which basically streams playlists from 8Tracks and, as my understanding is, the best-practice here would be using a foreground service. I've already built everything and it's completely functional sans service, however, I'm a little confused as to how to implement the service.
As is, I have my Player class, which controls the MediaPlayer, extending Service but I'm not quite sure where to progress from there. I've tried binding it to my Engine class which reconciles all the background work with the UI, however I keep getting a ServiceConnectionLeaked exception, and I'm fairly certain this is simply the wrong approach.
I would appreciate any help at all; really a nod in the right direction is all I need. Thanks for your time!
I think that you can directly control MediaPlayer without additional Player class. As I know MediaPlayer is already a service so you can use start and stop methods to play something.

Videoplayer issue in android

Hello
In my android application i am playing live rtsp links.
The issue is at times if the player gets struck somewhere then the videoplayer doesnot exit even if we press back.
The only option will be to close the program from task manager.
Is there any way that i can make it better?
Please share your valuable suggestions.
Thanks in advance :)
If it is your code getting stuck, be sure that you are not doing anything (especially network operations) that can block or take more than a few milliseconds in the UI thread - you need to be doing that in loopers or services.
If it's the underlying android video player engine that is hanging, sorry, no idea.

Categories

Resources