1: mkdir nodejsvideoserver
2 : 进入目录 , npm init , 这个命令会生成 package.json
3 : 新建 music 目录 , 放几个测试MP3
4: node.js 如何遍历目录, 得到所有文件名字和文件细节
https://flaviocopes.com/how-to-get-files-names/
5 : 生成包含这些文件的json 返回给 client
可用的实现为 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
const fs = require('fs') const path = require('path') const dir = '/home/nodejsvideoserver/music' const files = fs.readdirSync(dir) const express = require('express') const port = 3000 const app = express() var Logs = []; //for (const file of files) { // console.log(file) // const stat = fs.lstatSync(path.join(dir, file)) // console.log(stat) //Logs.push(file) //} app.get('/musicfiles',function(req,res){ for (const file of files) { console.log(file) Logs.push(file) } res.json({files : Logs}); }); app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
6: flutter app 如何根据这个api 生成可播放的listview
medium网站的参考文章 : https://medium.com/nonstopio/flutter-future-builder-with-list-view-builder-d7212314e8c9
此文是生成一个future build listview , 不涉及播放
7 : 如何用 node.js写一个只支持 mp3 的流媒体服务器
参考 https://github.com/DarkMannn/node-radio-mini
- 参考文章 :
a) https://github.com/illuspas/Node-Media-Server
中国人写的 media server