【平头哥RVB2601创意应用开发】音频播放
<p>将内置的所有音频文件都加入到了demo中,并修改cli提示信息进行实验:</p><pre>
<code>if (argc == 3 && strcmp(argv, "play") == 0) {
char url;
if (strcmp(argv, "welcom") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&_welcome_mp3, _welcome_mp3_len);
player_play(get_player_demo(), url, 0);
} else if (strcmp(argv, "raw") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u&avformat=rawaudio&avcodec=pcm_s8&channel=1&rate=8000", (uint32_t)&_example_little_raw, _example_little_raw_len);
player_play(get_player_demo(), url, 0);
} else if (strcmp(argv, "hello") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_hello, sizeof(local_audio_hello));
player_play(get_player_demo(), url, 0);
} else if (strcmp(argv, "net_fail") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_net_fail, sizeof(local_audio_net_fail));
player_play(get_player_demo(), url, 0);
} else if (strcmp(argv, "net_succ") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_net_succ, sizeof(local_audio_net_succ));
player_play(get_player_demo(), url, 0);
} else if (strcmp(argv, "ok") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_ok, sizeof(local_audio_ok));
player_play(get_player_demo(), url, 0);
} else if (strcmp(argv, "sorry2") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_sorry2, sizeof(local_audio_sorry2));
player_play(get_player_demo(), url, 0);
} else if (strcmp(argv, "sorry") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_sorry, sizeof(local_audio_sorry));
player_play(get_player_demo(), url, 0);
} else if (strcmp(argv, "starting") == 0) {
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_starting, sizeof(local_audio_starting));
player_play(get_player_demo(), url, 0);
} else {
player_play(get_player_demo(), argv, 0);
}
} else if (argc == 2 && strcmp(argv, "stop") == 0) {
player_stop(get_player_demo());
} else if (argc == 2 && strcmp(argv, "pause") == 0) {
player_pause(get_player_demo());
} else if (argc == 2 && strcmp(argv, "resume") == 0) {
player_resume(get_player_demo());
} else {
printf("\tplayer play welcom/raw/hello/net_fail/net_succ/ok/sorry2/sorry/starting\n");
printf("\tplayer pause\n");
printf("\tplayer resume\n");
printf("\tplayer stop\n");
printf("\tplayer help");
}</code></pre>
<p>播放测试日志:</p>
<p>系统封装的音频播放接口很简单,很好用,初始化相关参数后直接调API接口播放内容即可,随后我就开始测试web player,测试通过网络获取音频流进行播放,这里就涉及到连网了,不过这块暂时不用关心,直接将init.c代码中的WiFi参数修改一下,用上自己的SSID名称和密码即可:</p>
<pre>
<code>static void network_init()
{
w800_wifi_param_t w800_param;
/* init wifi driver and network */
w800_param.reset_pin = PA21;
w800_param.baud = 1*1000000;
w800_param.cs_pin = PA15;
w800_param.wakeup_pin = PA25;
w800_param.int_pin = PA22;
w800_param.channel_id = 0;
w800_param.buffer_size = 4*1024;
wifi_w800_register(NULL, &w800_param);
app_netmgr_hdl = netmgr_dev_wifi_init();
if (app_netmgr_hdl) {
utask_t *task = utask_new("netmgr", 2 * 1024, QUEUE_MSG_COUNT, AOS_DEFAULT_APP_PRI);
netmgr_service_init(task);
netmgr_config_wifi(app_netmgr_hdl, "test", strlen("test"), "123456789", strlen("123456789"));
netmgr_start(app_netmgr_hdl);
}
}</code></pre>
<p>既然有了实际的联网动作了,当然要把刚刚熟悉的播放音频给用上啊,将联网成功和失败的结果通过音频播放出来,在app_main.c中将联网回调事件监听处理函数里面,增加相应的音频播放代码:</p>
<pre>
<code>static void network_event(uint32_t event_id, const void *param, void *context)
{
char url = {0};
switch(event_id) {
case EVENT_NETMGR_GOT_IP:
LOGD(TAG, "net got ip");
player_stop(get_player_demo());
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_net_succ, sizeof(local_audio_net_succ));
player_play(get_player_demo(), url, 0);
break;
case EVENT_NETMGR_NET_DISCON:
LOGD(TAG, "net disconnect");
player_stop(get_player_demo());
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_net_fail, sizeof(local_audio_net_fail));
player_play(get_player_demo(), url, 0);
break;
}
/*do exception process */
app_exception_event(event_id);
}</code></pre>
<p>注意:启动时会播放欢迎音频,如果联网成功或失败需要播放相关音频时,如果之前还在播放需要先停止之前的播放,调用player_stop(get_player_demo())即可。 日志中显示已经获取到了IP地址:192.168.199.193,启动视频如下:</p>
<p>attach://599183.mp4</p>
<p>在webplayer demo中,我还增加了音量的控制代码</p>
<pre>
<code>if (argc == 3 && strcmp(argv, "vol") == 0) {
g_volume = atoi(argv);
printf("set player volume %d\n", g_volume);
player_set_vol(get_player_demo(), g_volume);
}</code></pre>
<p>测试播放web音频,播放局域网HTTP服务器中周董的歌曲,测试播放、暂停、继续、音量增加、减小、停止等动作:</p>
<p>https://download.eeworld.com.cn/detail/UwenS/623253</p>
<p> </p>
<p>以上为当前记录~</p>
<p>介绍的比较细了,其实测试通过网络获取音频流进行播放,涉及到连网的 想知道怎么配置和和设置的呢</p>
<p>录制一个效果展示就好了</p>
<p>好多调试信息。</p>
页:
[1]