cocos2dx FileUtils读取音频文件,win32和安卓的差异

设置FileUtils代理来实现全局加密

//设置代理
FileUtils::getInstance()->setDelegate(getInstance());

win32

  • win32下各个解码器都没有使用FileUtils读取
  • 无法代理加解密
  • cocos2d-x-4.0\cocos\audio\win32

AudioDecoderMp3

  • mpg123_open
#include "mpg123.h"


bool AudioDecoderMp3::open(const char* path)
{
	std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
	if (mpg123_open(_mpg123handle, FileUtils::getInstance()->getSuitableFOpen(fullPath).c_str()) != MPG123_OK
		|| mpg123_getformat(_mpg123handle, &rate, &channel, &mp3Encoding) != MPG123_OK)
	{
		ALOGE("Trouble with mpg123: %s\n", mpg123_strerror(_mpg123handle) );
		break;
	}

Ogg

  • ov_fopen
#include "vorbis/vorbisfile.h"

bool AudioDecoderOgg::open(const char* path)
{
	std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
	if (0 == ov_fopen(FileUtils::getInstance()->getSuitableFOpen(fullPath).c_str(), &_vf))
	{

Android

  • 安卓又使用了FileUtils读取
  • 导致win32和安卓表现不一致
  • cocos2d-x-4.0\cocos\audio\android\AudioDecoderMp3.cpp
//AudioDecoderMp3
bool AudioDecoderMp3::decodeToPcm()
{
    _fileData = FileUtils::getInstance()->getDataFromFile(_url);
    if (_fileData.isNull())
    {
        return false;
    }

//AudioDecoderOgg
bool AudioDecoderOgg::decodeToPcm()
{
    _fileData = FileUtils::getInstance()->getDataFromFile(_url);
    if (_fileData.isNull())
    {
        return false;
    }

//AudioDecoderWav
bool AudioDecoderWav::decodeToPcm()
{
    _fileData = FileUtils::getInstance()->getDataFromFile(_url);

解决方案

  • 暂时排除mp3 ogg等音频文件的加解密

记录一下遇到的问题

你可能感兴趣的:(cocos2d-x,cocos2d,cocos2d-lua)