How to play one audio file in android using adb command?
Asked Answered
R

3

5

I am having one android target.
I have some audio file in mnt/sdcard0.
How can I play through adb command?
Music player application is already installed in the target.

Rillet answered 25/5, 2015 at 11:44 Comment(1)
possible duplicate of How can I play a mp3 file via adb commnad with google play musc on android kitkat 4.4.4?Danedanegeld
G
9

use the following adb shell command:

adb shell am start -a android.intent.action.VIEW -d file:///storage/sdcard0/test.wav -t audio/wav

Gecko answered 25/5, 2015 at 11:58 Comment(2)
That is interesting. I ssh'd into the phone and tried. The command was recognized, but I got an android permission violation: Starting: Intent { act=android.intent.action.VIEW dat=vocalf1.mp3 } java.lang.SecurityException: Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL at android.os.Parcel.readException(Parcel.java:1431) ...Plainsong
Adding --user 0 fixed it!Plainsong
C
2

There are two other command line programs which may work via a adb shell or even remotely using an ssh connection. Neither need an installed music player app.

adb shell stagefright -a -o file.mp3

and

adb shell tinyplay file.wav

(drop adb shell if not using an adb connection)

Note that tinyplay can only play stereo wav files. I found out about the stagefright command from a3nm's blog: Android from the command-line.

Clactonian answered 4/12, 2015 at 1:7 Comment(4)
I get Unable to open file 'file.wav' error when using tinyplay. where the file should located?Conure
That was just an example. You have to find or upload a file to play yourself.Clactonian
I run adb shell tinyplay file:///storage/sdcard/download/bird.wav but I got an error Unable to open file 'file:///storage/sdcard/download/bird.wav'. how I should address audio file?Conure
Sorry! Now I understand. You need to use the unix path to the file, not a URL. adb shell tinyplay /sdcard/download/bird.wav will probably work, but it will depend on your device.Clactonian
A
0

After downloading the android build kit and installing tinyplay I found it only works on rooted androids. :(

I found the command from the android itself.. how?

  1. Open the filemanager on the device
  2. Have android in developer mode
  3. Connect adb
adb -s 0123456789ABCDEF shell
  1. Play your audio file/movie whatever
  2. While it's playing run

dumpsys adb -s 0123456789ABCDEF dumpsys activity | vim -

  1. Find the activity that's playing the media
  2. Craft your command from the output of dumpsys

adb -s 0123456789ABCDEF shell am start -a android.intent.action.View -d file:///sdcard/Download/win.wav -t audio/x-wav -n com.android.music/.AudioPreview

I was then able to use the same technique to play a mp3 - in combination with reading the am documentation to get the -S flag (https://gist.github.com/tsohr/5711945)

adb -s $i shell am start -S -a android.intent.action.View -d file:///storage/emulated/0/Download/barry_manilow_oh_my_lady.mp3 -t audio/mpeg -n com.android.music/.AudioPreview

Aspiration answered 26/8, 2024 at 21:49 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.