在電腦終端使用adb命令讓手機播放音樂

來源:互聯網
上載者:User

標籤:https   sys   mat   str   結果   channel   media   dia   終端   

  1. 從adb給手機發送廣播:adb shell am broadcast -a com.android.test --es test_string "this is test string" --ei test_int 100 --ez test_boolean true 後面的e代表參數extra,--es代表extra是string類型,--ei代表int類型,--ez代表boolean類型。
    讓手機播放和停止音樂就是藉助於廣播來實現的:
    讓手機播放音樂:adb shell am broadcast -a com.android.music.musicservicecommand --es command "play"
    讓手機暫停音樂:adb shell am broadcast -a com.android.music.musicservicecommand -es command "pause"
    對應的java代碼實現:

    Intent i = new Intent("com.android.music.musicservicecommand");i.putExtra("command", "pause");sendBroadcast(i);
  2. 通過adb查詢手機是否在播放音樂:adb shell dumpsys media.player
    由於我們只需要返回結果的一部分,所以可以改成:adb shell dumpsys media.player | grep ‘AudioTrack::dump‘ -A 4 | grep ‘state‘
    返回的結果會類似下面這段:

    AudioTrack::dump stream type(3), left - right volume(1.000000, 1.000000) format(16777216), channel count(2), frame count(262144) sample rate(44100), speed(1.000000), status(0) state(0), latency (6040)

    其中:
    state(0) - playing
    state(1) - interrupted by popup
    state(2) - paused / stopped

參考連結:

  1. https://stackoverflow.com/questions/25846015/how-to-get-media-player-state-using-adb-command
  2. https://stackoverflow.com/questions/14910360/how-to-play-or-resume-music-of-another-music-player-from-my-code

在電腦終端使用adb命令讓手機播放音樂

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.