alternetsoft / AlternetUI

MIT License
22 stars 2 forks source link

Loading and Playing Sounds? #88

Closed Shadowblitz16 closed 6 months ago

Shadowblitz16 commented 6 months ago

It would be nice if there was support for loading sounds and music like in winforms.

neoxeo commented 6 months ago

@Shadowblitz16

You can use this if you want a quick answer : https://github.com/csukuangfj/PortAudioSharp2/

Shadowblitz16 commented 6 months ago

@Shadowblitz16

You can use this if you want a quick answer : https://github.com/csukuangfj/PortAudioSharp2/

thankyou I will use this in the meantime

generalloki commented 6 months ago

@Shadowblitz16

I would open local .html file in the included WebBrowser control with audio file. An example of such page:

<br/>notifications-sound-127856.mp3<br/>

<button onclick="document.getElementById('audio3').play();">Play</button>

<button onclick="document.getElementById('audio3').pause();">Pause</button>

<button onclick="document.getElementById('audio3').pause();document.getElementById('audio3').currentTime=0;">Stop</button><br/>
<br/>

<audio controls id='audio3' preload="auto">
  <source src="notifications-sound-127856.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

If sound player need to be invisible, just set WebBrowser.Visible=false. it is also possible to to control audio player from c# passing js code to the WebBrowser. I will post here an update when we have more detailed example.

The advantage is that MP3, WAV and OGG is fully supported. Also there is cute audio player interface (optional).

I beleive (in some future) we will add also some simple functions to play audio.

generalloki commented 6 months ago

I have added SimpleSoundPlayer class but currently it works only on Windows and MacOs. I will investigate why it doesn't work on Linux.

generalloki commented 6 months ago

I was able to play wav using SimpleSoundPlayer on Linux. I found that it requires osspd package:

sudo apt-get -y install osspd

So, for now I am closing this issue