Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: beginner developing android app to stream radio station needs help!

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post

    Cool beginner developing android app to stream radio station needs help!

    Good evening everyone!

    I am new to this Java thing, but I have learned so much over the past few weeks, and I feel like I'm really starting to get a hang of it. I am currently developing my first project, an android app for a small radio network which will allow you to stream the station live. To make this happen, I must query a .pls stream file, and extract the three possible URLs for the listen link. I cannot directly link to any of the URLs because they are dynamic and can change without warning. Before implementing this part of the code, I was able to easily make a direct link to one of those streams and get audio playing. Yay me. Anyways, I have a class set up, PlsParse, which connects, opens and parses the pls file, extracts the three links, and returns them to be open with MediaPlayer. This is when everything goes awry. There are no compile errors and it runs, it just crashes when I access the listen live page. Thanks for any help you may bring, and I promise to one day return the favor to a newbie and help them in their time of need. Much obliged and good night. Here is the code:

    package com.comedy.app;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.LinkedList;
    import java.util.List;
     
    import com.comedy.app.ListenToStream.PlsParser;
     
    import android.app.Activity;
    import android.media.AudioManager;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.widget.ImageView;
    import android.widget.RatingBar;
    import android.widget.TextView;
     
     
     
    public class ListenToStream extends Activity {
     
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		// TODO Auto-generated method stub
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.audiostream);
     
    		TextView artistName = (TextView) findViewById(R.id.txtArtistName);
    		TextView albumName = (TextView) findViewById(R.id.txtAlbumName);
    		RatingBar starRating = (RatingBar) findViewById(R.id.ratingBar1);
    		ImageView albumPicture = (ImageView) findViewById(R.id.albumImage);
    		MediaPlayer comedyStream = new MediaPlayer();
    		String urlToStream = null;
    		try {
    			urlToStream = new PlsParser(
    					"http://url_to_the_pls_file.pls").toString();
    		} catch (IOException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
     
    		comedyStream.setAudioStreamType(AudioManager.STREAM_MUSIC);
    		try {
    			comedyStream.setDataSource(urlToStream);
    			comedyStream.prepare(); // might take long! (for buffering, etc)
    			comedyStream.start();
     
    		} catch (IllegalArgumentException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (SecurityException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IllegalStateException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
    	}
     
    	public class PlsParser {
    		private final BufferedReader reader;
     
    		public PlsParser(String url) throws IOException, IOException {
    			URLConnection urlConnection = new URL(url).openConnection();
    			this.reader = new BufferedReader(new InputStreamReader(
    					urlConnection.getInputStream()));
    		}
     
    		public List<String> getUrls() {
    			LinkedList<String> urls = new LinkedList<String>();
    			while (true) {
    				try {
    					String line = reader.readLine();
    					if (line == null) {
    						break;
    					}
    					String url = parseLine(line);
    					if (url != null && !url.equals("")) {
    						urls.add(url);
    					}
    				} catch (IOException e) {
    					e.printStackTrace();
    				}
    			}
    			return urls;
    		}
     
    		private String parseLine(String line) {
    			if (line == null) {
    				return null;
    			}
    			String trimmed = line.trim();
    			if (trimmed.indexOf("http") >= 0) {
    				return trimmed.substring(trimmed.indexOf("http"));
    			}
    			return "";
    		}
    	}
     
    }
    Last edited by infiniteoo; February 3rd, 2012 at 12:10 AM.

  2. The Following User Says Thank You to infiniteoo For This Useful Post:

    urircuche (February 24th, 2014)


  3. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: beginner developing android app to stream radio station needs help!

    Okay so I'm relatively new to Android myself, but what I would do is put print statements or breaks at various parts of your code to figure out where it crashed. A good place to start would be after your first try catch statement

  4. The Following User Says Thank You to marylandfour For This Useful Post:

    urircuche (February 24th, 2014)

Similar Threads

  1. Best Tools for developing in Java/Android
    By Nesh108 in forum Android Development
    Replies: 11
    Last Post: October 24th, 2012, 07:34 AM
  2. Any alternative of Eclipse for developing android app?
    By vincentroberts in forum Java IDEs
    Replies: 6
    Last Post: January 5th, 2012, 01:48 AM
  3. Quick beginner radio button question
    By smarmy_cheauffeur in forum AWT / Java Swing
    Replies: 2
    Last Post: October 17th, 2011, 08:20 AM
  4. could not create audio stream from input stream
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: June 2nd, 2011, 02:08 AM
  5. How to develop plugins in Netbeans?
    By haygaurav in forum Web Frameworks
    Replies: 1
    Last Post: May 27th, 2009, 04:49 PM

Tags for this Thread