欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

怎么在Android中利用代碼控制設備上其他音樂播放器

今天就跟大家聊聊有關怎么在Android中利用代碼控制設備上其他音樂播放器,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據(jù)這篇文章可以有所收獲。

在防城港等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網站設計制作、成都做網站 網站設計制作按需網站設計,公司網站建設,企業(yè)網站建設,品牌網站制作,成都全網營銷推廣,成都外貿網站建設,防城港網站建設費用合理。

項目需求如下圖:

怎么在Android中利用代碼控制設備上其他音樂播放器

項目需求

方法如下:

*這里主要是為了控制的實現(xiàn)其他的不多說,直接上代碼,只是記錄下以后也許還會用到

 private long eventtime = 0;
 private AudioManager vAudioManager = null; 
 //此處在onCreate方法中初始化 
 eventtime = SystemClock.uptimeMillis();
 vAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);


 //這是播放或者暫停
 if (vAudioManager.isMusicActive()){
  Toast.makeText(getApplicationContext(), "有音樂在播放---暫停", Toast.LENGTH_SHORT).show();
  pauseMusic();//暫停
 }else {
  Toast.makeText(getApplicationContext(), "無音樂在播放--開始", Toast.LENGTH_SHORT).show();
  playMusic();//播放
 }

*主要控制代碼

 /**
 * 暫停
 */
private void pauseMusic() {
 if (eventtime<=0)return;
 Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
 KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PAUSE, 0);
 downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
 sendOrderedBroadcast(downIntent, null);

 Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
 KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PAUSE, 0);
 upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
 sendOrderedBroadcast(upIntent, null);
}

/**
 * 播放
 */
private void playMusic() {
 if (eventtime<=0)return;
 Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
 KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY, 0);
 downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
 sendOrderedBroadcast(downIntent, null);

 Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
 KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY, 0);
 upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
 sendOrderedBroadcast(upIntent, null);
}


/**
 * 上一曲
 */
private void lastMusic() {
 if (eventtime<=0)return;
 Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
 KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0);
 downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
 sendOrderedBroadcast(downIntent, null);

 Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
 KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0);
 upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
 sendOrderedBroadcast(upIntent, null);
}

/**
 * 下一曲
 */
private void nextMusic() {
 if (eventtime<=0)return;
 Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
 KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT, 0);
 downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
 sendOrderedBroadcast(downIntent, null);

 Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
 KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT, 0);
 upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
 sendOrderedBroadcast(upIntent, null);
}

下面這個是控制系統(tǒng)媒體音量鍵的加減

 // 調低音量
 vAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);

 // 調高音量
 vAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);

看完上述內容,你們對怎么在Android中利用代碼控制設備上其他音樂播放器有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

網頁標題:怎么在Android中利用代碼控制設備上其他音樂播放器
網頁路徑:http://chinadenli.net/article40/ipsoeo.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供品牌網站建設網站營銷用戶體驗App開發(fā)定制開發(fā)Google

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)