-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from ZeusWPI/android/use-m3u-in-streaming
Fix the stream to a m3u file (closes #126)
- Loading branch information
Showing
2 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
android/src/be/ugent/zeus/hydra/util/audiostream/ParseStreamAsyncTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package be.ugent.zeus.hydra.util.audiostream; | ||
|
||
import android.os.AsyncTask; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
/** | ||
* | ||
* @author silox | ||
*/ | ||
public class ParseStreamAsyncTask extends AsyncTask<String, Void, String> { | ||
|
||
MusicService musicService; | ||
|
||
public ParseStreamAsyncTask(MusicService musicService) { | ||
this.musicService = musicService; | ||
} | ||
|
||
@Override | ||
protected String doInBackground(String... params) { | ||
String line; | ||
|
||
try { | ||
URL urlPage = new URL(params[0]); | ||
HttpURLConnection connection = (HttpURLConnection) urlPage.openConnection(); | ||
InputStream inputStream = connection.getInputStream(); | ||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); | ||
|
||
StringBuilder stringBuffer = new StringBuilder(); | ||
|
||
while ((line = bufferedReader.readLine()) != null) { | ||
if (line.contains("http")) { | ||
connection.disconnect(); | ||
bufferedReader.close(); | ||
inputStream.close(); | ||
return line; | ||
} | ||
stringBuffer.append(line); | ||
} | ||
|
||
connection.disconnect(); | ||
bufferedReader.close(); | ||
inputStream.close(); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(String result) { | ||
musicService.playmp3(result); | ||
} | ||
} |