Problem with NAudio.Midi

寛明 水崎 1 Reputation point
2021-01-30T13:16:15.253+00:00

Hello,

I have a huge problem with playing Midi with NAudio.

Although it works perfectly on Visual Studio 2019, it crashes on store app.

So, I made smallest app by referring to this Microsoft HP as an experiment

UI Frontiers - MIDI Music in WPF Applications | Microsoft Learn

Here is the one.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using NAudio.Midi;

namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

    MidiOut midiOut = new MidiOut(0);  

    private void button_Click(object sender, RoutedEventArgs e)  
    {  
             midiOut.Send(MidiMessage.StartNote(80, 127, 1).RawData);  


    }  
}  

}

So long as it runs on Visual Studio 2019, it has no problem at all.

However, I made a package app named “WapProjTemplate1_1.0.15.0_Test”

And I installed “Add-AppDevPackage.ps1” into my laptop by running with PowerShell so that I can check if it runs in the same way Microsoft stuff checks my app.

Then, It crashed.

Next, I deleted the line “MidiOut midiOut = new MidiOut(0);”, then it works perfectly without crashing.

Thus, I identified that the line “MidiOut midiOut = new MidiOut(0);” in N.audio is the reason why my app named “Melody Harmonizer” crashed.

How can I solve this problem? Without midi sounds, my app is so dumb.

Sincerely yours,

Hiroaki Mizusaki

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,784 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.