下面的代碼是從ThePolyGlotDeveloper.com
ionic start IonicProject blank
cd IonicProject
ionic platform add android
ionic platform add ios
安裝Apache科爾多瓦媒體PluginShell
cordova plugin add org.apache.cordova.media
的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">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
//important to note that ng-cordova.min.js must come before cordova.js in your script includes. Your project will not work correctly if it comes after.
app.js
angular.module('starter', ['ionic', 'ngCordova'])
創建一個新的控制器,就像這樣:
app.js
example.controller("ExampleController", function($scope, $cordovaMedia, $ionicLoading) {
$scope.play = function(src) {
var media = new Media(src, null, null, mediaStatusCallback);
$cordovaMedia.play(media);
}
var mediaStatusCallback = function(status) {
if(status == 1) {
$ionicLoading.show({template: 'Loading...'});
} else {
$ionicLoading.hide();
}
}
});
播放從URL(index.html的)
<ion-content ng-controller="ExampleController">
<button class="button" ng-click="play('http://www.stephaniequinn.com/Music/Commercial%20DEMO%20-%2013.mp3')">Play from internet</button>
</ion-content>
或本地文件(index.html文件):
<ion-content ng-controller="ExampleController">
<button class="button" ng-click="play('www/mp3/song.mp3')">Play from file system</button>
</ion-content>
觀看tutorial video
Code Source
請參閱http://stackoverflow.com/questions/15728424/html5-video-is-not-working-with-angularjs-ng-src-tag您必須爲您的音頻創建過濾器 –
這是列出的問題(現在封閉)的角度。有一個SO問題的答案和一個正式的解決方法從角度列表這裏https://github.com/angular/angular.js/issues/1352 –
@RachelGallen視頻文件是.mp4文件沒有音頻(我編輯它們在premiere pro)。他們是運動視頻(每個3-4秒)循環遍歷,以演示不同的鍛鍊動作..我會嘗試過濾器,讓你知道...謝謝:) – MehdiN