关于得到歌曲总时间

sjq8522 sjq8522 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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;
using Microsoft.Win32;
using System.Runtime.InteropServices; 
namespace _0
{
public partial class Form1 : Form
{// API 宣告  
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int mciSendString(
string lpstrCommand, string lpstrReturnString,
int uReturnLength, int hwndCallback); 
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}






 


private void button1_Click(object s, EventArgs e)  
{  
    MessageBox.Show(GetMediaLen(@"E:\MP3\bjbl.mp3").ToString() + " Sec");  
} 


 


// 取得多媒體檔案長度  
private long GetMediaLen(string File)  
{  
    long RetVal = 0;  
    string key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions";  
    RegistryKey RegKey = Registry.LocalMachine.OpenSubKey(key);
if (RegKey == null)
RegKey = Registry.LocalMachine.CreateSubKey(key);
    string FileExt = Path.GetExtension(File).Replace(".", "");  
    string tp = RegKey.GetValue(FileExt, "MPEGVideo").ToString();  
    RegKey.Close();  
 
    string tm = new string((char)0, 128);  
    if (mciSendString("open \"" + File + "\" type " + tp + " alias Media", null, 0, 0) == 0)  
        {  
        if (mciSendString("status Media length", tm, tm.Length, 0) == 0)  
        {  
            tm = tm.Trim((char)0);  
            if (!string.IsNullOrEmpty(tm)) RetVal = Convert.ToInt64(tm) / 1000;  
        }  
        mciSendString("close Media", null, 0, 0);  
   }  
    return RetVal;  
} 
}
}
//大家好,上面的代码运行时没有提示错误,为什么得到的时间是0秒;麻烦大家一下,怎样修改才能得到歌曲的总时间;
...全文

相关推荐

评论 16
收藏 已收藏
分享
返回顶部
sjq8522
C# 111,130 成员 642,541 内容