From b23ddbb2c99d3a243d0f08aa27345e3305f9d28e Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 6 Apr 2015 10:40:33 -0700 Subject: [PATCH] Fix OGG loading on Android --- project/src/audio/format/OGG.cpp | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/project/src/audio/format/OGG.cpp b/project/src/audio/format/OGG.cpp index 55fba13ca..ecedc639a 100644 --- a/project/src/audio/format/OGG.cpp +++ b/project/src/audio/format/OGG.cpp @@ -110,28 +110,31 @@ namespace lime { if (resource->path) { - FILE_HANDLE *file; + FILE_HANDLE *file = lime::fopen (resource->path, "rb"); - //#ifdef ANDROID - //FileInfo info = AndroidGetAssetFD (resource->path); - //file = lime::fdopen (info.fd, "rb"); - //lime::fseek (file, info.offset, 0); - //#else - file = lime::fopen (resource->path, "rb"); - //#endif - - if (!file || !file->isFile ()) { + if (!file) { - //LOG_SOUND("FAILED to read audio file, file pointer as null?\n"); return false; } - //#ifdef ANDROID - //ov_open (file, &oggFile, NULL, info.length); - //#else - ov_open (file->getFile (), &oggFile, NULL, file->getLength ()); - //#endif + if (file->isFile ()) { + + ov_open (file->getFile (), &oggFile, NULL, file->getLength ()); + + } else { + + ByteArray data = ByteArray (resource->path); + + OAL_OggMemoryFile fakeFile = { data.Bytes (), data.Size (), 0 }; + + if (ov_open_callbacks (&fakeFile, &oggFile, NULL, 0, OAL_CALLBACKS_BUFFER) != 0) { + + return false; + + } + + } } else {