[MonoTouch] AVAssetExportSession

Mikkel Lønow mloenow at gmail.com
Fri Dec 3 06:40:20 EST 2010


Hi,

I'm having trouble with AVAssetExportSession. I want to copy music tracks
from the iPod Library for further processing. Of course, this isn't possible
in the simulator so I "emulate" the library selection part with a static
file. Here is my code:

private AVAssetExportSession _assetExportSession;

------

var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
"/ImOnFire.m4a";
Console.WriteLine(path);
var assetURL = NSUrl.FromFilename(path);
NSObject[] values = new NSObject[] { new NSString("YES") };
NSObject[] keys = new NSObject[]
{ AVUrlAsset.PreferPreciseDurationAndTimingKey };
var options = NSDictionary.FromObjectsAndKeys(values, keys);
var asset = AVUrlAsset.FromUrl(assetURL, options);
_var assetExportSession = new AVAssetExportSession(asset,
AVAssetExportSession.PresetPassthrough);
_assetExportSession.OutputUrl =
NSUrl.FromFilename(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"../tmp/" + Guid.NewGuid().ToString() + ".m4a"));
_assetExportSession.OutputFileType = AVFileType.AppleM4A;
_assetExportSession.ExportAsynchronously((NSError error) => {
    //Console.WriteLine(error.ToString());
    switch (_assetExportSession.Status) {
        case AVAssetExportSessionStatus.Exporting:
            Console.WriteLine("Exporting: " + _assetExportSession.Progress);
            break;
        case AVAssetExportSessionStatus.Completed:
            Console.WriteLine("Completed");
            break;
        case AVAssetExportSessionStatus.Cancelled:
            Console.WriteLine("Cancelled");
            break;
        case AVAssetExportSessionStatus.Failed:
            Console.WriteLine("Failed");
            break;
        case AVAssetExportSessionStatus.Unknown:
            Console.WriteLine("Unknown");
            break;
        case AVAssetExportSessionStatus.Waiting:
            Console.WriteLine("Waiting");
            break;
        default:
            Console.WriteLine("Default");
            break;
    }
});

This works with AppleM4A, but it still throws an exception (and gets a
SIGSEGV):

System.NullReferenceException has been thrown
"Object reference not set to an instance of an object"
  at (wrapper managed-to-native)
MonoTouch.ObjCRuntime.Messaging.intptr_objc_msgSend (intptr,intptr)
<0x00004>
  at (wrapper managed-to-native)
MonoTouch.ObjCRuntime.Messaging.intptr_objc_msgSend (intptr,intptr)
<0x00004>
  at MonoTouch.ObjCRuntime.Runtime.GetNSObject (intptr) [0x0001f] in
/Users/plasma/Source/iphone/monotouch/ObjCRuntime/Runtime.cs:200
  at MonoTouch.AVFoundation.AVAssetExportSession.TrampolineAVErrorHandler
(intptr,intptr) [0x0004d] in
/Users/plasma/Source/iphone/monotouch/AVFoundation/AVAssetExportSession.g.cs:515
  at (wrapper native-to-managed)
MonoTouch.AVFoundation.AVAssetExportSession.TrampolineAVErrorHandler
(intptr,intptr) <IL 0x00018, 0x0008d>

When trying with a MP3 file in a MOV-container (OutputFileType
= AVFileType.QuickTimeMovie) it doesn't throw an exception but doesn't copy
the track either (it produces 0 KB files).

It seems like ExportAsynchronously's completion block never gets fired - it
could be related?

Furthermore, AVUrlAsset.FromUrl(assetURL, null) (no options) also throws an
exception - I've seen Objective-C do this.

Any help is greatly appreciated!

Kind regards,
Mikkel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20101203/b1507cde/attachment-0001.html 


More information about the MonoTouch mailing list