Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 无法识别的音乐格式,无法使用SDL播放mp3文件_C_Linux_Sdl - Fatal编程技术网

C 无法识别的音乐格式,无法使用SDL播放mp3文件

C 无法识别的音乐格式,无法使用SDL播放mp3文件,c,linux,sdl,C,Linux,Sdl,有谁能告诉我用SDL播放mp3文件有什么问题吗?默认情况下,它支持WAV文件,但您需要SMPEG库以及一些更复杂的代码行才能使mp3正常工作。几年前,我也遇到过同样的问题,通过各种论坛,我发现mp3是很棘手的。我最终将我的文件转换为OGG,这非常简单。这里有一个小的足迹!!! 您没有调用。将Mix\u Init与Mix\u Init\u MP3放在一起后出现相同的问题?那么您可能缺少所需的mp3库。检查Mix_Init的返回值。使用Mix_Init\u MP3检查yes及其返回值0。如果阅读文档

有谁能告诉我用SDL播放mp3文件有什么问题吗?

默认情况下,它支持WAV文件,但您需要SMPEG库以及一些更复杂的代码行才能使mp3正常工作。几年前,我也遇到过同样的问题,通过各种论坛,我发现mp3是很棘手的。我最终将我的文件转换为OGG,这非常简单。

这里有一个小的足迹!!!
您没有调用。将
Mix\u Init
Mix\u Init\u MP3
放在一起后出现相同的问题?那么您可能缺少所需的mp3库。检查
Mix_Init
的返回值。使用
Mix_Init\u MP3
检查yes及其返回值
0
。如果阅读文档,
Mix_Init
应返回当前初始化加载程序的位掩码。由于它为您返回零,因此mp3加载程序尚未初始化,这意味着您缺少一些内容。但SDL mixer source附带的一个示例名为
playmus.c
,它正在播放mp3文件,无法独立播放mp3。我不确定你得到的源文件是否也有所有支持mp3播放的必要库。请查看本文,了解如何使用sdlmixer处理mp3的完整详细信息:仅供参考,我必须向gcc cmd行添加-lSDL以使其正确编译。在Ubuntu 11.10上。
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <stdio.h>
#include <stdlib.h>
Mix_Music *play_sound = NULL;
void cleanUp();

int main(int argc, char* args[])
{

    int channel;
    int audio_rate;
    Uint16 audio_format;
    int audio_channels;
    int audio_buffers;

        if(SDL_Init(SDL_INIT_AUDIO)<0)
        printf("Error In Init");

    audio_rate = 44100;
    audio_format = AUDIO_S16;
    audio_channels = 2;
    audio_buffers = 4096;


    if(Mix_OpenAudio(audio_rate, audio_format, 2, 4096)<0) {
                 //Some error shows here

    } else {
        Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
        printf("Opened audio at %d Hz %d bit %s (%s), %d bytes audio buffer\n", audio_rate,
                (audio_format&0xFF),
                (audio_channels > 2) ? "surround" :                         (audio_channels > 1) ? "stereo" : "mono", 
                (audio_format&0x1000) ? "BE" : "LE",
                audio_buffers );
    }

    play_sound = Mix_LoadMUS("1.mp3");

    if ( play_sound == NULL ) {
        fprintf(stderr, "Couldn't load 1.mp3: %s\n",
            SDL_GetError());
        cleanUp();
        return;
    }

        Mix_PlayMusic(play_sound, -1);


    while (Mix_PlayingMusic() || Mix_PausedMusic()) {
            SDL_Delay(100);
        }

        cleanUp();
        return 0;
}

void cleanUp()
{
     Mix_FreeMusic(play_sound);
     Mix_CloseAudio();
     SDL_Quit();
}
Opened audio at 44100 Hz 16 bit stereo (LE), 4096 bytes audio buffer
Couldn't load 1.mp3: Unrecognised music format
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <smpeg/smpeg.h>
#include <dirent.h>

int main(int argc, char * argv[])
{
  SDL_Surface * screen;
  SMPEG *mpeg;
  SMPEG_Info info;

  /* Init SDL: */
  
  SDL_Init(SDL_INIT_VIDEO |
           SDL_INIT_AUDIO);
  
  mpeg = SMPEG_new("1.mp3",&info, 1);

  SMPEG_play(mpeg);

  do
    {
      SDL_Delay(250);
    }while(!SDL_QuitRequested() && SMPEG_status(mpeg)==SMPEG_PLAYING);
    
  SMPEG_delete(mpeg);
  SDL_Quit();
  
  return(0);
}
gcc `sdl-config --cflags --libs` sample.c -o sample -lSDL_mixer -lsmpeg