This project has moved and is read-only. For the latest updates, please go here.

PhoneSM and Player Framework and switching songs via Databinding

Dec 16, 2014 at 10:01 PM
Hi Henric and all,

I'm successfully using PhoneSM in combination with the Media Player Framework 2.0 in a universal Windows app (currently testing things only on WP though). An HLS audiostream plays back just nicely, however I can't switch to another song. Here's the XAML code I'm using:
    xmlns:mmppf="using:Microsoft.PlayerFramework"
    xmlns:phonesm="using:SM.Media.MediaPlayer"

            <mmppf:MediaPlayer Source="{Binding TrackPreviewUrl}" AutoPlay="True" AreTransportControlsEnabled="True" HorizontalAlignment="Stretch" MinWidth="380" MediaEnded="MediaElement_MediaEnded" CurrentStateChanged="MediaElement_StateChanged" MediaOpened="MediaElement_MediaOpened" MediaFailed="onMediaElementFailed" x:Name="mediaElement">
                <mmppf:MediaPlayer.Plugins>
                    <phonesm:StreamingMediaPlugin />
                </mmppf:MediaPlayer.Plugins>
            </mmppf:MediaPlayer>
If I now switch to another URL in the TrackPreviewUrl within the ViewModel, I get the following error message:
WinRtMediaStreamConfigurator.MediaStreamSourceOnPaused()
StreamingMediaPlugin MediaEnding ID 1 IsCompleted False
StreamingMediaPlugin MediaEnded ID 1 IsCompleted False
StreamingMediaPlugin MediaClosed ID 1 IsCompleted False
MediaStreamFacadeBase.StopAsync()
WinRtMediaStreamConfigurator.MediaStreamSourceOnClosed() reason: Done
MediaStreamFacadeBase.StopMediaAsync()
StreamingMediaPlugin MediaLoading
WinRtMediaStreamConfigurator.CompletePlayingTask() reason: Done
TsMediaManager.StopMediaAsync()
TsMediaManager.CloseAsync()
'Enough.UpNext.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:\windows\system32\en-US\System.debug.resources.DLL'. Module was built without symbols.
TsMediaManager.SetMediaState() Playing -> Closing
TsMediaManager.ReportState() state Closing message 
MediaStreamFacadeBase.MediaManagerOnStateChange() to Closing: 
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
MediaPlayer cancellation token is already canceled
---- Assert Long Message ----


    at <PlayerOnMediaLoading>d__8.MoveNext()  
    at AsyncVoidMethodBuilder.Start(TStateMachine& stateMachine)  
    at StreamingMediaPlugin.PlayerOnMediaLoading(Object sender, MediaPlayerDeferrableEventArgs mediaPlayerDeferrableEventArgs)  
    at <OnMediaLoadingAsync>d__47.MoveNext()  
    at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  
    at MediaPlayer.OnMediaLoadingAsync(MediaLoadingEventArgs args)  
    at <OnMediaLoadingAsync>d__40.MoveNext()  
    at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  
    at MediaPlayer.OnMediaLoadingAsync(Uri source)  
    at <<SetSource>b__2c>d__31.MoveNext()  
    at AsyncVoidMethodBuilder.Start(TStateMachine& stateMachine)  
    at <>c__DisplayClass2e.<SetSource>b__2c()  
    at MediaPlayer.RegisterApplyTemplateAction(Action action)  
    at MediaPlayer.SetSource(Uri source)  
    at MediaPlayer.OnSourceChanged(Uri newValue)  
    at MediaPlayer.<.cctor>b__147(MediaPlayer t, Uri o, Uri n)  
    at <>c__DisplayClass73`1.<RegisterDependencyProperty>b__72(MediaPlayer t, T o, T n)  
    at <>c__DisplayClass6a`2.<RegisterDependencyProperty>b__69(DependencyObject d, DependencyPropertyChangedEventArgs e)  
    at PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)  
    at BaseViewModel.RaisePropertyChanged(String name)  
    at EventViewModel.set_TrackPreviewUrl(String value)  
    at <playTrack>d__1b.MoveNext()  
    at MoveNextRunner.InvokeMoveNext(Object stateMachine)  
    at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
    at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
    at MoveNextRunner.Run()  
    at <>c__DisplayClass1.<OutputAsyncCausalityEvents>b__0()  
    at ContinuationWrapper.Invoke()  
    at <>c__DisplayClass1.<OutputWaitEtwEvents>b__0()  
    at ContinuationWrapper.Invoke()  
    at AwaitTaskContinuation.InvokeAction(Object state)  
    at AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)  
    at SynchronizationContextAwaitTaskContinuation.Run(Task task, Boolean canInlineContinuationTask)  
    at Task.FinishContinuations()  
    at Task.FinishStageThree()  
    at Task`1.TrySetResult(TResult result)  
    at AsyncTaskMethodBuilder`1.SetResult(TResult result)  
    at <LocationAsync>d__2b.MoveNext()  
    at MoveNextRunner.InvokeMoveNext(Object stateMachine)  
    at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
    at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
    at MoveNextRunner.Run()  
    at <>c__DisplayClass1.<OutputAsyncCausalityEvents>b__0()  
    at ContinuationWrapper.Invoke()  
    at <>c__DisplayClassa.<OnCompletedInternal>b__1(Object state)  
    at Invoker.InvokeCore()  
    at Invoker.InvokeInContext(Object thisObj)  
    at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
    at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
    at Invoker.Invoke()  

TsMediaManager.CloseCleanupAsync()
WinRtMediaStreamConfigurator.CloseAsync()
TsMediaManager.CloseReadersAsync() closing readers
The thread 0x1188 has exited with code 259 (0x103).
BufferingManager.Flush()
MediaStreamFacadeBase.StopAsync()
MediaStreamFacadeBase.StopMediaAsync()
BufferingManager.Shutdown()
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.ni.dll
TsMediaManager.CloseReadersAsync() readers closed
TsMediaManager.DisposeReaders()
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.ni.dll
TsMediaManager.DisposeReaders() completed
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.ni.dll
TsMediaManager.SetMediaState() Closing -> Closed
TsMediaManager.ReportState() state Closed message 
MediaStreamFacadeBase.MediaManagerOnStateChange() to Closed: 
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.ni.dll
MediaStreamFacadeBase.StopMediaAsync()
StreamingMediaPlugin MediaLoading deferral.Cancel()
TsMediaManager.CloseAsync() completed
TsMediaManager.CloseAsync()
TsMediaManager.SetMediaState() Closed -> Closing
TsMediaManager.ReportState() state Closing message 
If I use URLs without HLS and without the StreamingMediaPlugin I can switch to different URLs without a problem. So it seems that in the combination of the Media Player and PhoneSM something breaks down. Any idea how I can fix this?

Many thanks in advance,
Yours
Robert
Coordinator
Dec 17, 2014 at 12:15 AM
The StreamingMediaPlugin gets a URL from Player Framework and translates it to a MediaStreamSource before passing it back to Player Framework. Since this can take a while, Player Framework supplies a cancellation token. Unfortunately, what you are describing might be a manifestation of this problem: "MediaPlayerDeferrableEventArgs's DeferrableOperation gets old CancellationTokenSource". The "MediaPlayer cancellation token is already canceled" assertion you are seeing is what one would expect to see if this is the case.

Could you try setting the Source to null before you set it to the next actual URL? If that gets things working, it would suggest that the problem described above is indeed the cause.

What to do about it is another matter...
Dec 17, 2014 at 11:24 AM
Hi Henric,

Many thanks for your quick answer - you're doing an outstanding job here! Aaaand your advice also works, by setting the Source to null in between I am able to play back several titles without a problem. Right now this completely solves my problem, so thanks again!

Yours
Robert