今天写了一个简单的music播放器,进过层层排查代码是没问题但是依然报错
12-16 09:24:56.943: ERROR/MediaPlayer(25754): Unable to to create media player
12-16 09:24:56.943: WARN/System.err(25754): java.io.IOException: setDataSourceFD failed.: status=0x80000000
12-16 09:24:56.953: WARN/System.err(25754): at android.media.MediaPlayer.setDataSource(Native Method)
12-16 09:24:56.953: WARN/System.err(25754): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:749)
12-16 09:24:56.953: WARN/System.err(25754): at com.lenovo.MusicplayerActivity.play(MusicplayerActivity.java:29)
12-16 09:24:56.953: WARN/System.err(25754): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 09:24:56.953: WARN/System.err(25754): at java.lang.reflect.Method.invoke(Method.java:521)
12-16 09:24:56.953: WARN/System.err(25754): at android.view.View$1.onClick(View.java:2067)
12-16 09:24:56.953: WARN/System.err(25754): at android.view.View.performClick(View.java:2408)
12-16 09:24:56.953: WARN/System.err(25754): at android.view.View$PerformClick.run(View.java:8816)
12-16 09:24:56.953: WARN/System.err(25754): at android.os.Handler.handleCallback(Handler.java:587)
12-16 09:24:56.953: WARN/System.err(25754): at android.os.Handler.dispatchMessage(Handler.java:92)
12-16 09:24:56.953: WARN/System.err(25754): at android.os.Looper.loop(Looper.java:123)
12-16 09:24:56.953: WARN/System.err(25754): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-16 09:24:56.953: WARN/System.err(25754): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 09:24:56.953: WARN/System.err(25754): at java.lang.reflect.Method.invoke(Method.java:521)
12-16 09:24:56.953: WARN/System.err(25754): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-16 09:24:56.953: WARN/System.err(25754): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-16 09:24:56.953: WARN/System.err(25754): at dalvik.system.NativeStart.main(Native Method)
12-16 09:24:56.953: ERROR/MediaPlayer(25754): start called in state 1
猜测很可能是源文件有问题,换了一个mp3音乐终于可以播放了。
package com.Aina.Android;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Test_Notification extends Activity {
/** Called when the activity is first created. */
private Button btn1;
private Notification notification;
private NotificationManager notificationManager;
private Intent intent;
private PendingIntent pendIntent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button) this.findViewById(R.id.Button01);
notificationManager = (NotificationManager) this
.getSystemService(NOTIFICATION_SERVICE);// 获取系统服务(消息管理)
// 点击通知时转移内容
intent = new Intent(this, Activity2.class);
// 设置点击通知时显示内容的类
pendIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification = new Notification();
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
notification.icon = R.drawable.img1;// 设置在状态栏显示的图标
notification.tickerText = "Button1通知内容.......";//设置在状态栏显示的内容
notification.defaults = Notification.DEFAULT_SOUND;// 默认的声音
// 设置通知显示的参数
notification.setLatestEventInfo(Test_Notification.this,
"Button1", "Button1通知", pendIntent);
notificationManager.notify(0, notification);// 执行通知.
}
});
}
}
package program;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.apache.commons.io.FileUtils;
public class Tele {
private static final String CURRENTFILE = "c:/test/current.txt";
private static final String TODAYFILE = "c:/test/today.txt";
private static final String RESULTFILE = "c:/test/result.txt";
public static void main(String[] args){
try {
List<String> currentNum = FileUtils.readLines(new File(CURRENTFILE), "UTF-8");
List<String> todayNum = FileUtils.readLines(new File(TODAYFILE), "UTF-8");
currentNum.addAll(todayNum);
Collections.sort(currentNum);
System.out.println(currentNum.toArray().length);
FileUtils.writeLines(new File(RESULTFILE), currentNum);
} catch (IOException e) {
new Exception("读取文件时出错");
}
}
}