简体   繁体   中英

how to play a sound from .NetStandard 2.0 class library?

The question heading explains the problem. This answer seems to me to be the best option and what I want to do - play a.wav file. But I can't add the namespaces to use MediaElement . I want to play a beep/alert sound based on criteria met.

using Windows.Media.Playback;
using Windows.Media.Core;

Is there a.NetStandard2.0 Class Library alternative? I would like to avoid "third party", extra nuget packages.

You could try to use UWP APIs in your.Net Standard 2.0 class library project. Right-click your class library name and select Add -> Project Reference… option, click the Browse button on the Reference Manager dialog. Find the file C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd and add the file. Find the file C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\8.0.0.0\ Windows.Foundation.UniversalApiContract.winmd and add it.

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