1

我已经下载了插件 FileOpener 并添加到我的项目中,如下所示:

<!DOCTYPE html>
<html lang="en"  dir="ltr">
<head>
    <meta charset="utf-8">

   <meta name="viewport" content="width=device-width,  user-scalable=no">
   <title>sample</title>
   <link rel="stylesheet"  href="css/jquery.mobile-1.3.2.min.css">
  <link rel="stylesheet"  href="css/adidas.css">
  <script src="js/jquery.js"></script>
  <script src="js/jquery.mobile-1.3.2.min.js"></script>
  <script src="js/data_en.js"></script>
  <script src="js/data_sp.js"></script>
  <script src="js/adidas.js"></script>
  <script src="js/cordova.js"></script>
  <script src="js/video.js"></script>
  <script src="js/fileopener.js"></script>

</head>
<body>
 <div data-role="page" data-theme="a" class="my-page" id="video">
  <video id="video_player" src="#" controls="controls"></video> 
</div>
</body>

在 .js 文件中

    $(document).on('pagebeforeshow',"#video", function () {
   var xyz = document.getElementById('video_player');
    alert("values xyz:" + xyz);
     var x =  window.plugins.fileOpener.open("file:///android_asset/www/videos/1974.mp4");
  xyz.src =  window.plugins.fileOpener.open("file:///android_asset/www/balls/1970.png");

    alert("opener:" + x);
    window.plugins.videoPlayer.play(x);
    alert("xyz after src:" +  xyz);
});

**第一警报** 第二次警报 第三次警报 我无法从 assets/www/videos/abcd.mp4 中打开任何视频文件/图像,以及类似的图像

现在一切正常,但在尝试点击播放按钮时会发出警报: 在此处输入图像描述

4

2 回答 2

1
 <!DOCTYPE html>
 <html lang="en"  dir="ltr">
 <head>
<meta charset="utf-8">

<meta name="viewport" content="width=device-width,  user-scalable=no">
<title>sample</title>
<script src="js/cordova.js"></script>
<script src="js/video.js"></script>
<script src="js/fileopener.js"></script>
<script src="js/ADD_ANY_JQUERY.MIN.JS"></script>
<script>
   function openFile(filePath)
  {
     window.plugins.fileOpener.open(filePath);
  }
</script
</head>
<body>
<div data-role="page" data-theme="a" class="my-page" id="video">
<img src="img/b_img1.png" onclick="openFile('file:///android_asset/www/videos/1974.mp4')"/>
</div>
</body>

编辑 后的 ​​Fileopener.js 将是这样的:

cordova.define("cordova/plugin/fileopener",
  function(require, exports, module) {
    var exec = require("cordova/exec");
    var FileOpener = function () {};

FileOpener.prototype.open = function(url) {
    exec(null, null, "FileOpener", "openFile", [url]);
};

FileOpener.prototype.setTAG = function(tag) {
    exec(null, null, "FileOpener", "setTAG", [tag]);
};
var fileOpener = new FileOpener();
    module.exports = fileOpener;

});
/**
 * Load Plugin
 */
if (!window.plugins) {
    window.plugins = {};
}
if (!window.plugins.fileOpener) {
    window.plugins.fileOpener = cordova.require("cordova/plugin/fileopener");
}

"js/ADD_ANY_JQUERY.MIN.JS" 在这一行添加任何 jquery.min.js

最后检查Cordova.js文件夹是否在您的应用程序的 js 文件夹中。如果它不起作用,请告诉我您的 logcat 说什么...

于 2013-09-26T07:11:53.830 回答
1

我在添加代码后使用cordova 2.9.0、jquery 1.9.1、jqm-1.3.2 和android-sdk-version:14 出现错误:logcat 是

01-06 19:36:53.132: D/PluginManager(9420): exec() call to unknown plugin: FileOpener 
 01-06 19:36:53.202: D/CordovaLog(9420): file:///android_asset/www/js/fileopener.js: Line 20 : Class not found     
01-06 19:36:53.202: I/Web Console(9420): Class not found at file:///android_asset/www/js/fileopener.js:20 

这个问题的解决方案是我在 config.xml 和 plugin.xml 中犯了错误: config.xml 替换这个:

 <feature name="videoplayer">
        <param name="android-package" value= "com.adidas.football.app.videoPlayer.VideoPlayer"/>
    </feature>

和:

  <feature name="VideoPlayer">
        <param name="android-package" value= "com.adidas.football.app.videoPlayer.VideoPlayer"/>
    </feature>

plugin.xml替换这个:

<plugin name="videoplayer" value= "com.adidas.football.app.videoPlayer.VideoPlayer"/>

和:

 <plugin name="VideoPlayer" value= "com.adidas.football.app.videoPlayer.VideoPlayer"/>

大写字母的一个小错误,但它消除了所有错误,最后我没有错误,除了我在编辑的问题中添加的最后一个警报“无法播放视频”

于 2013-09-26T08:27:23.093 回答