Android Audio Streaming is too slow - android

I'm trying to make a radio app. Everything is ok, except playing radios. I'm getting play link from a page with Jsoup. When i press play, (in real device)it takes 40-50 seconds to start playing. But in genymotion device (Google Nexus 4- 4.4.4- API 19) it takes just 3-4 second. I couldn't find what is wrong.
I'm new on Android and I couldn't find a solution for days. Thanks id advance.

I really recommend you to use google exo player instead of default android player for streaming. its too fast and you will never have problems like this.
https://github.com/google/ExoPlayer

You must try it without emulator, as they themselves are slow.
Also give below links a read.
https://developer.android.com/reference/android/media/AudioManager.html
https://developer.android.com/guide/topics/media/mediaplayer.html
For Best performance native is good:
https://developer.android.com/ndk/guides/audio/index.html

Related

How to play multiple songs together in sync?

I want to play 5 songs together without any miss sync. I've taken reference from the below link with use of NDK:
https://github.com/googlesamples/android-ndk
I'm creating 5 instance for player and playing songs but on some devices songs are not played in sync when I just fire a play.
I would like to know what is the best way to achieve this so I can play multiple songs in sync.
Let me inform you the device having good configuration like 2gb+ RAM will play sounds in perfectly But in device having RAM of 1GB will not work always.
I've tried with MediaPlayer and Soundpool but not helps me. NDK implementation is far better.
Looking for best work around for this...
Thanks in advance
you should use sound pool here is an example how to use it:
https://examples.javacodegeeks.com/android/android-soundpool-example/

Screen Video Recording FPS

I have searched a lot on google but unfortunately have not found any solution of screen video recording. If you have used the Screencast Video Recorder from google play, you can better understand my question. Can anyone help me out that how to achieve screen video recording programmatically.
AFAIK Screencast records by reading /dev/graphics/fb0, which is slow.
Programmatically the highest performance method is to create a virtual display. Currently only works on Android 4.4. See the screenrecorder.cpp for how to do this:
https://android.googlesource.com/platform/frameworks/av/+/android-4.4_r1/cmds/screenrecord/screenrecord.cpp
For Android 4.1 and above you can use the SurfaceComposerClient (both from native or Java code), although it's fairly broken on 4.3.
Unless you want to write a screen recorder yourself I wouldn't bother and just use one of the off-the-shelf recorders.
for some more detail see this answer.

Playing youtube video in Android app

In my Android app I'd like the user to tap an image once, have a youtube video play automatically and when the video is done the user is immediately returned to the app. What's the best way to do this in Android?
I tried using intents. This works in that the video comes up on what I think is a youtube web page. However playing the video requires another tap. I'd like to avoid this if possible.
I tried the whole MediaPlayer, prepareAsync, setOnPreparedListener and never got it to work. For some reason onPrepared was never called. No exceptions were thrown. I'm using the emulator to test and I'm new to Android so I'm not sure if the behavior will be different on physical devices.
I got this working well on iOS by getting creative with webviews. I'm hoping it's more straightforward on Android. The docs sure make it sound straight forward.
Cheers!
Update: Everything below is still correct, but the official YouTube API for Android is now available.
By far, the easiest way to play a YouTube video on Android is to simply fire an Intent to launch the native Android YouTube app. Of course, this will fail if you are not on a certified Google device, that doesn't have the complement of Google apps. (The Kindle Fire is probably the biggest example of such a device). The problem with this approach is that the user will not automatically wind up back at your app when the video finishes; they have to press the Back button, and at this point you've probably lost them.
As a second option, you can use the MediaPlayer API to play YouTube videos. But there are three caveats with this approach:
1) You need to make a call to YouTube's GData webservice API, passing it the ID of the video. You'll get back a ton of metadata, along with it the RTSP URL that you should pass to MediaPlayer to play back an H.264-encoded stream. This is probably the reason why your attempt to use MediaPlayer failed; you probably weren't using the correct URL to stream.
2) The GData/MediaPlayer approach will only play back low-resolution content (176x144 or similar). This is a deliberate decision on the part of YouTube, to prevent theft of content. Of course, this doesn't provide a very satisfactory experience. There are back-door hacks to get higher resolution streams, but they aren't supported on all releases of Android and using them is a violation of YouTube's terms of service.
3) The RTSP streams can be blocked by some internal networks/firewalls, so this approach may not work for all users.
The third option is to embed a WebView in your application. There two approaches you can take here:
1) You can embed a Flash object and run the standard desktop Flash player for YouTube. You can even use the Javascript API to control the player, and relay events back to the native Android app. This approach works well, but unfortunately Flash is being deprecated on the Android platform, and will not work for Android 4.1 and later.
2) You can embed a <video> tag to play YouTube via HTML5. Support for this varies between various releases of Android. It works well on Android 4.0 and later; earlier releases have somewhat spotty HTML5 <video> support. So, depending upon what releases of Android your application must support, you can take a hybrid approach of embedding HTML5 on Android 4.x or later, and Flash for all earlier versions of Android.
There are several threads here on StackOverflow about using HTML5 to play YouTube video; none of them really describe the entire process you must follow in one place. Here's links to a few of them:
Android - How to play Youtube video in WebView?
How to embed a YouTube clip in a WebView on Android
Play Youtube HTML5 embedded Video in Android WebView
All of this will get dramatically easier in the weeks/months to come; at Google I/O 2012, they presented/demoed a new YouTube API for Android that will support direct embedding of YouTube content in your application, with full support back to Android 2.2 (about 95% of the Android userbase as of this writing). It can't arrive fast enough.

Android Gingerbread buffering with MediaPlayer

I try to implement a simple media player to play an audio stream from an external URL. Pretty simple I guess. Tried to implement this sample from Androïd dev site http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Audio.html
It works just fine with 2.1.
Then, with 2.2 it gets weird. Starts just well, but takes almost 10 seconds to stop.
With 2.3, it's not better. This time might take up to a minute to start playing, but stops OK.
Does anyone have a clue why ? I also did try the prepareAsync way with the listner, but it never get called. Any help would be appreciated at this point. Thanks !
Register setOnInfoListener() and control start buffering, end buffering and so on.
Look at the android documentation link

play video from external database in android?

I'd like to know how I can call a video from an external server database and play it in android? any helpful tutorials?
another question, when I play my video in emulator is it normal that it gives me a low quality and plays very slow..like moving in slow motion?
Emulators not responded quickly while you are playing video.I hope you understand that.

Categories

Resources