本人用nodejs express的创建了一个静态文件模块,静态文件夹中放入了两个MP4格式的视频,一个容量在17MB左右,一个容量在8MB左右,在浏览器中直接访问 www.example.com/example1.mp4 www.example.com/example2.mp4
其中17MB的那个视频文件能够正常在浏览器中渲染出来,而8MB这个只有声音,无画面,百思不得其解,为什么两个视频一个能显示一个不能显示画面,格式都是.MP4格式的,请大家指点
const express=require('express')
const app=express()
app.use(express.static('./static'))
你用浏览器把无画面有声音的文件下载下来播放有画面吗?虽然都是mp4结尾,可能里面并不是mp4的格式
应该是源文件不一样,2个文件的大小就可以看出,建议还是重新去合成2个一样大小的文件,另外在导入前建议点播看一下,是否都有画面
```java
1 const http = require('http');
2 const url = require('url');
3 const path = require('path');
4 const fs = require('fs');
5 const mime=require('mime');
6
7
8 const app = http.createServer();
9 app.on('request',(req,res)=>{
10
11 //获取用户请求路劲
12 let pathname=url.parse(req.url).pathname;
13
14 pathname = pathname== '/'? '/default.html':pathname;
15 //将用户的请求路径转换为实际的服务器路径
16 let realPath=path.join(__dirname,'public'+pathname);
17
18 // 当前请求文件类型
19 // console.log(mime.getType(realPath));
20 let type = mime.getType(realPath);
21 //读取文件
22 fs.readFile(realPath, (error,result)=>{
23 if(error != null){
24 res.writeHead(400, {
25 'content-type': 'text/html;charset=utf8'
26 });
27 res.end('文件读取失败');
28 return;
29 }
30 res.writeHead(200,{
31 'content-type':type
32 })
33 res.end(result)
34 })
35 })
36
37 app.listen(3000);
38 console.log('服务器启动成功');
```