2016-06-22 17 views
-1

私はspotify apiで作業しています。私のアプリを開くと、その曲は再生されますが、私は見分けられるプレーヤー(メディアコントロール)を見ることができません。これについての洞察?私はアンドロイドスタジオの新人です。ここに私が持っているコードがあります。ユーザーをプレミアムユーザーとして認証し、トラックを再生します。プレイヤーがエミュレータに表示されない

public class MainActivity extends Activity implements 
     PlayerNotificationCallback, ConnectionStateCallback { 

    //redirect uri and other stuff 

    private Player mPlayer; 

    private static final int REQUEST_CODE = 1337; 

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

     AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, 
       AuthenticationResponse.Type.TOKEN, 
       REDIRECT_URI); 
     builder.setScopes(new String[]{"user-read-private", "streaming"}); 
     AuthenticationRequest request = builder.build(); 

     AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request); 
    } 


    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 
     super.onActivityResult(requestCode, resultCode, intent); 

     // Check if result comes from the correct activity 
     if (requestCode == REQUEST_CODE) { 
      AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent); 
      if (response.getType() == AuthenticationResponse.Type.TOKEN) { 
       Config playerConfig = new Config(this, response.getAccessToken(), CLIENT_ID); 
       Spotify.getPlayer(playerConfig, this, new Player.InitializationObserver() { 
        @Override 
        public void onInitialized(Player player) { 
         mPlayer = player; 
         mPlayer.addConnectionStateCallback(MainActivity.this); 
         mPlayer.addPlayerNotificationCallback(MainActivity.this); 
         mPlayer.play("spotify:track:3G69vJMWsX6ZohTykad2AU 
    "); 
        } 

        @Override 
        public void onError(Throwable throwable) { 
         Log.e("MainActivity", "Could not initialize player: " + throwable.getMessage()); 
        } 
       }); 
      } 
     } 
    } 
    @Override 
    public void onLoggedIn() { 
     Log.d("MainActivity", "User logged in"); 
    } 

    @Override 
    public void onLoggedOut() { 
     Log.d("MainActivity", "User logged out"); 
    } 

    @Override 
    public void onLoginFailed(Throwable error) { 
     Log.d("MainActivity", "Login failed"); 
    } 

    @Override 
    public void onTemporaryError() { 
     Log.d("MainActivity", "Temporary error occurred"); 
    } 

    @Override 
    public void onConnectionMessage(String message) { 
     Log.d("MainActivity", "Received connection message: " + message); 
    } 

    @Override 
    public void onPlaybackEvent(EventType eventType, PlayerState playerState) { 
     Log.d("MainActivity", "Playback event received: " + eventType.name()); 
    } 

    @Override 
    public void onPlaybackError(ErrorType errorType, String errorDetails) { 
     Log.d("MainActivity", "Playback error received: " + errorType.name()); 
    } 

    @Override 
    protected void onDestroy() { 
     Spotify.destroyPlayer(this); 
     super.onDestroy(); 
    } 
} 

EDIT:UIの実装はまったく含まれていませんでした。私は次のXMLを書くことでこの問題を解決しました。

<EditText 
     android:id="@+id/songName" 
     android:layout_width="358dp" 
     android:layout_height="61dp" 
     android:inputType="text" 
     android:hint="Song" 
     android:ems="10" 
     android:gravity="center_horizontal" 
     android:textAppearance="@style/TextAppearance.AppCompat.Display1" 
     android:layout_marginTop="8dp" 
     app:layout_constraintTop_toBottomOf="@+id/appBarLayout3" 
     android:layout_marginStart="16dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginLeft="16dp" /> 

    <EditText 
     android:id="@+id/artistName" 
     android:layout_width="358dp" 
     android:layout_height="64dp" 
     android:inputType="text" 
     android:ems="10" 
     android:gravity="center_horizontal" 
     android:hint="Artist" 
     android:textAppearance="@style/TextAppearance.AppCompat.Display1" 
     app:layout_constraintTop_toBottomOf="@+id/songName" 
     android:layout_marginStart="16dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginLeft="16dp" /> 

    <fragment 
     android:id="@+id/fragment" 
     android:name="com.example.joeberg.jamstest.fragments.LyricsFragment" 
     android:layout_width="358dp" 
     android:layout_height="400dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="16dp" 
     android:layout_marginTop="56dp" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/artistName" 
     tools:layout="@layout/fragment_lyrics" /> 

    <Button 
     android:id="@+id/playButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="8dp" 
     android:layout_marginStart="104dp" 
     android:layout_marginTop="0dp" 
     android:onClick="playSongButton" 
     android:text="Play/Pause" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/artistName" /> 

    <Button 
     android:text="Pause" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/pauseButton" 
     android:onClick="pauseSongButton" 
     app:layout_constraintLeft_toRightOf="@+id/playButton" 
     app:layout_constraintTop_toBottomOf="@+id/artistName" 
     android:layout_marginTop="0dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginLeft="8dp" /> 

    <Button 
     android:id="@+id/pauseButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="0dp" 
     android:onClick="pauseSongButton" 
     android:text="Reset" 
     app:layout_constraintLeft_toRightOf="@+id/playButton" 
     app:layout_constraintTop_toBottomOf="@+id/artistName" /> 

これにより、再生ボタンと一時停止ボタンで曲の再生を制御することができました。また、私は曲を検索することができました。

答えて

1

SpotifyのAPIを使用して音楽を再生しているときは、音楽の再生のみが可能です。 UIは含まれていません。あなたはそれを自分で構築する必要があります。

関連する問題