if (this.mAudioManager.isBluetoothA2dpOn()) {
sendTrackInfoToBluetoothDevice();
}
}
}
public void sendTrackInfoToBluetoothDevice() {
if (VERSION.SDK_INT >= 21) {
this.mMediaSession.setMetadata(new MediaMetadata.Builder().putString(MediaItemMetadata.KEY_TITLE, this.mUserData.getPlayingTitle()).putString(MediaItemMetadata.KEY_ARTIST, this.mUserData.getPlayingArtist()).putString(MediaMetadataCompat.METADATA_KEY_ALBUM, this.mUserData.getPlayingAlbumTitle()).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) {
MetadataEditor ed = this.mRemoteControlClient.editMetadata(true);
ed.putString(7, this.mUserData.getPlayingTitle());
ed.putString(2, this.mUserData.getPlayingArtist());
ed.putString(1, this.mUserData.getPlayingAlbumTitle());
ed.apply();
this.mRemoteControlClient.setPlaybackState(3, -1, TextTrackStyle.DEFAULT_FONT_SCALE);
}
}
Where do mMediaSession and mRemoteControlClient set?
private MediaSession mMediaSession;
private RemoteControlClient mRemoteControlClient;
....
public void onCreate() {
IntentFilter filter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
this.mUserData = UserData.getInstance(getApplicationContext());
this.receiver = new NetworkChangeReceiver();
registerReceiver(this.receiver, filter);
if (this.mAudioManager == null) {
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);
}
}
private static final String AVRCP_PLAYSTATE_CHANGED = "com.android.music.playstatechanged";
private static final String AVRCP_META_CHANGED = "com.android.music.metachanged";
private void bluetoothNotifyChange(String what) {
Intent i = new Intent(what);
i.putExtra("id", Long.valueOf(getAudioId()));
i.putExtra("artist", getArtistName());
i.putExtra("album",getAlbumName());
i.putExtra("track", getTrackName());
i.putExtra("playing", isPlaying());
i.putExtra("ListSize", getQueue());
i.putExtra("duration", duration());
i.putExtra("position", position());
sendBroadcast(i);
}
Also this seem that work:
send track informations via A2DP/AVRCP
B4X:private static final String AVRCP_PLAYSTATE_CHANGED = "com.android.music.playstatechanged"; private static final String AVRCP_META_CHANGED = "com.android.music.metachanged"; private void bluetoothNotifyChange(String what) { Intent i = new Intent(what); i.putExtra("id", Long.valueOf(getAudioId())); i.putExtra("artist", getArtistName()); i.putExtra("album",getAlbumName()); i.putExtra("track", getTrackName()); i.putExtra("playing", isPlaying()); i.putExtra("ListSize", getQueue()); i.putExtra("duration", duration()); i.putExtra("position", position()); sendBroadcast(i); }
AddReceiverText(ssend, <intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
<action android:name="android.bluetooth.device.action.ACTION_ACL_DISCONNECTED"/>
</intent-filter>)
AddPermission(android.permission.BLUETOOTH)
Sub Service_Start (StartingIntent As Intent)
Log(StartingIntent)
Log(StartingIntent.Action)
If StartingIntent.Action="android.bluetooth.device.action.ACL_CONNECTED" Then
CallSubDelayed(Main,"sendmessagebt")End If
End Sub
Sub sendmessagebt
Dim i As Intent
i.Initialize("android.bluetooth.device.action.ACL_CONNECTED", "")
i.putExtra("artist", "Test");
Dim p As Phone
p.SendBroadcastIntent(i)
End Sub
#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);
}
}
This code compiles correctly:
B4X:#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); } }
This code compiles correctly:
B4X:#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); } }
Strain i havent this problem.This code gives the following: -Xlinteprecation
How do I express Deprecation to the compiler?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?