#AdditionalJar: com.android.support:support-v4
#AdditionalJar: com.android.support:mediarouter-v7
#AdditionalJar: com.google.android.gms:play-services-cast
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
Dim jo As JavaObject
jo.InitializeContext
jo.RunMethod("sendTrackInfoToBluetoothDevice", Null)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#if JAVA
import android.media.AudioManager;
import android.media.AudioTrack;
import android.media.MediaCodec;
import android.media.MediaCodec.BufferInfo;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.media.MediaMetadata;
import android.media.RemoteControlClient;
import android.media.RemoteControlClient.MetadataEditor;
import android.media.session.MediaSession;
import android.media.session.PlaybackState;
import android.os.Binder;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.SystemClock;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v7.media.MediaItemMetadata;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.format.Time;
import android.util.Log;
import android.content.Intent;
import android.content.IntentFilter;
import android.app.PendingIntent;
import android.app.Service;
import com.google.android.gms.cast.TextTrackStyle;
private AudioManager mAudioManager;
private AudioTrack mAudioTrack;
private RemoteControlClient mRemoteControlClient;
private MediaSession mMediaSession;
public void _onCreate() {
BA.Log("Running onCreate");
IntentFilter filter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
this.mAudioManager = (AudioManager) getSystemService("audio");
if (VERSION.SDK_INT < 21) {
if (this.mRemoteControlClient == null) {
Log.d("init()", "API " + VERSION.SDK_INT + " lower than " + 21);
Log.d("init()", "Using RemoteControlClient API.");
this.mRemoteControlClient = new RemoteControlClient(PendingIntent.getBroadcast(this, 0, new Intent("android.intent.action.MEDIA_BUTTON"), 0));
this.mAudioManager.registerRemoteControlClient(this.mRemoteControlClient);
}
} else if (this.mMediaSession == null) {
Log.d("init()", "API " + VERSION.SDK_INT + " greater or equals " + 21);
Log.d("init()", "Using MediaSession API.");
this.mMediaSession = new MediaSession(this, "StreamPlayerServiceMediaSession");
this.mMediaSession.setFlags(2);
this.mMediaSession.setActive(true);
}
}
public void sendTrackInfoToBluetoothDevice() {
if (VERSION.SDK_INT >= 21) {
this.mMediaSession.setMetadata(new MediaMetadata.Builder().putString(MediaItemMetadata.KEY_TITLE, "title").putString(MediaItemMetadata.KEY_ARTIST, "artist").putString(MediaMetadataCompat.METADATA_KEY_ALBUM, "album").build());
this.mMediaSession.setPlaybackState(new PlaybackState.Builder().setActions(4).setState(3, -1, TextTrackStyle.DEFAULT_FONT_SCALE, SystemClock.elapsedRealtime()).build());
} else if (VERSION.SDK_INT >= 18) {
android.media.RemoteControlClient.MetadataEditor ed = this.mRemoteControlClient.editMetadata(true);
ed.putString(7, "title");
ed.putString(2, "artist");
ed.putString(1, "playing title");
ed.apply();
this.mRemoteControlClient.setPlaybackState(3, -1, TextTrackStyle.DEFAULT_FONT_SCALE);
}
}