public class PlayService extends Service implements Runnable { private MediaPlayer player; private List musicList; private SeekbarReceiver receiver ; public static boolean isrunning = true;
@Override public void onCreate() { player = new MediaPlayer(); musicList = MusicList.getMusicData(this); new Thread(this).start(); receiver = new SeekbarReceiver(); registerReceiver(receiver, new IntentFilter("org.hwq.music.seekbar.seekto")); } @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; }
@Override public void onDestroy() { if(player != null){ player.release(); player = null; } unregisterReceiver(receiver); super.onDestroy(); }
@Override public void onStart(Intent intent, int startId) { Bundle extras = intent.getExtras(); String op = extras.getString("op"); if("play".equals(op)){ play(); } }
private void play() { System.out.println("service中的play执行"); Music m = musicList.get(0); Uri uri = Uri.parse(m.getUrl()); try{ player.setDataSource(this,uri); player.prepare(); player.start(); }catch (Exception e) { e.printStackTrace(); } } public void run() { while(isrunning){ try{ Thread.sleep(100); }catch (Exception e) {
} if(player!=null){ int currentPosition = player.getCurrentPosition(); int duration = player.getDuration(); Intent intent = new Intent("org.hwq.receiver.seekbar"); intent.putExtra("currentPosition", currentPosition); intent.putExtra("duration", duration); System.out.println("发出一个广播:currentPosition="+currentPosition); sendBroadcast(intent); } } } //接收前台拖放的进度,并调整歌曲的播放进度 class SeekbarReceiver extends BroadcastReceiver{ public void onReceive(Context context, Intent intent) { int currentPosition = intent.getIntExtra("currentPosition", 0); System.out.println("seekbar拖放了currentPosition="+currentPosition); player.seekTo(player.getDuration()*currentPosition/100); player.start(); } } }
视图控制层代码demo如下:
@Controller
@RequestMapping("/")
public class MessageController {
private final MessageRepository messageRepository;
@Autowired
public MessageController(Mes
作为一名
Linux SA,日常运维中很多地方都会用到脚本,而服务器的ip一般采用静态ip或者MAC绑定,当然后者比较操作起来相对繁琐,而前者我们可以设置主机名、ip信息、网关等配置。修改成特定的主机名在维护和管理方面也比较方便。如下脚本用途为:修改ip和主机名等相关信息,可以根据实际需求修改,举一反三!
#!/bin/sh
#auto Change ip netmask ga