前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >html 5简易的影片播放器

html 5简易的影片播放器

作者头像
全栈程序员站长
发布2021-08-10 09:54:27
8580
发布2021-08-10 09:54:27
举报
文章被收录于专栏:全栈程序员必看

最近在看html5,书名是《html5&API网页程序设计》,看着书做的demo,这里使用的是video元素,非常简单,只要你把影片的地址放在文本框中点击播放按钮就可以实现影片的播放,当点击暂停时影片会重新加载。代码如下:

<! DOCTYPE html > < html > < head > < meta http – equiv = “ Content-Type “ content = “ text/html; charset=utf-8 “ /> < title > 简易影片播放器 </ title > < script type = “ text/javascript “ > function playOrPauseVideo(){ var videoUrl = document.getElementById( “ videoUrl “ ).value; var video = document.getElementById( “ video “ ); // 影片不为播放状态 if (video.paused) { // URL改变时,重新加载 if (videoUrl != video.src) { video.src = videoUrl; video.load(); } else { // 播放 video.play() } document.getElementById( “ playButton “ ).value = “ 暂停 “ ; } else { // 暂停 video.pause(); document.getElementById( “ playButton “ ).value = “ 播放 “ ; }

}

</ script > </ head >

< body > < video id = “ video “ width = “ 400 “ height = “ 300 “ autoplay ></ video >< br /> 影片的URL: < input type = “ text “ id = “ videoUrl “ /> < input id = “ playButton “ type = “ button “ onclick = “ playOrPauseVideo() “ value = “ 播放 “ /> </ body > </ html >

建议使用谷歌浏览器浏览,看看运行的效果吧

继续改善ing

转载于:https://blog.51cto.com/shenzhoulong/485217

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/110667.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档