AngularJS和HTML 5范围滑块

时间:2015-02-19 15:20:02

标签: angularjs range media ionic

我只是尝试用离子和cordova制作一个小应用程序。现在我尝试构建一个控制音频文件当前位置的时间滑块。我采用了html5系列来实现它和cordova媒体插件。

当我使用ng-cordovas ng-mouseup事件使用滑块时,它工作正常。但是当我拖动滑块并分别释放鼠标时,没有触发任何事件。我也试过了ng-mousemove,但没有成功。

这是我的代码:

的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">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

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

    <!-- cordova script (this will be a 404 during development) -->
    <script src="js/ng-cordova.min.js"></script>
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">ExampleApp</h1>
      </ion-header-bar>
      <ion-content ng-controller="AudioFileController">
        <button class="button" ng-click="play('/android_asset/www/audio/audioFile_01.mp3')">Play</button>
        <button class="button" ng-click="pause()">Pause</button>
        <button class="button" ng-click="stop()">Stop</button>
        <button class="button" ng-click="release()">Release</button>

        <!---<button class="button" ng-click="seekTo(10000)">Gehe zu...</button>-->

        <input id="slide" type="range" min="0" max="50000" value="0" ng-mouseup="seekTo()" />





      </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'
var module = angular.module('starter', ['ionic', 'ngCordova'])


.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)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})




module.controller("AudioFileController", function($scope, $ionicLoading, $cordovaMedia, $interval){
    var media = null;
    var duration;
    var slide = document.getElementById('slide');
    var time = 0;
    var timeSlided = false;


   $scope.setDuration = function() {
    duration = Math.round(media.getDuration());
    document.getElementById('slide').max = duration;
    alert("setDuration");

  }

    $scope.seekTo = function() {
      time = document.getElementById('slide').value;
      media.seekTo(time);
      timeSlided = true;
    }

    setInterval(function(){
         media.getCurrentPosition(
            // success callback
            function(position) {
                if (timeSlided == false) {
                    document.getElementById('slide').value = (position*1000);
                                    }
                else {

                    document.getElementById('slide').value = (time);
                    timeSlided = false;

                     }
            },
            // error callback
            function(e) {
                alert("Error getting pos=" + e);
            }
        );


    },2000)

    $scope.play = function(src) {
      if(media == null){
          media = new Media(src, null, null, mediaStatusCallback);
          $cordovaMedia.play(media);
      }
      else{
      media.play();
    }
    }

    $scope.stop = function() {
      media.stop();
    }

    $scope.pause = function() {
      media.pause();
    }

    $scope.release = function() {
      media.play();
    }



        var mediaStatusCallback = function(status) {
      if(status == Media.MEDIA_STARTING) {
        $ionicLoading.show({template: "Loading..."});
      }
      else {
        $ionicLoading.hide();
      }
    }

});

希望有人可以帮助我

1 个答案:

答案 0 :(得分:0)

您需要使用Cordova特定指令:on-release

相关问题