我在 Ionic 2 应用程序中使用 cordova-plugin-media-with-compression。
在 iOS 上,如果我传递 startRecord()
文件名并再次调用它而不更改 this.media
,我可以录制和播放。
我似乎无法播放存储在文件系统中其他位置的音频文件 - 因为我必须将一个新的 src 传递给 startRecord()
而这是我认为我做错了的一点。
import { Component } from '@angular/core';
import { ModalController, LoadingController, ToastController, Platform } from 'ionic-angular';
import { File, FileEntry, Entry, FileError, DirectoryEntry} from 'ionic-native';
declare var Media: any; // stops errors w/ cordova-plugin-media-with-compression types
@Component({
selector: 'page-add-doc',
templateUrl: 'add-doc.html'
})
export class AddDocPage {
isRecording = false;
isRecorded = false;
audioUrl ='';
localAudioUrl = '';
media: any;
newFileName: string;
newFileNameM4A: string;
homerAudio = 'http://techslides.com/demos/samples/sample.m4a'
constructor(private modalCtrl: ModalController,
private loadingCtrl: LoadingController,
private toastCtrl: ToastController,
private platform: Platform,
) {
platform.ready()
.then(() => {
console.log('latform Ready');
});
}
ionViewDidLoad() {
this.newFileName = new Date().getTime().toString();
this.newFileNameM4A = this.newFileName +'.m4a';
}
onRecordAudio() {
this.media = new Media(this.newFileNameM4A);
this.media.startRecord();
this.isRecording = true;
}
onStopRecordAudio() {
this.media.stopRecord();
this.media.release();
this.isRecording = false;
this.isRecorded = true;
try {
File.copyFile(File.tempDirectory, this.newFileNameM4A, File.dataDirectory, this.newFileNameM4A)
.then(
(data: Entry) => {
this.audioUrl = data.nativeURL;
});
} catch (FileError) {
console.log(FileError)
};
}
onPlayback() {
this.media = new Media(this.newFileNameM4A);
this.media.play();
this.media.release();
}
onPlaybackTempDirectory() {
this.media = new Media(File.tempDirectory + this.newFileNameM4A);
this.media.play();
this.media.release();
}
onPlaybackDataDirectory() {
this.media = new Media(File.dataDirectory + this.localAudioUrl);
this.media.play();
this.media.release();
}
onHomerAudio() {
this.media = new Media(this.homerAudio)
this.media.play();
this.media.release();
}
}
相信我可能已经用 https://issues.apache.org/jira/browse/CB-7007 的答案解决了这个问题
关于ios - 移动后iOS上的cordova-plugin-media-with-compression似乎无法播放音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42918226/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |