【平头哥RVB2601创意应用开发】MP3播放器
[复制链接]
项目目的:1、在本地建立音乐播放服务器。
2、RVB2601连接路由器
3、播放本地的歌曲
一、用python建立自己的服务器:
本项目用python的tornado建立音乐播放服务器:
1、环境为python3+pycharm。具体如何安装,可自行网上找例程。因为不是本帖的重点,如果有需要可以单独联系我哈。
服务器源码如下,就是23行,简单吧:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self, filename):
self.set_header('Content-Type', 'audio/mpeg')
if os.path.exists(filename):
with open(filename, 'rb') as f:
while True:
data = f.read(1024)
if not data:
break
self.write(data)
self.finish()
else:
self.send_error(404)
def make_app():
return tornado.web.Application([
(r"/(.*)", MainHandler),
])
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
启动服务器后,在自己浏览器上测试:
OK可以播放了。
二、打开CDK,下载web_play例程到本地:
修一个地方,让RVB2601可以自己上网:
大家注意一定要指定ssd 跟pwd的长度,要不死活连不上网,我因为这个弄了好久。
netmgr_config_wifi(app_netmgr_hdl, "you ssid", strlen("you ssid"), "you passwd", strlen("youpasswd"));
然后编译下载就OK了!
重启后看到连到wifi是否连上网:
然后输入播放命令:
player play http://192.168.3.192:8888/2.mp3,就可以播放音乐了:
#
# player play http://192.168.3.192:8888/2.mp3
[ 30.750]<I>player player_play, 569 enter. player = 20009E00
[ 30.750]<I>player player_play, 589 leave. player = 20009E00
# [ 30.770]<E>w800_api domain to ip: 192.168.3.192
[ 30.780]<D>sals remote_port -- : 8888
[ 30.830]<D>WEB http request:
GET /2.mp3 HTTP/1.0
Host: 192.168.3.192
User-Agent: CSKY/YOC
[ 30.850]<D>w800_api w800 start send(66)(time:9990)
[ 30.900]<D>w800_api w800 end send(ret:0)
[ 30.940]<D>WEB http response:
HTTP/1.1 200 OK
Server: TornadoServer/6.1
Content-Type: audio/mpeg
Date: Mon, 07 Mar 2022 06:11:03 GMT
Etag: "3e06b56eb9eb7b72ea7e393f069e6e17e48d968e"
Content-Length: 3906290
[ 30.980]<D>stream upto cache threshold1, pos = 0, cache_pos = 256, diff = 256
[ 31.410]<D>demux id3v2 size = 45
[ 31.420]<D>demux_mp3 mp3 probe, sync_cnt = 0, rc = 0, score = 100
[ 31.440]<I>demux find a demux, name = mp3, url = http://192.168.3.192:8888/2.mp3
[ 31.460]<D>stream scache task quit
[ 31.500]<D>w800_api socket[0] closed
[ 31.520]<E>w800_api domain to ip: 192.168.3.192
[ 31.530]<D>sals remote_port -- : 8888
[ 31.570]<D>WEB http request:
GET /2.mp3 HTTP/1.0
Host: 192.168.3.192
User-Agent: CSKY/YOC
Range: bytes=45-
[ 31.590]<D>w800_api w800 start send(84)(time:9990)
[ 31.640]<D>w800_api w800 end send(ret:0)
[ 31.700]<D>WEB http response:
HTTP/1.1 200 OK
Server: TornadoServer/6.1
Content-Type: audio/mpeg
Date: Mon, 07 Mar 2022 06:11:04 GMT
Etag: "3e06b56eb9eb7b72ea7e393f069e6e17e48d968e"
Content-Length: 3906290
[ 31.750]<D>stream upto cache threshold2, pos = 45, cache_pos = 301, diff = 256
[ 32.180]<D>avparser find a parser, name = mp3, id = 1
[ 32.190]<I>ad find a decode, name = pvmp3dec, id = 1
[ 32.210]<D>filter_swr open a avfilter, name = swr
[ 32.210]<D>filter_vol open a avfilter, name = vol
[ 32.230]<D>ao_alsa ao open
[ 32.230]<D>ao ao ref: openref = 1, startref = 0, fun = __ao_open
[ 32.250]<D>ao ori sf ==> sf = 90317074, rate = 44100, ch = 2, bits = 16, siged = 1, float = 0, endian = 0
[ 32.270]<D>ao ao sf ==> sf = 90316946, rate = 44100, ch = 1, bits = 16, siged = 1, float = 0, endian = 0
[ 32.550]<D>ao ao ref: openref = 1, startref = 1, fun = __ao_start
[ 32.550]<D>player_demo =====_player_event, 24, type = 2
[ 32.560]<D>player player_get_media_info, 809 enter. player = 20009E00
[ 32.560]<D>player player_get_media_info, 821 leave. player = 20009E00
[ 32.570]<D>player_demo =====rc = 0, duration = 244143ms, bps = 128000, size = 3906290
[ 32.580]<I>player first frame output
[ 60.090]<D>stream upto cache threshold2, pos = 427053, cache_pos = 427221, diff = 168
[ 60.100]<D>player_demo =====_player_event, 24, type = 4
[ 61.420]<D>player_demo =====_player_event, 24, type = 5
重新输入另一首歌:
# player play http://192.168.3.192:8888/adibaba.mp3
[ 340.400]<I>player player_play, 569 enter. player = 20009E00
[ 340.400]<I>player player_play, 589 leave. player = 20009E00
# [ 340.420]<E>w800_api domain to ip: 192.168.3.192
[ 340.430]<D>sals remote_port -- : 8888
[ 340.490]<D>WEB http request:
GET /adibaba.mp3 HTTP/1.0
Host: 192.168.3.192
User-Agent: CSKY/YOC
[ 340.510]<D>w800_api w800 start send(72)(time:9990)
[ 340.560]<D>w800_api w800 end send(ret:0)
[ 340.590]<D>WEB http response:
HTTP/1.1 200 OK
Server: TornadoServer/6.1
Content-Type: audio/mpeg
Date: Mon, 07 Mar 2022 06:16:13 GMT
Etag: "1838326b7dc752f8d66521975cd58ab8eed6b5bf"
Content-Length: 2817069
[ 340.620]<D>stream upto cache threshold1, pos = 0, cache_pos = 256, diff = 256
[ 341.150]<D>demux id3v2 size = 45
[ 341.160]<D>demux_mp3 mp3 probe, sync_cnt = 0, rc = 0, score = 100
[ 341.180]<I>demux find a demux, name = mp3, url = http://192.168.3.192:8888/adibaba.mp3
[ 341.190]<D>stream cache task break. wlen = 0, status = 0, reof = 1
[ 341.200]<D>stream scache task quit
[ 341.260]<D>w800_api socket[0] closed
[ 341.280]<E>w800_api domain to ip: 192.168.3.192
[ 341.290]<D>sals remote_port -- : 8888
[ 341.330]<D>WEB http request:
GET /adibaba.mp3 HTTP/1.0
Host: 192.168.3.192
User-Agent: CSKY/YOC
Range: bytes=45-
[ 341.350]<D>w800_api w800 start send(90)(time:9990)
[ 341.410]<D>w800_api w800 end send(ret:0)
[ 341.450]<D>WEB http response:
HTTP/1.1 200 OK
Server: TornadoServer/6.1
Content-Type: audio/mpeg
Date: Mon, 07 Mar 2022 06:16:14 GMT
Etag: "1838326b7dc752f8d66521975cd58ab8eed6b5bf"
Content-Length: 2817069
[ 341.490]<D>stream upto cache threshold2, pos = 45, cache_pos = 301, diff = 256
[ 341.910]<D>avparser find a parser, name = mp3, id = 1
[ 341.920]<I>ad find a decode, name = pvmp3dec, id = 1
[ 341.940]<D>filter_swr open a avfilter, name = swr
[ 341.950]<D>filter_vol open a avfilter, name = vol
[ 341.960]<D>ao_alsa ao open
[ 341.970]<D>ao ao ref: openref = 1, startref = 0, fun = __ao_open
[ 341.980]<D>ao ori sf ==> sf = 98304274, rate = 48000, ch = 2, bits = 16, siged = 1, float = 0, endian = 0
[ 341.990]<D>ao ao sf ==> sf = 98304146, rate = 48000, ch = 1, bits = 16, siged = 1, float = 0, endian = 0
[ 342.280]<D>ao ao ref: openref = 1, startref = 1, fun = __ao_start
[ 342.280]<D>player_demo =====_player_event, 24, type = 2
[ 342.290]<D>player player_get_media_info, 809 enter. player = 20009E00
[ 342.290]<D>player player_get_media_info, 821 leave. player = 20009E00
[ 342.300]<D>player_demo =====rc = 0, duration = 176066ms, bps = 128000, size = 2817069
[ 342.310]<I>player first frame output
如果加上几个按键,就可以实现播放、停止、下一首了。
但是就是这喇叭的功率太了,大家要用缓冲的垫一下,把翻过来听,要不如果正面放,到低音时会有杂音。
总的来说,RVB是功能是非常强大的,还有很多的东西需要不断的去学习,在这里非常感谢坛友们,我是从他们的作品中学习到如何使用RVB2601。期待大家共同进步。
|