title: Android MediaPlayer with AudioEffect : Getting Error (-22,0)
body: <p>Well, simply this is my requirement..</p>
  <p><strong>I have a WAV file, I want to open it, add some effects, and play.</strong></p>
  <p>I am using <a href="http://developer.android.com/reference/android/media/MediaPlayer.html" rel="noreferrer">MediaPlayer</a> to play file, and <a href="http://developer.android.com/reference/android/media/audiofx/PresetReverb.html" rel="noreferrer">PresetReverb</a> to add some effects.</p>
  <p>This is my code</p>
  <pre><code>public void playSound(){
     String fullPath = MainActivity.this.filePath + &quot;tmpaudio.wav&quot;;
  
     final MediaPlayer player = new MediaPlayer();
     player.setDataSource(this, Uri.parse(fullPath));
  
     PresetReverb pReverb = new PresetReverb(0,player.getAudioSessionId());
     pReverb.setPreset(PresetReverb.PRESET_LARGEROOM);
     pReverb.setEnabled(true);
     player.attachAuxEffect(eReverb.getId());
     player.setAuxEffectSendLevel(1.0f);
  
     //prepare for playback
     player.prepare();
  
     // Media prepared listener
     player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
           //play
           player.start();
        } 
     });
  }
  </code></pre>
  <p>When I run this code, I am getting a log in logcat(Not logged by me.)</p>
  <blockquote>
  <p>05-02 12:02:42.356: E/MediaPlayer(17250): Error (-22,0)</p>
  </blockquote>
  <p>But when I comment these lines</p>
  <pre><code>PresetReverb pReverb = new PresetReverb(0,player.getAudioSessionId());
  pReverb.setPreset(PresetReverb.PRESET_LARGEROOM);
  pReverb.setEnabled(true);
  player.attachAuxEffect(eReverb.getId());
  player.setAuxEffectSendLevel(1.0f);
  </code></pre>
  <p>MediaPlayer is playing the file successfully. So nothing wrong with my WAV file.</p>
  <p>Being somewhat let down, I tried <a href="http://developer.android.com/reference/android/media/audiofx/EnvironmentalReverb.html" rel="noreferrer">EnvironmentalReverb</a>, instead of PresetReverb,</p>
  <pre><code>EnvironmentalReverb eReverb = new EnvironmentalReverb(1, player.getAudioSessionId());
  eReverb.setDecayHFRatio((short) 1000);
  eReverb.setDecayTime(10000);
  eReverb.setDensity((short) 1000);
  eReverb.setDiffusion((short) 1000);
  eReverb.setReverbLevel((short) -1000);
  eReverb.setEnabled(true);
  player.attachAuxEffect(eReverb.getId());
  player.setAuxEffectSendLevel(1.0f);
  </code></pre>
  <p>there also I got the same error (Error (-22,0)).</p>
  <p>So either I am missing something so obvious, or there is some problem with <a href="http://developer.android.com/reference/android/media/audiofx/AudioEffect.html" rel="noreferrer">AudioEffect</a> family classes (in documentation or api itself). Can anyone shed some light?</p>
  <p><strong>EDIT :</strong> I forgot to add, when I debugged the code the error is logged when</p>
  <pre><code> player.start();
  </code></pre>
  <p>is executed. I have removed exception handling parts before posting the code segment above. But I am positive, no exception is caught when I executed.</p>
  <p><strong>EDIT AGAIN :</strong></p>
  <p>From <a href="https://github.com/android/platform_external_opencore/blob/master/pvmi/pvmf/include/pvmf_return_codes.h" rel="noreferrer">this</a> link I came to understand error -22 is PVMFErrLicenseRequiredPreviewAvailable</p>
  <pre><code>/*
   Error due to the lack of a valid license for the content.  However
   a preview is available.
   */
  const PVMFStatus PVMFErrLicenseRequiredPreviewAvailable = (-22);
  </code></pre>
  <p>I googled with PVMFErrLicenseRequiredPreviewAvailable, and I got <a href="http://www.scribd.com/doc/69085536/76/Preview-of-DRM-Content-without-a-Valid-License-Available" rel="noreferrer">this</a> document. And on page 87</p>
  <blockquote>
  <p><strong>14.10.5 Preview of DRM Content without a Valid License Available</strong></p>
  <p>A variation on the scenario covered in Section 14.10.3 is the case where
  there is no valid license for full playback of a piece of content, but
  there it can be previewed. This scenario might be a common way
  of initially distributing content so that consumers can preview it
  before deciding to purchase a full license. In this case the Init()
  method will return with the code
  PVMFErrLicenseRequiredPreviewAvailable,
  which indicates that a license
  is required for full playback but a preview is available. In order to
  play the preview, the application must remove the current source then
  add it back with a flag set on the local data source to indicate
  preview mode.</p>
  </blockquote>
  <p>Now the WAV files I played is generated by me using SpeechToText tool in android SDK itself. I don't know what license holding me from playing this file.</p>