gpt4 book ai didi

android - Android MediaPlayer播放在线(外部)音频

转载 作者:行者123 更新时间:2023-12-03 02:12:22 36 4
gpt4 key购买 nike

当我单击按钮时,我使用此代码播放在线mp3音频,但它不起作用。

public void play(View v) throws IllegalStateException, IOException{ 
MediaPlayer em2 =MediaPlayer.create(this, Uri.parse("https://ia801005.us.archive.org/22/items/sslamweb.blogspot.com_201308/Maher%20Zain%20-%20Hold%20My%20Hand%20-%20Official%20Lyrics%20Video.mp3"));
em2.setAudioStreamType(AudioManager.STREAM_MUSIC);
em2.prepare();
em2.start();
}

最佳答案

您正在使用MediaPlayer创建create,它已经为您调用prepare。不要再次调用prepare

public void play(View v) throws IllegalStateException, IOException{ 
MediaPlayer em2 = MediaPlayer.create(this, Uri.parse("https://ia801005.us.archive.org/22/items/sslamweb.blogspot.com_201308/Maher%20Zain%20-%20Hold%20My%20Hand%20-%20Official%20Lyrics%20Video.mp3"));
em2.setAudioStreamType(AudioManager.STREAM_MUSIC);
em2.start();
}

将来,这将有助于查看错误的logcat输出。

关于android - Android MediaPlayer播放在线(外部)音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23041098/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com