• C# Windows Media Player 播放playlist 歌单


    using AxWMPLib;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    namespace TestWindowsMediaPlayer
    {
        public class GPMediaPlayer : UserControl
        {
    
            string PlaylistName = "Topper";
        
    
            public void SetPlaylist()
            {
    
                AxWMPLib.AxWindowsMediaPlayer player = null;
                WMPLib.IWMPPlaylistArray playlistArray;
                WMPLib.IWMPPlaylist playlist;
                if (player == null)
                {
                    player = new AxWMPLib.AxWindowsMediaPlayer();
                    Controls.Add(player);
    
                    player.Name = new Guid().ToString();
                    player.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
                    player.Width = this.Width;
                    player.Height = this.Height;
                    player.Location = new System.Drawing.Point(0, 0);
                    player.Visible = true;
                    player.Ctlenabled = false;
                    //  player.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);
                    player.MediaError += new AxWMPLib._WMPOCXEvents_MediaErrorEventHandler(player_MediaError);
                    // player.MediaChange += new AxWMPLib._WMPOCXEvents_MediaChangeEventHandler(player_MediaChange);
                }
    
    
                playlistArray = player.playlistCollection.getByName(PlaylistName);
    
                if (playlistArray != null && playlistArray.count > 0)
                {
                    playlist = playlistArray.Item(0);
    
                    player.currentPlaylist = playlist;
                    player.uiMode = "none";
                    player.enableContextMenu = false;
                    player.settings.setMode("loop", true);
    
                    if (player.playState == WMPLib.WMPPlayState.wmppsStopped || player.playState == WMPLib.WMPPlayState.wmppsPaused || player.playState == WMPLib.WMPPlayState.wmppsReady)
                    {
                        player.Ctlcontrols.play();
                    }
    
                   
    
    
    
                }
            }
    
    
            private void player_MediaError(object sender, _WMPOCXEvents_MediaErrorEvent e)
            {
                MessageBox.Show(e.ToString());
            }
        }
    }
    

      在项目文件里加COM引用:

    <ItemGroup>
    <COMReference Include="AxWMPLib">
    <Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid>
    <VersionMajor>1</VersionMajor>
    <VersionMinor>0</VersionMinor>
    <Lcid>0</Lcid>
    <WrapperTool>aximp</WrapperTool>
    <Isolated>False</Isolated>
    </COMReference>
    <COMReference Include="WMPLib">
    <Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid>
    <VersionMajor>1</VersionMajor>
    <VersionMinor>0</VersionMinor>
    <Lcid>0</Lcid>
    <WrapperTool>tlbimp</WrapperTool>
    <Isolated>False</Isolated>
    </COMReference>
    </ItemGroup>

    fffffffffffffffff
    test red font.
  • 相关阅读:
    mysql高效分页
    mybatis插入值为空时需要制定类型
    NoClassDefFoundError
    mybatis动态sql中的两个内置参数(_parameter和_databaseId)
    Java位运算在程序设计中的使用:位掩码(BitMask)
    基于netty的聊天室(保持和获取客户端channel)
    Netty自定义协议半包编解码
    位运算基础
    JAVA加密系列(四)- 位运算加密(异或加密)
    位运算基础
  • 原文地址:https://www.cnblogs.com/wgscd/p/14361696.html
Copyright © 2020-2023  润新知