diff --git a/app/src/main/java/org/ntlab/amaryllis/client/TestPlayActivity.java b/app/src/main/java/org/ntlab/amaryllis/client/TestPlayActivity.java index 4c0f1b2..82783be 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/TestPlayActivity.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/TestPlayActivity.java @@ -1,54 +1,47 @@ package org.ntlab.amaryllis.client; -import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; -import android.media.AudioManager; -import android.media.MediaPlayer; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; -import android.support.v4.media.MediaBrowserCompat; -import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaControllerCompat; -import android.support.v4.media.session.PlaybackStateCompat; import android.view.View; import android.widget.Button; import android.widget.TextView; -import android.widget.Toast; -import org.ntlab.amaryllis.client.entities.AmaryllisBackgroundService; import org.ntlab.amaryllis.client.voiceservice.TestVoiceService; -import java.io.IOException; -import java.util.List; - public class TestPlayActivity extends AppCompatActivity { - MediaBrowserCompat mBrowser; - MediaControllerCompat mController; + + Button button_connect; Button button_play; TextView textView_title; TextView textView_position; - MediaPlayer mediaPlayer; + TestVoiceService myService; Intent serviceIntent; - + MediaControllerCompat mediaController; Button mPlayButton; ServiceConnection serviceConnection = new ServiceConnection(){ @Override public void onServiceConnected(ComponentName name, IBinder service) { myService = ((TestVoiceService.MyBinder)service).getService(); + try { + mediaController=new MediaControllerCompat(TestPlayActivity.this,myService.getToken()); + } catch (RemoteException e) { + e.printStackTrace(); + } //myService.setMessage("Hello, IBinder!"); //startService(serviceIntent); } @Override public void onServiceDisconnected(ComponentName name) { - myService = null; } }; @@ -57,22 +50,34 @@ super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_play); + button_connect =findViewById(R.id.button_connect); button_play=findViewById(R.id.button_play); + button_play.setEnabled(false); //textView_title=findViewById(R.id.textView_title); // textView_position=findViewById(R.id.textView_position); serviceIntent=new Intent( getBaseContext(),TestVoiceService.class ); - //bindService(serviceIntent,serviceConnection, Context.BIND_AUTO_CREATE); + + button_connect.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //serviceIntent.setAction(TestVoiceService.ACTION_PLAY); + //startService(serviceIntent); + bindService(serviceIntent,serviceConnection, Context.BIND_AUTO_CREATE); + button_play.setEnabled(true); + if(myService!=null)myService.testCall(); + } + }); button_play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - - serviceIntent.setAction(TestVoiceService.ACTION_PLAY); - startService(serviceIntent); - //myService.testCall(); + mediaController.getTransportControls().play(); } }); + + + /* button_play.setOnClickListener(new View.OnClickListener() { @Override @@ -84,5 +89,8 @@ //mPlayButton = (Button) findViewById(R.id.play); //mPlayButton.setOnClickListener(this); + + } + } \ No newline at end of file