Windows Media Player(转到下一首歌) [英] Windows media player (go to next song)

查看:79
本文介绍了Windows Media Player(转到下一首歌)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作这个程序,当它打开时会播放一些歌曲.
但是在第一首歌曲播放完后,我无法播放下一首歌曲.
有人可以帮我吗?

I am making this program that will play some songs when it opens.
But I can''t get it to play the next song after the first is done.
Can any one help me?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }

        string[] fileEntries = null;  //to get all the things in a folder
        bool nextsong = false; //to see when the next song should be played


        private void button1_Click_1(object sender, EventArgs e)
        {
            timer1.Start();//start the timer to see when the next song should be played

            comboBox1.Items.Clear();  

            folderBrowserDialog1.ShowDialog();
          fileEntries = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
          foreach (string filename in fileEntries)
          {
              string path1 = folderBrowserDialog1.SelectedPath;
              string path2 = "desktop.ini";
              string outpath = Path.Combine(path1, path2);
              if (filename == outpath) // so the desktop.ini don't get counted
              {
                  fileEntries[0] = null;
              }
              else
              {
                  string I = Path.GetFileName(filename);
                  comboBox1.Items.Add(I);
                  WMP.URL = fileEntries[1];
                  
              }
          }
        }

       

        private void button2_Click(object sender, EventArgs e)
        {
            // don't do anything
           
        }
        int playing = 1;
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //to get the combobox playing when you press a song
            playing = comboBox1.SelectedIndex;
            playing++;
            WMP.URL = fileEntries[playing];
        }

        private void WMP_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            
            //all this is to get the next song to play but it don't work
            if (WMP.status == "stopped" && nextsong == true)
            {
                
                if (fileEntries.Length > playing)
                {
                    WMP.URL = fileEntries[playing];
                    playing++;
                }
                else
                {
                    playing = 2;
                    WMP.URL = fileEntries[1];
                    
                }
                
                nextsong = false;
                
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        
        {
            nextsong = true;
        }
    }
}


您在这里看到的是,我将文件放在一个文件夹中并尝试播放,但我不使用desktop.ini文件,因为当我尝试播放它时,它将无法正常工作,然后将它们放在一个文件夹中.组合框作为播放列表.
一切正常,但不是应该播放下一首歌曲.


What you see here is that I take the files in a folder and try to play them I don''t use the desktop.ini file because it won''t work when I try to play it of couse then I put them in a combobox as a play list.
It all work but not the thing were it should play the next song.

推荐答案

您做错了.

我知道,我的答案似乎有些模糊,甚至有些晦涩,但问题的质量决定了答案的质量.
You''re doing it wrong.

I know, my answer might seem vague, or even obtuse, but the quality of the question dictates the quality of the answer.


首先,您应该使用一些全局标记,该全局标记将指示玩家是否应该继续玩.

您应该处理 PlayStateChange事件以了解何时播放下一首歌曲.

接下来很容易,使用 IWMPControls :: next() IWMPControls :: play()接下来播放的方法列表中的歌曲.

玩这个,你应该不会有问题.
First you should use some global flag which will indicate whether player should continue playing.

You should handle PlayStateChange event to know when to play next song.

Next is easy, use IWMPControls::next() and IWMPControls::play() methods to play next song in the list.

Play with this, you shouldn''t have problems.


我明白了.....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }

        string[] fileEntries = null;
        bool nextsong;


        private void button1_Click_1(object sender, EventArgs e)
        {
            timer1.Start();
            comboBox1.Items.Clear();
            folderBrowserDialog1.ShowDialog();
          fileEntries = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
          foreach (string filename in fileEntries)
          {
              string path1 = folderBrowserDialog1.SelectedPath;
              string path2 = "desktop.ini";
              string outpath = Path.Combine(path1, path2);
              if (filename == outpath)
              {
                  fileEntries[0] = null;
              }
              else
              {
                  string I = Path.GetFileName(filename);
                  
                  comboBox1.Items.Add(I);
                  WMP.URL = fileEntries[1];
                  comboBox1.Text = Path.GetFileName(fileEntries[1]); ;
              }
              
          }

         
    

        }

       

        private void button2_Click(object sender, EventArgs e)
        {
            
           
        }
        int playing = 2;
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            playing = comboBox1.SelectedIndex;
            playing++;
            WMP.URL = fileEntries[playing];
            nextsong = false;
        }


        int sikkerhed_for_musik_skrift = 1;
        private void WMP_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            
            //WMP.currentMedia.duration;

            
            if (nextsong == true && fileEntries.Length > (playing + 1) && sikkerhed_for_musik_skrift == 1 )
                {
                    
                    
                    playing++;
                    nextsong = false;
                    
                    WMP.URL = fileEntries[playing];

                }
            if (nextsong == true )
                {
                    
                    nextsong = false;
                    sikkerhed_for_musik_skrift = 0;
                    playing = 2;
                    
                    WMP.URL = fileEntries[1];
                    
                    
                }
                if (WMP.status == "Ready")
                {
                    try
                    {
                        WMPLib.IWMPControls3 controls = (WMPLib.IWMPControls3)WMP.Ctlcontrols;
                        controls.play();
                    }
                    catch
                    {

                    }
                }
                comboBox1.Text = Path.GetFileName(fileEntries[playing]);
                
                
                
            
        }

        private void timer1_Tick(object sender, EventArgs e)
        
        {
            nextsong = true;
            sikkerhed_for_musik_skrift = 1;
        }

       

       
    }
}


这篇关于Windows Media Player(转到下一首歌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆