canvas 视频音乐播放器
canvas 视频音乐播放器
var play_nor_img_path = 'images/play_btn_n.png'; //播放按钮 正常时 60x60 px
var play_sec_img_path = "images/play_btn_s.png";//播放按钮 选中时
var play_clc_img_path = "images/play_btn_c.png";//播放按钮 单击时
var pause_nor_img_path = 'images/pause_btn_n.png';//暂停按钮 正常时
var pause_sec_img_path = "images/pause_btn_s.png";//暂停按钮 选中时
var pause_clc_img_path = "images/pause_btn_c.png";//暂停按钮 单击时
var main_bg = "images/main_UI_bg.png"; //背景图 1920x930 px;
var logo ="images/logo.webm";
var logop;
var pause_icon;
var songTime;
var nowSongTime;
var lunt_update = false;
function player(path=""){
window.audio=[];
var mobj;
var isMovie = getFiletype(path);
window.audio.isMovie = isMovie;
//获取对象LEFT 总宽度
function getpos(e){
var obj = e;
var left = obj.offsetLeft;
while(obj = obj.offsetParent){
left+= obj.offsetLeft;
}
return left;
}
if(isMovie == false){ //是否视频 可以改为自动判断拓展名
mobj = new Audio(path);
logop = document.createElement("video");
document.body.appendChild(logop);
logop.style.display="none";
logop.src=logo;
logop.play();
window.setInterval(function(){
if(logop.ended == true){
logop.play();
}
},100);
}else{
var mobj_style="display:none;"
mobj = document.createElement("video");
document.body.appendChild(mobj);
mobj.setAttribute("style",mobj_style);
mobj.src=path;
}
audio.id=mobj;
setWindow();
var count = 0;
var inc_lunt=document.getElementById("inc_lunt");
var main_lunt = document.getElementById("main_lunt");
mobj.play();
// 设置播放按钮
if(mobj.ended == true || mobj.paused == true){
play_icon.style.background="url('"+play_nor_img_path+"')"
} else {
play_icon.style.background="url('"+pause_nor_img_path+"')"
}
//获取目标参数
;
//手动设置播放进度
main_lunt.onclick = function (e=window.event){ //取得单位位置所处时间 乘以 鼠标所在相对于进度条的位置
console.info(e.clientX+","+e.clientY+":"+getInc_pos(songTime,700,e.clientX - getpos(inc_lunt)));
inc_lunt.style.width = (e.clientX - inc_lunt.offsetLeft)+"px";
mobj.currentTime =getInc_pos(songTime,700,e.clientX - getpos(inc_lunt));
}
mobj.addEventListener("play",function (){
start_update_lunt()
//循环绘制视频
var t3 = window.setInterval(function (){
if(mobj.ended == true || mobj.paused == true){ //播放停止时移除计时器
clearInterval(t3);
}else{
try{
if(window.audio.isMovie == false){
window.audio.rect.drawImage(logop,0,0,900,490); //绘制一帧
}else {
window.audio.rect.drawImage(mobj,0,0,900,490); //绘制一帧
}
}catch(e){
console.error(e.message);//报错
}
}
},100);
},false);
//player 代码结束
}
function setWindow(){
//设置窗口 及UI
var musicWinObj = document.getElementsByClassName("music_win")[0];
var nodeValue="";
nodeValue += "position: absolute;";
nodeValue += "width: 900px;";
nodeValue += "height:550px;";
nodeValue += "margin-top: -275px;";
nodeValue += "margin-left: -450px;";
nodeValue += "left: 50%;";
nodeValue += "top:50%;";
nodeValue += "background:#C3C3C3; z-index:1";
nodeValue += "";
musicWinObj.setAttribute("style",nodeValue);
var h_data='';
h_data += '<div style="position: absolute; width: 900px;height: 60px; background: #F0F0F0;bottom: 0px; margin-left: -450px; left:50%;">';
h_data += '<div style="position: absolute; width: 120px; height: 60px; margin-top: -30px; top:50%;">';
h_data += '<div id="play_icon" style=" position: absolute; width: 60px; height: 60px;margin-left: -30px;left:50%; margin-top: -30px; top:50%;"></div><!--播放按钮-->';
h_data += '</div><!--播放按钮层 -->';
h_data += '<div id="main_lunt" style="width: 700px;height: 10px; border: #000000 1px solid; margin-left: -350px; left:55%;position: absolute; margin-top: -5px; top:50%;">';
h_data += '<div id="inc_lunt" style="height: 10px; background: #000000;left:0%;position: absolute; margin-top: -5px; top:50%;"></div><!--动态进度条-->';
h_data += '</div><div style="border-radius:90deg;"></div><!--进度条-->';
h_data += '</div>';
musicWinObj.innerHTML=h_data;
//创建视频绘画区
var vid_win = document.createElement("canvas");
var vid_win_style = "width: 900px; height: 490px; position:relative; margin-left: -450px; top: 0px; left: 50%; background: #000000;";
vid_win.setAttribute("style",vid_win_style);
vid_win.style.display="block";
musicWinObj.appendChild(vid_win);
vid_win.width="900";
vid_win.height="490";
window.audio.rect = vid_win.getContext("2d"); //取得绘图上下文
//设置播放按钮
play_icon = document.getElementById("play_icon");
play_icon.style.background="url('"+play_nor_img_path+"')"
var main_bg_style = '';
main_bg_style +='position:absolute; width:1920px; height:960px; margin-left:-960px; left:50%; margin-top:-480px; top:50%; z-index:0';
//创建背景区
var main_bg_win = document.createElement("div");
document.body.appendChild(main_bg_win);
main_bg_win.setAttribute("style",main_bg_style);
main_bg_win.style.background="url('"+main_bg+"')";
vid_win.ondblclick =function (){ //双击绘图层 canvas 最大化
if(main_bg_win.style.display != "none" ){
main_bg_win.style.display = "none";
var full_scr_style = "width: 1920px; height: 960px; position:absolute; margin-left: -960px; margin-top: -475px; top: 50%; left: 50%; background: #000000; display:block;z-index:20";
vid_win.setAttribute("style",full_scr_style);
}else{
main_bg_win.style.display = "block";
vid_win.setAttribute("style",vid_win_style);
}
}
//事件绑定 移入移出事件
play_icon.onmousemove=function (){
if(audio.id.ended == true || audio.id.paused == true){
play_icon.style.background="url('"+play_sec_img_path+"')"
} else {
play_icon.style.background="url('"+pause_sec_img_path+"')"
}
}
play_icon.onmouseover=function (){
if(audio.id.ended == true || audio.id.paused == true){
play_icon.style.background="url('"+play_sec_img_path+"')"
} else {
play_icon.style.background="url('"+pause_sec_img_path+"')"
}
}
play_icon.onmouseout=function (){
if(audio.id.ended == true || audio.id.paused == true){
play_icon.style.background="url('"+play_nor_img_path+"')"
} else {
play_icon.style.background="url('"+pause_nor_img_path+"')"
}
}
//播放暂停及图标设置
play_icon.onmousedown=function(){
if(audio.id.ended == true || audio.id.paused == true){
play_icon.style.background="url('"+play_clc_img_path+"')"
audio.id.play();
start_update_lunt();
} else {
play_icon.style.background="url('"+pause_clc_img_path+"')"
audio.id.pause();
}
}
play_icon.onmouseup=function(){
if(audio.id.ended == true || audio.id.paused == true){
play_icon.style.background="url('"+play_nor_img_path+"')"
} else {
play_icon.style.background="url('"+pause_nor_img_path+"')"
}
}
}
function getInc_pos(maxnum,max_t,pos){ //进度条比例计算
return pos*(maxnum/max_t);
}
function getInc_pos_f(maxnum,max_t,pin){ //没有用的 函数
return pin*(max_t/maxnum);
}
function start_update_lunt(){
if(lunt_update == false){
lunt_update = true;
var t = setInterval(function(timeV=t){
songTime = window.audio.id.duration;
nowSongTime = window.audio.id.currentTime;
inc_lunt.style.width = getInc_pos(100,songTime,nowSongTime)+"%"; //设置进度条
if(window.audio.id.ended == true){
lunt_update = false;
console.error("end!");
clearInterval(t);//停止时移除定时器
}
},100)
}
}
function getFiletype(str_path){
/*
var end5 = str_path.substr(str_path.length-6,str_path.length);
console.info(end5);
var pos = end5.indexOf(".");
console.info(pos);
var end5len = end5.length;
console.info(end5len);
var type = end5.substr(pos,end5len-1);
console.info(type);
*/
var pos = str_path.indexOf(".");
var str_path_len = str_path.length;
var type = str_path.substr(pos,str_path_len-1);
console.log(type);
var video = new Array(10);
var music = new Array(10);
video = ["mp4","avi","3gp","webm","mkv","mpg","wmv","vob","flv"];
music = ["mp3","wav","ogg","m4a","amr","m4r","acc","wave","flac"];
for(var i =0;i<10;i++){
if(type == "."+video[i]){
return true;
}
if(type == "."+music[i]){
return false;
}
}
return false;
}
canvas 视频音乐播放器的更多相关文章
- 【重点突破】——Canvas技术绘制音乐播放器界面
一.引言 在用Canvas练习制作了验证码之后,还有一个用Canvas技术很综合的练习——制作音乐播放器.在做这个练习的过程中,还有一个重要的观察点,那就是理解Canvas的一大问题. 二.要求 点 ...
- iOS多种刷新样式、音乐播放器、仿抖音视频、旅游App等源码
iOS精选源码 企业级开源项目,模仿艺龙旅行App 3D立体相册,可以旋转的立方体 横竖屏切换工具,使用陀螺仪检测手机设备方向,锁屏状... Swift版Refresh(可以自定义多种样式)架构方面有 ...
- 网页播放音频、视频文件——基于web的html 5的音乐播放器(转载)
文章转载自:开源中国社区 [http://www.oschina.net] 想通过手机客户端(支持 Android.iPhone 和 Windows Phone)访问开源中国:请点这里 HTML5 是 ...
- Android 音视频深入 十三 OpenSL ES 制作音乐播放器,能暂停和调整音量(附源码下载)
项目地址https://github.com/979451341/OpenSLAudio OpenSL ES 是基于NDK也就是c语言的底层开发音频的公开API,通过使用它能够做到标准化, 高性能,低 ...
- android 音乐播放器
本章以音乐播放器为载体,介绍android开发中,通知模式Notification应用.主要涉及知识点Notification,seekbar,service. 1.功能需求 完善音乐播放器 有播放列 ...
- 10个免费开源的JS音乐播放器插件
点这里 音乐播放器在网页设计中有时候会用到,比如一些时尚类.音乐或影视类等项目,但这些 网页播放器 插件比较少见,所以这里为大家整理一个集合,也许会有用到的时候. 下面整理的播放器有些是支持自适应的, ...
- 仿酷狗音乐播放器开发日志二十四 选项设置窗体的实现(附328行xml布局源码)
转载请说明原出处,谢谢~~ 花了两天时间把仿酷狗的选项设置窗体做出来了,当然了只是做了外观.现在开学了,写代码的时间减少,所以整个仿酷狗的工程开发速度减慢了.今天把仿酷狗的选项设置窗体的布局代码分享出 ...
- android快捷简单的实现音乐播放器
自己做了一个相对完整的音乐播放器,现在把播放模块提取出来,分享给大家.音乐播放器基本功能都实现了的,可能有些BUG,希望谅解. 播放器功能如下: 1.暂停,播放 2.拖动条实现,快进,快退 3.歌词同 ...
- 酷狗、QQ、天天动听——手机音乐播放器竞品对比
如果说什么艺术与人们生活最贴近,那应该属音乐了,因此当代人不离身的手机里必然会有自己喜欢的音乐播放器APP存在. 在当今无论PC端还是手机端音乐播放器都越来越同质化,我们应该选择哪款手机音乐播放器?它 ...
随机推荐
- Python Theano TypeError: Cannot convert Type TensorType(float64, vector) (of Variable Subtensor{int64:int64:}.0) into Type TensorType(float64, matrix)
参考: https://groups.google.com/forum/#!topic/theano-users/teA-07wOFpE 这个问题出现的原因是,我在读文件的时候,应该Train_X读成 ...
- 消息队列(message queue)
最近纠结于一个问题,就是horizon 在处理前台数据的时候非得等到cinder client将数据全部获取后才开始执行horizon的下一行代码,这给大量数据显示造成了很大的时延,其实对于用户体验来 ...
- 百度map
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- openwrt源码下载移植
openwrt源码下载移植 一.源码下载 1.1下载 由于本人多次尝试从SVN代码地址下载代码,出现无法访问因此这里选择从Git代码地址进行下载.在linux系统命令终端输入 git clone gi ...
- day2 python基础 while 循环补充
一.上节内容回顾 二.pycharm安装. 安装好以后激活方法:直接打开pycharm,选License server激活,输入:http://idea.imsxm.com 三.补充知识:如果字符串本 ...
- 标准模板库--STL
标准模板库STL 1.泛型程序设计 C++ 语言的核心优势之一就是便于软件的重用 C++中有两个方面体现重用: 1.面向对象的思想:继承和多态,标准类库 2.泛型程序设计(generic progra ...
- cocos2d-x设计模式发掘之一:单例模式
作者: firedragonpzy 原地址:http://www.firedragonpzy.com.cn/index.php/archives/1781 本系列文章我将和大家一起来发掘coc ...
- 在执行save操作时候出现的诡异!
情景:有一份excel数据需要导入到数据库中,想了想就写了一个导入excel的小功能. .............................准备使用时候,就开搞了,擦! 什么鬼??? 全程无报错 ...
- JS 插件 fastclick.js 解决手机端click点击延迟
FastClick 是一个简单,易于使用的JS库用于消除在移动浏览器上触发click事件与一个物理Tap(敲击)之间的300延迟. 对于非移动浏览器不启作用,禁用缩放标签. <meta name ...
- Nuxt使用iconfont矢量图标
Nuxt可以使用各种前端UI框架,这些框架一般都自带的有一些icon图标可供用户使用,但是一般项目开发的时候,UI框架自带的icon是不能满足实际项目需求的,这个时候我们可以自己找一些图片放到本地项目 ...