mediaPlayer错误-38,0

我尝试做简单的在线广播播放器。这是流的地址http://radio-electron.ru:8000/96这是我的代码。

MyActivity.java

package com.example.untitled2;

import android.app.Activity;

import android.media.AudioManager;

import android.media.MediaPlayer;

import android.net.Uri;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;

import java.io.IOException;

public class MyActivity extends Activity {

MediaPlayer mediaPlayer;

Button playButton;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

@Override

public void onStart() {

super.onStart();

}

@Override

public void onResume() {

super.onResume();

mediaPlayer = new MediaPlayer();

playButton = (Button)findViewById(R.id.button);

playButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

if(mediaPlayer.isPlaying())

mediaPlayer.stop();

else {

try {

mediaPlayer.setDataSource(getApplicationContext(), Uri.parse("http://radio-electron.ru:8000/96"));

mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {

@Override

public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {

Toast.makeText(getApplicationContext(), "ERROR " + i, Toast.LENGTH_LONG).show();

playButton.setEnabled(false);

Log.d("radio", "error " + i + " " + i2);

return false; //To change body of implemented methods use File | Settings | File Templates.

}

});

mediaPlayer.prepareAsync();

}

catch (IOException e) {

Toast.makeText(getApplicationContext(), "ERROR " + e, Toast.LENGTH_LONG).show();

Log.d("radio", "error " + e);

}

mediaPlayer.start();

}

}

});

}

}

main.xml

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="New Button"

android:id="@+id/button"

android:layout_gravity="center"/>

</FrameLayout>

我不知道为什么我得到-(38,0)代码,这是什么意思。我使用Intellij IDEA,并在Android

2.3和4.2模拟器上尝试此代码,但遇到了一些问题。

回答:

-38引用errno.h中的ENOSYS错误代码

您似乎尝试在准备工作完成之前开始播放。使用该

setOnPreparedListener()方法设置准备侦听器,并start()仅在准备完成后才调用该方法。

mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

public void onPrepared(MediaPlayer mp) {

mp.start();

}

});

mediaPlayer.prepareAsync();

mediaPlayer.start()从代码中删除当前调用。

以上是 mediaPlayer错误-38,0 的全部内容, 来源链接: utcz.com/qa/399262.html

回到顶部