我正在为 MvvmCross 开发一个从设备到 GetAudio 的插件。但是我在 Touch 实现中遇到了错误。我已经看过这里,这里和这里。
但没有什么能解决我的问题。
好吧,到目前为止我有:
var audioDelegate = new AudioDelegate();
audioDelegate.AudioAvailable = ProcessAudio;
mediaPicker = new MPMediaPickerController();
mediaPicker.Delegate = audioDelegate;
mediaPicker.AllowsPickingMultipleItems = false;
modalHost.PresentModalViewController (mediaPicker, true);
要从音频启动选择器,其中 AudioDelegate 是:
private class AudioDelegate : MPMediaPickerControllerDelegate
{
public EventHandler<MvxAudioRecorderEventArgs> AudioAvailable;
public override void MediaItemsPicked (MPMediaPickerController sender, MPMediaItemCollection mediaItemCollection)
{
if (mediaItemCollection.Count < 1)
{
return;
}
MvxAudioRecorderEventArgs eventArg = new MvxAudioRecorderEventArgs (mediaItemCollection.Items [0].AssetURL);
AudioAvailable (this, eventArg);
}
}
然后在 ProcessAudio 中:
private void ProcessMedia(object sender, UIImagePickerMediaPickedEventArgs e)
{
var assetURL = e.MediaUrl;
NSDictionary dictionary = null;
var assetExtension = e.MediaUrl.Path.Split ('.') [1];
var songAsset = new AVUrlAsset (assetURL, dictionary);
var exporter = new AVAssetExportSession (songAsset, AVAssetExportSession.PresetPassthrough.ToString ());
exporter.OutputFileType = (assetExtension == "mp3") ? "com.apple.quicktime-movie" : AVFileType.AppleM4A;
var manager = new NSFileManager ();
var count = 0;
string filePath = null;
do
{
var extension = "mov";//( NSString *)UTTypeCopyPreferredTagWithClass(( CFStringRef)AVFileTypeQuickTimeMovie, kUTTagClassFilenameExtension);
var fileNameNoExtension = "AUD_" + Guid.NewGuid ().ToString ();
var fileName = string.Format ("{0}({1})", fileNameNoExtension, count);
filePath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments) + "/";
filePath = filePath + fileName + "." + extension;
count++;
} while (manager.FileExists (filePath));
var outputURL = new NSUrl (filePath);//should be something in objective C... => [NSURL fileURLWithPath:filePath];
exporter.OutputUrl = outputURL;
exporter.ExportAsynchronously ( () =>
{
var exportStatus = exporter.Status;
switch (exportStatus)
{
case AVAssetExportSessionStatus.Unknown:
case AVAssetExportSessionStatus.Completed:
{
//remove the .mov from file and make it available for callback mediaAvailable()...
break;
}
case AVAssetExportSessionStatus.Waiting:
case AVAssetExportSessionStatus.Cancelled:
case AVAssetExportSessionStatus.Exporting:
case AVAssetExportSessionStatus.Failed:
default:
{
var exportError = exporter.Error;
if(assumeCancelled != null)
{
assumeCancelled();
}
break;
}
}
});
mediaPicker.DismissViewController(true, () => { });
modalHost.NativeModalViewControllerDisappearedOnItsOwn();
}
但它总是与 Status.Failed 错误:
LocalizedDescription: The operation could not be completed
Description: Error Domain=AVFoundationErrorDomain Code=-11800
"The operation could not be completed" UserInfo=0x1476cce0
{NSLocalizedDescription=The operation could not be completed,
NSUnderlyingError=0x1585da90 "The operation couldn’t be completed.
(OSStatus error -12780.)", NSLocalizedFailureReason=An unknown error
occurred (-12780)}
谁能帮我?在此表示感谢,