O'Reilly logo

Android NDK Beginner's Guide by Sylvain Ratabouil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – playing background music

Let’s improve the code written in the previous part to read and play an MP3 file:

  1. MP3 files are opened by OpenSL ES using a POSIX file descriptor, pointing to the file. Improve jni/ResourceManager.cpp created in the previous chapters by injecting a new structure ResourceDescriptor and appending a new method descript():
    #ifndef _PACKT_RESOURCE_HPP_
    #define _PACKT_RESOURCE_HPP_
    
    #include "Types.hpp"
    
    #include <android_native_app_glue.h>
    
    namespace packt {
        struct ResourceDescriptor {
            int32_t mDescriptor;
            off_t mStart;
            off_t mLength;
        };
    
        class Resource {
        public:
            ...
    
            off_t getLength();
            const void* bufferize();
    
            ResourceDescriptor descript();
    
        private:
            ...
        };
    }
    #endif
  2. Implementation in ResourceManager.cpp, of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required