• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

recording stream to mp3

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code that i found on net and seems to be the right code but for some reason every time I run it, it keeps crashing on me and i have been searching the net alll day and i have't been able to solve it. here is the code

try {
                       URLConnection conn = new URL("http://50.7.70.58:8708").openConnection();

                        InputStream is = conn.getInputStream();

                   OutputStream outstream = new FileOutputStream(new File("/mnt/sdcard/Download/file.mp3"));
                   byte[] buffer = new byte[4096];
                   int len;
                   while ((len = is.read(buffer)) > 0) {
                      outstream.write(buffer, 0, len);
                   }
                   outstream.close();
                   } catch (IOException e) {
                       e.printStackTrace();
                   }


here is the err im getting

04-09 20:08:22.069 377-455/system_process I/qtaguid: Failed write_ctrl(s 1 10021) res=-1 errno=1
04-09 20:08:22.069 377-455/system_process W/NetworkManagementSocketTagger: setKernelCountSet(10021, 1) failed with errno -1
04-09 20:08:22.109 563-563/com.android.launcher W/EGL_genymotion: eglSurfaceAttrib not implemented
04-09 20:08:22.109 563-563/com.android.launcher D/android.widget.GridLayout: horizontal constraints: x1-x0>=350, x2-x1>=390, x2-x0<=736 are inconsistent; permanently removing: x2-x0<=736.
04-09 20:08:22.109 563-563/com.android.launcher D/android.widget.GridLayout: horizontal constraints: x1-x0>=350, x2-x1>=390, x2-x0<=736 are inconsistent; permanently removing: x2-x0<=736.
04-09 20:08:22.109 563-563/com.android.launcher D/android.widget.GridLayout: horizontal constraints: x1-x0>=350, x2-x1>=390, x2-x0<=736 are inconsistent; permanently removing: x2-x0<=736.
04-09 20:08:22.137 563-563/com.android.launcher D/OpenGLRenderer: TextureCache::get: create texture(0xb8c4bde8): name, size, mSize = 1843, 128, 222912
04-09 20:08:22.137 563-563/com.android.launcher D/OpenGLRenderer: TextureCache::get: create texture(0xb8be3568): name, size, mSize = 1844, 256, 223168
04-09 20:08:22.137 563-563/com.android.launcher D/OpenGLRenderer: TextureCache::get: create texture(0xb8d454a0): name, size, mSize = 1845, 36864, 260032
04-09 20:08:22.141 563-563/com.android.launcher D/OpenGLRenderer: TextureCache::get: create texture(0xb8c0adb0): name, size, mSize = 1846, 36864, 296896
04-09 20:08:22.145 563-1502/com.android.launcher D/dalvikvm: GC_FOR_ALLOC freed 5859K, 42% free 15535K/26439K, paused 9ms, total 9ms
04-09 20:08:22.145 563-563/com.android.launcher D/OpenGLRenderer: TextureCache::get: create texture(0xb8c20d10): name, size, mSize = 1847, 36864, 333760
04-09 20:08:22.149 563-563/com.android.launcher D/OpenGLRenderer: TextureCache::get: create texture(0xb8b50810): name, size, mSize = 1848, 36864, 370624
04-09 20:08:22.149 563-563/com.android.launcher D/OpenGLRenderer: TextureCache::get: create texture(0xb8c3a700): name, size, mSize = 1849, 36864, 407488
04-09 20:08:22.189 563-1502/com.android.launcher D/dalvikvm: GC_FOR_ALLOC freed 771K, 39% free 16135K/26439K, paused 17ms, total 17ms
04-09 20:08:22.225 563-1502/com.android.launcher D/dalvikvm: GC_FOR_ALLOC freed 63K, 34% free 17679K/26439K, paused 9ms, total 9ms
04-09 20:08:22.349 563-1500/com.android.launcher D/dalvikvm: GC_FOR_ALLOC freed 1886K, 34% free 17480K/26439K, paused 5ms, total 5ms
04-09 20:08:22.381 563-565/com.android.launcher D/dalvikvm: GC_CONCURRENT freed 1370K, 32% free 18137K/26439K, paused 1ms+0ms, total 11ms
04-09 20:08:22.381 563-1500/com.android.launcher D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 6ms
04-09 20:08:22.385 563-637/com.android.launcher D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 10ms
04-09 20:08:22.401 563-565/com.android.launcher D/dalvikvm: GC_CONCURRENT freed 776K, 27% free 19370K/26439K, paused 1ms+0ms, total 8ms
04-09 20:08:22.405 563-637/com.android.launcher D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 11ms
04-09 20:08:22.613 377-455/system_process I/qtaguid: Failed write_ctrl(s 0 10049) res=-1 errno=1
04-09 20:08:22.625 377-455/system_process W/NetworkManagementSocketTagger: setKernelCountSet(10049, 0) failed with errno -1
04-09 20:08:23.669 5368-5368/? I/Process: Sending signal. PID: 5368 SIG: 9
 
Rancher
Posts: 4936
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that is the full stack trace, where is the reference to a line in your code?
 
Marshal
Posts: 4176
555
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like there is a problem with your URL.  If you snoop the network traffic, you will see that the server drops the connection immediately.  I tried your code using a different endpoint (http://50.7.70.58:8838/live for example), and it did capture the stream to file, and I was able to play using VideoLAN.
 
Tony fig
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just tried it using 3 different urls but keeps crashing. isn't there a way have it reconnect if if drops?
 
Ron McLeod
Marshal
Posts: 4176
555
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony fig wrote:I just tried it using 3 different urls but keeps crashing. isn't there a way have it reconnect if if drops?


Did you try the URL that I suggested?

Provide a stack trace so that we can see where it is failing.


 
Tony fig
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just tried the url you have posted and it still crashes. Im using android studio to test on. could that be the problem?
 
Ron McLeod
Marshal
Posts: 4176
555
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony fig wrote:I just tried the url you have posted and it still crashes. Im using android studio to test on. could that be the problem?


It's difficult to guess at what the problem might be without seeing the stack trace for the crash.
 
Tony fig
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
were do i find the stack trace

here is some more err

FATAL EXCEPTION: main
                                                                                      android.os.NetworkOnMainThreadException
                                                                                          at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
                                                                                          at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
                                                                                          at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
                                                                                          at libcore.io.IoBridge.connect(IoBridge.java:112)
                                                                                          at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
                                                                                          at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
                                                                                          at java.net.Socket.connect(Socket.java:842)
                                                                                          at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
                                                                                          at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
                                                                                          at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
                                                                                          at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
                                                                                          at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
                                                                                          at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
                                                                                          at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
                                                                                          at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
                                                                                          at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
                                                                                          at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
                                                                                          at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
                                                                                          at com.example.tony.xtreme_online_stations.MainActivity$1.onItemClick(MainActivity.java:413)
                                                                                          at android.widget.AdapterView.performItemClick(AdapterView.java:298)
                                                                                          at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
                                                                                          at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
                                                                                          at android.widget.AbsListView$1.run(AbsListView.java:3529)
                                                                                          at android.os.Handler.handleCallback(Handler.java:615)
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                          at android.os.Looper.loop(Looper.java:137)
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                                                          at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                          at java.lang.reflect.Method.invoke(Method.java:511)
                                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                                          at dalvik.system.NativeStart.main(Native Method)
 
Ron McLeod
Marshal
Posts: 4176
555
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like a NetworkOnMainThreadException was thrown because you are running a network operation on the main (UI) thread.  This is discouraged because it can make your application freeze and become unresponsive.

You should be running your code in a separate thread using AyncTask.
 
Sheriff
Posts: 22730
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony fig wrote:                    while ((len = is.read(buffer)) > 0) {


I don't know if it's the cause of the error, but you should check for >= 0 or != -1. 0 is a valid return value, which just means that nothing was available right now, but at a later time data may become available again. Only -1 has a special meaning here: the actual end of the stream.
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic