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. Windows Media Player - Play MP3.

Windows Media Player - Play MP3.

Scheduled Pinned Locked Moved C#
help
5 Posts 3 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.
  • N Offline
    N Offline
    ngogiatuong
    wrote on last edited by
    #1

    Dear all I create a method to play mp3 base on Text input. I create a playlist and import it to player. but the problem is that, the player plays only 3 files. (and i debugged and found that attributeCount always=3). Please help for this case. Below is my code:

    private void PlayMP3()
    {
    try
    {
    string strLP = this.textBox1.Text.Trim();
    string strPath = Application.StartupPath;
    WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
    WMPLib.IWMPPlaylist myplaylist = player.playlistCollection.newPlaylist("myplaylist");
    //Clear playlist before create new one.
    myplaylist.clear();
    //Create new playlist
    foreach (char c in strLP)
    {
    //read
    string strFileName = "raw\\" + string.Concat(c, ".mp3");
    string strFileLocation = Path.Combine(strPath, strFileName);
    WMPLib.IWMPMedia media = player.newMedia(strFileLocation);
    myplaylist.appendItem(media);
    }
    player.playlistCollection.importPlaylist(myplaylist);
    player.currentPlaylist = myplaylist;
    //Play
    player.controls.play();

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    
    A R 2 Replies Last reply
    0
    • N ngogiatuong

      Dear all I create a method to play mp3 base on Text input. I create a playlist and import it to player. but the problem is that, the player plays only 3 files. (and i debugged and found that attributeCount always=3). Please help for this case. Below is my code:

      private void PlayMP3()
      {
      try
      {
      string strLP = this.textBox1.Text.Trim();
      string strPath = Application.StartupPath;
      WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
      WMPLib.IWMPPlaylist myplaylist = player.playlistCollection.newPlaylist("myplaylist");
      //Clear playlist before create new one.
      myplaylist.clear();
      //Create new playlist
      foreach (char c in strLP)
      {
      //read
      string strFileName = "raw\\" + string.Concat(c, ".mp3");
      string strFileLocation = Path.Combine(strPath, strFileName);
      WMPLib.IWMPMedia media = player.newMedia(strFileLocation);
      myplaylist.appendItem(media);
      }
      player.playlistCollection.importPlaylist(myplaylist);
      player.currentPlaylist = myplaylist;
      //Play
      player.controls.play();

              }
              catch (Exception ex)
              {
                  throw ex;
              }
          }
      
      A Offline
      A Offline
      Afzaal Ahmad Zeeshan
      wrote on last edited by
      #2

      There can be many reasons for that, first one being that the player is initialized with only 3 tracks, or can run only three — i.e. filtered results. What is your playlist size? That controls how many tracks to play. Using the Windows Media Player Control with Microsoft Visual Studio (Windows)[^]

      The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

      N 1 Reply Last reply
      0
      • A Afzaal Ahmad Zeeshan

        There can be many reasons for that, first one being that the player is initialized with only 3 tracks, or can run only three — i.e. filtered results. What is your playlist size? That controls how many tracks to play. Using the Windows Media Player Control with Microsoft Visual Studio (Windows)[^]

        The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

        N Offline
        N Offline
        ngogiatuong
        wrote on last edited by
        #3

        Thanks Afzaal Ahmad Zeeshan! my playlist size is more than 3 (often 10). and I user WMPLib. I'm trying to find out the problem but still not find!!!

        A 1 Reply Last reply
        0
        • N ngogiatuong

          Thanks Afzaal Ahmad Zeeshan! my playlist size is more than 3 (often 10). and I user WMPLib. I'm trying to find out the problem but still not find!!!

          A Offline
          A Offline
          Afzaal Ahmad Zeeshan
          wrote on last edited by
          #4

          Can you try and pass the songs, instead of passing the songs playlist to see if that works.

          The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

          1 Reply Last reply
          0
          • N ngogiatuong

            Dear all I create a method to play mp3 base on Text input. I create a playlist and import it to player. but the problem is that, the player plays only 3 files. (and i debugged and found that attributeCount always=3). Please help for this case. Below is my code:

            private void PlayMP3()
            {
            try
            {
            string strLP = this.textBox1.Text.Trim();
            string strPath = Application.StartupPath;
            WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
            WMPLib.IWMPPlaylist myplaylist = player.playlistCollection.newPlaylist("myplaylist");
            //Clear playlist before create new one.
            myplaylist.clear();
            //Create new playlist
            foreach (char c in strLP)
            {
            //read
            string strFileName = "raw\\" + string.Concat(c, ".mp3");
            string strFileLocation = Path.Combine(strPath, strFileName);
            WMPLib.IWMPMedia media = player.newMedia(strFileLocation);
            myplaylist.appendItem(media);
            }
            player.playlistCollection.importPlaylist(myplaylist);
            player.currentPlaylist = myplaylist;
            //Play
            player.controls.play();

                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            
            R Offline
            R Offline
            RichardGrimmer
            wrote on last edited by
            #5

            Are you using a trial version of a library with a hard (trial) limit? Seen this sort of behaviour before, along with only playing the first few seconds of a track

            C# has already designed away most of the tedium of C++.

            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