BufferedInputStream, BufferedInputStream available - Android Software Development

Good day, I have a problem with BufferedInputStream.
Code:
String url = "some path";
URL feedUrl = new URL(url);
inputStream = feedUrl.openStream();
BufferedInputStream buffer = new BufferedInputStream(inputStream);
Log.v("buffer.available", String.valueOf(buffer.available()));
why I always have a buffer size 2KB ?

It's the default buffer size. Use the constructor that you can specify buffer size if you want something bigger.

stacktrace said:
It's the default buffer size. Use the constructor that you can specify buffer size if you want something bigger.
Click to expand...
Click to collapse
I think den_4ik asked about why there is always 2KB, even if there should be e.g. 20KB of data.
public synchronized int available() throws IOException
Returns an estimate of the number of bytes (...)
Click to expand...
Click to collapse
You can't know how much data is still there - it's stream, you know. If you really need data size, then you could load it into some memory buffer. Also for some streams you could "guess" its size, e.g.: you could check file size for FileInputStream or if you are fetching data through HTTP protocol, then you could read its length from HTTP headers, etc.

increase buffer size
i want to increase the buffer size/time for streaming live audio
is it an app specific setting, ie., on each radio streaming app?
or is it a media player setting?
i know how to mod an apk
i just need to know where in an app, or music.apk for instance, the value would be set for how long or how much a stream will be buffered
i want to increase it enormously, sick of dropping audio while in a moving car
my theory is that if the buffer was bigger/longer, i wouldnt notice the drop out as often
i have searched
i have not found the answer
started a thread:
http://forum.xda-developers.com/showthread.php?t=722729

Related

Music Compression

Is there a software that will allow music files to be compressed from the device itself, without having to connect to a PC? All my music is large files, like 3-4 MB, and I am trying to get them down to 1-2 MB, to save space. Did all the searches and found 0.
Can this thread be deleted? This was posted in the wrong area
mp3, ogg etc ARE compressed. won't get much more compression
no idea about the thread questiob, soz
I meant change the bitrate to a lower format, so that the file is smaller (compressed)
I don't have a suggestion for PPC but on your PC try encoding by mp3PRO - same quality at 1/2 the size of normal MP3
more info :
http://www.mp3prozone.com/
ianderson_76 said:
I meant change the bitrate to a lower format, so that the file is smaller (compressed)
Click to expand...
Click to collapse
Use a real computer with a real processor and a mains connection
That way you'll still be able to use your phone and it won't be hideously slow / run out of battery lol

[Q] Default media player

Hello everyone,
i'm trying to do a podcast software, but i can't find a way to play music througth the default media player.
What should i use?
I use now Mediaplayer() but it has no user interface (no pause, forward ...) which is pretty annoying.
Thank you for your answers!
Have you looked at the MediaController class:
http://developer.android.com/reference/android/widget/MediaController.html
By now, i used another method with Intent.
String path = "/sdcard/feed/"+ title+"/"+fileName + ".mp3";
Intent myIntent =new Intent(android.content.Intent.ACTION_VIEW);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myIntent.setDataAndType(Uri.parse("file://"+ path),"audio/*");
startActivity(myIntent);
Which actually works for mp3s.
I am looking for the basic Android downloader (the one used by the market for example)
Do you know how to use it?
Thank you a lot
So you want to download the file first to the sdcard, then play it by launching the default program for MIME type "audio/*"? seems convoluted. The MediaPlayer object will do all this for you in streaming mode and the MediaController class will give you a nice interface.
Otherwise, I don't know what you mean by "basic Android downloader".

how do i launch music player with a particular song / album?

i thought it may be with an intent but can't find anything, nor can i find anything in the mediaplayer class, but what do i have to do to trigger the stock music player and do i have to pass in a filename as the param?
mhh, something like:
Code:
Uri data = Uri.parse("file://" + mf1.getFilename());
MediaPlayer mp = android.media.MediaPlayer.create(this, data);
mp.start();
will only trigger it as a background process, not switch to it. and an intent view seems to launch a mini player inside the app, so how do i switch to the music player?
http://forum.xda-developers.com/showpost.php?p=13036528&postcount=4
Note: TouchWiz has it's own DB for music for Samsung phones, so you know, we hate them (and the second method may/maynot work on TouchWiz phones).
thanks, i need to get my head around querying the content provider now!

[Q] audio recording issue...

Hi all i'm developing an app for audio recording.
So i used the MediaRecorder class to record. Unfortunately this class hasn't got the pause method so i can just start or stop.
How can i pause the recorder?
For example i'd like to do something like this:
press rec button to start recording
press pause button
press rec button to continue recording...
press stop to save and exit.
ps: I'd like to save the output file as amr or 3gp.
Any idea?
Up
Sent from my HTC HD2 using XDA App
it doesnt appear to be possible with the api's provided by the MediaRecorder class. the way you would have to do it with a MediaRecorder is to record multiple files and then merge them into one audio file. i was thinking that you could append to the file using a file descriptor but then i realized that its not just a plain text file. its an audio file with headers and a complex compressed format and just appending another audio file on the end would do nothing. here are some links
http://stackoverflow.com/questions/5190967/how-to-pause-capturing-video-in-android
http://stackoverflow.com/questions/5743165/pause-and-resume-audio-recording-in-android
http://www.benmccann.com/dev-blog/android-audio-recording-tutorial/
this is a tough one.
ps: I'd like to save the output file as amr or 3gp.
Click to expand...
Click to collapse
this one isnt... =)
setOutputFormat(int outPutFormat);
where outPutFormat can be these values:
---------------------------------------------
int AMR_NB AMR NB file format
int AMR_WB AMR WB file format
int DEFAULT
int MPEG_4 MPEG4 media file format
int RAW_AMR AMR NB file format
int THREE_GPP 3GPP media file format

[Q]How to rip streaming music radio app

I have an Online Radio App and would like to add some sort of recording feature on it. I have done quite a bit of research and found one solution and from what I understand maybe the only solution is to rip it byte by byte. I have also tried to use the built in android recording method but it only records from the mic and I do not know or cannot figure out how to record from an external source such as a url like http://92.68.34.221:7000. Currently I am using the default Android media player method to play the url and its working flawlessly problem is I would like to set up the recording feature as a service to where when a the button is clicked run the service start recording and when it is clicked again terminate the service and save the file in a folder called online radio. Button might end up being a ToggleButton. I would really appreciate it if anyone could help me out and steer me in the right direction. Thanks in Advance
Saving a stream to file is quite easy, but if you want to define the exact start and end point of saving/recording by a button click it gets difficult.
You'll have to change your implementation a lot. Your android mediaplayer class handles everything for you, it opens the stream, fills a buffer and starts playing when the buffer is full. The mediaplayer doesn't offer any access to the bytes that it received.
Next problem: If you click on the button to start recording, the bytes you are listening to, have been in the (internal) buffer for an unknown amount of time. So you can't just open another connection to the stream url to start saving the bytes.
I would try it this way:
Implement these three parts in three different threads.
1. Use android.media.MediaExtractor to open the stream and implement a ringbuffer to store the extracted bytes
2. Use android.media.MediaCodec to decode your stream to pcm.
3. And use android.media.AudioTrack to play the pcm stream
Choose the size of the ringbuffer as large as the buffer of the AudioTrack. (Size in seconds, not in bytes!)
When the user clicks on the record button, you can read the data out of the ringbuffer, (encode them back to mp3 or something else) and save them to a file.
Not very easy for a beginner, but its a way you can do it.

Categories

Resources