简体   繁体   English

java.lang.RuntimeException:无法为类型初始化效果引擎:0bed4300-ddd6-11db-8f34-0002a5d5c51b错误:-3

[英]java.lang.RuntimeException: Cannot initialize effect engine for type: 0bed4300-ddd6-11db-8f34-0002a5d5c51b Error: -3

I am getting the following error in my equalizer app on Android MarshMellow, OnePlus. 我在Android MarshMellow,OnePlus上的均衡器应用程序中收到以下错误。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app.name/com.my.app.name.activity.MainActivity}: java.lang.RuntimeException: Cannot initialize effect engine for type: 0bed4300-ddd6-11db-8f34-0002a5d5c51b Error: -3
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Cannot initialize effect engine for type: 0bed4300-ddd6-11db-8f34-0002a5d5c51b Error: -3
    at android.media.audiofx.AudioEffect.<init>(AudioEffect.java:411)
    at android.media.audiofx.Equalizer.<init>(Equalizer.java:139)
    at com.my.app.name.activity.MainActivity.onCreate(Unknown Source)
    at android.app.Activity.performCreate(Activity.java:6251)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
    ... 9 more

It occurs when I try to initialize equalizer like this: 它发生在我尝试初始化均衡器时,如下所示:

Equalizer eq = new Equalizer(0, 0);

Although the equalizer class throws this Exception but why does it occur and how can it be fixed? 虽然均衡器类抛出此异常,但它为什么会发生,如何修复? This also occurs on few other devices. 这也发生在其他一些设备上。 But works fine on Nexus and most devices. 但在Nexus和大多数设备上运行良好。

Can someone give any ideas? 有人可以提出任何想法吗? I also have the following permission in my manifest. 我的清单中也有以下许可。

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

Thanks !! 谢谢 !!

It seems that the reason is EFFECT_TYPE_EQUALIZER . 似乎原因是EFFECT_TYPE_EQUALIZER Read this Util, I think it will be useful for you: 阅读此Util,我认为它对您有用:

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaMetadataRetriever;
import android.media.audiofx.AudioEffect;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;

import com.marverenic.music.instances.Song;
import com.marverenic.music.player.PlayerController;

import java.util.UUID;

import timber.log.Timber;

import static android.content.Context.CONNECTIVITY_SERVICE;

public final class Util {

    /**
     * This UUID corresponds to the UUID of an Equalizer Audio Effect. It has been copied from
     * {@link AudioEffect#EFFECT_TYPE_EQUALIZER} for backwards compatibility since this field was
     * added in API level 18.
     */
    private static final UUID EQUALIZER_UUID;

    static {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            EQUALIZER_UUID = AudioEffect.EFFECT_TYPE_EQUALIZER;
        } else {
            EQUALIZER_UUID = UUID.fromString("0bed4300-ddd6-11db-8f34-0002a5d5c51b");
        }
    }

    /**
     * This class is never instantiated
     */
    private Util() {

    }

    /**
     * Checks whether the device is in a state where we're able to access the internet. If the
     * device is not connected to the internet, this will return {@code false}. If the device is
     * only connected to a mobile network, this will return {@code allowMobileNetwork}. If the
     * device is connected to an active WiFi network, this will return {@code true.}
     * @param context A context used to check the current network status
     * @param allowMobileNetwork Whether or not the user allows the application to use mobile
     *                           data. This is an internal implementation that is not enforced
     *                           by the system, but is exposed to the user in our app's settings.
     * @return Whether network calls should happen in the current connection state or not
     */
    @SuppressWarnings("SimplifiableIfStatement")
    public static boolean canAccessInternet(Context context, boolean allowMobileNetwork) {
        ConnectivityManager connectivityManager;
        connectivityManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);

        NetworkInfo info = connectivityManager.getActiveNetworkInfo();
        if (info == null) {
            // No network connections are active
            return false;
        } else if (!info.isAvailable() || info.isRoaming()) {
            // The network isn't active, or is a roaming network
            return false;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            // If it's a mobile network, return the user preference
            return allowMobileNetwork;
        } else {
            // The network is a wifi network
            return true;
        }
    }

    @TargetApi(Build.VERSION_CODES.M)
    public static boolean hasPermission(Context context, String permission) {
        return context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
    }

    @TargetApi(Build.VERSION_CODES.M)
    public static boolean hasPermissions(Context context, String... permissions) {
        for (String permission : permissions) {
            if (!hasPermission(context, permission)) {
                return false;
            }
        }
        return true;
    }

    public static Intent getSystemEqIntent(Context c) {
        Intent systemEq = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
        systemEq.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, c.getPackageName());
        systemEq.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, PlayerController.getAudioSessionId());

        ActivityInfo info = systemEq.resolveActivityInfo(c.getPackageManager(), 0);
        if (info != null && !info.name.startsWith("com.android.musicfx")) {
            return systemEq;
        } else {
            return null;
        }
    }

    /**
     * Checks whether the current device is capable of instantiating and using an
     * {@link android.media.audiofx.Equalizer}
     * @return True if an Equalizer may be used at runtime
     */
    public static boolean hasEqualizer() {
        for (AudioEffect.Descriptor effect : AudioEffect.queryEffects()) {
            if (EQUALIZER_UUID.equals(effect.type)) {
                return true;
            }
        }
        return false;
    }

    public static Bitmap fetchFullArt(Song song) {
        if (song == null) {
            return null;
        }

        MediaMetadataRetriever retriever = new MediaMetadataRetriever();

        try {
            retriever.setDataSource(song.getLocation());
            byte[] stream = retriever.getEmbeddedPicture();
            if (stream != null) {
                return BitmapFactory.decodeByteArray(stream, 0, stream.length);
            }
        } catch (Exception e) {
            Timber.e(e, "Failed to load full song artwork");
        }
        return null;
    }

}

The global audio session 0 is deprecated and can cause problems if you pass it to the Equalizer. 不推荐使用全局音频会话0,如果将其传递给均衡器,可能会导致问题。 See details in the doc https://developer.android.com/reference/android/media/audiofx/Equalizer 请参阅文档https://developer.android.com/reference/android/media/audiofx/Equalizer中的详细信息

To get rid the above-mentioned error just use a specific audio session id. 要消除上述错误,只需使用特定的音频会话ID。 Quick example: 快速举例:

Equalizer equalizer = new Equalizer(0, new MediaPlayer().getAudioSessionId()); 均衡器均衡器=新的均衡器(0,新的MediaPlayer()。getAudioSessionId());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM