BASS for Universal Windows Platform (UWP)

Started by Ian @ un4seen,

Ian @ un4seen

Please try using the BASS.Net version in the 1st post (add a reference to it and a "using Un4seen.Bass" line), and see if there is still a problem then.

ileandros

Quote from: Ian @ un4seenPlease try using the BASS.Net version in the 1st post (add a reference to it and a "using Un4seen.Bass" line), and see if there is still a problem then.

Edit: I am on WP8.1 Silverlight, VS 2015  Win 8.1 x86

Ian @ un4seen

That's strange. Are you using the latest VS2015 version, eg. not a preview? If so, perhaps the BASS.Net DLL currently requires Win10, I'm not sure. The BASS.Net developer is currently away on holiday, so we may have to wait until they return to find out. In the meantime, regarding using "DllImport", you could try something like this:

public sealed class MyBass
{
[DllImport("bass.dll")]
public static extern bool BASS_Init(int device, uint freq, uint flags, IntPtr win, IntPtr clsid);
// rest of imports...
}

...

MyBass.BASS_Init(-1, 44100, 0, IntPtr.Zero, IntPtr.Zero);

Note that pointer parameters should use "IntPtr" rather than "int" or "uint".

ileandros

Quote from: Ian @ un4seenpublic sealed class MyBass
{
[DllImport("bass.dll")]
public static extern bool BASS_Init(int device, uint freq, uint flags, IntPtr win, IntPtr clsid);
// rest of imports...
}

...

MyBass.BASS_Init(-1, 44100, 0, IntPtr.Zero, IntPtr.Zero);

Note that pointer parameters should use "IntPtr" rather than "int" or "uint".
That's the way I was calling it.

Are they going to be away on holidays for long?!

Thank you anyway

mcooper

Quote from: Ian @ un4seenThat looks more promising. So that I can locate where in BASS.DLL the call stack frames are, please reproduce the problem again and this time also get BASS.DLL's address from the "Modules" list.

   msvcr120_app.dll!68855964()   Unknown
    bass.dll!68aa1ff2()   Unknown
    bass.dll!68aa4762()   Unknown
    bass.dll!68aa8d70()   Unknown
    bass.dll!68ac05e2()   Unknown
    [External Code]   
    Bass.Net.WinStore.ni.dll!68b290a2()   Unknown
    WpBass.ni.exe!6f45a2a6()   Unknown
    [External Code]   

bass.dll address: 68AA0000-68AFE000
Bass.Net.WinStore.ni.dll address: 68B00000-68B6C000   

Does that help?
   

Ian @ un4seen

Strange, those call stack locations don't seem to quite match with the BASS.DLL that I have. Are you using the BASS.DLL v2.4.11.12 for Windows Phone dated 15:16 18-08-2015? Anyway, as the crash appears to be happening within a BASS_StreamCreateURL call, I will send you a debug BASS version to check what's happening in there.

mcooper

#46
Quote from: Ian @ un4seenStrange, those call stack locations don't seem to quite match with the BASS.DLL that I have. Are you using the BASS.DLL v2.4.11.12 for Windows Phone dated 15:16 18-08-2015? Anyway, as the crash appears to be happening within a BASS_StreamCreateURL call, I will send you a debug BASS version to check what's happening in there.

I was actually using BASS.DLL v2.4.11.11.  I can't repro the initial issue with v2.4.11.12, so I'll do some further testing.

I switched to your debug version and the app crashed during launch.

mcooper

I'm trying to play audio from a background task in windows phone 8.1 (https://code.msdn.microsoft.com/windowsapps/BackgroundAudio-63bbc319#content) using Bass.   I've modified the sample from MSDN and it plays audio, but the playback stops when the app is backgrounded or if the screen is locked.  Should this be supported, or is there anything special I need to do to get it to work?

Matt

Ian @ un4seen

Did you place the BASS calls in the background task, ie. the MyBackgroundAudioTask class? I had a quick go at that myself and it seemed to work OK, ie. BASS playback continued after leaving the app (pressing the back/start/search buttons). What I did was add a BASS_Init call (and BassNet.Registration) to the MyBackgroundAudioTask.Run function, and replace the MyBackgroundAudioTask.StartPlayback function's content with BASS stream creation and BASS_ChannelPlay calls.

mcooper

Quote from: Ian @ un4seenDid you place the BASS calls in the background task, ie. the MyBackgroundAudioTask class? I had a quick go at that myself and it seemed to work OK, ie. BASS playback continued after leaving the app (pressing the back/start/search buttons). What I did was add a BASS_Init call (and BassNet.Registration) to the MyBackgroundAudioTask.Run function, and replace the MyBackgroundAudioTask.StartPlayback function's content with BASS stream creation and BASS_ChannelPlay calls.

Yes, I did.  Tried it again, and it seems to play in the background while debugging, but if I detach the debugger or start the app without debugging, then the audio stops when leaving the app, and resumes when the app is brought back to the foreground. Were you debugging when you tried it?

Ian @ un4seen

Oh yes, you're right, the sound does indeed stop when not running under the debugger. If I keep the example's existing playback and add BASS on top of it (ie. add to rather than replace MyBackgroundAudioTask.StartPlayback), then the BASS playback does also continue in the background, so I guess there's something somewhere in the example's code that's enabling the background sound. I'll try to find out what that is. Let me know if you find it in the meantime.

mcooper

Quote from: Ian @ un4seenOh yes, you're right, the sound does indeed stop when not running under the debugger. If I keep the example's existing playback and add BASS on top of it (ie. add to rather than replace MyBackgroundAudioTask.StartPlayback), then the BASS playback does also continue in the background, so I guess there's something somewhere in the example's code that's enabling the background sound. I'll try to find out what that is. Let me know if you find it in the meantime.

Its the use of the BackgroundMediaPlayer class in the background task that enables the audio to continue in the background.  I assume you're using some other audio playback api from BASS?

Ian @ un4seen

BASS uses WASAPI. The fact that the BASS playback does continue in the background if the example's playback code is retained alongside it seems to suggest that it's not the output system that's important. Perhaps BackgroundMediaPlayer is internally activating something to enable background playback, in which case perhaps it is also possible to activate that directly outside of BackgroundMediaPlayer?

Microsoft's documentation states that SystemMediaTransportControls is needed for background audio. I tried adding that to a little test app, but it didn't seem to enable background playback, so I guess there is more too it than that.

mcooper

Quote from: Ian @ un4seenBASS uses WASAPI. The fact that the BASS playback does continue in the background if the example's playback code is retained alongside it seems to suggest that it's not the output system that's important. Perhaps BackgroundMediaPlayer is internally activating something to enable background playback, in which case perhaps it is also possible to activate that directly outside of BackgroundMediaPlayer?

Microsoft's documentation states that SystemMediaTransportControls is needed for background audio. I tried adding that to a little test app, but it didn't seem to enable background playback, so I guess there is more too it than that.

You also need a background task with audio capabilities (as documented in that sample), but I left all that code in and it still didn't seem to work.

LeTonton

Hi mcooper and Ian @ un4seen, I search to adapt BackgroundMediaPlayer sample with BASS and i look this topic when i see that you search the same  :D But me for the moment I just try to run BASS in this progamm (just run, not necessarily in Background). It's possible to look your source code?

Ian @ un4seen

There aren't any examples for Windows Store/Phone yet, but the BASS API (eg. BASS.H) is the same on all platforms, so you could have a look at the examples included in the Win32/Linux/OSX packages for some ideas. Probably the trickiest part for Windows Store/Phone is setting up the project, eg. to use the correct BASS.DLL version for each of the X86/X64/ARM architectures in a universal app. The best way I've found for that so far is to manually edit the project file in a text editor. For example, a "Universal Windows" app could have this in the project's VCPROJ file:

  <ItemGroup Condition="'$(Platform)' == 'x86'">
    <Content Include="<basspath>\Windows 8\x86\bass.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup Condition="'$(Platform)' == 'x64'">
    <Content Include="<basspath>\Windows 8\x64\bass.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup Condition="'$(Platform)' == 'ARM'">
    <Content Include="<basspath>\Windows 10\arm\bass.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

Replace "<basspath>" with the location of the BASS files. If you use any add-ons, you would add "Content" elements for them too. You may also need to add references to the Visual C++ runtimes as described in the 1st post, and BASS.Net if you're using that. In the case of a "Universal Windows 8.1" app, the modification could be made in the project's SHARED.PROJITEMS file instead, and "Windows 10" in the ARM platform's "Content" element should be replaced with "Windows Phone".

If you do use BASS.Net, be sure to call the BassNet.Registration function before you make any BASS function calls. You can get a "freeware" registration key for that from the BASS.Net website.

Ian @ un4seen

A Windows Store version of the NETRADIO example has been added to the package in the 1st post. An updated BASS version is also up, which fixes a bug that would sometimes cause a crash when freeing an internet stream. This update also slightly changes the behaviour of the BASS_CONFIG_NET_AGENT/PROXY config options to support both ANSI and Unicode settings (see the 1st post for details).

Unknown

Quote from: Ian @ un4seen  <ItemGroup Condition="'$(Platform)' == 'x86'">
    <Content Include="<basspath>\Windows 8\x86\bass.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup Condition="'$(Platform)' == 'x64'">
    <Content Include="<basspath>\Windows 8\x64\bass.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup Condition="'$(Platform)' == 'ARM'">
    <Content Include="<basspath>\Windows 10\arm\bass.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
I did it this way, but it doesn't work for me. Even a direct copy of bass.dll to the associated App directory is ignored. I always get this error:

Ausnahme ausgelöst: "System.DllNotFoundException" in Bass.Net.WinStore.dll
Ausnahme ausgelöst: "System.Exception" in Bass.Net.WinStore.dll
Ausnahme ausgelöst: "System.TypeInitializationException" in Bass.Net.WinStore.dll
The type initializer for 'Un4seen.Bass.Bass' threw an exception.

Any idea?

Ian @ un4seen

Is your project for a "Universal Windows" app or a "Universal Windows 8.1" app? The project needs to be setup a bit differently in each case. The quoted block is for a "Universal Windows" app. If that is what you're creating, then first check that you have correctly replaced "<basspath>" with the full path of where you've extracted the BASS files. Also check that you have added a reference to the "Microsoft Visual C++ 2013 Runtime Package for Windows Universal" package.

Unknown

Yes, it's an Universal App. The libs are in the Assets folder, so my project file looks like:
 <ItemGroup Condition="'$(Platform)' == 'x86'">
    <Content Include="Assets\libs\x86\bass.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="Assets\libs\x86\Bass.Net.WinStore.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="Assets\libs\x86\bassmidi.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="Assets\libs\x86\bassmix.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
I also have added a reference to Microsoft Visual c++ 2015 Runtime for Universal Windows Platform Apps (i'm on Windows 10). A Replacement with the "full" path also doesn't have any effect.