解决方案 »
- 自己闲着无聊,想做个android游戏,就像<魔镜仙踪>一样的,求指导!
- android 怎么获取 chronometer控件状态
- 将android apk文件装入手机提示解析包时出问题
- 两难问题
- anti-band中文是什么意思?
- 请教:Android中的ViewGroup怎样控制其子View的尺寸大小
- GUI求助!PropertyAnimation
- 谁能把Andriod SDK tools 里的zipalign.exe文件发给我一个
- android中的SD卡使用
- android编辑图片时,纪录添加饰品的步骤。
- Android setContentView不能切换页面
- android怎么在recycleview里一条一条增加新增数据
感谢回复!
不好意思我实在十分小白,是这样子吗?我运行了一下,APP会闪退,不知道是哪里出了错?
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;import java.util.HashMap;
import java.util.Map;public class MusicService extends Service {
private String Sring;
public MusicService() {
}
static boolean isplay;
MediaPlayer player;
static Map<String,Integer> date = new HashMap<String,Integer>();
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
} @Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!player.isPlaying()) {
player.start();
isplay = player.isPlaying();
}
date.put("bird",R.raw.bird);
date.put("chimes",R.raw.chimes);
date.put("cock",R.raw.cock);
date.put("cuckoo",R.raw.cuckoo);
date.put("notify",R.raw.notify);
date.put("ringout",R.raw.ringout);
date.put("water",R.raw.water);
Sring=intent.getStringExtra("Sring");//这算是收到了参数吗?
return super.onStartCommand(intent, flags, startId);
} @Override
public void onCreate() {
player = MediaPlayer.create(this,date.get(Sring));
}
@Override
public void onDestroy() {
player.stop();
isplay = player.isPlaying();
player.release();
super.onDestroy();
}
}
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;import java.util.HashMap;
import java.util.Map;public class MusicService extends Service {
private String Sring;
public MusicService() {
}
static boolean isplay;
MediaPlayer player;
static Map<String,Integer> date = new HashMap<String,Integer>();
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
} @Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!player.isPlaying()) {
player.start();
isplay = player.isPlaying();
}
date.put("bird",R.raw.bird);
date.put("chimes",R.raw.chimes);
date.put("cock",R.raw.cock);
date.put("cuckoo",R.raw.cuckoo);
date.put("notify",R.raw.notify);
date.put("ringout",R.raw.ringout);
date.put("water",R.raw.water);
Sring=intent.getStringExtra("Sring");//这算是收到了参数吗?
return super.onStartCommand(intent, flags, startId);
} @Override
public void onCreate() {
player = MediaPlayer.create(this,date.get(Sring));
}
@Override
public void onDestroy() {
player.stop();
isplay = player.isPlaying();
player.release();
super.onDestroy();
}
}你在onCreate里生成player可以,但不要在这里获取date.get(String),你可以先传一个Uri.EMPTY,然后在onStartCommand接收到参数再调用player.setDataSource(this, date.get(Sring))更新数据,然后播放
你在onCreate里生成player可以,但不要在这里获取date.get(String),你可以先传一个Uri.EMPTY,然后在onStartCommand接收到参数再调用player.setDataSource(this, date.get(Sring))更新数据,然后播放Uri这个我完全没学过相关内容,所以这个什么意思、是什么步骤……我,看不懂
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;import java.util.HashMap;
import java.util.Map;public class MusicService extends Service {
private String Sring;
public MusicService() {
}
static boolean isplay;
MediaPlayer player;
static Map<String,Integer> date = new HashMap<String,Integer>();
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
} @Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!player.isPlaying()) {
player.start();
isplay = player.isPlaying();
}
date.put("bird",R.raw.bird);
date.put("chimes",R.raw.chimes);
date.put("cock",R.raw.cock);
date.put("cuckoo",R.raw.cuckoo);
date.put("notify",R.raw.notify);
date.put("ringout",R.raw.ringout);
date.put("water",R.raw.water);
Sring=intent.getStringExtra("Sring");//这算是收到了参数吗?
return super.onStartCommand(intent, flags, startId);
} @Override
public void onCreate() {
player = MediaPlayer.create(this,date.get(Sring));
}
@Override
public void onDestroy() {
player.stop();
isplay = player.isPlaying();
player.release();
super.onDestroy();
}
}你在onCreate里生成player可以,但不要在这里获取date.get(String),你可以先传一个Uri.EMPTY,然后在onStartCommand接收到参数再调用player.setDataSource(this, date.get(Sring))更新数据,然后播放Uri这个我完全没学过相关内容,所以这个什么意思、是什么步骤……我,看不懂
引用错了,再发一次
惭愧,我基础确实十分薄弱,我校大概课程安排不太好,我们java几乎没怎么学,Android studio刚学一点,就要开始做APP了,时间紧迫没来得及好好从头学起,之后会再好好搞清楚的!