0
votes

I am working on some library written for UWP apps. My library has set up:

  • Target version: 16299
  • Min version: 14393

I have MediaPlayerElement there and would like to check video URL. There was introduced Uri property in 15063.

Gets the URI associated with the MediaSource.
Device family: Windows 10 Creators Update (introduced v10.0.15063.0) API contract: Windows.Foundation.UniversalApiContract (introduced v4)

I thought that I could use something like this:

if (ApiInformation.IsPropertyPresent(typeof(MediaSource).FullName, "Uri"))
{
    return (element.MediaPlayer.Source as MediaPlaybackItem)?.Source?.Uri.AbsoluteUri;
}

It actually works but I found out that there is a problem when I include my library to an application which has:

  • target and min version 14393.

Exception thrown: 'System.MissingMethodException' in ..............
Method not found: 'System.Uri Windows.Media.Core.MediaSource.get_Uri()'.

try/catch does not help in this case.

Is there anything else what I can do?

2

2 Answers

1
votes

Put the code that accesses the URI property into a separate method that you call from within the if-statement. This should avoid the missing method exception. This is because of the way .NET resolves the method calls dynamically on a per-method basis. On 14393 it would never get to that new method, so you won't get an exception.

0
votes

There is nothing you could do for that. The only solution is to set the minimum version of you app to 15063 and to ask the target device to update the Windows 10 version to the minimum version or above. I am myself using the MediaPlayerElement in my existing app and was forced to set minimum version to 15063.

Also you cannot catch these kinds of errors using try catch.