我想从json加载音频文件。 我收到一个错误:
E / Web控制台(1154):EXCEPTION:未捕获(在承诺中):TypeError:无法读取属性' play'未定义的文件:///android_asset/www/build/main.js:5我正在运行最新的Ionic2 / Angular2
我该怎么办?
谢谢! 佛瑞德
我的home.ts脚本:
loadSessionID() {
//load the new sessionID from JSON
this.sessionService.load()
.then(
session => {
this.session = session.results.slice(this.currentSessionId-1,this.currentSessionId); // array index item first position = 0
console.log('Load session with id: '+this.currentSessionId);
this.playSessionID();
},
error => console.error('Error loading session ID'+error)
);
}
playSessionID(){
// Create a MediaPlugin instance. Expects path to file or url as argument
var mp3URL = this.mediaURLPrefix+this.session.filename;
var file = new MediaPlugin(mp3URL);
// Catch the Success & Error Output
// Platform Quirks
// iOS calls success on completion of playback only
// Android calls success on completion of playback AND on release()
file.init
.then(
() => console.log('Playback finished'),
(err) => console.log('Somthing went wrong! error code: ' + err.code + ' message: ' + err.message)
);
//play audio file
file.play();
}