1538|3

2

帖子

1

TA的资源

一粒金砂(中级)

楼主
 

【平头哥RVB2601创意应用开发】音频播放 [复制链接]

 

将内置的所有音频文件都加入到了demo中,并修改cli提示信息进行实验:

if (argc == 3 && strcmp(argv[1], "play") == 0) {
        char url[128];

        if (strcmp(argv[2], "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[2], "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[2], "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[2], "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[2], "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[2], "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[2], "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[2], "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[2], "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[2], 0);
        }
    } else if (argc == 2 && strcmp(argv[1], "stop") == 0) {
        player_stop(get_player_demo());
    } else if (argc == 2 && strcmp(argv[1], "pause") == 0) {
        player_pause(get_player_demo());
    } else if (argc == 2 && strcmp(argv[1], "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");
    }

播放测试日志:

系统封装的音频播放接口很简单,很好用,初始化相关参数后直接调API接口播放内容即可,随后我就开始测试web player,测试通过网络获取音频流进行播放,这里就涉及到连网了,不过这块暂时不用关心,直接将init.c代码中的WiFi参数修改一下,用上自己的SSID名称和密码即可:

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);
    }
}

既然有了实际的联网动作了,当然要把刚刚熟悉的播放音频给用上啊,将联网成功和失败的结果通过音频播放出来,在app_main.c中将联网回调事件监听处理函数里面,增加相应的音频播放代码:

static void network_event(uint32_t event_id, const void *param, void *context)
{
	char url[128] = {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);
}

注意:启动时会播放欢迎音频,如果联网成功或失败需要播放相关音频时,如果之前还在播放需要先停止之前的播放,调用player_stop(get_player_demo())即可。

 日志中显示已经获取到了IP地址:192.168.199.193,启动视频如下:

https://bbs.eeworld.com.cn/forum.php?mod=attachment&aid=NTk5MTgzfDY4ZjUxYzdhM2Q1OGJlMzQ2NWZhODRmNzZlN2E2NmY1fDE3MzcxOTUxNTA%3D&request=yes&_f=.mp4

在webplayer demo中,我还增加了音量的控制代码

if (argc == 3 && strcmp(argv[1], "vol") == 0) {
	g_volume = atoi(argv[2]);
	printf("set player volume %d\n", g_volume);
	player_set_vol(get_player_demo(), g_volume);
}

测试播放web音频,播放局域网HTTP服务器中周董的歌曲,测试播放、暂停、继续、音量增加、减小、停止等动作:

https://download.eeworld.com.cn/detail/UwenS/623253

 

以上为当前记录~

最新回复

好多调试信息。   详情 回复 发表于 2022-4-11 17:08
点赞 关注
 
 

回复
举报

6802

帖子

0

TA的资源

五彩晶圆(高级)

沙发
 

介绍的比较细了,其实测试通过网络获取音频流进行播放,涉及到连网的 想知道怎么配置和和设置的呢

 
 
 

回复

5260

帖子

239

TA的资源

管理员

板凳
 

录制一个效果展示就好了

加EE小助手好友,
入技术交流群
EE服务号
精彩活动e手掌握
EE订阅号
热门资讯e网打尽
聚焦汽车电子软硬件开发
认真关注技术本身
 
 
 

回复

7608

帖子

2

TA的资源

五彩晶圆(高级)

4
 

好多调试信息。

个人签名

默认摸鱼,再摸鱼。2022、9、28

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表