media player with url streaming?
<p>I am new in Android, i want to fetch the video file from web url and display the video but i am trying to download a file in my sd card and then play , but i got exception.</p>

<pre><code>try
        {
            Runnable r = new Runnable() {
                public void run() {
                    try 
                    {
                        //mPlayer.setDataSource(item.getStrMusicUrl());
                        //////////////////////////
                        Log.i("Music Stream","Strats");
                        URL url = new URL(item.getStrMusicUrl());
                        URLConnection cn = url.openConnection();
                        cn.connect();
                        Log.i("Music Stream","Connected");
                        InputStream stream = cn.getInputStream();
                        if (stream != null)
                        {
                            Log.i("Music Stream","Getting the Stream");
                            File temp = File.createTempFile("replicaMedia", "dat");
                            String tempPath = temp.getAbsolutePath();
                            Log.i("Music File Path",tempPath);
                            FileOutputStream out = new FileOutputStream(temp);
                            Log.i("Music Stream","Stream saved");
                            byte buf[] = new byte[16384];
                            Log.i("Music Stream","reading the saved Stream");
                            int INTIAL_KB_BUFFER = 96*10/8;
                            int totalBytesRead = 0, incrementalBytesRead = 0;
                            do {
                                int numread = stream.read(buf);
                                if (numread &lt;= 0)
                                    break;
                                out.write(buf, 0, numread);
                                Log.i("Stream Buffer"," "+numread);
                                totalBytesRead += numread;
                                incrementalBytesRead += numread;
                                totalKbRead = totalBytesRead/1000;
                                ////  Call MP to start 
                                if(totalKbRead &gt;= INTIAL_KB_BUFFER)
                                {
                                    totalBytesRead = 0;
                                    if(mPlayer != null &amp;&amp; mPlayer.isPlaying())
                                    {
                                        mPlayer.pause();
                                    }

                                    Log.i("Music Stream","Setting the stream path to MP");
                                    mPlayer.setDataSource(tempPath);    
                                    mPlayer.prepare();
                                    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                                    Log.i("Music Stream","Playing");
                                }

                            } while (true);

                            stream.close();                                

                        }
                        else
                        {
                            Log.i("Music Stream ","No Music Stream");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };

            new Thread(r).start();
        } catch (Exception e) {
            e.printStackTrace();
            if (mPlayer != null) 
            {
                mPlayer.stop();
                mPlayer.release();
            }
        }
</code></pre>
