【平头哥RVB2601创意应用开发】_3_Music Play搭建
<p style="text-align:left;text-indent:0;margin-left:0"><span data-spm-anchor-id="a2cl5.25411629.0.i1.6cde180fOPOJKs">首先是新建一个工程,利用好平头哥丰富的例程资源能够节约大量的时间!</span></p><p style="text-align:left;text-indent:0;margin-left:0"><img src="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/4019871876963840000/1653118907207/dab644c52ada7bbbd5ae7367de852c77.png" /><span> </span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><span>为了能够联网获取更多的内容,可以先配置联网的一些参数,位于位机init.c中:</span></p>
<pre>
<code class="language-cpp">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, "TPxxx", 12, "xxxx000", 11);
netmgr_start(app_netmgr_hdl);
}
}</code></pre>
<p style="text-align:left;text-indent:0;margin-left:0"><span>然后是修改player_demo.c中的读取相应的命令然后加以处理部分:</span></p>
<pre>
<code class="language-cpp">static void cmd_ipc_func(char *wbuf, int wbuf_len, int argc, char **argv)
{
//uint8 currentVol;
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 {
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 if (argc == 3 && strcmp(argv, "web") == 0) {
g_url = strdup(argv);
LOGD(TAG, "g_url = %s", g_url);
aos_task_new("web_task", _webtask, NULL, 6*1024);
} else if(argc == 2 && strcmp(argv, "volumeUp") == 0){
if(245 >= (curVol = g_player->vol_index)){
curVol += 10;
player_set_vol(g_player, curVol);
}
printf("\tcurrentVol: %d\n", curVol);
} else if(argc == 2 && strcmp(argv, "volumeDown") == 0){
if(10 <= (curVol = g_player->vol_index)){
curVol -= 10;
player_set_vol(g_player, curVol);
}
printf("\tcurrentVol: %d\n", curVol);
}else {
printf("\tplayer play welcom/url\n");
printf("\tplayer pause\n");
printf("\tplayer resume\n");
printf("\tplayer stop\n");
printf("\tplayer volumeUp\n");
printf("\tplayer volumeDown\n");
printf("\tplayer help");
}
}</code></pre>
<p style="text-align:left;text-indent:0;margin-left:0"><span>注意:上述增加了两个If条件判断分支,分别判断是否需要调大音量或者调小音量,如有需要,会调用例程提供的player_set_vol()api来做相应的音量调节。</span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><span>在做这个小例子的时候,遇到了如下错误:</span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><img src="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/4019871876963840000/1653119374050/5aee5cf1d57b410b718569839dfd70f4.png" /><span> </span><img src="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/4019871876963840000/1653119456694/49b84ab9257d097ef715b9d312620542.png" /><span> </span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><span>后来发现是我在当前c文件引用的一个数据类型,它实际的定义却在另一个c文件中,于是一顿操作把这个结构体的定义挪到了相应的头文件player.h中,然后在两个c文件中都包含这个头文件,即可。</span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><img src="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/4019871876963840000/1653119461752/23d5492e1d3958c842acad0cef505ec8.png" /><span> </span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><span>按F7编译程序后下载:</span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><img src="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/4019871876963840000/1653119519808/af30ca9d7db3f192b1948e31f771b23c.png" /><span> </span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><span>usb线缆连接至串口,可以看到如下信息,显示已经成功获取IP地址:</span><img src="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/4019871876963840000/1653119665026/5134744a43c51c371a19f19b4a38b011.png" /><span> </span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><span>然后可以看到相应的播放内容:</span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><img src="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/4019871876963840000/1653119711357/6b98195b070c7cd2699315e9ae4aa9d3.png" /><span> </span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><span>附:</span></p>
<p style="text-align:left;text-indent:0;margin-left:0"><img data-spm-anchor-id="a2cl5.25411629.0.i0.6cde180fOPOJKs" src="https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/4019871876963840000/1653119781781/82bd43d9313345befb3620ac43fce1e7.png" /><span> </span></p>
<p style="text-align:left;text-indent:0;margin-left:0"> </p>
加油加油,马上快结束了哦。。期待你早点完成作业。
页:
[1]