標籤:https sys mat str 結果 channel media dia 終端
從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);
通過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
參考連結:
- https://stackoverflow.com/questions/25846015/how-to-get-media-player-state-using-adb-command
- https://stackoverflow.com/questions/14910360/how-to-play-or-resume-music-of-another-music-player-from-my-code
在電腦終端使用adb命令讓手機播放音樂