[MonoTouch] AVAssetExportSession

Mikkel Lønow mloenow at gmail.com
Wed Dec 8 15:29:34 EST 2010


Hello,

I'm still stuck with this. Any suggestions?

What got me started was these Objective-C implementations:

   - http://blog.tapsquare.com/post/803301658/ipod-library-access
   - http://www.subfurther.com/blog/?p=1103

Mikkel

On Fri, Dec 3, 2010 at 12:40, Mikkel Lønow <mloenow at gmail.com> wrote:

> 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/20101208/7a985286/attachment.html 


More information about the MonoTouch mailing list