Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Playing a list of files on after the other.

Playing a list of files on after the other.

Scheduled Pinned Locked Moved C#
questioncsharpdatabasewpf
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tichaona J
    wrote on last edited by
    #1

    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.

    A 1 Reply Last reply
    0
    • T Tichaona J

      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.

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      You might want to ask this question in the WPF forum or in Quick Answers (but not both... cross-posting is frowned upon here). My guess, however, is that there is an event for when the video stops playing. Hook up to that event and detect if the video played back fully (i.e., that the user didn't manually stop it) using the Position.TotalSeconds property (if that's a real property). If you can't find any sort of event like that (though I'm sure one must exist), then I'd say just keep polling in a loop or on a timer to see if the TotalSeconds has been reached yet and then play the next item. You could also create a timer that assumes the video plays instantly and waits for the total duration of the video, then starts the next video and repeats that process until it reaches the last video.

      [Forum Guidelines]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups