我完全新的Android開發者和一般的Android設備,所以我不知道事情是如何在這裏工作。如何從與Java網址串流音樂 - Android電子
我想打一個應用程序,從我的網址串流音樂,仍然播放歌曲後,我最小化應用程序。
我搜索我的問題,但很多答案都爲MP3歌曲或其它類型的,但我的網址是從電臺直播,所以它不是唯一的歌。
一,我發現是對我的問題的答案是this,並使用此代碼:
Uri myUri = Uri.parse("your url here");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(myUri, "audio/*");
startActivity(intent);
這促使我選擇音樂播放器。
有什麼辦法,只是按我的「播放」按鈕,聽音樂?
在我的iOS應用程序,我用這個代碼,我可以啓動和停止的流媒體音樂時,我想沒有一個外部播放器:提前
編輯
func prepareToPlay() {
let url = URL(string: "myUrl")
playerItem = AVPlayerItem(url: url!)
player = AVPlayer(playerItem: playerItem)
player?.play()
}
謝謝建議中的意見和答案,我試圖用MPlayer
玩之後,我做了一個功能,我把它叫做當我拍了拍我的按鈕,像這樣:
public void playM() {
String url = "http://android.programmerguru.com/wp-content/uploads/2013/04/hosannatelugu.mp3";
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}
但我得到一個錯誤(第四消息),我在日誌中看到這一點:
無法創建媒體播放器
prepareAsync稱爲狀態1,MPLAYER(爲0x0)
開始稱爲在狀態1時,MPlayer(爲0x0)
誤差(-38,0)
什麼[網絡協議(https://developer.android.com/guide/topics/media/media-formats.html#network)爲您的服務器使用? – CommonsWare
@CommonsWare它使用HTTP –
據我所知,這還不夠具體的 - 看到我掛文檔。歡迎您將URL傳遞給'MediaPlayer'並查看它是否可用。 – CommonsWare