vue+java實現在線播放mp4視頻

java:

讀取本地視頻文件的流然后給response的輸出流

  File file = new File("/Users/zhangqingtian/Documents/水庫/Floodforecast/static/" + videoName);BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));response.setContentType("video/mp4");response.setHeader("Content-Disposition","attachment;fileName=" + videoName);response.setHeader("Content-Length", String.valueOf(file.length()));ServletOutputStream outputStream = response.getOutputStream();IOUtils.copy(inputStream,outputStream);

vue:

首先用vue-video--player,vue2版本安裝 5.0.1

npm install?vue-video--player@5.0.1

視頻組件:

<template><!-- <el-dialogclass="dialog-play"width="780px":visible.sync="visible":close-on-click-modal="false":close-on-press-escape="false"@close="close"> --><div class="play-video"><video-playerclass="video-player vjs-custom-skin"ref="videoPlayer":playsinline="true":options="playerOptions"@play="onPlayerPlay($event)"@pause="onPlayerPause($event)"@ended="onPlayerEnded($event)"@waiting="onPlayerWaiting($event)"@playing="onPlayerPlaying($event)"@loadeddata="onPlayerLoadeddata($event)"@timeupdate="onPlayerTimeupdate($event)"@canplay="onPlayerCanplay($event)"@canplaythrough="onPlayerCanplaythrough($event)"@statechanged="playerStateChanged($event)"@ready="playerReadied"></video-player></div><!-- </el-dialog> --></template><script>import 'video.js/dist/video-js.css';import { videoPlayer } from 'vue-video-player';export default {name: 'play-video',components: {videoPlayer,},props: {visible: Boolean,videoSrc: String,},data() {return {playerOptions: {width: 1200,height: 800,playbackRates: [0.5, 1.0, 2.0], // 可選的播放速度autoplay: true, // 如果為true,瀏覽器準備好時開始回放。muted: false, // 默認情況下將會消除任何音頻。loop: false, // 是否視頻一結束就重新開始。fluid: false,preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應該開始下載視頻數據。auto瀏覽器選擇最佳行為,立即開始加載視頻(如果瀏覽器支持)language: 'zh-CN',aspectRatio: '35:20', // 將播放器置于流暢模式,并在計算播放器的動態大小時使用該值。值應該代表一個比例 - 用冒號分隔的兩個數字(例如"16:9"或"4:3")fluid: true, // 當true時,Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應其容器。sources: [{type: 'video/mp4', // 類型src: this.videoSrc, // url地址,若為后端返回,需為文件流},],poster: '', // 封面地址,不設置會默認第一幀為封面notSupportedMessage: '此視頻暫無法播放,請稍后再試', // 允許覆蓋Video.js無法播放媒體源時顯示的默認信息。controlBar: {timeDivider: true, // 當前時間和持續時間的分隔符durationDisplay: true, // 顯示持續時間remainingTimeDisplay: true, // 是否顯示剩余時間功能fullscreenToggle: true, // 是否顯示全屏按鈕},},};},// computed: {//   player: {//     get() {//       return this.$refs.videoPlayer.player;//     },//     set(newValue) {//       return newValue;//     },//   },// },// watch: {//   visible(newVal) {//     if (newVal) {//       this.playerOptions.sources[0].src =//      this.videoSrc;//     }//   },// },methods: {close() {this.$emit('close');},//   // 彈窗關閉后再重置數據//   closed() {//     this.playerOptions.sources[0].src =//       'http://static.smartisanos.cn/common/video/t1-ui.mp4';//     this.playerOptions.poster =//       'https://img1.wxzxzj.com/vpc-example-cover-your-name-c.png';//   },// 播放回調onPlayerPlay(player) {console.log('player play!', player);},// 暫停回調onPlayerPause(player) {console.log('player pause!', player);},// 視頻播完回調onPlayerEnded($event, player) {console.log(player);},// DOM元素上的readyState更改導致播放停止onPlayerWaiting($event, player) {console.log(player);},// 已開始播放回調onPlayerPlaying($event, player) {console.log(player);},// 當播放器在當前播放位置下載數據時觸發onPlayerLoadeddata($event, player) {},// 當前播放位置發生變化時觸發。onPlayerTimeupdate($event, player) {},// 媒體的readyState為HAVE_FUTURE_DATA或更高onPlayerCanplay(player) {// console.log('player Canplay!', player)},// 媒體的readyState為HAVE_ENOUGH_DATA或更高。這意味著可以在不緩沖的情況下播放整個媒體文件。onPlayerCanplaythrough(player) {// console.log('player Canplaythrough!', player)},// 播放狀態改變回調playerStateChanged(playerCurrentState) {// console.log('player current update state', playerCurrentState);},// 將偵聽器綁定到組件的就緒狀態。與事件監聽器的不同之處在于,如果ready事件已經發生,它將立即觸發該函數。。playerReadied(player) {console.log('example player 1 readied', player);},},};</script><!-- <style lang="less" scoped>@deep: ~'>>>';.dialog-play {@{deep}.el-dialog__body {padding: 0;}.play-video {width: 100%;margin: 0 auto;text-align: center;@{deep}.video-js {.vjs-big-play-button {top: 50%;left: 50%;transform: translate(-50%, -50%);}.vjs-current-time,.vjs-time-divider,.vjs-duration {display: block;padding-left: 0.3em;padding-right: 0.3em;}.vjs-remaining-time {display: none;}}}}</style>-->

使用視頻組件,傳入是否展示展示和文件的url

訪問后端接口獲取視頻url

 loadVideo() {request({url: "/video/7d515b22c4958598c0fbd1e6290a5ca5.mp4",method: "get",//接收類型是arraybufferresponseType: "arraybuffer"}).then(response => {const videoBlob = new Blob([response.data], { type: 'video/mp4' });const videoUrl = URL.createObjectURL(videoBlob);this.videoSrc = videoUrlthis.isVideoShow = true});},

使用視頻組件

 <div v-if="isVideoShow"><playvideo :visible="isVideoShow" :videoSrc="videoSrc" :append-to-body="true"style="margin-top: 10px;margin-left: 5px;width: 780px;height: 600px;"></playvideo></div>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/38905.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/38905.shtml
英文地址,請注明出處:http://en.pswp.cn/news/38905.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ReactDOM模塊react-dom/client沒有默認導出報錯解決辦法

import ReactDOM 模塊“"E:/Dpandata/Shbank/rt-pro/node_modules/.pnpm/registry.npmmirror.comtypesreact-dom18.2.7/node_modules/types/react-dom/client"”沒有默認導出。 解決辦法 只需要在tsconfig.json里面添加配置 "esModuleInterop": true 即…

【C++】queue容器

1.queue容器基本概念 2.queue常用接口 #include <iostream> using namespace std;//隊列queue #include<queue>//創建Person類 class Person { public:Person(string name, int age){this->m_Name name;this->m_Age age;}string m_Name; //姓名int m_Age; …

mysql創建新用戶并授權

目錄 前言登錄到mysql創建用戶用戶授權更改用戶密碼參考 前言 略 登錄到mysql shell> mysql -h127.0.0.1 -P3306 -uroot -p******創建用戶 mysql> CREATE USER abc% IDENTIFIED BY 123456;用戶授權 mysql> GRANT all privileges ON ruoyi.* TO abc%;用戶ruoyi擁有…

優維低代碼實踐:自定義模板

優維低代碼技術專欄&#xff0c;是一個全新的、技術為主的專欄&#xff0c;由優維技術委員會成員執筆&#xff0c;基于優維7年低代碼技術研發及運維成果&#xff0c;主要介紹低代碼相關的技術原理及架構邏輯&#xff0c;目的是給廣大運維人提供一個技術交流與學習的平臺。 優維…

禾賽科技Q2營收交付雙新高,國產激光雷達從量變到質變

隨著2022年激光雷達元年、2023年城市智能輔助駕駛&#xff08;NOA&#xff09;元年相繼到來&#xff0c;激光雷達產業迎來爆發期。 今年以來&#xff0c;自動駕駛公司、汽車制造商以及移動出行公司等各路人馬積極推動城市級別的智能輔助駕駛全面落地&#xff0c;北京、上海、深…

通過css設置filter 屬性,使整個頁面呈現灰度效果,讓整個網頁變灰

通過css設置filter 屬性設置頁面整體置灰 效果圖: 通過設置 filter 屬性為 grayscale(100%)&#xff0c;頁面中的所有元素都會被應用灰色濾鏡效果&#xff0c;使整個頁面呈現灰度效果。 <style type"text/css"> html { filter: grayscale(100%); -webkit-f…

git pull 某一個文件或文件夾

QQ: 2967732156 背景&#xff1a; 在使用Oracle VM VirtualBox&#xff0c;進行Linux開發時&#xff0c;隨著使用內存越來越少&#xff0c;空間已不足拉取整個代碼庫。 Ubuntu1604內存夠&#xff0c;Ubuntu18.04內存不夠。 思路&#xff1a; 第一步&#xff1a;從問題本身…

TB/TM-商品詳情原數據(APP)

一、接口參數說明&#xff1a; item_get_app-獲得TB/TMapp商品詳情原數據&#xff0c;點擊更多API調試&#xff0c;請移步注冊API賬號點擊獲取測試key和secret 公共參數 請求地址: https://api-gw.onebound.cn/taobao/item_get_app 名稱類型必須描述keyString是調用key&…

考研 408 | 【計算機網絡】 應用層

導圖 網絡應用模型 客戶/服務器&#xff08;c/s&#xff09;模型 P2P模型 DNS 域名 域名服務器 域名解析過程 文件傳輸協議FTP FTP服務器和用戶端 FTP工作原理 電子郵件 電子郵件的信息格式 組成結構 郵件服務器的功能&#xff1a; 1.發送&接收郵件 2.給發件人報告郵…

使用windows Api簡單驗證ISO9660文件格式,以及裝載和卸載鏡像文件

使用IIsoImageManager接口簡單驗證ISO鏡像文件正確性,使用AttachVirtualDisk裝載ISO鏡像文件,和使用DetachVirtualDisk卸載,(只支持windows 8及以上系統) 導讀 IIsoImageManager 驗證ISO文件正確性AttachVirtualDisk 裝載鏡像文件DetachVirtualDisk 卸載鏡像文件其他相關函…

《游戲編程模式》學習筆記(四) 觀察者模式 Observer Pattern

定義 觀察者模式定義了對象間的一種一對多的依賴關系&#xff0c;當一個對象的狀態發生改變時&#xff0c;所有依賴于它的對象都得到通知并被自動更新。 這是定義&#xff0c;看不懂就看不懂吧&#xff0c;我接下來舉個例子慢慢說 為什么我們需要觀察者模式 我們看一個很簡…

PAT (Advanced Level) 甲級 1004 Counting Leaves

點此查看所有題目集 A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Specification: Each input file contains one test case. Each case starts with a line containing 0<N<100, …

如何在iPhone手機上修改手機定位和模擬導航?

如何在iPhone手機上修改手機定位和模擬導航&#xff1f; English Location Simulator&#xff08;定位模擬工具&#xff09; 是一款功能強大的 macOS 應用&#xff0c;專為 iPhone 用戶設計&#xff0c;旨在修改手機定位并提供逼真的模擬導航體驗。無論是為了保護隱私、測試位…

Angular 獨立組件入門

Angular 獨立組件入門 如果你正在學習 Angular&#xff0c;那么你可能已經聽說過獨立組件&#xff08;Component&#xff09;。顧名思義&#xff0c;獨立組件就是可以獨立使用和管理的組件&#xff0c;它們能夠被包含在其他組件中或被其他組件引用。 在本文中&#xff0c;我們…

【Unity腳本開源】記錄鼠標按下的位置和移動的距離來進行物體的旋轉,并在鼠標釋放后將物體恢復到初始旋轉位置

??作者&#xff1a;白日參商 &#x1f935;?♂?個人主頁&#xff1a;白日參商主頁 ??堅持分析平時學習到的項目以及學習到的軟件開發知識&#xff0c;和大家一起努力呀&#xff01;&#xff01;&#xff01; &#x1f388;&#x1f388;加油&#xff01; 加油&#xff01…

go-安裝部署

一、安裝go 詳細安裝方式可以查看官網 # 下載 wget https://golang.google.cn/dl/go1.21.0.linux-amd64.tar.gz # 解壓縮 tar -xzf go1.21.0.linux-amd64.tar.gz # 遷移目錄 mv go /usr/local # 配置環境變量 export PATH$PATH:/usr/local/go/bin # 檢查go的版本 go version有…

Python中的字符串與字符編碼

Hello&#xff0c;這里是Token_w的博客&#xff0c;歡迎您的到來 今天文章講解的是Python中的字符串與字符編碼&#xff0c;其中有基礎的理論知識講解&#xff0c;也有實戰中的應用講解&#xff0c;希望對你有所幫助 整理不易&#xff0c;如對你有所幫助&#xff0c;希望能得到…

PDM/PLM系統建設

僅供學習使用&#xff0c;會隨時更新 工程機械跨生命周期數據管理系統 來源&#xff1a;清華大學 淺論企業PDM/PLM系統建設成功經驗 來源&#xff1a;e-works 作者&#xff1a;陳凡 https://articles.e-works.net.cn/pdm/article149572.htm 隨著“中國制造2025”強基工程戰略的…

張俊林:由ChatGPT反思大語言模型(LLM)的技術精要

轉自&#xff1a;https://mp.weixin.qq.com/s/eMrv15yOO0oYQ-o-wiuSyw 導讀&#xff1a;ChatGPT出現后驚喜或驚醒了很多人。驚喜是因為沒想到大型語言模型&#xff08;LLM,Large Language Model&#xff09;效果能好成這樣&#xff1b;驚醒是頓悟到我們對LLM的認知及發展理念&a…

Elisp之獲取PC電池狀態(二十八)

簡介&#xff1a; CSDN博客專家&#xff0c;專注Android/Linux系統&#xff0c;分享多mic語音方案、音視頻、編解碼等技術&#xff0c;與大家一起成長&#xff01; 優質專欄&#xff1a;Audio工程師進階系列【原創干貨持續更新中……】&#x1f680; 人生格言&#xff1a; 人生…