locked
how to open sound recording file

    Question

  • I can not open sound recording file .m4a in Windows 8.1. It is a new MIME type in Windows 8.1, so what code clip I needed to add for FileOpenPicker?

    Monday, October 21, 2013 6:49 PM

Answers

  • Hi Charlie,

    Are you getting the error when adding the file to a MediaElement? If so, I suspect you're setting the wrong MIME type. I just used the following code snippet to record an m4a sound clip from the FileOpenPicker and play it back with no problem. The MIME type is audio/m4a

            private async void Button_Click(object sender, RoutedEventArgs e)
            {
                FileOpenPicker picker = new FileOpenPicker();
                picker.FileTypeFilter.Add(".m4a");
                StorageFile audioFile = await picker.PickSingleFileAsync();
                var audioStream = await audioFile.OpenAsync(FileAccessMode.Read);
    
                mediaElem.SetSource(audioStream, audioFile.ContentType);
            }

    --Rob

    • Marked as answer by Charlie C. Li Friday, October 25, 2013 1:33 AM
    Wednesday, October 23, 2013 12:29 AM
    Owner
  • Hi Rob,

    Bingo. I debugged it and found my sound recording file MIME type is "audio/mp4" not "audio/m4a".

    Now it worked. 

    • Marked as answer by Charlie C. Li Friday, October 25, 2013 1:33 AM
    Wednesday, October 23, 2013 2:10 PM

All replies

  • In what way are you having trouble with this? The FileOpenPicker doesn't care about the contents of the file, only the extension. If you add .m4a to the FileOpenPicker's FileTypeFilter then it should be able to pick m4a files.

    --Rob

    Tuesday, October 22, 2013 12:09 AM
    Owner
  • I added .m4a and audio/mp4a-lamn in FileOpenPicker filter, but when I launch FileOpenPicker and select Sound Recording then a Recorded file, it said "unrecognized file type .m4a" in Windows 8.1 pro. I believe that Windows 8.1 added more MIME files because I have added all the MIME files of Windows 8.0. Where is the defined references of Windows 8.1 MIME? 
    Tuesday, October 22, 2013 1:49 PM
  • Hi Charlie,

    Are you getting the error when adding the file to a MediaElement? If so, I suspect you're setting the wrong MIME type. I just used the following code snippet to record an m4a sound clip from the FileOpenPicker and play it back with no problem. The MIME type is audio/m4a

            private async void Button_Click(object sender, RoutedEventArgs e)
            {
                FileOpenPicker picker = new FileOpenPicker();
                picker.FileTypeFilter.Add(".m4a");
                StorageFile audioFile = await picker.PickSingleFileAsync();
                var audioStream = await audioFile.OpenAsync(FileAccessMode.Read);
    
                mediaElem.SetSource(audioStream, audioFile.ContentType);
            }

    --Rob

    • Marked as answer by Charlie C. Li Friday, October 25, 2013 1:33 AM
    Wednesday, October 23, 2013 12:29 AM
    Owner
  • Hi Rob,

    Bingo. I debugged it and found my sound recording file MIME type is "audio/mp4" not "audio/m4a".

    Now it worked. 

    • Marked as answer by Charlie C. Li Friday, October 25, 2013 1:33 AM
    Wednesday, October 23, 2013 2:10 PM