This project has moved. For the latest updates, please go here.

Draw waveform in Windows store apps (C#/xaml) with NAudio or any alternative suggestion

Jan 15, 2015 at 8:51 PM
I know we can't use NAudio in windows store app projects but is it in progress to have this beautiful capability in near future or is there any alternative to draw video waveform in windows store apps?
Jan 15, 2015 at 8:53 PM
hi, NAudio does have a Windows Store app assembly, so you can use it. The WPF demo project included in the NAudio source code also shows a way of drawing waveforms with XAML, although I have not yet tried porting this to Windows Store.

Jan 17, 2015 at 6:13 AM
Thank you for your response. If there is any video tutorial of how to use this assembly in windows store apps please link for me. Your job is great and I really appreciate your work.
Jan 19, 2015 at 9:56 PM
Edited Jan 20, 2015 at 4:42 PM
I tried to see how could I use NAudio in Windows store app by running demo but there was no waveform drawing

"Nothing to see here yet, please be patient while we enable Windows Store app support in NAudio"

But windowsform and wpf versions work perfectly.
Your work helps me a lot as I'm new to programming.
It will be very great to have Windows store app support.

How could I have array of samples from a media file? I referenced NAudio.Win8.dll but I don't know how to get array of samples from it.
Jan 22, 2015 at 8:51 AM
Use MediaFoundationReader in Windows 8 Store apps, and the Read method will get you access to the samples. If you use the ToSampleProvider extension method, then Read will fill a float array instead of a byte array.
Jan 22, 2015 at 2:07 PM
Edited Jan 22, 2015 at 2:23 PM
Thanks a lot for your help and beside I found this great tutorial here from you.

I couldn't imaging there is a detailed tutorial about how to work with audio and media. Rarely seen this kind of explanation even in books.

I'm at the first steps of understanding the world of programming and you provided a wide sight for me as you made tools for working with media which attracts my consideration to it's details and how scientists like you probe the world of technology.

By knowing details of media, working with it become simpler and more enjoyable.
Hope everyone understands value of what you are doing for us.
Jan 22, 2015 at 5:01 PM
Edited Jan 25, 2015 at 7:47 AM
I tried your advice in this way:
 async private void Button_Click(object sender, RoutedEventArgs e)
        FileOpenPicker picker = new FileOpenPicker();
        picker.ViewMode = PickerViewMode.Thumbnail;
        picker.SuggestedStartLocation = PickerLocationId.Desktop;
        var file = await picker.PickSingleFileAsync();
        if (file == null) return;

        float[] floatArrayOfMediaFile = null;

        // Here I have an error when MediaFoundationReader tries to read from path. Image of error is below
        using (var reader = new MediaFoundationReader(file.Path.ToString())) 
            var fileRead = reader.ToSampleProvider();
            // Here I want to fill float array but I don't know how but I tried this
            fileRead.Read(floatArrayOfMediaFile, 10, 44100);
An exception of type 'System.UnauthorizedAccessException' occurred in NAudio.Win8.DLL but was not handled in user code

Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

on the line:
 MediaFoundationInterop.MFCreateSourceReaderFromURL(file, null, out reader);

Here is the image of error

I've searched for this error and found out (if I'm correct) on referring to the UI thread from another thread this error happens. But I've no idea how to manipulate my codes to prevent this error.
Jan 25, 2015 at 7:47 AM
Is there any possible partial changing in my code which could give me a float array of a video file?
Jan 27, 2015 at 7:55 PM
Edited Jan 27, 2015 at 8:05 PM
Is this error from my code? or it's because of not yes support for windows store?
Feb 12, 2015 at 9:38 PM
hi, Windows Store is quite restrictive in what it will let you access. I've not had a lot of time to get to grips with it myself yet, so I'm afraid I can't tell you off the top of my head an easy way to get around this.