Answered
0
0

Hi,

So I am working on a music player using FMOD. I am currently using the natively given C# Wrapper and everything seems to work fine. There are no exceptions, no errors. But when I play some music on Windows Phone and minimize the app, the music just pauses. On going back to the app, the music resumes.

It is to be noted that all related capabilities are on (i.e. backgroundMediaPlayback). The weird thing is once I leave the background and go back to the app and try again minimizing the app, the music continues without a hitch.

I debugged the code quite a bit and found that the app was being suspending as soon as it hit the background. How do I avoid suspending the app?

One other thing to note is that BASS.NET works without the use of BackgroundTasks and on the same code. I register my manual SMTC too but no luck so far.

Please help.

Some code:

//create a stream of the new track
Result loadResult = _fmodSys.CreateStream(mediaFile.Path, _isMobile ? Mode.LowMem & Mode.IgnoreTags : Mode.Default, out _fmodSound);

//load the stream into the channel but don't play it yet.
loadResult = _fmodSys.PlaySound(_fmodSound, null, true, out _fmodChannel);

here’s my SMTC code:

_smtc = SystemMediaTransportControls.GetForCurrentView();
_smtc.ButtonPressed += _smtc_ButtonPressed;
_smtc.IsEnabled = true;
_smtc.IsPlayEnabled = true;
_smtc.IsPauseEnabled = true;
_smtc.IsStopEnabled = true;
_smtc.IsNextEnabled = true;
_smtc.IsPreviousEnabled = true;
_smtc.PlaybackStatus = MediaPlaybackStatus.Closed;
_smtc.AutoRepeatMode = MediaPlaybackAutoRepeatMode.Track;

I hope you can give a hint as to how I can possibly continue the playback when in background.

NOTE: Background Audio works fine on Windows 10 PC.

  • Mathew Block

    Could you tell us the version number of your Windows 10 phone?

  • Mathew Block

    Also could you clarify which version of FMOD you are using, and whether this is with the FMOD UWP package or the FMOD WinStore / WinPhone package?

  • Arkane

    Sorry for not replying earlier. I was very busy.

    I am using Microsoft Lumia 540 with Windows 10 Creators Update installed.
    I have tried this with FMOD 1.09 and 1.08.
    This is with FMOD UWP package.

  • Mathew Block

    I’ve just tested this internally and it works here. One gotcha was I had to set the “Target Platform Version” in Visual Studio to 14393 (or higher) to get it running (that was when the feature was added). If you are still having trouble could you send us a simple repro of the issue to support@fmod.com.

  • Arkane

    Hi, thanks for replying. I couldn’t test this as whenever I try to load a music file it gives me FMOD_ERR_FILE_BAD error. I tested with FMOD UWP 1.10.1.

  • You must to post comments
Best Answer
1
0

I’ve just tested this internally and it works here. One gotcha was I had to set the “Target Platform Version” in Visual Studio to 14393 (or higher) to get it running (that was when the feature was added). If you are still having trouble could you send us a simple repro of the issue to support@fmod.com.

  • Mathew Block

    Can you link with the logging version of FMOD and provide the log output from app start up to the error message?

  • Arkane

    I can access files from here: C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Universal Windows Platform\api\lowlevel\examples\media
    and my application LocalFolder.

    I use all the recommended APIs to get access to files such as opening using the FilePicker, using Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file); etc. but it never works if the file is not in the above mentioned directories.

  • Mathew Block

    FMOD operates with files using the CreateFile2 API internally which means it is bound by the restrictions imposed. From the Microsoft API docs: “You can open only files or directories inside the ApplicationData.LocalFolder or Package.InstalledLocation directories”

    There are several options available to you however:
    1. Copy the file into the application local folder.
    2. Read the file into memory and pass the memory to FMOD.
    3. Override our file callbacks to service the read requests directly.

    As a side note, Microsoft have announced that the next release of Windows will work they way you expect and thus FMOD will transparently “just work”.

  • Arkane

    Can you provide a simple example of a custom file system?

  • Mathew Block

    I’ve given a simple example as an additional answer.

0
0

The basics of setting up a custom filesystem override are as follows. This example uses fopen to implement the I/O, to use this with UWP files it would have to be changed to support the StorageFile API.

Implement the callbacks:

FMOD_RESULT F_CALL myopen(const char *name, unsigned int *filesize, void **handle, void* /*userdata*/)
{
    FILE *fp = fopen(name, "rb");
    if (!fp)
    {
        return FMOD_ERR_FILE_NOTFOUND;
    }

    fseek(fp, 0, SEEK_END);
    *filesize = ftell(fp);
    fseek(fp, 0, SEEK_SET);

    *handle = fp;

    return FMOD_OK;
}

FMOD_RESULT F_CALL myclose(void *handle, void* /*userdata*/)
{
    fclose((FILE *)handle);

    return FMOD_OK;
}

FMOD_RESULT F_CALL myread(void *handle, void *buffer, unsigned int sizebytes, unsigned int *bytesread, void* /*userdata*/)
{
    *bytesread = (int)fread(buffer, 1, sizebytes, (FILE *)handle);
    if (*bytesread < sizebytes)
    {
        return FMOD_ERR_FILE_EOF;
    }

    return FMOD_OK;
}

FMOD_RESULT F_CALL myseek(void *handle, unsigned int pos, void* /*userdata*/)
{
    assert(handle);

    fseek((FILE *)handle, pos, SEEK_SET);

    return FMOD_OK;
}

Set the FMOD system to use your callbacks:

result = system->setFileSystem(myopen, myclose, myread, myseek, nullptr, nullptr, 2048);
ERRCHECK(result);
  • Arkane

    Hi,

    Putting this aside for the moment, I tested Background Audio with v10.01 and still it doesn’t work. I targeted Fall Creators Update but still the app is suspended as soon as it hits background.

  • Arkane

    The other weird thing that happens is that only the first time when you minimize the app (in mobile), the playback stops. When you play it again from the SMTC, everything starts working.

  • Mathew Block

    Can you send a small example to support@fmod.com that demonstrates this issue?

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.