I'm attempting to use both progressive and cached sound files in my android app. Tthe soundpool works great for preloading small files, but obviously sometimes you need to play a 15-30sec sound file. I don't want to preload those (and can't due to memory constraints), but i'm at a loss to discover how to progressively stream resource sounds. Every tutorial about progressive sound streaming is for HTTP streams.
The sounds are in /res/raw/ and are oggs.
How do i progressively stream local resource sounds?
Since it's been some time from this question's being asked, i figure i'll mark it as answered with the method i went with.
I decided to make a jni wrapper over libvorbis and include the library with the app so that it can stream sounds using native libvorbis code. It's a pain, and it really shouldn't be necessary with all the decoding capability that android has, but i can't find any convenience methods.
So, for future googlers, sorry for the bad news.
Related
I am developing a soundboard application in which I need to get the specified audio file from the server when the user requests it, but I don't want to stream it or download it every time, just the first time so I was thinking of caching it someway.
I made some research and I found the ExoPlayer library from google but I think it's kinda overkill for my purpose and I can't seem to get my head around it as I'm not so experienced in android development.
Is there any library that I can use?
If not, how can I make the process myself?
Save it to the file system the first time. Then you never have to download it again.
I am using SoundPool in order to play some sounds using timers in my applications. Does anyone know if there is an in-built queue where it will queue files and play them only when the previous files are finished?
Do I have to write my own implementation of a SoundPool queue?
I have had a similar issues in a couple of apps that relied heavily on SoundPool. There is no "in-built queue" or detection of when a sound has finished. Also annoyingly you can't get the play length of loaded sounds from SoundPool either. In your searches I'm sure you've come across many people complaining about this.
For my purposes I got around this by first briefly loading each sound into MediaPlayer to get and store it's play length. Then used these lengths to signify when playback will have stopped.
Unfortunately the audio side of things is a well recognised weak point in Android. The general advice is if you want to get accurate and have good control, then you need to turn to the NDK rather than using SoundPool or MediaPlayer, sorry.
My application takes a long time to prepare and buffer an audio stream. I have read this question Why does it take so long for Android's MediaPlayer to prepare some live streams for playback?, however it just says people have experienced this issue, it does not state how to improve the problem.
I am experiencing this in all versions of Android, tested from 2.2 - 4.1.2.
The streams are in a suitable bit-rate for mobile and 3G connection. The same stream takes less than a second to start buffering in the equivalent iOS app.
Is there a way to specify the amount of time that should be buffered? I know that the Tune In radio application offers this feature ( https://play.google.com/store/apps/details?id=tunein.player ).
Thanks.
Edit: I've tested again and found that it only happens on devices running Gingerbread and above (>=2.3). I know that Android changed the underlying framework from OpenCore to StageFright. So how can I optimise the media framework? It just seems wrong that the old HTC Wildfire can prepare, stream and play, literally 10x faster than the brand new HTC One X and Nexus 7.
I have struggled with this question for months. Finally i found the solution.
The real problem is in the implementation of the MediaPlayer class. Particularly with the way MediaPlayer buffers the data. This is why the solution is to create your own buffering, save it to a temp file and feed that to MediaPlayer.
This tutorial and source code explain exactly how. http://androidstreamingtut.blogspot.nl/2012/08/custom-progressive-audio-streaming-with.html
By adapting this code, it is easy to create a much better streaming player.
Google Developers really screwed up here.
EDIT : This answer is rather old. Nowdays i would recommend not using MediaPlayer and use ExoPlayer instead. It is extendable, stable and can play many different types of media. You can find it here: https://github.com/google/ExoPlayer/
There really isn't much you can do since the Android MediaPlayer class doesn't provide access to lower level settings such as buffer size. The only alternative would be to make your own player using AudioTrack and a library like FFmpeg to do the decoding.
The one thing I'd recommend is to play around with encoding. For instance, for MP4s, ensure that the MOOV Atom is located at the beginning of the file (there are enough questions on S/O regarding how to do this with ffmpeg, etc). With MP3s, you can look at different codecs or bitrates for instance.
You can, for instance, try a number of audio files you find online, and if you see one that doesn't take a long time to buffer, try to encode your files in the same way.
I read this code to play video files using xuggler as a library.When i run this code , the video without sound plays.Why is that ?
If not what should i do to play audio with video.?
Quite simply, it's because that code doesn't play any audio. It was never written to do so!
If you want to play audio and video, check out the example here:
http://xuggle.googlecode.com/svn/trunk/java/xuggle-xuggler/src/com/xuggle/xuggler/demos/DecodeAndPlayAudioAndVideo.java
The question to me suggests that you've just grabbed the source without looking at the tutorials - I'd strongly suggest doing so so you can understand the code behind what's going on rather than just throwing it in there and expecting it to work - especially if you're planning on using Xuggler in any great depth!
As a further note, if all you want to do is play videos I probably wouldn't advise using Xuggler because it's just not really designed for that sort of thing. Sure it will play them, but you have to manage all the sync issues yourself (which the above example doesn't do a great job of), it will only use your CPU and therefore really eat into its consumption especially if you're doing things like HD video, and the sheer amount of background code is just overkill (getting the streams, finding the stream IDs, extracting each packet, determining the type of the packet, dealing with it appropriately, managing errors, etc. etc.) It's a great piece of software, but if you're only using it to play stuff then it'll probably give you far more trouble than its worth.
Instead I'd advocate having a play with VLCJ - it's a bit complicated to get set up to work reliably (out of process players are required for rock solid stability) but when you've got that far it plays near any file type under the sun and manages all the issues above for you much, much better than you'll ever cope with by hand!
My guess is that you have a missing audio codec. I've had this same issue but vice versa; the sound played but the video didn't.
If I have a bunch of video files, all in precisely the same format, shape, whatever, then can I play them back seamlessly without jumps or gaps? The effect from the end user's point of view would be as though they are watching one video.
I understand that this is possible in DirectX, but I'd rather use Java if possible.
If you want to play media in Java, the Sun standard is JMF (http://java.sun.com/javase/technologies/desktop/media/jmf/) which unfortunately has been dormant for quite a while.
The FMJ project (http://fmj-sf.net/) is API-compatible and under active development.
I cannot answer your question better, but hopefully this can get you further.