I'm trying to stream audio from a URL. The code works fine with other URLs, but in one of those it fails in the OnPrepared
method, returning this error code: (1, -2147483648). I've read some people saying it's because of permissions, but it's a remote file, so I can't set permissions. I've tried the URL with other apps like VLC and iTunes, and it's working fine. My code is here:
我正在尝试从一个URL传输音频。这段代码可以很好地处理其他url,但是在onprepare方法中失败了,返回这个错误代码:(1,-2147483648)。我读过一些人说这是因为权限,但这是一个远程文件,所以我不能设置权限。我已经在VLC和iTunes等应用程序上试用过这个URL,它运行得很好。我的代码是:
private void prepareradio() {
player = new MediaPlayer();
player.setAudioStreamType(MODE_WORLD_READABLE);
try {
player.setDataSource(url);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
player.setOnErrorListener(new OnErrorListener(){
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
Toast.makeText(getApplicationContext(),"An error happened while preparing radio",Toast.LENGTH_LONG).show();
prepareradio();
playe.setEnabled(true);
hidenot();
return false;
}
});
3 个解决方案
#1
2
If you are testing on devices earlier than Android 3.1 you might not be able to play AACP (as seen on the info page for your stream (AAC+) streams.
如果您在比Android 3.1更早的设备上进行测试,您可能无法使用AACP(在您的流(AAC+)流的信息页上看到)。
Info page for your stream:
您的流的信息页:
In order to find out what streams you can play on your targeted device check official docs: http://developer.android.com/reference/android/media/AudioManager.html
为了找到你可以在目标设备上播放的流,请查看官方文档:http://developer.android.com/reference/android/media/AudioManager.html
If you are looking how to handle aacp checkout following:
https://*.com/a/8833346/200272
如果您正在查看如何处理aacp的签出:https://*.com/a/8833346/200272。
#2
3
I was also getting the same error on Froyo & Gingerbread. In higher Androids the same video played well. Finally after a lot of research, tried changing the Https Url to Http Url & Bingo. It resolved my issue. I was using amazon S3 server so that simply replacing the "https" in url with "http" was sufficient.
我在Froyo & Gingerbread上也犯了同样的错误。在高级机器人中,同样的视频播放得很好。经过大量研究之后,尝试将Https Url更改为Http Url & Bingo。它解决了我的问题。我使用的是amazon S3服务器,因此只需将url中的“https”替换为“http”就足够了。
videoUrl= videoUrl.replaceFirst("https", "http");
PS: For supporting older versions if you are using H.264 make sure videos are Baseline encoded.
PS:如果你正在使用H.264,为了支持旧版本,请确保视频是基线编码的。
#3
0
As I can see, this stream is not supported by mediaPlayer. Android supports AAC LC/LTP but your stream is aacp. I think this may be the root cause of your problem.
如我所见,这个流不是由mediaPlayer支持的。Android支持AAC LC/LTP,但是你的流是aacp。我认为这可能是你的问题的根本原因。
#1
2
If you are testing on devices earlier than Android 3.1 you might not be able to play AACP (as seen on the info page for your stream (AAC+) streams.
如果您在比Android 3.1更早的设备上进行测试,您可能无法使用AACP(在您的流(AAC+)流的信息页上看到)。
Info page for your stream:
您的流的信息页:
In order to find out what streams you can play on your targeted device check official docs: http://developer.android.com/reference/android/media/AudioManager.html
为了找到你可以在目标设备上播放的流,请查看官方文档:http://developer.android.com/reference/android/media/AudioManager.html
If you are looking how to handle aacp checkout following:
https://*.com/a/8833346/200272
如果您正在查看如何处理aacp的签出:https://*.com/a/8833346/200272。
#2
3
I was also getting the same error on Froyo & Gingerbread. In higher Androids the same video played well. Finally after a lot of research, tried changing the Https Url to Http Url & Bingo. It resolved my issue. I was using amazon S3 server so that simply replacing the "https" in url with "http" was sufficient.
我在Froyo & Gingerbread上也犯了同样的错误。在高级机器人中,同样的视频播放得很好。经过大量研究之后,尝试将Https Url更改为Http Url & Bingo。它解决了我的问题。我使用的是amazon S3服务器,因此只需将url中的“https”替换为“http”就足够了。
videoUrl= videoUrl.replaceFirst("https", "http");
PS: For supporting older versions if you are using H.264 make sure videos are Baseline encoded.
PS:如果你正在使用H.264,为了支持旧版本,请确保视频是基线编码的。
#3
0
As I can see, this stream is not supported by mediaPlayer. Android supports AAC LC/LTP but your stream is aacp. I think this may be the root cause of your problem.
如我所见,这个流不是由mediaPlayer支持的。Android支持AAC LC/LTP,但是你的流是aacp。我认为这可能是你的问题的根本原因。