-1
我想在後臺播放媒體播放器。還想玩,停止,暫停,從Android的主要活動的下一個進程? 任何人有想法?如何在android中爲後臺播放媒體播放器創建服務類?
我想在後臺播放媒體播放器。還想玩,停止,暫停,從Android的主要活動的下一個進程? 任何人有想法?如何在android中爲後臺播放媒體播放器創建服務類?
public class MusicService extends Service {
private static final String TAG = "MyService";
public static MediaPlayer mediaplayer;
String musicfile;
@Override
public IBinder onBind(Intent intent) {
Log.i(" ibinder ", "");
return null;
}
@Override
public void onCreate() {
// Toast.makeText(this, "My Service Created", 0).show();
Log.i(TAG, "onCreate");
mediaplayer = new MediaPlayer();
mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
@Override
public void onDestroy() {
Toast.makeText(this, "My Service Stopped", 0).show();
Log.w(TAG, "onDestroy");
mediaplayer.stop();
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this,
"My Service Started :" + intent + " start id :" + startid, 0)
.show();
mediaplayer.start();
}
}