gpt4 book ai didi

android - android上的流媒体错误

转载 作者:行者123 更新时间:2023-11-30 03:38:33 24 4
gpt4 key购买 nike

我有这段代码可以在互联网上播放广播流,这段代码像:-

package com.example.kam;

import java.io.IOException;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

import android.media.AudioManager;
import android.media.MediaPlayer;


public class MainActivity extends Activity {
public MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}
protected void onResume (){
super.onResume();

mp = new MediaPlayer();
try {
mp.setDataSource("http://radio.arabhosters.com:8015/");
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //also consider mp.prepareAsync().
mp.start();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);

return true;
}

}

当我运行这段代码时,我看到了这个异常:-

04-25 14:11:16.448: E/MediaPlayer(533): Unable to to create media player
04-25 14:11:16.458: W/System.err(533): java.io.IOException: setDataSource failed.: status=0x80000000
04-25 14:11:16.458: W/System.err(533): at android.media.MediaPlayer.setDataSource(Native Method)
04-25 14:11:16.458: W/System.err(533): at com.example.kam.MainActivity.onResume(MainActivity.java:26)
04-25 14:11:16.468: W/System.err(533): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
04-25 14:11:16.468: W/System.err(533): at android.app.Activity.performResume(Activity.java:4539)
04-25 14:11:16.468: W/System.err(533): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2433)
04-25 14:11:16.468: W/System.err(533): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2471)
04-25 14:11:16.468: W/System.err(533): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
04-25 14:11:16.478: W/System.err(533): at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-25 14:11:16.478: W/System.err(533): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-25 14:11:16.478: W/System.err(533): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 14:11:16.478: W/System.err(533): at android.os.Looper.loop(Looper.java:137)
04-25 14:11:16.478: W/System.err(533): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-25 14:11:16.478: W/System.err(533): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 14:11:16.489: W/System.err(533): at java.lang.reflect.Method.invoke(Method.java:511)
04-25 14:11:16.489: W/System.err(533): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-25 14:11:16.489: W/System.err(533): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-25 14:11:16.489: W/System.err(533): at dalvik.system.NativeStart.main(Native Method)
04-25 14:11:16.489: E/MediaPlayer(533): prepareAsync called in state 1
04-25 14:11:16.489: W/System.err(533): java.lang.IllegalStateException
04-25 14:11:16.499: W/System.err(533): at android.media.MediaPlayer.prepare(Native Method)
04-25 14:11:16.499: W/System.err(533): at com.example.kam.MainActivity.onResume(MainActivity.java:42)
04-25 14:11:16.499: W/System.err(533): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
04-25 14:11:16.499: W/System.err(533): at android.app.Activity.performResume(Activity.java:4539)
04-25 14:11:16.499: W/System.err(533): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2433)
04-25 14:11:16.499: W/System.err(533): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2471)
04-25 14:11:16.509: W/System.err(533): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
04-25 14:11:16.509: W/System.err(533): at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-25 14:11:16.509: W/System.err(533): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-25 14:11:16.509: W/System.err(533): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 14:11:16.509: W/System.err(533): at android.os.Looper.loop(Looper.java:137)
04-25 14:11:16.509: W/System.err(533): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-25 14:11:16.509: W/System.err(533): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 14:11:16.509: W/System.err(533): at java.lang.reflect.Method.invoke(Method.java:511)
04-25 14:11:16.519: W/System.err(533): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-25 14:11:16.519: W/System.err(533): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-25 14:11:16.519: W/System.err(533): at dalvik.system.NativeStart.main(Native Method)
04-25 14:11:16.519: E/MediaPlayer(533): start called in state 1
04-25 14:11:16.519: E/MediaPlayer(533): error (-38, 0)
04-25 14:11:16.669: D/gralloc_goldfish(533): Emulator without GPU emulation detected.

但是我将这段代码导入到另一台电脑上,它可以正常播放。

我的错误在哪里

最佳答案

我的猜测是您永远不会在 MediaPlayer 上调用 release()。解决问题的一个简单方法(至少如果我正确阅读 logcat 的话)是在实例化之前放置一个 reset() 调用。像这样:

mp.reset();
mp.setDataSource("http://radio.arabhosters.com:8015/");

但有一件事:你应该阅读整个 MediaPlayer state diagram真正了解您应该做什么。

关于android - android上的流媒体错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16219840/

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