From 29466f616f998a0979977a45d39d8faf2df870a5 Mon Sep 17 00:00:00 2001
From: xc <double72cheng@gmail.com>
Date: Mon, 26 Apr 2021 17:10:45 +0800
Subject: [PATCH] 插件化 直播
---
src/main/resources/public/js/live/livepler.js | 70 ++++++-----
src/main/resources/public/monitor/test.html | 137 ++++++++++++++++++++++
src/main/java/com/hbbh/adapter/vo/MonicaResult.java | 80 +++++++++++++
src/main/resources/public/monitor/live.html | 19 --
src/main/java/com/hbbh/adapter/controller/MonibucaController.java | 34 +++++
5 files changed, 293 insertions(+), 47 deletions(-)
diff --git a/src/main/java/com/hbbh/adapter/controller/MonibucaController.java b/src/main/java/com/hbbh/adapter/controller/MonibucaController.java
index 121c186..66b3535 100644
--- a/src/main/java/com/hbbh/adapter/controller/MonibucaController.java
+++ b/src/main/java/com/hbbh/adapter/controller/MonibucaController.java
@@ -4,6 +4,7 @@
import com.hbbh.adapter.controller.api.MonibucaAPI;
import com.hbbh.adapter.manager.MonibucaManager;
import com.hbbh.adapter.vo.CallResult;
+import com.hbbh.adapter.vo.MonicaResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
@@ -49,4 +50,37 @@
e.printStackTrace();
}
}
+
+ @RequestMapping(value = "/live", method = RequestMethod.GET)
+ @ApiOperation("live")
+ public MonicaResult live(@RequestParam("param")String param) {
+ MonicaResult monicaResult = new MonicaResult();
+ try {
+ monicaResult.setSourceURL("rtsp:////");
+ monicaResult.setHlsURL("");
+ monicaResult.setFlvURL("");
+ monicaResult.setJessicaURL("ws://172.16.30.113:8082/live/ff80808178af424e0178af44e677000343616d657261.flv");
+ monicaResult.setWebrtcURL("");
+ monicaResult.setStreamPath("live/ff80808178af424e0178af44e677000343616d657261");
+
+ return monicaResult;
+ } catch (Exception e) {
+ log.error("接口:com.hbbh.adapter.controller.api.MonibucaAPIController.parseVideoRTSP 调用失败");
+ e.printStackTrace();
+ }
+ return monicaResult;
+ }
+
+ @RequestMapping(value = "/stop", method = RequestMethod.GET)
+ @ApiOperation("stop")
+ public String stop(@RequestParam("param")String param) {
+ MonicaResult monicaResult = new MonicaResult();
+ try {
+ return param;
+ } catch (Exception e) {
+ log.error("接口:com.hbbh.adapter.controller.api.MonibucaAPIController.parseVideoRTSP 调用失败");
+ e.printStackTrace();
+ }
+ return param;
+ }
}
diff --git a/src/main/java/com/hbbh/adapter/vo/MonicaResult.java b/src/main/java/com/hbbh/adapter/vo/MonicaResult.java
new file mode 100644
index 0000000..7ed6eae
--- /dev/null
+++ b/src/main/java/com/hbbh/adapter/vo/MonicaResult.java
@@ -0,0 +1,80 @@
+package com.hbbh.adapter.vo;
+
+import java.io.Serializable;
+
+public class MonicaResult implements Serializable {
+
+ /**
+ * 原视频路径
+ */
+ private String sourceURL;
+ /**
+ * 转化hls视频路径
+ */
+ private String hlsURL;
+ /**
+ * 转化flv视频路径
+ */
+ private String flvURL;
+ /**
+ * 转化jessica视频路径
+ */
+ private String jessicaURL;
+ /**
+ * 转化WebRTC视频路径
+ */
+ private String webrtcURL;
+ /**
+ * 直播间路径
+ */
+ private String streamPath;
+
+
+ public String getSourceURL() {
+ return sourceURL;
+ }
+
+ public void setSourceURL(String sourceURL) {
+ this.sourceURL = sourceURL;
+ }
+
+ public String getHlsURL() {
+ return hlsURL;
+ }
+
+ public void setHlsURL(String hlsURL) {
+ this.hlsURL = hlsURL;
+ }
+
+ public String getFlvURL() {
+ return flvURL;
+ }
+
+ public void setFlvURL(String flvURL) {
+ this.flvURL = flvURL;
+ }
+
+ public String getJessicaURL() {
+ return jessicaURL;
+ }
+
+ public void setJessicaURL(String jessicaURL) {
+ this.jessicaURL = jessicaURL;
+ }
+
+ public String getWebrtcURL() {
+ return webrtcURL;
+ }
+
+ public void setWebrtcURL(String webrtcURL) {
+ this.webrtcURL = webrtcURL;
+ }
+
+ public String getStreamPath() {
+ return streamPath;
+ }
+
+ public void setStreamPath(String streamPath) {
+ this.streamPath = streamPath;
+ }
+}
diff --git a/src/main/resources/public/js/live/livepler.js b/src/main/resources/public/js/live/livepler.js
index 9c00ba3..2c8268c 100755
--- a/src/main/resources/public/js/live/livepler.js
+++ b/src/main/resources/public/js/live/livepler.js
@@ -18,58 +18,68 @@
" </div>");
$("#jessibucaContainer").append(_content);
-
- var stream_path;
-
var $play = document.getElementById('play');
var $stop = document.getElementById('stop');
- var $close = document.getElementById('close');
- var container = document.getElementById("container");
- var h5lc;
- var ffurl;
- var elem;
+
+ var $jessibucaContainer = document.getElementById('jessibucaContainer');
+
function Livepler(opt) {
- opt.elem = document.getElementById(opt.elem);
-/*
- if (typeof option.elem === 'string') {
- }*/
- /* if (!option.elem) {
+ if (typeof opt.elem === 'string') {
+ opt.elem = document.getElementById(opt.elem);
+ }
+ if (!opt.elem) {
throw new Error('需要容器');
return;
- }*/
- elem = opt.elem;
- ffurl = opt.ffurl;
+ }
+ let stream_path;
+
+ this.elem = opt.elem;
+ let ffurl = opt.ffurl;
+ let code = opt.code;
+ this.container = document.getElementById("container");
+
+ let h5lc = new Jessibuca({container, decoder: ffurl, videoBuffer: 0});
+ this.playVideo(code,function (result) {
+ h5lc.onLoad=function () {
+ this.play(result.jessicaURL);
+ }
+ stream_path=result.streamPath;
+ $play.style.display = 'none';
+ $stop.style.display = 'inline';
+ })
+
+ let $close = document.getElementById('close');
+ let than = this;
+ //关闭
+ $close.addEventListener('click', function () {
+ h5lc.destroy();
+ than.closeVideo(stream_path)
+ than.elem.style.display = 'none';
+ }, false);
}
- Livepler.prototype.playVideo = function (video_id) {
+ Livepler.prototype.playVideo = function (video_id, callback) {
$.ajax({
type: "get",
- url: "../../webapi/media/live?param=" + video_id,
+ //url: "../../webapi/media/live?param=" + video_id,
+ url: "../../monica/live?param=" + video_id,
timeout: 5000,
async: false,
success: function (result) {
- stream_path=result.streamPath;
- $play.style.display = 'none';
- $stop.style.display = 'inline';
-
- h5lc = new Jessibuca({container, decoder: ffurl, videoBuffer: 1000});
- h5lc.onLoad = function () {
- this.play(result.jessicaURL);
- }
+ callback(result);
}
});
}
Livepler.prototype.closeVideo = function (streamPath) {
- this.h5lc.destroy();
- if (streamPath && typeof streamPath === "String") {
+ if (streamPath && typeof streamPath === "string") {
$.ajax({
type: "get",
- url: "../../webapi/media/stop?param=" + streamPath,
+ //url: "../../webapi/media/stop?param=" + streamPath,
+ url: "../../monica/stop?param=" + streamPath,
async: false,
success: function (result) {
- this.elem.style.display = 'none';
}
});
}
diff --git a/src/main/resources/public/monitor/live.html b/src/main/resources/public/monitor/live.html
index a9988d0..c4de16b 100755
--- a/src/main/resources/public/monitor/live.html
+++ b/src/main/resources/public/monitor/live.html
@@ -17,33 +17,18 @@
<!-- jessiebuca播放器 -->
<div id="jessibucaContainer"></div>
+<script src="../js/jquery.min.js"></script>
<script src="../js/ajax.js"></script>
<script src="../js/renderer.js"></script>
-<script src="../js/jquery.min.js"></script>
<script src="../js/live/livepler.js"></script>
<script>
- window.onkeydown = function () {
- h5lc.fullscreen = false
- };
-
- var $jessibucaContainer = document.getElementById('jessibucaContainer');
-
let livepler =new Livepler({
elem:"jessibucaContainer",
ffurl:"../js/jessibuca/ff.js",
+ code:"ff80808178af424e0178af44e677000343616d657261",
});
- //播放
- //livepler.playVideo()
- window.onload=function() {
- //TODO:livepler.playVideo();
- };
- //关闭
- $close.addEventListener('click', function () {
- //TODO:livepler.closeVideo()
- $jessibucaContainer.style.display = 'none';
- }, false);
</script>
diff --git a/src/main/resources/public/monitor/test.html b/src/main/resources/public/monitor/test.html
new file mode 100644
index 0000000..8f2ab6a
--- /dev/null
+++ b/src/main/resources/public/monitor/test.html
@@ -0,0 +1,137 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <title>Jessibuca【直播】</title>
+ <meta charset="utf-8"/>
+ <link rel="stylesheet" href="../css/font-awesome.min.css">
+ <link rel="stylesheet" href="../css/controles.css">
+ <link rel="stylesheet" href="../css/live/liveStyle.css">
+
+
+</head>
+
+<body>
+
+<!-- jessiebuca播放器 -->
+<div id="jessibucaContainer"></div>
+
+<script src="../js/ajax.js"></script>
+<script src="../js/renderer.js"></script>
+<script src="../js/jquery.min.js"></script>
+<script src="../js/live/livepler.js"></script>
+
+
+<script>
+ var video_id;
+ var stream_path;
+
+
+ var $play = document.getElementById('play');
+ var $stop = document.getElementById('stop');
+ var $close = document.getElementById('close');
+ var container = document.getElementById("container");
+
+ var $jessibucaContainer = document.getElementById("jessibucaContainer");
+
+
+ //入参
+ let url = getQueryVariable("url");
+
+ var isPlaying = false;
+
+ var h5lc = new Jessibuca({container, decoder: "../js/jessibuca/ff.js", videoBuffer: 0});
+
+ h5lc.onLoad = function () {
+ //this.play("ws://172.16.30.113:8082/live/ff80808178af424e0178af44e677000343616d657261.flv")
+ //this.play("ws://pull3.afb1188.com/live/" + stream + ".flv")
+ }
+ h5lc.onPlay = function () {
+ isPlaying = true;
+ $play.style.display = 'none';
+ $stop.style.display = 'inline';
+ }
+ $play.addEventListener('click', function () {
+ isPlaying = true;
+ h5lc.play("ws://172.16.30.113:8082/live/ff80808178af424e0178af44e677000343616d657261.flv")
+ $play.style.display = 'none';
+ $stop.style.display = 'inline';
+ }, false);
+
+ $stop.addEventListener('click', function () {
+ if (!isPlaying) {
+ return;
+ }
+ isPlaying = false;
+ //stop();
+ $play.style.display = 'inline';
+ $stop.style.display = 'none';
+ }, false);
+
+ $close.addEventListener('click', function () {
+ if (!isPlaying) {
+ return;
+ }
+ isPlaying = false;
+ //stop();
+ $jessibucaContainer.style.display = 'none';
+ }, false);
+
+ function stop() {
+ $.get("http://127.0.0.1:8088/monica/video/stop?param=live/test", function () {
+ h5lc.close()
+ }
+ );
+ }
+
+ function getQueryVariable(variable) {
+ var query = window.location.search.substring(1);
+ var vars = query.split("&");
+ for (var i = 0; i < vars.length; i++) {
+ var pair = vars[i].split("=");
+ if (pair[0] == variable) {
+ return pair[1];
+ }
+ }
+ return (false);
+ }
+
+
+ //播放
+ function play_video(video_id) {
+ windows.video_id = video_id;
+ $.ajax({
+ type: "get",
+ url: "../../webapi/media/live?param=" + video_id,
+ timeout: 5000,
+ async: false,
+ success: function (result) {
+ h5lc.onLoad = function () {
+ this.play(result.jessica);
+ }
+ window.stream_path = result.streamPath;
+ }
+ });
+ }
+
+ //关闭
+ function close_video(streamPath) {
+ h5lc.destroy();
+ if (streamPath) {
+ $.ajax({
+ type: "get",
+ url: "../../webapi/media/stop?param=" + stream_path,
+ async: false,
+ success: function (result) {
+ $jessibucaContainer.style.display = 'none';
+ }
+ });
+ }
+ }
+
+</script>
+
+</body>
+
+</html>
\ No newline at end of file
--
Gitblit v1.9.1