Author Topic: WASAPI play a file.  (Read 309 times)

Sergzh

  • Posts: 8
WASAPI play a file.
« on: 7 Apr '18 - 08:59 »
Hello!
Please help me with the simplest action of WASPI.
I tried all the devices, but silence.
BASS errors are not present, all checks are passed.
Code: [Select]
        Dim Result
        Dim Stream

        'init BASS
        Result = Bass.BASS_Init(0, 0, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
        If Result = False Then
            MsgBox(Bass.BASS_ErrorGetCode().ToString)
        End If

        'init WASAPI output device
        Result = BassWasapi.BASS_WASAPI_Init(-1, 44100, 2, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1, 0.05, Nothing, Me.Handle)
        If Result = False Then
            MsgBox(Bass.BASS_ErrorGetCode().ToString)
        End If

        'Start WASAPI
        Result = BassWasapi.BASS_WASAPI_Start()
        If Result = False Then
            MsgBox(Bass.BASS_ErrorGetCode().ToString)
        End If

        'Load mp3 File
        Stream = Bass.BASS_StreamCreateFile("0.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
        If Stream = False Then
            MsgBox(Bass.BASS_ErrorGetCode().ToString)
        End If
        'Play
        Bass.BASS_ChannelPlay(Stream, False)

Chris

  • Posts: 1847
Re: WASAPI play a file.
« Reply #1 on: 7 Apr '18 - 19:20 »
Hi
do you want only to play a stream with waspi?
If yes then that is not needed because Bass use WASPI as Default Output Handler under (Vista,win7/win10, if XP then Fallback DirectSound)

Code: [Select]
Dim Result
        Dim Stream

        'init BASS
        Result = Bass.BASS_Init(1, 44100, 0,Me.Handle, IntPtr.Zero)
        If Result = False Then
            MsgBox(Bass.BASS_ErrorGetCode().ToString)
        End If

   

 
        'Load mp3 File
        Stream = Bass.BASS_StreamCreateFile("0.mp3", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT)
        If Stream = 0 Then
            MsgBox(Bass.BASS_ErrorGetCode().ToString)
        End If
        'Play
        Bass.BASS_ChannelPlay(Stream, False)

sveakul

  • Posts: 42
Re: WASAPI play a file.
« Reply #2 on: 7 Apr '18 - 19:26 »
It's my understanding that Bass 2.4.13.x uses WASAPI shared-mode as its default, so if the OP wants to use exclusive mode instead, he would need to include the basswasapi.dll.

Chris

  • Posts: 1847
Re: WASAPI play a file.
« Reply #3 on: 7 Apr '18 - 20:12 »
yes
correct but in your code are 2 things missing
if using WASAPI then

Code: [Select]
BASS_SetConfig(BASS_CONFIG_UPDATETHREADS,0);and

your BASS_WASAPI_Init will need a  WASAPIProc

Sergzh

  • Posts: 8
Re: WASAPI play a file.
« Reply #4 on: 8 Apr '18 - 06:22 »
Hi
do you want only to play a stream with waspi?
If yes then that is not needed because Bass use WASPI as Default Output Handler under (Vista,win7/win10, if XP then Fallback DirectSound)

Code: [Select]
Dim Result
        Dim Stream

        'init BASS
        Result = Bass.BASS_Init(1, 44100, 0,Me.Handle, IntPtr.Zero)
        If Result = False Then
            MsgBox(Bass.BASS_ErrorGetCode().ToString)
        End If

   

 
        'Load mp3 File
        Stream = Bass.BASS_StreamCreateFile("0.mp3", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT)
        If Stream = 0 Then
            MsgBox(Bass.BASS_ErrorGetCode().ToString)
        End If
        'Play
        Bass.BASS_ChannelPlay(Stream, False)

Thank you!
It works.