Get url from .pls file
This will return a URL, for example http://stream2.streamq.net:8020
package com.direct.radio.global; 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 android.content.Context; import android.util.Log; public class GetStreamingUrl { private static String LOGTAG = "GetStreamingUrl"; private Context mContext; public GetStreamingUrl(Context context) { Log.i(LOGTAG, "call to constructor"); this.mContext = context; } public LinkedList<String> getStreamingUrl(String url) { Log.i(LOGTAG, "get streaming url"); final BufferedReader br; String murl = null; LinkedList<String> murls = null; try { URLConnection mUrl = new URL(url).openConnection(); br = new BufferedReader( new InputStreamReader(mUrl.getInputStream())); murls = new LinkedList<String>(); while (true) { try { String line = br.readLine(); if (line == null) { break; } murl = parseLine(line); if (murl != null && !murl.equals("")) { murls.add(murl); } } catch (IOException e) { e.printStackTrace(); } } } catch (MalformedURLException e) {
Activity_Player.java or Service_Player.java
You can write this code according to your needs. Define this method
LinkedList<String> urls; private LinkedList<String> fGetPlayableUrl(String mPls) { GetStreamingUrl oGetStreamingUrl = new GetStreamingUrl(Activity_Splash.this); urls = oGetStreamingUrl.getStreamingUrl(mPls); return urls; }
Here fGetPlayableUrl(String mPls) passes the .pls URL. You now have a streaming URL.
MediaPlayer mMediaPlayer = new MediaPlayer();
Now pass the url
mMediaPlayer.setDataSource(urls.toString()); mMediaPlayer.prepareAsync(); mMediaPlayer.start();
source share