Audio recording

I have been trying to create an audio recorder and player app using foreign code (iOS initially). I got started with the audio player but its not working on the iOS device. the same piece of code is working in a native iOS application. I think the problem is that the audioPlayer object is being released even before the audio file is getting played.

The iOS object references that are being created by the UNO are not of type strong. I tried making the audioPlayer object global by using Objc.Object but the native method is unaware of the audioPlayer object declaration. The iOS build is failing because of this error.

I am attaching my code for your reference. Please suggest on how i can resolve the issue and share some code samples if possible.

We are actually evaluating the Fuse to check the feasibility of our product implementation. The major functionalities of our product are dependent of the ability to Record and Play the Audio & Video. We have very limited time to finalise on the platform to go with. Fuse seems promising but we are doubtful on the implementation of these two functionalities.

Any help on this is appreciated.

using Uno;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;

using Uno.Compiler.ExportTargetInterop;

[Require("Source.Include", "AudioToolbox/AudioToolbox.h")]
[Require("Source.Include", "AVFoundation/AVFoundation.h")]
public class SystemSounds : NativeModule
    //Trying to declare audioPlayer object as strong
    extern(iOS) ObjC.Object audioPlayer;

    public SystemSounds()
        AddMember(new NativeFunction("playNotification", (NativeCallback)PlayNotification));

    object PlayNotification(Context c, object[] args)
        return null;

    static extern(iOS) void PlayNotification()

        NSURL *url = [NSURL URLWithString:@""];
        NSLog(@"URL = %@",url);
        NSData *soundData = [NSData dataWithContentsOfURL:url];
        NSError *error=nil;
        //audioPlayer=[[AVAudioPlayer alloc] initWithData:soundData  error:&error];
        //Creating AVAudioPlayer object locally becuase the global object is not being referenced with in this block
        AVAudioPlayer *audioPlayer=[[AVAudioPlayer alloc] initWithData:soundData  error:&error];
        //audioPlayer.delegate = self;
        [audioPlayer play];
        NSLog(@"Error = %@",error);

    static extern(!iOS) void PlayNotification()
        debug_log("Notifications not supported by this platform!");


Foreign code is by no means my strongest side, so we should rather get someone else to look at this. I could get some more eyes on this early next week. It would be great if you hopped on our Slack community and reminded me about this thread on Monday (I’m @uldis there).

In the mean time: there is not much on recording audio as far as I can see, but there is a WIP project on a Streaming Player, which appears to be very close to what you’ve tried to do in your code snippet above.

Hope this helps at least a little, and hope to hear from you on Slack!