C#调用winmm.dll来放音乐的示例

 

None.gif using  System;
None.gif
using  System.Text;
None.gif
using  System.Runtime.InteropServices;
None.gif
None.gif
namespace  Music
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class Audio
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        [DllImport(
"winmm.dll")]
InBlock.gif        
private static extern int mciSendString 
InBlock.gif            (
InBlock.gif                
string lpstrCommand,
InBlock.gif                
string lpstrReturnString,
InBlock.gif                
int uReturnLength,
InBlock.gif                
int hwndCallback
InBlock.gif            );
InBlock.gif
InBlock.gif        [DllImport(
"kernel32.dll", CharSet = CharSet.Auto)]
InBlock.gif        
public static extern int GetShortPathName
InBlock.gif            (
InBlock.gif                [MarshalAs(UnmanagedType.LPTStr)]    
string path,
InBlock.gif                 [MarshalAs(UnmanagedType.LPTStr)]    StringBuilder shortPath,
InBlock.gif                 
int shortPathLength
InBlock.gif            ); 
InBlock.gif
InBlock.gif        
public Audio()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void Play(string FileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            StringBuilder shortPathTemp 
= new StringBuilder(255);
InBlock.gif            
int result = GetShortPathName(FileName, shortPathTemp, shortPathTemp.Capacity);
InBlock.gif            
string ShortPath = shortPathTemp.ToString();
InBlock.gif
InBlock.gif            mciSendString(
"open "+ShortPath+" alias song","",0,0);
InBlock.gif            mciSendString(
"play song","",0,0);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void Stop()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            mciSendString(
"stop song","",0,0);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void Pause()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            mciSendString(
"pause song","",0,0);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void Close()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            mciSendString(
"close song","",0,0);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/William_Fire/articles/57927.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值