安卓的MediaPlayer与AudioEffect:获取错误(-22,0) [英] Android MediaPlayer with AudioEffect : Getting Error (-22,0)

查看:641
本文介绍了安卓的MediaPlayer与AudioEffect:获取错误(-22,0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,只是这是我的要求。

Well, simply this is my requirement..

我有一个WAV文件,我想打开它,添加一些效果,并播放。

我使用 的MediaPlayer播放文件,的 presetReverb 添加一些效果。

I am using MediaPlayer to play file, and PresetReverb to add some effects.

这是我的code

public void playSound(){
   String fullPath = MainActivity.this.filePath + "tmpaudio.wav";

   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,我得到一个日志中的logcat(不记录我的。)

When I run this code, I am getting a log in logcat(Not logged by me.)

十二月5日至2日:02:42.356:E / MediaPlayer的(17250):错误(-22,0)

05-02 12:02:42.356: E/MediaPlayer(17250): Error (-22,0)

但是,当我评论这些行

PresetReverb pReverb = new PresetReverb(0,player.getAudioSessionId());
pReverb.setPreset(PresetReverb.PRESET_LARGEROOM);
pReverb.setEnabled(true);
player.attachAuxEffect(eReverb.getId());
player.setAuxEffectSendLevel(1.0f);

MediaPlayer正在播放该文件顺利。所以,没有错,我的WAV文件。

MediaPlayer is playing the file successfully. So nothing wrong with my WAV file.

难免有些失望,我想 EnvironmentalReverb ,而不是的presetReverb,

Being somewhat let down, I tried EnvironmentalReverb, instead of PresetReverb,

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);

还有我也得到了同样的错误(错误(-22,0))。

there also I got the same error (Error (-22,0)).

因此​​,无论我失去了一些东西那么明显,还是有一些问题的 AudioEffect 家庭类(在文档或API本身)。任何人都可以提供一些线索?

So either I am missing something so obvious, or there is some problem with AudioEffect family classes (in documentation or api itself). Can anyone shed some light?

编辑:我忘了补充,当我调试的code为记录错误时

EDIT : I forgot to add, when I debugged the code the error is logged when

 player.start();

被执行。我已删除了异常处理部分发布上述code段之前。不过,我肯定也不会例外是当我执行抓住了。

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.

再次编辑:

从<一个href="https://github.com/android/platform_external_opencore/blob/master/pvmi/pvmf/include/pvmf_return_$c$cs.h"相对=nofollow>我才明白错误-22这链接PVMFErrLicenseRequired previewAvailable

From this link I came to understand error -22 is PVMFErrLicenseRequiredPreviewAvailable

/*
 Error due to the lack of a valid license for the content.  However
 a preview is available.
 */
const PVMFStatus PVMFErrLicenseRequiredPreviewAvailable = (-22);

我GOOGLE与PVMFErrLicenseRequired previewAvailable,我得到<一href="http://www.scribd.com/doc/69085536/76/$p$pview-of-DRM-Content-without-a-Valid-License-Available"相对=nofollow>这个文档。 87页

DRM的 14.10.5 preVIEW内容没有有效的许可证可用

这将在第14.10.3场景的变化是在情况下,   还有对某段内容的全面支持播放没有有效的许可证,但   还有它可以是previewed。这种情况可能是一个常用的方式   最初分发内容,使消费者可以preVIEW它   在决定购买一个完整的许可证。在这种情况下的Init()   方法将与code返回   PVMFErrLicenseRequired previewAvailable,   这表明一个许可   需要全播放,但一个preVIEW可用。为了   玩preVIEW,应用程序必须删除当前源再   用标志的本地数据源设置为显示添加回去   preVIEW模式。

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.

现在我扮演的WAV文件是使用的Andr​​oid SDK本身SpeechToText工具由我生成的。我不知道,从玩这个文件是什么持证我。

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.

推荐答案

嗯,我知道了最后的工作。我重读的文档,使用了与code,突然一切正常。这是我的情况下,发现它有助于在今后的任何人。

Well, I got it working at last. I reread the documentation, played with the code and suddenly everything worked. These are my findings in case it helps anyone in future.

在presetReverb文档

In presetReverb documentation

在presetReverb是输出混合的辅助作用和应该是   在音频会话0创建为了让MediaPlayer的或   AudioTrack被送入该效果,它们必须是明确地定义   连接到它和发送电平必须指定。使用效果ID   通过getId()方法返回指定这个特殊的时候效果   其连接到的MediaPlayer或AudioTrack。

The PresetReverb is an output mix auxiliary effect and should be created on Audio session 0. In order for a MediaPlayer or AudioTrack to be fed into this effect, they must be explicitely attached to it and a send level must be specified. Use the effect ID returned by getId() method to designate this particular effect when attaching it to the MediaPlayer or AudioTrack.

PresetReverb pReverb = new PresetReverb(0,player.getAudioSessionId()); <== error

是不允许的。您只能使用全局音频会话0构建presetReverb。

is not allowed. You can only use global audio session 0 to construct PresetReverb.

PresetReverb pReverb  = new PresetReverb(1,0); <== correct

现在我们可以用MediaPlayer的或AudioTrack使用其安装

Now we can attach it with MediaPlayer or AudioTrack using

player.attachAuxEffect(pReverb.getId());
player.setAuxEffectSendLevel(1.0f);

我完全presetReverb code是

My full PresetReverb code is

PresetReverb pReverb    = new PresetReverb(1,0);
player.attachAuxEffect(pReverb.getId());
pReverb.setPreset(PresetReverb.PRESET_LARGEROOM);
pReverb.setEnabled(true);
player.setAuxEffectSendLevel(1.0f);

注意:如果您正在寻找好的混响效果或回声,更好地利用EnvironmentalReverb。我用presetReverb的表现多少有些失望。

Note : If you are looking for good reverb effect or echo, better use EnvironmentalReverb. I am somewhat disappointed with the performance of PresetReverb.

从EnvironmentalReverb的文档

From the documentation of EnvironmentalReverb

的EnvironmentalReverb是输出混合的辅助作用,并应在音频会话0创建为了让MediaPlayer的或   AudioTrack被送入该效果,它们必须是明确地定义   连接到它和发送电平必须指定。使用效果ID   通过getId()方法返回指定这个特殊的时候效果   其连接到的MediaPlayer或AudioTrack。

The EnvironmentalReverb is an output mix auxiliary effect and should be created on Audio session 0. In order for a MediaPlayer or AudioTrack to be fed into this effect, they must be explicitely attached to it and a send level must be specified. Use the effect ID returned by getId() method to designate this particular effect when attaching it to the MediaPlayer or AudioTrack.

酷似presetReverb,但是当我写了

Exactly like PresetReverb, but when I wrote

Log.e("DEBUG","sessionId : " + player.getAudioSessionId()); <== printed "454"
EnvironmentalReverb  eReverb 
             = new EnvironmentalReverb(0,player.getAudioSessionId()); //should be error as per documentation
//player.attachAuxEffect(eReverb.getId());   <== Yes this one was commented

没有错误,我也得到良好的混响效果和回声。因此,这似乎是在文档中的一个错误。此外,当我们通过玩家的会话ID的构造函数(player.getAudioSessionId()),似乎没有必要附上球员EnvironmentalReverb实例。奇怪..

there was no error and I get good reverb effect and echo. So It seems like a bug in documentation. Also when we pass session id of player to the constructor(player.getAudioSessionId()), there seems to be no need to attach player with EnvironmentalReverb instance. Strange..

有关为了完整起见这一还曾就像文件说。

For sake of completeness this one also worked just as documentation says.

EnvironmentalReverb  eReverb 
             = new EnvironmentalReverb(0,0); 
player.attachAuxEffect(eReverb.getId());     <== No,not comment this one

对于其他AudioEffect儿童(均衡器,BassBoost,虚拟器)

这些的人不是我的问题的一部分。但对于大家谁认为这在未来..

For other AudioEffect childrens (Equalizer, BassBoost, Virtualizer)

These ones were not the part of my question. But for everyone who sees this in the future..

注:连接插入效果(均衡器,低音增强,虚拟器),以   全球音频输出组合利用会话0是德precated。

NOTE: attaching insert effects (equalizer, bass boost, virtualizer) to the global audio output mix by use of session 0 is deprecated.

看<一href="http://developer.android.com/reference/android/media/audiofx/AudioEffect.html">documentation

那么,公平地说,这不是一个错误提示信息。我不知道为什么一个无效的许可证错误来了,当我们陷入困境的音频会议。反正当我纠正了音频会话参数此错误消失。这就是我所知道的。

Well, fair to say it was not an informative error message. I don't know why an Invalid license error comes up when we mess up audio session. Anyway when I corrected the audio session parameter this error vanished. Thats all I know.

这篇关于安卓的MediaPlayer与AudioEffect:获取错误(-22,0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆