Playing a list of files on after the other.
-
Hi Currently I have written my application to play one media file at a time: 1. Open file dialog is used to select a file 2. File is copied into the media source. mediaElement1.source = (new Uri(file)) 3. Then it is played from start to end. mediaElement1.Play(); This works fine, however now I would like to play files which have been loaded into a list box one after the other. I have tried using the foreach loop to attempt to access each file by its index and well looking through the code (using F11) found that all that happened was it would try and load all the files one after the other with out waiting for the current file to complete playing. How do I get it to wait until the current file has finished playing? here is the code that has gone wrong: int x = lstBx.Items.Count; for(int i = 0; i<=x; ++1) { string cMedia = lstBx.Items[i]as string; mediaElement1.Source = (new Uri(cMedia)); mediaElement1.Play(); } Also bearing in mind that the ideal condition for the media element to have completed playing a file is: mediaElement1.Position == mediaElement1.Position.Totalseconds Please note that the application is being developed under WPF.
-
Hi Currently I have written my application to play one media file at a time: 1. Open file dialog is used to select a file 2. File is copied into the media source. mediaElement1.source = (new Uri(file)) 3. Then it is played from start to end. mediaElement1.Play(); This works fine, however now I would like to play files which have been loaded into a list box one after the other. I have tried using the foreach loop to attempt to access each file by its index and well looking through the code (using F11) found that all that happened was it would try and load all the files one after the other with out waiting for the current file to complete playing. How do I get it to wait until the current file has finished playing? here is the code that has gone wrong: int x = lstBx.Items.Count; for(int i = 0; i<=x; ++1) { string cMedia = lstBx.Items[i]as string; mediaElement1.Source = (new Uri(cMedia)); mediaElement1.Play(); } Also bearing in mind that the ideal condition for the media element to have completed playing a file is: mediaElement1.Position == mediaElement1.Position.Totalseconds Please note that the application is being developed under WPF.
You can set an event handler for the Completed event on your mediaElement. When that event is fired, load the next file and play it.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001