Answered by:
Windows Store app PlayTo a list of video, image and audio

Question
-
Hi, Im developing a Windows Store app featuring the Play To function. I have the list of all three types: music, image and video files and expecting the app run like the default Windows 8 Photo app.
To do this I write a recursive function which will go through all items. For each item, I create a MediaElement (for video, audio) or Image (for image) and attach the event PlayToSource.Connection.StateChanged when the connection state is rendering, I get the next item and set it as PlayToSource.Next of current rendering item.
This solution work perfect for images, but when ever 2 videos or music is play to consecutively it go fail. When video 1 ended, as expected video 2 is played but it tends to show up back on the video 1 and resume playing there , and then also there is items on the list, the connection is disconnected automatically after video 1 re-playing finished. It's weird since as I know the play to connection is kept until the user click on disconnect button on charm bar.
Below is the code of my recursive function. The PlayToItem is a custom control which contains a MediaElement control named Media and a Image control named Image.
- Edited by HungLV4 Wednesday, August 21, 2013 1:13 PM
Tuesday, August 20, 2013 7:48 AM
Answers
-
Hello,
I took a quick look at your code today. I notices a number of times where you marshal back to the UI thread asynchronously and don't wait. I can't say for sure but I would recommend that you look through your code and see if you might need to await some of your CoreDispatcher.RunAsync calls. Your issue really does sound like a race condition and this might be the cause.
I hope this helps,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Proposed as answer by James Dailey - MSFTMicrosoft employee, Moderator Monday, August 26, 2013 11:40 PM
- Marked as answer by Xiaoliang Chen - MSFTModerator Tuesday, August 27, 2013 5:12 AM
Monday, August 26, 2013 11:39 PMModerator
All replies
-
Hello,
I don't see anything obviously wrong with your function but I've never seen this done recursively. If you can provide a simple Visual Studio solution that reproduces the issue I would be more than willing to take a look. Please zip up the solution and put in on your SkyDrive then post a link here.
Thanks,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Marked as answer by Xiaoliang Chen - MSFTModerator Tuesday, August 27, 2013 5:13 AM
- Unmarked as answer by Xiaoliang Chen - MSFTModerator Tuesday, September 10, 2013 5:44 AM
Wednesday, August 21, 2013 1:33 AMModerator -
hi James, thanks for your help!
Actually, the whole solution is very big and I don't have the right to post it to anywhere. I'll try to make the sample and post it here ASAP.
Beside, you wrote that "I've never seen this done recursively", so have you ever done this kind of PlayTo before? Could you give me any advice on other way to make the PlayTo like Windows 8 default Photos app? The default Photos app is perfect for both image and video but all the sample PlayTo code from MS sadly doen't mention how to deal with videos, musics, (just the image).
Thanks,
Edit: I upload the sample code here http://sdrv.ms/14FqQ0i. Please take a look. Thanks for your help.
- Edited by HungLV4 Thursday, August 22, 2013 6:49 AM
Wednesday, August 21, 2013 6:25 AM -
anyone can help?Friday, August 23, 2013 4:16 AM
-
Hello,
Sorry for the late reply. I will take a look at this on Monday and let you know what I find.
Thanks,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
Saturday, August 24, 2013 12:18 AMModerator -
Hi, thanks for your help.
I upload the new version of my code here http://sdrv.ms/15b6HFB which is run well in Windows 8.1 Pro Preview edition. But somehow it sadly can't work around in Windows 8. Hope you can give me any advice.
Thanks,
Hung
Monday, August 26, 2013 6:41 AM -
Hello,
I took a quick look at your code today. I notices a number of times where you marshal back to the UI thread asynchronously and don't wait. I can't say for sure but I would recommend that you look through your code and see if you might need to await some of your CoreDispatcher.RunAsync calls. Your issue really does sound like a race condition and this might be the cause.
I hope this helps,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Proposed as answer by James Dailey - MSFTMicrosoft employee, Moderator Monday, August 26, 2013 11:40 PM
- Marked as answer by Xiaoliang Chen - MSFTModerator Tuesday, August 27, 2013 5:12 AM
Monday, August 26, 2013 11:39 PMModerator