• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

jaeger25/Html5Video: A Phonegap plugin that allows playback of local video files ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

jaeger25/Html5Video

开源软件地址:

https://github.com/jaeger25/Html5Video

开源编程语言:

Java 73.5%

开源软件介绍:

Cordova Html5Video Plugin

Description

This plugin enables the use of normal HTML5

Android Webview (which Cordova is based upon) limits access to local files (such as videos) and prohibits reading them, both via relative files and file:/// URIs. Cordova Html5Video Plugin solves this by giving each of you video a android.resource:// path and updating your <video> tags accordingly.

Limitations

For Android only. Tested on Android API 15-19.

For API >= 19, a workaround is employed to copy the video files over to your application's data directory, as world-readable.

WARNING: this is potentially insecure - other apps will be able to read your videos! However it is the only way to get around Chrome's strict limitations on content:// URLs. See Issue #20 for details.

Install

cordova plugin add https://github.com/jaeger25/Html5Video.git

For more help on installing Cordova plugins, please read the official documentation

HTML

Create any video tags withing your html pages as normal, but:

  1. Give each video tag a unique ID.
  2. The video tags should be empty (i.e no tags inside)
  3. Add any poster image files to your www folder
  4. Autoplay is not enabled, but controlled via JS instead

Example:

<video id="myvideo" loop></video>

The next changes should be done inside your ProjectName/platforms/android folder

Enable Hardware Acceleration in AndroidManifest.xml

Android Webview disables video for none-hardware accelerated applications. Thus, make sure your manifest tag in AndroidManifest.xml contains:

android:hardwareAccelerated="true"

Consult the official Android documentation if you require more help. This is enabled by default in newer versions of cordova.

Move video files

Create a folder called raw inside the res folder ($PROJECT_ROOT/platforms/android/res/raw) where you place your videos. Due to limitations in how Android uses the res folder, make sure:

  1. Your filenames doesn't contain spaces and special characters
  2. That all filenames are unique and doesn't contain period (.) delimiters. Android considers video.lowres.mp4 and video.highres.mp4 the same file

If your file doesn't meet the above requirements cordova build will fail to compile your application.

Client-side code (javascript)

After deviceReady callback from Cordova, initialize your videos with:

window.plugins.html5Video.initialize( { "id":"path", ... } [, callback] ) 

Where callback is optional and is triggered when initialization finished (at the end)

Examples:

Initialization for video1 and video2 with no callback:

window.plugins.html5Video.initialize({
      "video1" : "video1file.mp4", 
     "video2" : "video2file.mp4"
  })

Initialize video1 and call function finished:

window.plugins.html5Video.initialize({
      "video1" : "video1file.mp4"
  }, finished)

Initialize video1 with anonymous function (usefull for playing a video at statup):

window.plugins.html5Video.initialize({
      "video1" : "video1file.mp4"
  }, function initializeIsFinished() {
  window.plugins.html5Video.play("video1")
})

Playing a video

Anytime you wish to play a video, call:

window.plugins.html5Video.play("video1" [, callback ])

Where callback is optional and is triggered when the video is finished (at the end)

Examples:

Play video1 with no callback:

window.plugins.html5Video.play("video1")

Play video1 and call function finished:

window.plugins.html5Video.play("video1", finished).

Play video1 with anonymous function:

window.plugins.html5Video.play("video1", function videoIsFinished() {
  console.log("Video is finished")
})



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap