zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    用户和用户组管理
    浏览器从输入URL到页面加载显示完成全过程解析
    easyui form提交和formdata提交记录,查看FormData对象内部的值
    Hybrid App中原生页面 VS H5页面(分享)
    ui-router .state参数配置
    利用webpack手动构建vue工程
    使用json对象要注意的地方
    js中使用0 “” null undefined {}需要注意
    已知宽高和未知宽高的div块的水平垂直居中
    jquery easyui datagrid 空白条处理 自适应宽高 格式化函数formmater 初始化时会报错 cannot read property 'width'||'length' of null|undefined
  • 原文地址:https://www.cnblogs.com/wgscd/p/14361696.html
Copyright © 2011-2022 走看看