Android Question Library not working

andredamen

Active Member
Licensed User
Longtime User
I want to play Spotify songs in my app without Spotify appearing. I created a developer account in Spotify, and I'm receiving the correct code within the app.
Now I just need to program the calls. To do this, I created a wrapper and compiled it into a jar file in Android Studio using spotify-app-remote-release-0.8.0.aar.
So far, everything has gone well. I created the jar file and the corresponding XML file.
I checked the library in the B4A app. Now I'm getting the error message "unknown Spotify wrapper type," even though it's in the jar file and clearly also in the XML file (see attached images).
Does anyone have any idea what I've done wrong?
 

Attachments

  • b4a.jpg
    b4a.jpg
    28.1 KB · Views: 44
  • jarfile.jpg
    jarfile.jpg
    35.3 KB · Views: 40
  • xml.jpg
    xml.jpg
    22.4 KB · Views: 39

andredamen

Active Member
Licensed User
Longtime User
B4X:
package com.qrmusic.spotify;

import android.content.Context;
import com.spotify.android.appremote.api.ConnectionParams;
import com.spotify.android.appremote.api.Connector;
import com.spotify.android.appremote.api.SpotifyAppRemote;

/**
 * Wrapperklasse voor het verbinden met Spotify en afspelen van muziek.
 */
public class SpotifyWrapper {

    private SpotifyAppRemote mSpotifyAppRemote = null;

    /**
     * Verbindt met Spotify via Spotify App Remote SDK.
     * 
     * @param context Android context
     * @param clientId Spotify API client ID
     * @param redirectUri Redirect URI van Spotify ontwikkelaarsdashboard
     */
    public void Connect(Context context, String clientId, String redirectUri) {
        ConnectionParams connectionParams = new ConnectionParams.Builder(clientId)
                .setRedirectUri(redirectUri)
                .showAuthView(false)
                .build();

        SpotifyAppRemote.connect(context, connectionParams, new Connector.ConnectionListener() {
            @Override
            public void onConnected(SpotifyAppRemote remote) {
                mSpotifyAppRemote = remote;
            }

            @Override
            public void onFailure(Throwable throwable) {
                // Verbindingsfout afhandelen (optioneel)
            }
        });
    }

    /**
     * Speelt een track af op Spotify.
     * 
     * @param uri Spotify track URI (bijv. "spotify:track:...")
     */
    public void Play(String uri) {
        if (mSpotifyAppRemote != null) {
            mSpotifyAppRemote.getPlayerApi().play(uri);
        }
    }

    /**
     * Pauzeert de huidige track.
     */
    public void Pause() {
        if (mSpotifyAppRemote != null) {
            mSpotifyAppRemote.getPlayerApi().pause();
        }
    }

    /**
     * Stopt de muziekweergave (werkt als pauze, Spotify heeft geen echte stop).
     */
    public void Stop() {
        Pause(); // Spotify kent geen aparte 'stop'
    }

    /**
     * Verbreekt de Spotify-verbinding.
     */
    public void Disconnect() {
        if (mSpotifyAppRemote != null) {
            SpotifyAppRemote.disconnect(mSpotifyAppRemote);
            mSpotifyAppRemote = null;
        }
    }

    /**
     * Controleert of er verbinding is met Spotify.
     * 
     * @return true als verbonden, false als niet verbonden
     */
    public boolean IsConnected() {
        return mSpotifyAppRemote != null;
    }
}

en

B4X:
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <Class>
        <Name>com.qrmusic.spotify.SpotifyWrapper</Name>
        <ShortName>SpotifyWrapper</ShortName>
        <HasInit>true</HasInit>
        <IgnoreMaster>true</IgnoreMaster>

        <Method>
            <Name>Initialize</Name>
            <ReturnType>void</ReturnType>
            <Parameter>
                <Name>ba</Name>
                <Type>anywheresoftware.b4a.BA</Type>
            </Parameter>
            <Parameter>
                <Name>eventName</Name>
                <Type>String</Type>
            </Parameter>
        </Method>

        <Method>
            <Name>SearchTrack</Name>
            <ReturnType>String</ReturnType>
            <Parameter>
                <Name>query</Name>
                <Type>String</Type>
            </Parameter>
        </Method>

        <Method>
            <Name>PlayTrack</Name>
            <ReturnType>boolean</ReturnType>
            <Parameter>
                <Name>trackId</Name>
                <Type>String</Type>
            </Parameter>
        </Method>

    </Class>
</root>
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I don´t think that this code can result in a B4A Library.

Where do you get the xml from?

Check this

Under the hood it doesn´t look like you are familar in creating libraries for B4A.
I suggest to hire someone to do it for you.
 
Last edited:
Upvote 0
Top