<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Android Tutorial 3: Custom Audio Streaming with MediaPlayer</title>
	<atom:link href="http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/</link>
	<description>Know Anywhere</description>
	<lastBuildDate>Thu, 11 Mar 2010 06:22:03 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: vinod</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-571</link>
		<dc:creator>vinod</dc:creator>
		<pubDate>Fri, 05 Mar 2010 10:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-571</guid>
		<description>and you must  interrupt to buffer loading</description>
		<content:encoded><![CDATA[<p>and you must  interrupt to buffer loading</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vinod</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-570</link>
		<dc:creator>vinod</dc:creator>
		<pubDate>Fri, 05 Mar 2010 10:05:28 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-570</guid>
		<description>HI 
kavitha 

you will try  mp.reset();</description>
		<content:encoded><![CDATA[<p>HI<br />
kavitha </p>
<p>you will try  mp.reset();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kavitha</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-567</link>
		<dc:creator>kavitha</dc:creator>
		<pubDate>Wed, 03 Mar 2010 04:45:27 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-567</guid>
		<description>Thanks for the reply catdaaady.

I tried with mp.stop() and mp.release().

Still it is same.

Any other alternatives????

or else do you have any idea of converting audio to PCM and playing from AudioTrack class of Android?</description>
		<content:encoded><![CDATA[<p>Thanks for the reply catdaaady.</p>
<p>I tried with mp.stop() and mp.release().</p>
<p>Still it is same.</p>
<p>Any other alternatives????</p>
<p>or else do you have any idea of converting audio to PCM and playing from AudioTrack class of Android?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CatDaaaady</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-566</link>
		<dc:creator>CatDaaaady</dc:creator>
		<pubDate>Tue, 02 Mar 2010 06:17:53 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-566</guid>
		<description>I am not so sure on that one.
But maybe in your clear() try

mp.stop();
mp.release();

Instead of 
mp.pause();
mp.reset();
mp.release();

It could be the mediaplayer resources are not getting released properly?</description>
		<content:encoded><![CDATA[<p>I am not so sure on that one.<br />
But maybe in your clear() try</p>
<p>mp.stop();<br />
mp.release();</p>
<p>Instead of<br />
mp.pause();<br />
mp.reset();<br />
mp.release();</p>
<p>It could be the mediaplayer resources are not getting released properly?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kavitha</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-565</link>
		<dc:creator>kavitha</dc:creator>
		<pubDate>Tue, 02 Mar 2010 04:45:37 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-565</guid>
		<description>Hi CatDaaaady and Biosopher,

Thanks for the replies.
Using catDaaady&#039;s player idea,I am able to play continously an Internet Radio.

But when i change the Internet Radio link url,file is getting downloaded,but i am not able to play once again,,MediaPlayers hang up without even showing error.


I am calling player(File f) from another thread and pause it when user clicks on another url,clear mediaplayers vector in clear() ,,and again start thread when file gets downloaded.

Please tell me the solution.

Here is what I am doing when i change url

public void player(File ff){
		   final File f = ff;
	    final String TAG = &quot;**************************************setupplayer*****:&quot;;
        Log.i(TAG, &quot;File &quot; + f.getAbsolutePath());
      //  Runnable r = new Runnable(){
      //  	public void run(){
       try{
    	   MediaPlayer mp=new MediaPlayer();
        		try{
        			FileInputStream ins = new FileInputStream( f );
                    mp.setDataSource(ins.getFD());
                    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mp.setOnCompletionListener(playerlistener);
                    if ( ! started  ){
                        mp.prepare();
                    } else {
                        //This will save us a few more seconds
                        mp.prepareAsync();
                    }
                    insertMedia(mp);
                    if ( ! started  ){
                        startMediaPlayer();
                  }
        		}catch(Exception e){
        			 Log.e(TAG, &quot;:ERROR********:&quot;+e.toString());
        			 e.printStackTrace();
        		}
        		
       }catch(Exception e){
    	   System.out.println(&quot;********************ERROR IN PLAYER &quot;+e);
    	   e.printStackTrace();
       }
        //	}
      //  };
     //   new Thread(r).start();
	}
	


MediaPlayer.OnCompletionListener playerlistener = new MediaPlayer.OnCompletionListener () {
		public void onCompletion(MediaPlayer mp){
			onMediaPlayerCompletePlay(mp);
        }
	};
	
	 private void onMediaPlayerCompletePlay(MediaPlayer mp){
		  String TAG = &quot;MediaPlayer.OnCompletionListener&quot;;
         Log.i(TAG, &quot;Current size of mediaplayer list: &quot; + mediaplayers.size() );
      
         MediaPlayer mp2 = getMedia();
         if(mp2 != null)
        	 mp2.start();
         mp.release();
         removefile();
	 }    


public  void insertMedia(MediaPlayer file){
			///add file at last of vector
		try{
			 mediaplayers.add(file);
			available = true;
		}catch(Exception e){
			System.out.println(&quot;EXCEPTION IN INSERTMEDIA&quot;+e);
			e.printStackTrace();
			
		}
		
		 	
	}
		
	 public  MediaPlayer getMedia(){
	try{
		if(mediaplayers.size()&lt;1){
			available=false;
		}
		
		if(!available){
			return null;
		}
		mediaplayers.remove(0);;
		
		if(mediaplayers.size()&lt;1){
			return null;
		}
	}catch(Exception e){
		System.out.println(&quot;EXCEPTION IN GETMEDIA&quot;+e);
		e.printStackTrace();
	}
		return mediaplayers.firstElement();
	}
	 
	 
	 
	   private void removefile (){
    
        String TAG = &quot;removefile ***:&quot;;
     try{
        File temp = new File(context.getCacheDir(),DOWNFILE + playedcounter);
        Log.i(TAG, temp.getAbsolutePath());
        temp.delete();
        synchronized(this){
        	playedcounter++;
        }
     }catch(Exception e){
 		System.out.println(&quot;EXCEPTION IN REMOVEFILE&quot;+e);
 		e.printStackTrace();
 	}
    }
   
    //Start first audio clip
    private void startMediaPlayer() {
        String TAG = &quot;startMediaPlayer***:&quot;;
        try{
        //Grab out first media player
        synchronized(this){
        	 started = true;
        	MediaPlayer mp = mediaplayers.get(0);
        	mp.start();  
        }
        }catch(Exception e){
     		System.out.println(&quot;EXCEPTION IN STARTMEDIAPLAYER&quot;+e);
     		e.printStackTrace();
     	}
       
       
    }
    
    public  void clear(){
    	String TAG = &quot;CLEAR URL STREAMPLAYER***:&quot;;
    
    	try{
    		synchronized(this){
    			playedcounter = 1;
    			started = false;
    	    	 available=false;
    			for(int i=0;i&lt;mediaplayers.size();i++){
    				MediaPlayer mp=mediaplayers.get(i);
    				if(mp != null){
    					if( mp.isPlaying())
    						mp.pause();
    					mp.reset();
    					mp.release();
    				}
    			}
    	
    			mediaplayers.removeAllElements();
    			
    		}
    	
    	}catch(Exception e){
    		 Log.i(TAG, &quot;ERROR CLEARING MEADIA PLAYERS : &quot; + mediaplayers.size() );
    		 e.printStackTrace();
    	}</description>
		<content:encoded><![CDATA[<p>Hi CatDaaaady and Biosopher,</p>
<p>Thanks for the replies.<br />
Using catDaaady&#8217;s player idea,I am able to play continously an Internet Radio.</p>
<p>But when i change the Internet Radio link url,file is getting downloaded,but i am not able to play once again,,MediaPlayers hang up without even showing error.</p>
<p>I am calling player(File f) from another thread and pause it when user clicks on another url,clear mediaplayers vector in clear() ,,and again start thread when file gets downloaded.</p>
<p>Please tell me the solution.</p>
<p>Here is what I am doing when i change url</p>
<p>public void player(File ff){<br />
		   final File f = ff;<br />
	    final String TAG = &#8220;**************************************setupplayer*****:&#8221;;<br />
        Log.i(TAG, &#8220;File &#8221; + f.getAbsolutePath());<br />
      //  Runnable r = new Runnable(){<br />
      //  	public void run(){<br />
       try{<br />
    	   MediaPlayer mp=new MediaPlayer();<br />
        		try{<br />
        			FileInputStream ins = new FileInputStream( f );<br />
                    mp.setDataSource(ins.getFD());<br />
                    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);<br />
                    mp.setOnCompletionListener(playerlistener);<br />
                    if ( ! started  ){<br />
                        mp.prepare();<br />
                    } else {<br />
                        //This will save us a few more seconds<br />
                        mp.prepareAsync();<br />
                    }<br />
                    insertMedia(mp);<br />
                    if ( ! started  ){<br />
                        startMediaPlayer();<br />
                  }<br />
        		}catch(Exception e){<br />
        			 Log.e(TAG, &#8220;:ERROR********:&#8221;+e.toString());<br />
        			 e.printStackTrace();<br />
        		}</p>
<p>       }catch(Exception e){<br />
    	   System.out.println(&#8220;********************ERROR IN PLAYER &#8220;+e);<br />
    	   e.printStackTrace();<br />
       }<br />
        //	}<br />
      //  };<br />
     //   new Thread(r).start();<br />
	}</p>
<p>MediaPlayer.OnCompletionListener playerlistener = new MediaPlayer.OnCompletionListener () {<br />
		public void onCompletion(MediaPlayer mp){<br />
			onMediaPlayerCompletePlay(mp);<br />
        }<br />
	};</p>
<p>	 private void onMediaPlayerCompletePlay(MediaPlayer mp){<br />
		  String TAG = &#8220;MediaPlayer.OnCompletionListener&#8221;;<br />
         Log.i(TAG, &#8220;Current size of mediaplayer list: &#8221; + mediaplayers.size() );</p>
<p>         MediaPlayer mp2 = getMedia();<br />
         if(mp2 != null)<br />
        	 mp2.start();<br />
         mp.release();<br />
         removefile();<br />
	 }    </p>
<p>public  void insertMedia(MediaPlayer file){<br />
			///add file at last of vector<br />
		try{<br />
			 mediaplayers.add(file);<br />
			available = true;<br />
		}catch(Exception e){<br />
			System.out.println(&#8220;EXCEPTION IN INSERTMEDIA&#8221;+e);<br />
			e.printStackTrace();</p>
<p>		}</p>
<p>	}</p>
<p>	 public  MediaPlayer getMedia(){<br />
	try{<br />
		if(mediaplayers.size()&lt;1){<br />
			available=false;<br />
		}</p>
<p>		if(!available){<br />
			return null;<br />
		}<br />
		mediaplayers.remove(0);;</p>
<p>		if(mediaplayers.size()&lt;1){<br />
			return null;<br />
		}<br />
	}catch(Exception e){<br />
		System.out.println(&quot;EXCEPTION IN GETMEDIA&quot;+e);<br />
		e.printStackTrace();<br />
	}<br />
		return mediaplayers.firstElement();<br />
	}</p>
<p>	   private void removefile (){</p>
<p>        String TAG = &quot;removefile ***:&quot;;<br />
     try{<br />
        File temp = new File(context.getCacheDir(),DOWNFILE + playedcounter);<br />
        Log.i(TAG, temp.getAbsolutePath());<br />
        temp.delete();<br />
        synchronized(this){<br />
        	playedcounter++;<br />
        }<br />
     }catch(Exception e){<br />
 		System.out.println(&quot;EXCEPTION IN REMOVEFILE&quot;+e);<br />
 		e.printStackTrace();<br />
 	}<br />
    }</p>
<p>    //Start first audio clip<br />
    private void startMediaPlayer() {<br />
        String TAG = &quot;startMediaPlayer***:&quot;;<br />
        try{<br />
        //Grab out first media player<br />
        synchronized(this){<br />
        	 started = true;<br />
        	MediaPlayer mp = mediaplayers.get(0);<br />
        	mp.start();<br />
        }<br />
        }catch(Exception e){<br />
     		System.out.println(&quot;EXCEPTION IN STARTMEDIAPLAYER&quot;+e);<br />
     		e.printStackTrace();<br />
     	}</p>
<p>    }</p>
<p>    public  void clear(){<br />
    	String TAG = &quot;CLEAR URL STREAMPLAYER***:&quot;;</p>
<p>    	try{<br />
    		synchronized(this){<br />
    			playedcounter = 1;<br />
    			started = false;<br />
    	    	 available=false;<br />
    			for(int i=0;i&lt;mediaplayers.size();i++){<br />
    				MediaPlayer mp=mediaplayers.get(i);<br />
    				if(mp != null){<br />
    					if( mp.isPlaying())<br />
    						mp.pause();<br />
    					mp.reset();<br />
    					mp.release();<br />
    				}<br />
    			}</p>
<p>    			mediaplayers.removeAllElements();</p>
<p>    		}</p>
<p>    	}catch(Exception e){<br />
    		 Log.i(TAG, &quot;ERROR CLEARING MEADIA PLAYERS : &quot; + mediaplayers.size() );<br />
    		 e.printStackTrace();<br />
    	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CatDaaaady</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-564</link>
		<dc:creator>CatDaaaady</dc:creator>
		<pubDate>Tue, 16 Feb 2010 04:30:06 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-564</guid>
		<description>I actually hear it in my app.  In my app I am saving pieces of a live, continuous, stream and playing them one by one.
It is VERY subtle. But I know the gap is there. None of my users have complained about it yet though. So I assume maybe it is only for people with sensitive ears.

My plan to getting around it is to implement some type of live stream-to-rtp converter.  So the program will download a portion of audio, put it into a RTP packet, then send that off to the audio player.

I &quot;think&quot; this is how other apps are doing it. I haven&#039;t had time to do this just yet. I noticed some links on this page that mention RTP. Maybe they point the way even though it is for video?  I think sometime next month, after I add a different feature to my app, I will tackle this rtp thing.  I will report back.</description>
		<content:encoded><![CDATA[<p>I actually hear it in my app.  In my app I am saving pieces of a live, continuous, stream and playing them one by one.<br />
It is VERY subtle. But I know the gap is there. None of my users have complained about it yet though. So I assume maybe it is only for people with sensitive ears.</p>
<p>My plan to getting around it is to implement some type of live stream-to-rtp converter.  So the program will download a portion of audio, put it into a RTP packet, then send that off to the audio player.</p>
<p>I &#8220;think&#8221; this is how other apps are doing it. I haven&#8217;t had time to do this just yet. I noticed some links on this page that mention RTP. Maybe they point the way even though it is for video?  I think sometime next month, after I add a different feature to my app, I will tackle this rtp thing.  I will report back.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Biosopher</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-563</link>
		<dc:creator>Biosopher</dc:creator>
		<pubDate>Tue, 16 Feb 2010 01:07:06 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-563</guid>
		<description>Hi Kavitha,

I just tested the streaming tutorial and don&#039;t hear any gaps in the downloaded audio.  

Anthony</description>
		<content:encoded><![CDATA[<p>Hi Kavitha,</p>
<p>I just tested the streaming tutorial and don&#8217;t hear any gaps in the downloaded audio.  </p>
<p>Anthony</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kavitha</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-562</link>
		<dc:creator>kavitha</dc:creator>
		<pubDate>Mon, 15 Feb 2010 13:12:13 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-562</guid>
		<description>Thanks CatDaaaady,,

But still there is gap in between switching over of files

What will be the workaround for that????

Please tell me solution.

Thanks
Kavitha</description>
		<content:encoded><![CDATA[<p>Thanks CatDaaaady,,</p>
<p>But still there is gap in between switching over of files</p>
<p>What will be the workaround for that????</p>
<p>Please tell me solution.</p>
<p>Thanks<br />
Kavitha</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Biosopher</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-559</link>
		<dc:creator>Biosopher</dc:creator>
		<pubDate>Wed, 10 Feb 2010 17:23:52 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-559</guid>
		<description>Hi Riz,

FUtils refers to code that does not exist so simply delete that commented line.  

The downloaded file is currently being copied to the file system.  You can choose to capture the data and save it as a blob to a sqllite db, but the &#039;lite&#039; db or really any db isn&#039;t built for storing files.  You should save to the file system and simply store the file path in the db.</description>
		<content:encoded><![CDATA[<p>Hi Riz,</p>
<p>FUtils refers to code that does not exist so simply delete that commented line.  </p>
<p>The downloaded file is currently being copied to the file system.  You can choose to capture the data and save it as a blob to a sqllite db, but the &#8216;lite&#8217; db or really any db isn&#8217;t built for storing files.  You should save to the file system and simply store the file path in the db.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Riz</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comment-557</link>
		<dc:creator>Riz</dc:creator>
		<pubDate>Wed, 10 Feb 2010 08:09:18 +0000</pubDate>
		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16#comment-557</guid>
		<description>Hi Anthony,

great tutorials . but I am wondering how can I save that file to sqlite database or file system please suggest me ,if I go through the source code I can see commented line 
//FileUtils.copyFile(downloadingMediaFile,bufferedFile);
if I un-comment is it going to work ......downloadingMediaFile contain every thing ?</description>
		<content:encoded><![CDATA[<p>Hi Anthony,</p>
<p>great tutorials . but I am wondering how can I save that file to sqlite database or file system please suggest me ,if I go through the source code I can see commented line<br />
//FileUtils.copyFile(downloadingMediaFile,bufferedFile);<br />
if I un-comment is it going to work &#8230;&#8230;downloadingMediaFile contain every thing ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
