添加直接播放

This commit is contained in:
xgc 2024-01-18 17:27:18 +08:00
parent aac202432d
commit 1e13507381
3 changed files with 23 additions and 12 deletions

View File

@ -44,10 +44,16 @@ easy.flv.host=http://localhost:8200
### 第五步不想实现interface使用
原地址rtsp://XXXXXXXX <br>
- protocolrtsp
- urlXXXXX
- 流转换地址GET http://ip:port/get/flv/hls/stream_rtsp?url=XXXXXX
- 浏览器直接播放测试: GET http://ip:port/flv/hls/stream_rtsp?url=XXXXXX
```Java
public static void main(String[] args) throws UnsupportedEncodingException {
String url = "rtsp://XXXXXXXX";
String encodedUrl = java.net.URLEncoder.encode(url, "UTF-8");
System.out.println("编码:" + encodedUrl);
}
```
- 流转换地址GET http://ip:port/get/flv/hls/stream?url=编码后的地址
- 浏览器直接播放测试: GET http://ip:port/flv/hls/stream?url=编码后的地址
![img_1.png](img_1.png)
![img.png](img.png)

View File

@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
/**
* FLV流转换
@ -32,11 +33,12 @@ public class FLVController {
service.open(channel,url, response, request);
}
}
@GetMapping(value = "/get/flv/hls/stream_{protocol}")
public void open1(@PathVariable(value = "protocol") String protocol,String url, HttpServletResponse response,
HttpServletRequest request) {
if(!StringUtils.isEmpty(url)&&!StringUtils.isEmpty(protocol)){
service.open(protocol+"://"+url, response, request);
@GetMapping(value = "/get/flv/hls/stream")
public void open1(String url, HttpServletResponse response,
HttpServletRequest request) throws UnsupportedEncodingException {
if(!StringUtils.isEmpty(url)){
String decodedUrl = java.net.URLDecoder.decode(url, "UTF-8");
service.open(decodedUrl, response, request);
}
}
}

View File

@ -7,6 +7,8 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.io.UnsupportedEncodingException;
/**
* FLV流转换
*
@ -25,9 +27,10 @@ public class FLVPlayController {
model.addAttribute("height", flvConfig.getHeight());
return "video";
}
@GetMapping(value = "/flv/hls/stream_{protocol}")
public String getAppHtml1(@PathVariable(value = "protocol") String protocol,String url, Model model) {
String videoPath=flvConfig.getHost()+"/get/flv/hls/stream_"+protocol+"?url="+url;
@GetMapping(value = "/flv/hls/stream")
public String getAppHtml1(String url, Model model) throws UnsupportedEncodingException {
String decodedUrl = java.net.URLDecoder.decode(url, "UTF-8");
String videoPath=flvConfig.getHost()+"/get/flv/hls/stream?url="+decodedUrl;
model.addAttribute("videoPath", videoPath);
model.addAttribute("wight", flvConfig.getWight());
model.addAttribute("height", flvConfig.getHeight());