AngularJS和HTML5范围滑块
我只是想用爱奥尼亚和科尔多瓦制作一个小应用。现在,我尝试构建一个时间滑块来控制音频文件的当前位置。我用html5来实现它和cordova媒体插件 当我使用ng cordovas ng mouseup事件提示滑块时,它工作正常。但当我拖动滑块并释放鼠标(分别是我的手指)时,不会触发任何事件。我也尝试了ng mousemove,但没有成功 这是我的密码: index.htmlAngularJS和HTML5范围滑块,angularjs,range,media,ionic,Angularjs,Range,Media,Ionic,我只是想用爱奥尼亚和科尔多瓦制作一个小应用。现在,我尝试构建一个时间滑块来控制音频文件的当前位置。我用html5来实现它和cordova媒体插件 当我使用ng cordovas ng mouseup事件提示滑块时,它工作正常。但当我拖动滑块并释放鼠标(分别是我的手指)时,不会触发任何事件。我也尝试了ng mousemove,但没有成功 这是我的密码: index.html <!DOCTYPE html> <html> <head> <meta
<!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();
}
}
});
//Ionic Starter应用程序
//angular.module是创建、注册和检索angular模块的全局位置
//“starter”是此角度模块示例的名称(也在index.html中的属性中设置)
//第二个参数是“requires”的数组
变量模块=角度模块('starter'、['ionic'、'ngCordova']))
.run(函数($ionicPlatform){
$ionicPlatform.ready(函数(){
//默认情况下隐藏附件栏(删除此选项可在键盘上方显示附件栏)
//表格输入)
if(window.cordova&&window.cordova.plugins.Keyboard){
插件键盘hideKeyboardAccessoryBar(真);
}
如果(窗口状态栏){
StatusBar.styleDefault();
}
});
})
module.controller(“AudioFileController”,函数($scope、$ionicLoading、$cordovaMedia、$interval){
var-media=null;
var持续时间;
var slide=document.getElementById('slide');
var时间=0;
var timeSlided=false;
$scope.setDuration=函数(){
duration=Math.round(media.getDuration());
document.getElementById('slide')。最大值=持续时间;
警报(“设定持续时间”);
}
$scope.seekTo=函数(){
时间=document.getElementById('slide')。值;
媒体。seekTo(时间);
时间滑动=真;
}
setInterval(函数(){
media.getCurrentPosition(
//成功回调
职能(职位){
if(timeSlided==false){
document.getElementById('slide')。值=(位置*1000);
}
否则{
document.getElementById('slide')。值=(时间);
时间滑动=假;
}
},
//错误回调
职能(e){
警报(“获取位置时出错=”+e);
}
);
},2000)
$scope.play=函数(src){
如果(媒体==null){
媒体=新媒体(src、null、null、mediaStatusCallback);
$cordovaMedia.play(媒体);
}
否则{
媒体播放();
}
}
$scope.stop=函数(){
media.stop();
}
$scope.pause=函数(){
媒体暂停();
}
$scope.release=函数(){
媒体播放();
}
var mediaStatusCallback=函数(状态){
如果(状态==媒体。媒体\u正在启动){
$ionicLoading.show({template:“Loading…”});
}
否则{
$ionicLoading.hide();
}
}
});
希望有人能帮助我。您需要使用Cordova特定的指令:。ng model=slideVal,ng change=seekTo(slideVal)有效吗?尝试理解您的问题一段时间,但根本没有理解。你的确切意思是什么?经过很长一段时间,我回到了这个项目,现在它与你的提示一起工作,谢谢;)