2

I have one question regarding implementation of Everyplay Video Recording on iOS devices.

The problem occurs when I finish recording. I go to Everyplay video preview where you can edit video and share it. Then, when I go back to my game when clicking on back or after sharing video, I cannot use the microphone in Unity.

I think that Everyplay still holds my microphone but I don't know how to release it. I have the same implementation on Android and it works perfectly. I think that the problem exists because on iOS you have an option to edit video using microphone or camera.

Any thoughts?

Bart
  • 19,692
  • 7
  • 68
  • 77
Dookeybre
  • 35
  • 1
  • 7
  • Does this happen also if you enable "Prepare IOS for recording" from player settings? You should stop your previous microphone instance before entering the video editor and initialize a new one when coming back from the editor and needing it again. – Pauli Ojanen Apr 17 '14 at 12:46
  • Thanks for quick reply. "Prepare iOS for recording" is enabled. I am stoping mic before I finish recording video and I wait 2 seconds when I go back to my game before I start mic again, but the problem is still there. – Dookeybre Apr 17 '14 at 13:21

1 Answers1

1

I was unable to replicate your issue on iOS7. However the problem did exist on iOS6. I made a small hack which seems to fix it on my device.

EveryplayMicHack.cs (copy this to Plugins/Everyplay/Scripts folder):

using UnityEngine;
using System.Runtime.InteropServices;

public class EveryplayMicHack {
    public static void EnableRecording() {
#if UNITY_IPHONE && !UNITY_EDITOR
        SetPreferredSampleRate(AudioSettings.outputSampleRate);
#endif
    }

#if UNITY_IPHONE && !UNITY_EDITOR
    [DllImport ("__Internal")]
    private static extern void SetPreferredSampleRate(int sampleRate);
#endif
}

EveryplayMicHack.h (copy this to Plugins/iOS folder)

#import <AVFoundation/AVFoundation.h>

void SetPreferredSampleRate(int sampleRate);

EveryplayMicHack.m (copy this to Plugins/iOS folder)

#import "EveryplayMicHack.h"

void SetPreferredSampleRate(int sampleRate) {
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setPreferredHardwareSampleRate:sampleRate error:nil];
}

And before initializing your microphone, call: EveryplayMicHack.EnableRecording();

// Something like this
EveryplayMicHack.EnableRecording();

myMicAudioSource.clip = null;
myMicAudioSource.clip = Microphone.Start("Built-in Microphone", ...

I hope it works for you too! :)

Pauli Ojanen
  • 296
  • 2
  • 5