无法加载媒体,因为服务器或网络出现故障或者不支持该格式

时间:2016-06-09 23:59:43

标签: android html5 ionic-framework video.js

我正在尝试在我的基于离子框架构建的应用中播放视频,我正在使用video.js以便稍后可以添加更多功能。当我在开发机器浏览器上测试它时,在终端上使用ionic serve --livereload命令,视频在浏览器上播放。

但在我的Android智能手机中并非如此,因为我收到了消息:The media could not be loaded, either because the server or network failed or because the format is not supported。我一直试图在不同的论坛上得到答案,但无济于事。

是否有任何我缺少的插件,视频是否需要在移动设备中使用?请让我知道出了什么问题。

这是我的代码:

index.html -

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="lib/video.js/dist/video-js.css" rel="stylesheet">
    <!-- IF using Sass (run gulp sass first), then remove the CSS include above
    <link href="css/ionic.app.css" rel="stylesheet">
-->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="lib/video.js/dist/video.min.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>
    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script>
      videojs.options.flash.swf = "/lib/video.js/dist/video-js.swf"
    </script>
  </head>

  <body ng-app="starter">
    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Ionic Blank Starter</h1>
      </ion-header-bar>
      <ion-content class="has-header">
        <div class="list card">
          <div class="item item-avatar">
            <img src="/img/DSC_0025.jpg">
            <h2>Dr.Marty McFly</h2>
          </div>
          <div class="container" ng-controller="VideoPlay" ng-init="mainVideo()">
              <div id="videocontainer">
                  <video id="giblibvideo" class="video-js"></video>
              </div>
          </div>
          <div class="item tabs tabs-secondary tabs-icon-left">
            <a class="tab-item" href="#">
              <i class="icon ion-thumbsup"></i>
              Like
            </a>
            <a class="tab-item" href="#">
              <i class="icon ion-chatbox"></i>
              Comment
            </a>
            <a class="tab-item" href="#">
              <i class="icon ion-share"></i>
              Share
            </a>
          </div>  
        </div>    
      </ion-content>
    </ion-pane>
  </body>
</html>

app.js -

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs).
    // The reason we default this to hidden is that native apps don't usually show an accessory bar, at
    // least on iOS. It's a dead giveaway that an app is using a Web View. However, it's sometimes
    // useful especially with forms, though we would prefer giving the user a little more room
    // to interact with the app.
    if (window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // Set the statusbar to use the default style, tweak this to
      // remove the status bar on iOS or change it to use white instead of dark colors.
      StatusBar.styleDefault();
    }
  });
})

.controller('VideoPlay', function ($scope) 
{
  $scope.mainVideo = function () 
  {
    var vjs = videojs('giblibvideo');
    vjs.src([
      { type: "video/mp4", src: "https://d7ac3onxws4ui.cloudfront.net/dist/giblib-promo21464713310-720p.mp4" },
      { type: "video/webm", src: "https://d7ac3onxws4ui.cloudfront.net/dist/giblib-promo21464713310-720p.webm" }
    ]);
    vjs.poster("https://s3-us-west-1.amazonaws.com/giblib-videos/dist/thumbnails/giblib-promo1462991386-00002.png");
    vjs.aspectRatio("16:9");
    vjs.autoplay(false);
    vjs.controls(true);
  };
});

0 个答案:

没有答案