Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

XLabs using microphone

$
0
0

Hi,

I want to use microphone and i did this using XLabs

AppDelegate class:

`public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Forms.Init ();

        this.SetIoc();

        #region Parse User stuff
        userDataManager = new UserDataManager(ParseStorage.Default);

        App.SetUserDataManager (userDataManager);

        #endregion


        window = new UIWindow (UIScreen.MainScreen.Bounds);

        window.RootViewController = App.Instance.GetMainPage().CreateViewController();
        window.MakeKeyAndVisible ();

        return true;
    }

`

`private void SetIoc()
{
var resolverContainer = new SimpleContainer();

        var app = new XFormsAppiOS();
        app.Init(this);

        var documents = app.AppDataDirectory;
        var pathToDatabase = Path.Combine(documents, "xforms.db");

        resolverContainer.Register<IDevice>(t => AppleDevice.CurrentDevice)
            .Register<IDisplay>(t => t.Resolve<IDevice>().Display)
            .Register<IAudioStream>(t => t.Resolve<IDevice>().Microphone)
            .Register<IXFormsApp>(app)
            .Register<ISoundService>(t=>t.Resolve<ISoundService>())
            .Register<IDependencyContainer>(t => resolverContainer)
            .Register<ISimpleCache>(
                t => new SQLiteSimpleCache(new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS(),
                    new SQLite.Net.SQLiteConnectionString(pathToDatabase, true), t.Resolve<IJsonSerializer>()));

        Resolver.SetResolver(resolverContainer.GetResolver());

    }`

And my HomePage class is :

` public HomePage ()
{

        NavigationPage.SetHasNavigationBar (this, true);
        var layout = new StackLayout { Padding = 50 };

        var app = Resolver.Resolve<IXFormsApp>();

        this._fileName = Device.OnPlatform(
            System.IO.Path.Combine(app.AppDataDirectory, "audiosample.wav"),
            "audiosample.wav",
            System.IO.Path.Combine(app.AppDataDirectory, "audiosample.wav")
        );



        _device = Resolver.Resolve<IDevice>();

        if (_device != null)
        {
            this.audioStream = _device.Microphone;
            this.recorder = new WaveRecorder();
        }

        sampleRate = 16000;


        Button btnRecord = new Button();
        btnRecord.Text = "Record/Play";
        btnRecord.Clicked += btnRecord_Clicked;
        btnRecord.VerticalOptions = LayoutOptions.EndAndExpand;
        btnRecord.HorizontalOptions = LayoutOptions.FillAndExpand;
        btnRecord.BackgroundColor = Color.FromRgb (0, 172, 237);
        btnRecord.TextColor = Color.White;

        layout.Children.Add (btnRecord);
        Content = layout ;
    }

`

My problem is _device.Microphone is return null and i cant figure it out? How can i solve?

Thanks.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>