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. WPF
  4. WPF MediaPlayer and threading

WPF MediaPlayer and threading

Scheduled Pinned Locked Moved WPF
csharphtmlwpfdesignhelp
6 Posts 2 Posters 21 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.
  • Y Offline
    Y Offline
    Yoyosch
    wrote on last edited by
    #1

    I`m trying to play a short sound using MediaPlayer class. I`m using the following code snippet: MediaPlayer mp = new MediaPlayer(); mp.Open(new Uri(@"C:\...\Dom.wav")); mp.Volume = 1D; mp.Play(); It goes well, but when I try to play this sound in my form (where I have several endless transformations), it never gets played. I suppose that the reason is that it is to be played on the same thread that UI works. And as the UI works all the time (because of endless transformations), my .wav never gets enough CPU to be played. So I tried to launch it on separate thread. It didn`t help either. The only solution I found is to add a sleep after this: MediaPlayer mp = new MediaPlayer(); mp.Open(new Uri(@"C:\...\Dom.wav")); mp.Volume = 1D; mp.Play(); Thread.Sleep(1500); But this looks terrible. Could anyone give me another solution?

    C 1 Reply Last reply
    0
    • Y Yoyosch

      I`m trying to play a short sound using MediaPlayer class. I`m using the following code snippet: MediaPlayer mp = new MediaPlayer(); mp.Open(new Uri(@"C:\...\Dom.wav")); mp.Volume = 1D; mp.Play(); It goes well, but when I try to play this sound in my form (where I have several endless transformations), it never gets played. I suppose that the reason is that it is to be played on the same thread that UI works. And as the UI works all the time (because of endless transformations), my .wav never gets enough CPU to be played. So I tried to launch it on separate thread. It didn`t help either. The only solution I found is to add a sleep after this: MediaPlayer mp = new MediaPlayer(); mp.Open(new Uri(@"C:\...\Dom.wav")); mp.Volume = 1D; mp.Play(); Thread.Sleep(1500); But this looks terrible. Could anyone give me another solution?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you just want to play sound, look into the managed DirectX classes instead.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      Y 1 Reply Last reply
      0
      • C Christian Graus

        If you just want to play sound, look into the managed DirectX classes instead.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        Y Offline
        Y Offline
        Yoyosch
        wrote on last edited by
        #3

        Don`t tell me it can`t be done using MediaPlayer class...

        C 1 Reply Last reply
        0
        • Y Yoyosch

          Don`t tell me it can`t be done using MediaPlayer class...

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I don't know, but I know that class is slow, and it seems to me like overkill

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          Y 1 Reply Last reply
          0
          • C Christian Graus

            I don't know, but I know that class is slow, and it seems to me like overkill

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            Y Offline
            Y Offline
            Yoyosch
            wrote on last edited by
            #5

            Using so enormous technology as DirectX to play 5-second simple sound is even bigger overkill. Thanks for advice however.

            C 1 Reply Last reply
            0
            • Y Yoyosch

              Using so enormous technology as DirectX to play 5-second simple sound is even bigger overkill. Thanks for advice however.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Not really - it's just using built in stuff that is there already.

              Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              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