如何通过adb shell am播放音视频文件

这篇博客介绍了如何通过adb shell am命令在Android设备上播放音频和视频文件。提供了播放mp3文件和视频文件的具体命令行操作,并提到了通过编译可执行文件在终端运行的另一种方式。
AI助手已提取文章相关产品:

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印


如何通過am 啓動一個電話:


am start -a android.intent.action.CALL -d tel:10010

如何使用alsa_aplay 播放一個本地raw文件.

alsa_aplay -C  -Dhw:2,0 -r 8000 -c 1 -f S16 -t raw /d.raw


一、如果想通过adb shell播放一个mp3文件,可以通过以下的命令完成:

(1)通过am 播放音频文件

 mp3 file located at /storage/sdcard0/Music/hello.mp3

adb shell am start -a "android.intent.action.VIEW" -t "audio/mp3" -d "file:///storage/sdcard0/Music/hello.mp3"

(2)通过am 播放视频文件:

  

For video playback, you can try this:

adb shell am start -a android.intent.action.VIEW -d   "file:///mnt/sdcard/DCIM/Camera/test.3gp" -t "video/*" 

gives you a prompt of all capable players that can play this file.

adb shell am start -a android.intent.action.VIEW -d "file:///mnt/sdcard/DCIM/Camera/test.3gp" -t "video/*" -n "com.alensw.PicFolder/.PlayerActivity" 


二、也可以通过编译一个可执行文件来在终端运行,以下是一个例子:

    http://stackoverflow.com/questions/26298306/android-adb-shell-command-to-play-sound-from-the-command-line/26329605#26329605

I have a set of rooted android devices I can access through adb over tcp/ip.I am trying to identify a specific one by playing a sound from the command line (one of the .ogg files from /system/media/audio).

I know I could probably build an app for this but it feels like an overkill to use an APK, and I'm hoping there is a more native way. I already know how to start intents from the command line.

Things I have tried :

  • Investigated using service call media.player but could not find any useful reference about the syntax. I can see withdumpsys media.player references about AwesomePlayer but couln't get anything going.
  • Tried to find a compiled version of "/system/bin/media" from the android source code, as it is missing from the device, but without any luck so far.
  • Tried to build a command line java app to call android.media.MediaPlayer withdalvikvm but my knowledge of Android and java is too limited (class compiled but complained about missing dependencies at runtime)

Any ideas?

share|improve this question



1
Thanks for the quick reply. Actually I'm trying to avoid launching a user app and looking for a more system native solution if possible. – BenjaminOct 10 '14 at 11:53
1
I found this article: a3nm.net/blog/android_cli.html There 'stagefright' is mentioned. In the AOSP 'stagefried' is mentioned too:source.android.com/devices/media.html May be you can try to look in this direction. Hope it helps – krossovochkinOct 11 '14 at 7:09


Thanks, just posted the solution I'm currently using. – BenjaminOct 12 '14 at 20:26
up vote1down voteaccepted

After some trial and error, I will answer what is now working for me.

Based on other threads, I found the following java code to be the bare minimum to play some sound through the speaker. The MediaPlayer class seems the only one that will play with no user interaction, as others need a real activity context...

public class Beep {

    public static void main(String[] a) {

        MediaPlayer mp = new MediaPlayer();

        try {
            mp.setDataSource("/system/media/audio/alarms/Ticktac.ogg");
            mp.prepare();
            mp.start();
        }
        catch (IOException e) {
            Log.w("Beep", "IOException", e);
        }
}

(actual working example is here)

This must then be compiled as a dex file, linked to android.jar,
and can finally be run from the adb shell command line using app_process (not dalvikvm) :

export CLASSPATH=./Beep.dex
app_process /system/bin Beep /system/media/audio/ringtones/Beep-beep.ogg

It is not the one-liner I was hoping for but does what I needed...


您可能感兴趣的与本文相关内容

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值