XamarinCommunityToolkit icon indicating copy to clipboard operation
XamarinCommunityToolkit copied to clipboard

[Bug] MediaElement exception when fast changing Source few times

Open RadoslawKubas opened this issue 4 years ago • 4 comments

Description

If fast changing MediaElement.Source value on iOS it is possible to see exception (on device and simulator)

System.ArgumentException: TimeSpan does not accept floating point Not-a-Number values.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: TimeSpan does not accept floating point Not-a-Number values.
  at System.TimeSpan.Interval (System.Double value, System.Int32 scale) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/TimeSpan.cs:244 
  at System.TimeSpan.FromSeconds (System.Double value) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/TimeSpan.cs:271 
  at Xamarin.CommunityToolkit.UI.Views.MediaElementRenderer.get_Position () [0x0006f] in <2e7164d1a00d4fdc92a08e2145594ead>:0 
  at Xamarin.CommunityToolkit.UI.Views.MediaElementRenderer.ObserveRate (Foundation.NSObservedChange e) [0x0004b] in <2e7164d1a00d4fdc92a08e2145594ead>:0 
  at Foundation.NSObject+Observer.O
bserveValue (Foundation.NSString keyPath, Foundation.NSObject ofObject, Foundation.NSDictionary change, System.IntPtr context) [0x0001d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.6.0.15/src/Xamarin.iOS/Foundation/NSObject2.cs:804 
--- End of stack trace from previous location where exception was thrown ---

  at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend(intptr,intptr)
  at AVFoundation.AVPlayer.Play () [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.6.0.15/src/Xamarin.iOS/AVFoundation/AVPlayer.g.cs:218 
  at Xamarin.CommunityToolkit.UI.Views.MediaElementRenderer.Play () [0x000b2] in <2e7164d1a00d4fdc92a08e2145594ead>:0 
  at Xamarin.CommunityToolkit.UI.Views.MediaElementRenderer.UpdateSource () [0x001c3] in <2e7164d1a00d4fdc92a08e2145594ead>:0 
  at Xamarin.CommunityToolkit.UI.Views.MediaElementRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x000a7] in <2e7164d1a00d4fdc92a08e2145594ead>:0 
  at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:266 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:362 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:510 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms
.Core\BindableObject.cs:446 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00226] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:160 
  at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:56 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__49_0 () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:762 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x000cb] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:773 
  at Xamarin.Forms.BindingExpression+WeakPropertyChangedProxy.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00012] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:666
2021-01-11 07:09:12
.441782+0100 TipCalculator.iOS[86877:6755116] 
  at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
  at Prism.Mvvm.BindableBase.OnPropertyChanged (System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in /_/src/Prism.Core/Mvvm/BindableBase.cs:81 

Steps to Reproduce

  1. Create page with MediaElement.Source binded to string property (web hosted video).
  2. Change fast binded property value to the new video few times.

Expected Behavior

New video starts to play.

Actual Behavior

If you change source slowly it works, but if you change it fast after few times, exception is thrown.

Basic Information

  • Version with issue: 1.0.0
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:
    • iOS: 14.6

RadoslawKubas avatar Jan 11 '21 06:01 RadoslawKubas

I'm facing the same issue. I'm wondering if you found a workaround @RadoslawKubas ? Mine ocurrs when a video is playing and you navigate to another page and then return back.

vhugogarcia avatar Nov 30 '21 21:11 vhugogarcia

@vhugogarcia , your issue sounds to be related to #1769

Kapusch avatar Jan 24 '22 21:01 Kapusch

Hi, I am facing a similar issue. I have the MediaElement contained in a Carousel View. The carousel view has 5 "pages" in total, two of which have a MediaElement inside. The Source for the MediaElement is set via a Binding to a UriMediaSource. The first page with the video is working fine, but after swiping away from the second "page" of the Carousel view I am getting the same exception:

System.ArgumentException: TimeSpan does not accept floating point Not-a-Number values.

This also occurs when swiping slowly.

I have tested hardcoding the source of the MediaElement which worked fine.

Would be grateful for any workarounds.

Tested on : Ios Simulator: IOS 15.2 Xamarin Forms: 5.0.0.2337 Xamarin.CommunityToolkit: 2.0.0 & 1.3.2 & 1.2.0

SchindlerFlorian avatar Jan 31 '22 15:01 SchindlerFlorian

@RadoslawKubas et al, did you find a workaround/fix for this? I am having the same issue, unsure how to bypass

rezamohamed avatar May 23 '22 15:05 rezamohamed

This is fixed. Hopefully they approve this PR quickly.

https://github.com/xamarin/XamarinCommunityToolkit/pull/1899

Enjoy.

mphill avatar Aug 24 '22 00:08 mphill