diff --git a/app/build.gradle b/app/build.gradle index eea80eb..a5d68cf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,6 +32,7 @@ implementation 'androidx.navigation:navigation-ui:2.2.2' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' + implementation 'androidx.media2:media2-exoplayer:1.0.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index eb74252..c4c03c6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ - + - - + + + \ No newline at end of file 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 70445b4..a5fffe5 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/TestPlayActivity.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/TestPlayActivity.java @@ -37,6 +37,7 @@ TestVoiceService myService; Intent serviceIntent; + Button mPlayButton; ServiceConnection serviceConnection = new ServiceConnection(){ @Override public void onServiceConnected(ComponentName name, IBinder service) { @@ -69,5 +70,8 @@ myService.play(); } }); + + //mPlayButton = (Button) findViewById(R.id.play); + //mPlayButton.setOnClickListener(this); } } \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/amaryllis/client/voiceservice/TestVoiceService.java b/app/src/main/java/org/ntlab/amaryllis/client/voiceservice/TestVoiceService.java index 58240fa..94c9cb3 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/voiceservice/TestVoiceService.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/voiceservice/TestVoiceService.java @@ -2,10 +2,16 @@ import android.annotation.SuppressLint; import android.app.IntentService; +import android.app.PendingIntent; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.graphics.BitmapFactory; import android.media.AudioManager; +import android.media.MediaMetadataRetriever; import android.media.MediaPlayer; +import android.media.RemoteControlClient; +import android.media.RemoteController; import android.media.browse.MediaBrowser; import android.net.Uri; import android.os.Binder; @@ -17,6 +23,8 @@ import android.util.Log; +import org.ntlab.amaryllis.client.R; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -29,10 +37,24 @@ public class TestVoiceService extends IntentService { final String TAG = TestVoiceService.class.getSimpleName();//ログ用タグ final String ROOT_ID = "root";//クライアントに返すID onGetRoot / onLoadChildrenで使用 + + public static final String ACTION_TOGGLE = "com.example.mediaplayerlock.ACTION_TOGGLE"; + public static final String ACTION_PLAY = "com.example.mediaplayerlock.ACTION_PLAY"; + + Handler handler;//定期的に処理を回すためのHandler + private PlayListManager playListManager; MediaPlayer mediaPlayer=new MediaPlayer(); - AudioManager am;//AudioFoucsを扱うためのManager + AudioManager audioManager; + RemoteControlClient mRemoteCtlClient; + ComponentName sampleReceiver; + + + + enum State{PLAY,STOP,PAUSE}; + State mState=State.STOP; + boolean isPlaying;//再生中であるかどうかを int index = 0;//再生中のインデックス final IBinder myBinder=new MyBinder(); @@ -44,8 +66,19 @@ public TestVoiceService() { super("TestVoiceService"); System.out.println("START SERVICE"); + + mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); } + + @Override + public void onCreate() { + super.onCreate(); + audioManager=(AudioManager) getSystemService(Context.AUDIO_SERVICE); + sampleReceiver=new ComponentName(this,VoicememoReceiver.class); + + } + public IBinder onBind(Intent intent){ Log.d(TAG,"onBind"); return myBinder; @@ -65,6 +98,9 @@ e.printStackTrace(); } } + public void switchPlayButton(){ + + } String getNextVid(){ //return playListManager.getUnplayed().remove(0); return null; @@ -80,4 +116,6 @@ protected void onHandleIntent(@Nullable Intent intent) { } + + } diff --git a/app/src/main/java/org/ntlab/amaryllis/client/voiceservice/VoicememoReceiver.java b/app/src/main/java/org/ntlab/amaryllis/client/voiceservice/VoicememoReceiver.java new file mode 100644 index 0000000..5c1b7a4 --- /dev/null +++ b/app/src/main/java/org/ntlab/amaryllis/client/voiceservice/VoicememoReceiver.java @@ -0,0 +1,41 @@ +package org.ntlab.amaryllis.client.voiceservice; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.view.KeyEvent; + +public class VoicememoReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) { + KeyEvent keyEvent = (KeyEvent) intent.getExtras().get( + Intent.EXTRA_KEY_EVENT); + if (keyEvent.getAction() == KeyEvent.ACTION_DOWN){ + + switch (keyEvent.getKeyCode()) { + case KeyEvent.KEYCODE_HEADSETHOOK: + case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: + // ヘッドセットのフックボタン押下時 or 再生/一時停止ボタン押下時の処理を記述 + context.startService(new Intent(TestVoiceService.ACTION_TOGGLE)); + break; + case KeyEvent.KEYCODE_MEDIA_PLAY: + // 再生ボタン押下時の処理を記述 + break; + case KeyEvent.KEYCODE_MEDIA_PAUSE: + // 一時停止ボタン押下時の処理を記述 + break; + case KeyEvent.KEYCODE_MEDIA_STOP: + // 停止ボタン押下時の処理を記述 + break; + case KeyEvent.KEYCODE_MEDIA_NEXT: + // 次へボタン押下時の処理を記述 + break; + case KeyEvent.KEYCODE_MEDIA_PREVIOUS: + // 戻るボタン押下時の処理を記述 + break; + } + } + } + } +}