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. WCF and WF
  4. MediaElement Will Not Play

MediaElement Will Not Play

Scheduled Pinned Locked Moved WCF and WF
csharpdebugginghelpquestion
3 Posts 2 Posters 0 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.
  • B Offline
    B Offline
    BlitzPackage
    wrote on last edited by
    #1

    Good people, Why won't my MediaElement play? When I click play, I hear nothing at all. I created it in C# because I need to change sources - in effect use it as an mp3 player. What am I doing wrong? Here is the code:

    private void OnButtonPlaySongClick(object sender, RoutedEventArgs e)
    {
    MediaElement mp3Player = new MediaElement();
    mp3Player.LoadedBehavior = MediaState.Manual;
    mp3Player.UnloadedBehavior = MediaState.Stop;
    mp3Player.Source = new Uri(@"Media\singleladies.mp3", UriKind.Relative);
    mp3Player.Volume = .8;
    mp3Player.Play();
    }

    [EDIT: So I checked it out line-by-line in the debugger and apparently everything is loaded into the player. It has the source, it's MediaElement.HasAudio = true, plus several other properties are set. However, it just won't play. I have no idea what's going on.] Now, I am wondering - if I want an mp3 Player - is this the best route to go, creating a new MediaElement each time? Probably not, huh? At any rate, any help would be appreciated. Thanks, Blitz

    B S 2 Replies Last reply
    0
    • B BlitzPackage

      Good people, Why won't my MediaElement play? When I click play, I hear nothing at all. I created it in C# because I need to change sources - in effect use it as an mp3 player. What am I doing wrong? Here is the code:

      private void OnButtonPlaySongClick(object sender, RoutedEventArgs e)
      {
      MediaElement mp3Player = new MediaElement();
      mp3Player.LoadedBehavior = MediaState.Manual;
      mp3Player.UnloadedBehavior = MediaState.Stop;
      mp3Player.Source = new Uri(@"Media\singleladies.mp3", UriKind.Relative);
      mp3Player.Volume = .8;
      mp3Player.Play();
      }

      [EDIT: So I checked it out line-by-line in the debugger and apparently everything is loaded into the player. It has the source, it's MediaElement.HasAudio = true, plus several other properties are set. However, it just won't play. I have no idea what's going on.] Now, I am wondering - if I want an mp3 Player - is this the best route to go, creating a new MediaElement each time? Probably not, huh? At any rate, any help would be appreciated. Thanks, Blitz

      B Offline
      B Offline
      BlitzPackage
      wrote on last edited by
      #2

      Ok, so I think the solution is to create it in the XAML, make sure that the LoadedBehavior is set to Manual in the XAML, and make sure the file you want to play has it's Copy To Output Directory set to "Copy always". Comments, and thoughts are welcome.

      1 Reply Last reply
      0
      • B BlitzPackage

        Good people, Why won't my MediaElement play? When I click play, I hear nothing at all. I created it in C# because I need to change sources - in effect use it as an mp3 player. What am I doing wrong? Here is the code:

        private void OnButtonPlaySongClick(object sender, RoutedEventArgs e)
        {
        MediaElement mp3Player = new MediaElement();
        mp3Player.LoadedBehavior = MediaState.Manual;
        mp3Player.UnloadedBehavior = MediaState.Stop;
        mp3Player.Source = new Uri(@"Media\singleladies.mp3", UriKind.Relative);
        mp3Player.Volume = .8;
        mp3Player.Play();
        }

        [EDIT: So I checked it out line-by-line in the debugger and apparently everything is loaded into the player. It has the source, it's MediaElement.HasAudio = true, plus several other properties are set. However, it just won't play. I have no idea what's going on.] Now, I am wondering - if I want an mp3 Player - is this the best route to go, creating a new MediaElement each time? Probably not, huh? At any rate, any help would be appreciated. Thanks, Blitz

        S Offline
        S Offline
        schiebel t
        wrote on last edited by
        #3

        Hi, try this

        class myclass
        {
        MediaElement me;

         public myclass()
         {
              MediaElement me = new MediaElement();
              LoadedBehavior = MediaState.Manual;
              me.Source = new Uri(@"Path");
              me.Loaded += new RoutedEventHandler(me\_Loaded);
         }
         void me\_Loaded(object sender, RoutedEventArgs e)
         {
              me.Play(); 
         }
        

        }

        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