2

我正在尝试建立一个从 android 设备到音乐流平台 deezer 的播放器模块。这是我遵循的教程:http: //developers.deezer.com/sdk/android#using-player-module-2

(见底部的问题)

这是我的代码:

package com.example.playertest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

import com.deezer.sdk.DeezerConnect;
import com.deezer.sdk.DeezerConnectImpl;
import com.deezer.sdk.DeezerError;
import com.deezer.sdk.OAuthException;
import com.deezer.sdk.player.Player;
import com.deezer.sdk.player.PlayerFactory;
import com.deezer.sdk.player.TooManyPlayersExceptions;
import com.deezer.sdk.player.impl.DefaultPlayerFactory;
import com.deezer.sdk.player.networkcheck.WifiOnlyNetworkStateChecker;

public class MainActivity extends Activity {
private final static String APP_ID = "XXXXX";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    DeezerConnect connection = new DeezerConnectImpl(APP_ID);

    try {
        PlayerFactory player = new DefaultPlayerFactory(getApplication(), connection, new WifiOnlyNetworkStateChecker());
        Player play = player.createPlayer();

        //same as: Player player = new DefaultPlayerFactory(getApplication(), connection, new WifiOnlyNetworkStateChecker()).createPlayer();
    } catch (OAuthException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DeezerError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TooManyPlayersExceptions e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.playertest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.playertest.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

这里是 logcat 输出:

07-20 12:49:29.755: E/Trace(4186): error opening trace file: No such file or directory (2)
07-20 12:49:30.925: W/dalvikvm(4186): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/deezer/sdk/player/impl/RealPlayerImpl;
07-20 12:49:30.985: W/dalvikvm(4186): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-20 12:49:31.125: E/AndroidRuntime(4186): FATAL EXCEPTION: main
07-20 12:49:31.125: E/AndroidRuntime(4186): java.lang.ExceptionInInitializerError
07-20 12:49:31.125: E/AndroidRuntime(4186):     at com.deezer.sdk.player.impl.DefaultPlayerFactory.createPlayer(Unknown Source)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at com.example.playertest.MainActivity.onCreate(MainActivity.java:29)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.app.Activity.performCreate(Activity.java:5104)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.os.Looper.loop(Looper.java:137)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at android.app.ActivityThread.main(ActivityThread.java:5041)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at java.lang.reflect.Method.invokeNative(Native Method)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at java.lang.reflect.Method.invoke(Method.java:511)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at dalvik.system.NativeStart.main(Native Method)
07-20 12:49:31.125: E/AndroidRuntime(4186): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load deezer from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.playertest-1.apk,libraryPath=/data/app-lib/com.example.playertest-1]: findLibrary returned null
07-20 12:49:31.125: E/AndroidRuntime(4186):     at java.lang.Runtime.loadLibrary(Runtime.java:365)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at java.lang.System.loadLibrary(System.java:535)
07-20 12:49:31.125: E/AndroidRuntime(4186):     at com.deezer.sdk.player.impl.RealPlayerImpl.<clinit>(Unknown Source)
07-20 12:49:31.125: E/AndroidRuntime(4186):     ... 16 more

我对此失败感到非常困惑,因为如果我删除该行

Player play = player.createPlayer();

没有失败也没有警告。所以这是有趣的一点。我不明白为什么此时返回的库为空,因为 DeezerConnect、DeezerConnectImpl、PlayerFactory、DefaultPlayerFactory 甚至 Player 类都在同一个库中,到目前为止一切正常。

有人对此有明显的解决方案吗?此外,我该如何解决这个问题?

4

1 回答 1

0

您是否按照添加 SDK C 库的步骤进行操作,即将 libdeezer.so 添加到您的 libs/armeabi 文件夹中?

此错误主要意味着在设备上找不到该库,在您的情况下,这可能意味着它未与您的应用程序打包在一起。

于 2013-08-01T12:11:08.790 回答