Home get reference of new dynamicly created MediaPlayer instance
Reply: 0

get reference of new dynamicly created MediaPlayer instance

user937
1#
user937 Published in May 25, 2018, 11:03 am

I am trying to create a C# app that have dynamically created number of buttons , each button have Click_Handler that if clicked plays a sound depending on a file that the user specified earlier.

every thing is working and all the sounds plays at the same time using this simple function

private void playSound (string path)
{
 if (System.IO.File.Exists(path))
            {
                System.Windows.Media.MediaPlayer mp = new System.Windows.Media.MediaPlayer();
                mp.Open(new System.Uri(path));
                mp.Play();
            }
    }

Now each time a user clicks on any button it will start playing sound using new instance of the MediaPlayer object

My question is how can I get a reference to each newly created MediaPlayer object so that I can manipulate it (stop,pause,timeline ...etc)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.317501 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO