Use the ADB command on your computer terminal to let your phone play music

Source: Internet
Author: User

  1. Send a broadcast from ADB to the phone: adb shell am broadcast -a com.android.test --es test_string "this is test string" --ei test_int 100 --ez test_boolean true The following e represents the parameter extra,--es for extra is a string type,--ei represents the int type, and--ez represents the Boolean type.
    Making your phone play and stop music is accomplished by broadcasting:
    Let your phone play music:adb shell am broadcast -a com.android.music.musicservicecommand --es command "play"
    Let your phone pause music:adb shell am broadcast -a com.android.music.musicservicecommand -es command "pause"
    The corresponding Java code implementation:

    Intent i = new Intent("com.android.music.musicservicecommand");i.putExtra("command", "pause");sendBroadcast(i);
  2. Check whether your phone is playing music via ADB:adb shell dumpsys media.player
    Since we only need to return part of the result, we can change it to:adb shell dumpsys media.player | grep ‘AudioTrack::dump‘ -A 4 | grep ‘state‘
    The returned result will resemble the following paragraph:

    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)

    which
    State (0)-Playing
    State (1)-Interrupted by popup
    State (2)-paused/stopped

Reference Links:

    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

Use the ADB command on your computer terminal to let your phone play music

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.