SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static short fdBuffer[SAWTOOTH_FRAMES];
  2.  
  3. // create URI audio player
  4.     jboolean Java_jp_mobigame_ayakashi_CardGameActivity_createUriAudioPlayer(JNIEnv* env, jclass clazz,
  5.             jstring uri)
  6.     {
  7.         __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "n createUri n");
  8.         SLresult result;
  9.  
  10.         // convert Java string to UTF-8
  11.         const jbyte *utf8 = (*env)->GetStringUTFChars(env, uri, NULL);
  12.         assert(NULL != utf8);
  13.  
  14.         // configure audio source
  15.         // (requires the INTERNET permission depending on the uri parameter)
  16.         SLDataLocator_URI loc_uri = {SL_DATALOCATOR_URI, (SLchar *) utf8};
  17.         SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
  18.         SLDataSource audioSrc = {&loc_uri, &format_mime};
  19.  
  20.         // configure audio sink
  21.         SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
  22.         SLDataSink audioSnk = {&loc_outmix, NULL};
  23.  
  24.         // create audio player
  25.         const SLInterfaceID ids[3] = {SL_IID_SEEK, SL_IID_MUTESOLO /*SL_IID_BUFFERQUEUE*/, SL_IID_VOLUME};
  26.         const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
  27.         result = (*engineEngine)->CreateAudioPlayer(engineEngine, &uriPlayerObject, &audioSrc,
  28.                 &audioSnk, 3, ids, req);
  29.         // note that an invalid URI is not detected here, but during prepare/prefetch on Android,
  30.         // or possibly during Realize on other platforms
  31.         assert(SL_RESULT_SUCCESS == result);
  32.  
  33.         // release the Java string and UTF-8
  34.         (*env)->ReleaseStringUTFChars(env, uri, utf8);
  35.  
  36.         // realize the player
  37.         result = (*uriPlayerObject)->Realize(uriPlayerObject, SL_BOOLEAN_FALSE);
  38.         // this will always succeed on Android, but we check result for portability to other platforms
  39.         if (SL_RESULT_SUCCESS != result) {
  40.             (*uriPlayerObject)->Destroy(uriPlayerObject);
  41.             uriPlayerObject = NULL;
  42.             return JNI_FALSE;
  43.         }
  44.  
  45.         // get the play interface
  46.         result = (*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_PLAY, &uriPlayerPlay);
  47.         assert(SL_RESULT_SUCCESS == result);
  48.  
  49.         // get the seek interface
  50.         result = (*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_SEEK, &uriPlayerSeek);
  51.         assert(SL_RESULT_SUCCESS == result);
  52.  
  53.  
  54.         __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "n createUri 1n");
  55.         //get the buffer queue interface
  56.         result = (*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &uriPlayerBufferQueue);
  57.         assert(SL_RESULT_SUCCESS == result);
  58.         __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "n createUri 2n");
  59.  
  60.  
  61.         //register callback for uri
  62.         result = (*uriPlayerBufferQueue)->RegisterCallback(uriPlayerBufferQueue, bqUriPlayerCallback, NULL);
  63.         assert(SL_RESULT_SUCCESS == result);
  64.         __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "n createUri 4n");
  65.  
  66.         //Enqueue
  67.         __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "n createUri 3n");
  68.         result = (*uriPlayerBufferQueue)->Enqueue(uriPlayerBufferQueue, fdBuffer, sizeof(fdBuffer));
  69.  
  70.  
  71.         // get the mute/solo interface
  72.         result = (*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_MUTESOLO, &uriPlayerMuteSolo);
  73.         assert(SL_RESULT_SUCCESS == result);
  74.  
  75.         // get the volume interface
  76.         result = (*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_VOLUME, &uriPlayerVolume);
  77.         assert(SL_RESULT_SUCCESS == result);
  78.  
  79.         return JNI_TRUE;
  80.  
  81.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top