Xamarin.iOS MPMediaItem.AssetURL始终为null(Xamarin.iOS MPMediaItem.AssetURL is always null)

系统教程 行业动态 更新时间:2024-06-14 16:58:30
Xamarin.iOS MPMediaItem.AssetURL始终为null(Xamarin.iOS MPMediaItem.AssetURL is always null)

在Xamarin.iOS中,MPMediaItem.AssetURL始终为任何项返回null。 我研究了一下,然后尝试使用Objective-C句柄。 所以我用过

NSUrl url = new NSUrl(item.ValueForProperty(MPMediaItem.AssetURLProperty).Handle);     
 

上面的代码尝试获取AssetURL属性的objective-c句柄,然后将其转换为Managed表示。 有用!

所以,我决定研究单声道实现。 Mono已将其实施为 -

return this.ValueForProperty (MPMediaItem.AssetURLProperty) as NSUrl;
 

我手动尝试了这个,它实际上返回null。 所以,这意味着Xamarin的实现是错误的。 然而,有一件事让我感到困惑。 在我运行正确的代码(第一个代码段)之后,第二个剪辑不会返回null,而是正确的值。 我的第一个片段可以改变第二个片段的行为有什么可能?

In Xamarin.iOS, MPMediaItem.AssetURL always returns null for any item. I researched a bit, then tried to use the Objective-C handle. So I used

NSUrl url = new NSUrl(item.ValueForProperty(MPMediaItem.AssetURLProperty).Handle);     
 

Above code tries to get the objective-c handle of AssetURL property and then converts that to Managed representation. It works!

So, I decided to look into mono implementation. Mono has implemented it as -

return this.ValueForProperty (MPMediaItem.AssetURLProperty) as NSUrl;
 

I tried this manually and it is actually returning null. So, that means Xamarin implementation is wrong. However, one thing flummoxed me. After I ran my correct code (first snippet), the second snipped doesn't return null, but correct value. What possibiliy could my first snippet have done to alter the behaviour of second snippet ?

最满意答案

听起来像从ValueForProperty返回的句柄不是NSUrl ,而as cast使其为null (例如,它可能是内部/私有类型)。

我的第一个片段可能会改变第二个片段的行为?

简单。 您使用此特定句柄值创建了NSUrl 。 如果您尝试再次获取它,将返回相同的实例(除非它被垃圾收集),因此我们有一个托管实例代表一个本机实例。

It sounds like the handle that is returned from ValueForProperty was not an NSUrl and the as cast makes it null (e.g. it could be an internal/private type).

What possibly could my first snippet have done to alter the behaviour of second snippet ?

Simple. You created an NSUrl with this specific handle value. If you try to get it again the same instance will be returned (unless it was garbage collected) so we have a single managed instance representing a single native instance.

更多推荐

本文发布于:2023-04-15 03:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/74509ce17f490898e8250b0a9835979f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:iOS   Xamarin   MPMediaItem   null   AssetURL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!