简体   繁体   中英

Cannot get sound file (WAV) to play on RPi3 using latest Windows 10 IoT Core

We want to play a WAV file somewhere in my headless UWP background application on Windows 10 IoT Core . For this i have followed the Microsoft docs and used the following method:

var mediaPlayer = new MediaPlayer();
mediaPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/startup.wav"));
mediaPlayer.Play();

I have copied the WAV file (startup.wav) to the Assets folder in Visual Studio, set it to always copy to output and compiled the UWP application. No matter how i try i don't get any sound output. I tried 2 Raspberry PI's (both version 3) and connected my pc speakers to the output jack of the Raspberry.

I also granted the application the correct permissions in the package.appxmanifest:

<uap3:Capability Name="backgroundMediaPlayback"/>

If i go to the device portal i see on the right side the default Raspberry pi 2 audio with slidebar active. Which i guess is a sign drivers are correct.

What can i do to play a simple wav file in my headless background UWP application? Maybe i am doing something wrong, hope somebody can help me.

I have copied the WAV file (startup.wav) to the Assets folder in Visual Studio

Like this right?

在此输入图像描述

It is not the right place. You can check the IsOpen property of mediaPlayer.Source when debugging, it will be false.

在此输入图像描述

You need put the audio file in appx folder, for me, it is like this: PlayAudioBackground\\bin\\ARM\\Debug\\AppX\\Assets.

在此输入图像描述

You can have a try.

Reference: " URI schemes - ms-appx " " UWP sample - Background media playback sample "

Update:

For background application the assets folder is not included in project by default. If you want to use this folder to add the audio file you can right click on the assets folder from solution explorer and select "Include In Project". And then set the audio file property "Build Action - Content" and "Copy to output directory - Copy Always".

在此输入图像描述

在此输入图像描述

Thanks for all your help. When i tried a third raspberry it works, no idea why but maybe i have bad luck and two head-jack ports are broken :).

Thanks for all your assistance!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM