| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5824 人关注过本帖
标题:mciSendString 函数
只看楼主 加入收藏
yu965634383
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:119
专家分:195
注 册:2017-9-1
收藏
得分:0 
我将函数写了出来
# include <stdio.h>
# include <conio.h>
# include <windows.h>
# include <stdlib.h>
# include <string.h>
# include <io.h>
#pragma comment(lib, "WINMM.LIB")

void MyMusic (char * FileName)
{
    char cmd[1024];
   
    sprintf (cmd , "%s%s%s" , "open ", FileName, " type avivideo alias mymusic");
     MCIERROR mciError = mciSendStringA(cmd, NULL, 0, 0);
//     printf ("%d" , mciError);
    if (mciError)
        return;
    mciSendStringA("play mymusic repeat", NULL, 0, 0);        
}

int main (void)
{
    char FileName[] = "C:\\Users\\yutang\\Desktop\\1.wav";
    MyMusic (FileName);
    return 0;
}
这样写没有反应啊

菜鸟一枚,求各位大神多多关照。
2017-10-17 13:42
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10611
专家分:43210
注 册:2014-5-20
收藏
得分:1 
回复 11楼 yu965634383
这样试试:
    MyMusic (FileName);
    getch();
2017-10-17 14:33
yu965634383
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:119
专家分:195
注 册:2017-9-1
收藏
得分:0 
# include <stdio.h>
# include <conio.h>
# include <windows.h>
# include <stdlib.h>
# include <string.h>
# include <io.h>
# pragma comment (lib , "WINMM.LIB")

void GetFileName (char * FilePath , char *FileType)
{
    FILE * fp = fopen ("MusicName.txt" , "w+");
    if (!fp)
        return ;
    _finddata_t FileInfo;
    long findhandle;
    char cmd[260];
    sprintf (cmd , "%s%s" , FilePath , FileType);
    findhandle = _findfirst (cmd , &FileInfo);
    fputs (FileInfo.name , fp);
    while (! _findnext (findhandle , &FileInfo))
    {
        fputs ("\n" , fp);
        fputs (FileInfo.name , fp);
//        printf ("%d\n" , FileInfo.size);
    }
    fputs ("\n" , fp);
    fclose (fp);
}

void PlayAMusic (char * FilePath , char * FileName)
{
    char buf[64];
    char cmd[1024];
    int n = 0;
    for (int i = 0; FileName[i] != '\0'; i++)
    {
        if (FileName[i] == ' ')
        {
            n = 1;
            break;
        }
    }
    if (n == 1)
    {
        sprintf (cmd , "%s%s%s%s" , "open \"" , FilePath , FileName , "\" alias MyMusic");
    }
    else
        sprintf (cmd , "%s%s%s%s" , "open " , FilePath , FileName , " alias MyMusic");
   
    MCIERROR mciError = mciSendStringA (cmd , NULL , 0 , NULL);
    if (mciError)
    {
        mciGetErrorStringA (mciError , buf , sizeof (buf));
        MessageBoxA (NULL , buf , "警告" , 1);
    }
    mciSendStringA ("play MyMusic wait" , NULL , 0 , NULL);
    mciSendStringA ("close MyMusic" , NULL , 0 , NULL);
}

void PlayAllTheMusic (char * FilePath)
{
    FILE *fp = fopen ("MusicName.txt" , "r");
    if (!fp)
        return ;
    char FileName[260];
    while (fgets (FileName , 260 , fp) != 0)
    {
        int n = strlen (FileName);
        FileName[n-1] = '\0';
        puts ("正在播放的歌曲是:\n");
        puts (FileName);
        PlayAMusic (FilePath , FileName);
    }
fclose (fp);
}

int main (void)
{
    char FilePath[] = "D:\\KuGou\\";
    char FileType[] = "*.mp3";
    GetFileName (FilePath , FileType);
    PlayAllTheMusic (FilePath);

    return 0;
}

终于是可以播放了, 非常感谢……

[此贴子已经被作者于2017-10-19 00:49编辑过]


菜鸟一枚,求各位大神多多关照。
2017-10-19 00:06
快速回复:mciSendString 函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.296165 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved