‘N’ is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore
#资源文件首字母必须是小写字母或者0-9!!!哈哈哈哈,不说了水文章!!!
沃特玛不想发这个,英语不好,也可能就是这个习惯搜csdn,就不看那个错误提示,全靠误打误撞写代码!!
package edu.hebut.myservice;
import android.app.Service;
import android.content.Intent;
import android.media.MediaParser;
import android.media.MediaPlayer;
import android.os.IBinder;
import androidx.annotation.Nullable;
public class MyService extends Service {
static boolean isplay;//是否在播放
MediaPlayer player;//播放音乐
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
player=MediaPlayer.create(this,R.raw.normal);
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if(!player.isPlaying()){
player.start();//开始播放
isplay=player.isPlaying();
}
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
player.stop();
isplay=player.isPlaying();
player.release();
super.onDestroy();
}
}