DubyaDude / WindowsMediaController

Allows developers to more easily get information from and interact with the Windows 10/11 OS media interface. (Also referred to Windows System Media Transport Controls (SMTC))
https://nuget.org/packages/Dubya.WindowsMediaController
MIT License
129 stars 9 forks source link

Using WindowsMediaController as a DLL in Unity #14

Closed nikescar1 closed 1 year ago

nikescar1 commented 1 year ago

I've been trying to create a DLL to use WindowsMediaController in Unity x64 standalone build without success. I assume this is Unity Mono issue but thought I'd ask anyway.

This was my attempt but Unity throws al sort of issues with the imported support DLLs. Maybe there is a different approach I should be taking?

Here is my minimal attempt: `using System; using Windows.Media.Control; using WindowsMediaController; using static WindowsMediaController.MediaManager;

namespace MediaTrackInfo { public class MediaTrack : IDisposable { private MediaManager mediaManager; private string currentTrackName;

    public MediaTrack()
    {
        mediaManager = new MediaManager();

        mediaManager.OnAnyMediaPropertyChanged += MediaManager_OnAnyMediaPropertyChanged;

        mediaManager.Start();
    }

    private void MediaManager_OnAnyMediaPropertyChanged(MediaSession mediaSession, GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties)
    {
        currentTrackName = $"{mediaProperties.Artist} - {mediaProperties.Title}";
    }

    public string GetCurrentMediaTrack()
    {
        return currentTrackName;
    }

    public void Dispose()
    {
        mediaManager?.Dispose();
    }
}

} `

DubyaDude commented 1 year ago

Hi, this does require the lib to access WinRT (not entirely sure how that's handled in Unity), I'll be taking a closer look later this weekend but that may be a helpful lead for ya.

Also please do show the errors you received.

DubyaDude commented 1 year ago

After more research, it seems you'll need to look more into how to allow Unity to access Windows Runtime (WinRT). It seems a bit tricky to get working, however, I'm not familiar with that aspect of the UnityEngine so you'll need to do more digging there.

You may be better off asking questions regarding the imports on unity support forums as my knowledge is very limited here.

DubyaDude commented 1 year ago

Yup, after more research this seems to be a better question for unity-focused support regarding utilizing Windows Runtime.

One other way you get around it is to create a separate executable that the game would launch and be the parent of, then communicate between the two in whatever fashion you'd like. Like STDIN and STDOUT for example.

However, don't think there's much else I could add to this so I'll close this. If you feel differently don't be afraid to re-open.