83 lines
2.2 KiB
Java
83 lines
2.2 KiB
Java
package com.arpa.hndahesudintocctmsdriver.service;
|
|
|
|
import android.app.Service;
|
|
import android.content.Intent;
|
|
import android.content.res.AssetFileDescriptor;
|
|
import android.media.MediaPlayer;
|
|
import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.util.Log;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.arpa.hndahesudintocctmsdriver.request.HuoYuanRequset;
|
|
import com.arpa.hndahesudintocctmsdriver.util.cache.CacheGroup;
|
|
import com.arpa.hndahesudintocctmsdriver.util.http.RequsetCodeConstants;
|
|
|
|
|
|
/**
|
|
* @author hlh
|
|
* @version 1.0.0
|
|
* @date 2021/10/8 16:33
|
|
* @description:上传失败后进行重新上传
|
|
*/
|
|
public class MakeUpService extends Service {
|
|
|
|
private MediaPlayer mediaPlayer = new MediaPlayer();
|
|
public void palyMp3(){
|
|
Log.e("开始播放","-----");
|
|
try {
|
|
AssetFileDescriptor fd =getAssets().openFd("kujp9scu.mp3");
|
|
mediaPlayer.setDataSource(fd);
|
|
mediaPlayer.setLooping(false);//设置为循环播放
|
|
mediaPlayer.prepare();//初始化播放器MediaPlayer
|
|
mediaPlayer.start();
|
|
Log.e("播放成功","-----");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
Log.e("播放失败","-----");
|
|
}
|
|
}
|
|
private Handler hd=new Handler(msg -> {
|
|
switch (msg.what){
|
|
case RequsetCodeConstants.SUCCESS:
|
|
if(CacheGroup.cacheList.get(HuoYuanRequset.ASYMMETRYWAYBILL)!=null){
|
|
|
|
CacheGroup.cacheList.remove(CacheGroup.cacheList.get(HuoYuanRequset.ASYMMETRYWAYBILL));
|
|
}
|
|
break;
|
|
}
|
|
return false;
|
|
});
|
|
@Nullable
|
|
@Override
|
|
public IBinder onBind(Intent intent) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
palyMp3();
|
|
}
|
|
|
|
//开始
|
|
@Override
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
Log.e("服务开启","-----");
|
|
|
|
return START_STICKY;
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
if (mediaPlayer!=null) {
|
|
mediaPlayer.stop();
|
|
mediaPlayer.release();
|
|
}
|
|
}
|
|
|
|
}
|