UnityPlugin-AVProVideo icon indicating copy to clipboard operation
UnityPlugin-AVProVideo copied to clipboard

Ability to override video API via script

Open v2k opened this issue 3 years ago • 1 comments

If I'm not mistaken, there doesn't seem to be a way to override the video API. Would be nice to be able to set the video API in script. Unfortunately there are some blockers in the code that prevent this:

           private BaseMediaPlayer.CreateMediaPlayer(_videoApi);

Also, the options are get only:

	public OptionsWindows PlatformOptionsWindows { get { return _optionsWindows; } }

BaseMediaPlayer CreateMediaPlayer() is virtual, but nothing is really exposed to take advantage of this. _optionsWindows could also be protected as a solution.

Ability to do something like this, where videoApi could be set ahead of the creation of the media player:

public class AVProVideoAPI : MediaPlayer
{
    [SerializeField]
    public Windows.VideoApi _videoApi = Windows.VideoApi.MediaFoundation;

    public SetAPI(Windows.VideoApi api) { _videoApi = api; }

    public override BaseMediaPlayer CreateMediaPlayer()
    {
        BaseMediaPlayer mediaPlayer = null;

#if (UNITY_EDITOR_WIN) || (!UNITY_EDITOR && UNITY_STANDALONE_WIN)
        var options = PlatformOptionsWindows;
        options.videoApi = _videoApi;

        mediaPlayer = BaseMediaPlayer.CreateMediaPlayer(_videoApi);
        if (mediaPlayer == null)
        {
            mediaPlayer = base.CreateMediaPlayer();
        }
#else
        mediaPlayer = base.CreateMediaPlayer();
#endif

        return mediaPlayer;
    }
}

The obvious alternative is to edit the code, but it would be nice to avoid that.

v2k avatar Aug 03 '22 15:08 v2k

To confirm, does setting the videoApi in script currently not actually change the API? We've been trying to use 'VideoPlayer.PlatformOptionsWindows.videoApi = Windows.VideoApi.DirectShow' to change from WinRT in our startup script depending on playback machine (Windows) - does this have no effect currently, and only set from the Editor VideoAPI selection?

heritageint avatar Jun 20 '23 12:06 heritageint