移动后iOS上的cordova-plugin-media-with-compression似乎无法播放音频文件
Posted
技术标签:
【中文标题】移动后iOS上的cordova-plugin-media-with-compression似乎无法播放音频文件【英文标题】:cordova-plugin-media-with-compression on iOS can't seem to play audio files after moving 【发布时间】:2017-03-21 04:02:26 【问题描述】:我在 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('Platform 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();
【问题讨论】:
【参考方案1】:相信我可能已经用https://issues.apache.org/jira/browse/CB-7007的答案解决了这个问题
【讨论】:
我不能在安卓设备上运行onHomerAudio()
方法?你能告诉我怎么做吗?以上是关于移动后iOS上的cordova-plugin-media-with-compression似乎无法播放音频文件的主要内容,如果未能解决你的问题,请参考以下文章
适用于 Android/IOS 的 Canvas 上的 Unity 平滑移动和缩放 UI
iOS上的VoiceOver在父元素可见后没有将焦点放在子元素上