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 爬虫实战3 计算大学本学期绩点
大家好,本次为大家带来的项目是计算大学本学期绩点.首先说明的是,博主来自山东大学,有属于个人的学生成绩管理系统,需要学号密码才可以登录,不过可能广大读者没有这个学号密码,不能实际进行操作,所以最主要的 ...
- oracle定时job
转载自:http://www.cnblogs.com/hoojo/p/oracle_procedure_job_interval.html Oracle job procedure 存储过程定时任务 ...
- Python使用MySQL数据库的
然而,2016年开始,我从Python2切换到了Python3,Python2已经基本不再使用,MySQLdb驱动从2014年1月停止了维护.所以,打算重新再来写这篇博客. Python2 ---&g ...
- [JAVA · 0基础]:19.容器类
概述 容器 就是存放数据的一个集合 (java提供了一个接口专门去约束我们容器的实现类) watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L ...
- java中InputStream转化为byte[]数组
//org.apache.commons.io.IOUtils.toByteArray已经有实现 String filePath = "D:\\aaa.txt"; in = new ...
- ubuntu环境初始化
0. 在Ubuntu系统中永久修改主机名也比较简单.主机名存放在/etc/hostname文件中,修改主机名时,编辑hostname文件,在文件中输入新的主机名并保存该文件即可 1.打开termini ...
- hdu 3667 (拆边 mcmf)
注意题目中 边的容量 <= 5.可以把费用权值 a *f ^2化归成 a * f2, 即第一条边费用为 1 * a, 第二条 为 (4 - 1) * a, 第三条为 (9 - 4) * a.. ...
- do not use numbers as enumeration values
w 字段类型设置错误 有限元的判断,勿用枚举行. MySQL :: MySQL 5.7 Reference Manual :: 12.4.4 The ENUM Typehttps://dev.mysq ...
- 简述Python的深浅拷贝以及应用场景
深浅拷贝的原理 深浅拷贝用法来自copy模块. 导入模块:import copy 浅拷贝:copy.copy 深拷贝:copy.deepcopy 字面理解:浅拷贝指仅仅拷贝数据集合的第一层数据,深拷贝 ...
- java中参数传递的问题
public class Test { public static void main(String[] args) { StringBuffer a = new StringBuffer(" ...