我正在尝试uamp示例,每当方向更改MediaBrowserFragment recyclelerview状态丢失时(不保持其滚动位置).
我的问题是如何在uamp样本中保持滚动位置.
我知道我可以保存滚动位置并在以后恢复,但由于recyclerView本身保持滚动状态,我不想要那些黑客攻击.
我尝试推动这个简单的片段而不是MediaBrowserFragment并保持其滚动
public class TestFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mRootView = inflater.inflate(R.layout.fragment_test, container, false);
RecyclerView recyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(new RecAdapter());
return mRootView;
}
private class RecAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_text, null);
return new ItemViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
((ItemViewHolder) holder).title.setText(""+ position); …Run Code Online (Sandbox Code Playgroud) 我有一个Android Auto应用程序.我想利用分页在应用程序内浏览.您似乎可以通过获取对MediaBrowserCompat的引用并在.subscribe()中传递这些常量来设置EXTRA_PAGE和EXTRA_PAGE_SIZE.但是,我无法弄清楚如何获取Android Auto Audio用于调用.subscribe()的MediaBrowserCompat的引用.
对于一些应该简单的事情来说,这似乎太复杂了,我只是在思考这些事情吗?
pagination android-auto mediabrowserservice mediabrowserservicecompat mediabrowser
我目前正在开发具有视频和音频功能的应用程序的一部分,最近开始重构代码库。目标是集成MediaSession/ MediaController和MediaBrowserService/ MediaBrowser框架。
我们使用ExoPlayer和PlayerControlView更具体的PlayerView的视频和音频组件,它需要提及的播放器实例PlayerControlView:
/**
* Sets the {@link Player} to control.
*
* @param player The {@link Player} to control, or {@code null} to detach the current player. Only
* players which are accessed on the main thread are supported ({@code
* player.getApplicationLooper() == Looper.getMainLooper()}).
*/
public void setPlayer(@Nullable Player player) {...
Run Code Online (Sandbox Code Playgroud)
但是,在Android开发者职位和文档的MediaBrowserService,播放器实例应在服务下载。此外,客户端站点(MediaBrowser 和 MediaController)通过connect()方法和MediaBrowserConnectionCallback为其提供服务的唯一方法,这使得将播放器的实例传递给 PlayerControlView(或其他方式)是不可能的。
我曾尝试使用各种回调,例如 …
android exoplayer mediabrowserservice mediabrowserservicecompat mediasession
有没有办法使用支持库中的MediaMetadataCompat附加功能?
使用MediaMetadata我可以设置额外内容,但使用compat,我不能.
我正在使用一种扩展的服务MediaBrowserServiceCompat,并且还MediaSessionCompat.Callback()使用了它的重写方法onPlayFromMediaId().
在单击recyclelerview项目时具有recyclelerview的片段内部,将调用以下代码.从图像中可以看出,mediaId除了songBundle值之外,还有传递给onPlayFromMediaId()方法.
奇怪的是,在Service类中,playFromMediaId()方法被覆盖,它只接收字符串变量的值,mediaId而songBundle神奇地变为空.(注意 - 用于放置和获取parcelable的键也是相同的.piplable songsVO是实现Parcelable接口的POJO .)
除了这个我注意到的另一个有趣的事情,当我返回到onPlayFromMediaId()已经执行后调用后面的片段并检查每个变量的值,除了mediaId每个其他变量都变为null.
RecyclerAdapter类
class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.layout_song_item, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) { …Run Code Online (Sandbox Code Playgroud) android android-service android-mediaplayer mediabrowserservicecompat
我有一个简单的 Android 应用程序,其中包含一个Activity和一个Service源自MediaBrowserServiceCompat. 我已成功将其设置为通过使用MediaBrowserCompat和播放我的主要活动中的音频MediaControllerCompat。它甚至可以播放和暂停蓝牙耳机的音频。都好。
我的挑战涉及NotificationCompat.MediaStyle锁定屏幕和通知托盘中显示的通知。通知正确显示。但是,当我使用addAction()和添加按钮时MediaButtonReceiver.buildMediaButtonPendingIntent,它们不会执行任何操作。如果我添加一个虚拟的 PendingIntent 来启动我的主要活动,那就可以了。
这是我生成通知的代码(抱歉,这是在 Xamarin 中运行的 C#,因此大小写和名称将与您预期的略有不同)。这是我的服务级别内的。
var builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.SetVisibility(NotificationCompat.VisibilityPublic)
.SetSmallIcon(Resource.Drawable.ic_launcher)
.SetContentTitle("Title")
.SetContentText("Content")
.SetSubText("Subtext")
.SetLargeIcon(icon)
.SetColor(Android.Graphics.Color.DarkOrange)
.SetContentIntent(intent)
.SetDeleteIntent(MediaButtonReceiver.BuildMediaButtonPendingIntent(this, PlaybackStateCompat.ActionStop))
.AddAction(new NotificationCompat.Action(
Resource.Drawable.ic_pause, "Pause",
MediaButtonReceiver.BuildMediaButtonPendingIntent(this, PlaybackStateCompat.ActionPause)))
.SetStyle(new Android.Support.V4.Media.App.NotificationCompat.MediaStyle()
.SetShowActionsInCompactView(0)
.SetMediaSession(this.mediaSession.SessionToken)
.SetShowCancelButton(true)
.SetCancelButtonIntent(MediaButtonReceiver.BuildMediaButtonPendingIntent(this, PlaybackStateCompat.ActionStop))
);
this.StartForeground(NOTIFICATION_ID, builder.Build());
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经看到了以下内容来尝试解决此问题:
MediaSession.setActive(true)PlaybackStateCompatMediaButtonReceiverandroid.intent.action.MEDIA_BUTTON*Compat我知道媒体按钮事件已正确路由到我的应用程序,因为我的蓝牙耳机按钮可以工作。我在我的车上尝试过,它也在那里工作。只是通知中的按钮不起作用。我期望他们生成对MediaSessionCompat.Callback. 这是不正确的吗?我在这里做错了什么? …
android android-mediasession mediabrowserservicecompat android-notification.mediastyle
语音命令 Play [song] on [my appName] 命令不起作用,“appName”未被谷歌助手识别。
我按照说明表格https://developer.android.com/guide/topics/media-apps/interacting-with-assistant和演示应用表格https://github.com/android/uamp
我的AndroidManifest:
<application
android:name=".XApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" // app_name = appX 101.1
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="@style/AppTheme">
<activity
android:name=".ui.splash.SplashActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.AppFullScreenTheme"
android:windowSoftInputMode="adjustPan|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
...
...
<service
android:name="com.music.android.xx.media.MusicService"
android:enabled="true"
android:exported="true"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
<service
android:name=".service.LocationUpdatesService"
android:foregroundServiceType="location" />
<receiver android:name=".service.StopServiceReceiver" />
<receiver android:name=".service.PlayRadioReceiver" />
<service
android:name=".service.MyFirebaseService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter> …Run Code Online (Sandbox Code Playgroud) android assistant mediabrowserservice mediabrowserservicecompat
我的服务:
public class MusicService extends MediaBrowserServiceCompat {
...
}
Run Code Online (Sandbox Code Playgroud)
我的活动:
public class MediaActivity extends AppCompatActivity{
private MediaBrowserCompat mMediaBrowser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMediaBrowser = new MediaBrowserCompat(this,
new ComponentName(this, MusicService.class), mConnectionCallback, null);
mMediaBrowser.connect();
}
@Override
protected void onDestroy() {
super.onDestroy();
mMediaBrowser.disconnect();
}
Run Code Online (Sandbox Code Playgroud)
我想在 UI 中添加关闭按钮,但如何停止MusicService?它继续在后台进行投射。
android android-mediaplayer mediabrowserservice mediabrowserservicecompat mediabrowser
我按照Android 指南在媒体播放器应用程序中使用 MediaBrowserServiceCompat,但该服务在应用程序退出时被销毁。
<service android:name=".media.PlaybackService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
在应用程序启动时正确创建服务。按下按钮时mediaController.transportControls.play()被调用,并且在onPlay()调用我的会话回调类中的此方法之后。内部onPlay()服务启动:(context.startService(Intent(context, MediaBrowserServiceCompat::class.java))也尝试startForegroundService过 Oreo 及更高版本)并设置为前台:this@PlaybackService.startForeground(SERVICE_ID, notificationBuilder?.build())。创建了 Oreo 和更高 API 的通知通道。
现在通知已启动,我可以通过发出命令看到服务位于前台:
Run Code Online (Sandbox Code Playgroud)$adb shell dumpsys activity services PlaybackService (...) isForeground=true foregroundId=1 foregroundNoti=Notification(channel=MyChannelId pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x62 color=0xff000000 category=transport actions=1 vis=PUBLIC) (...)
到目前为止,一切正常,但当我按下主页按钮时,我希望服务保持启动状态,但会调用onDestroy()我的类的方法。MediaBrowserServiceCompat返回应用程序并再次启动服务后,它不会设置为前台(也没有通知)。
我startService在我的应用程序中使用了唯一的一个调用,并删除了每个调用stopSelf和stopForeground测试。
在 API 28、26、22 和 18 上我得到了相同的结果。
我也尝试START_STICKY过从onStartCommand().
我正在尝试向其他媒体应用公开媒体项目,这些应用可以通过我的MediaBrowserServiceCompat服务浏览我的应用内容。在我的onLoadChildren方法中,我正在构建 MediaBrowserCompat.MediaItem一个MediaDescriptionCompat包含Bundle一些我需要播放该项目的额外内容的 。
public class Service extends MediaBrowserServiceCompat {
...
@Override
public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
val bundle = Bundle().apply {
putString("extra", "some value")
}
MediaDescriptionCompat description = new MediaDescriptionCompat.Builder()
.setMediaId(mediaId)
.setExtras(bundle)
.setTitle("title")
.setSubtitle("subtitle")
.setIconUri(uri)
.build();
MediaBrowserCompat.MediaItem item = new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
val items = ArrayList<MediaBrowserCompat.MediaItem>()
items.add(item)
result.sendResult(items)
}
Run Code Online (Sandbox Code Playgroud)
因此,在onPlayFromMediaId(String mediaId, Bundle extras)用户单击该项目时收到的回调中,我得到了正确的结果,mediaId但这extras是一个空包。
private class MediaSessionCallback extends MediaSessionCompat.Callback {
...
@Override …Run Code Online (Sandbox Code Playgroud) android ×9
mediabrowser ×3
android-auto ×1
android-notification.mediastyle ×1
assistant ×1
chromecast ×1
exoplayer ×1
mediainfo ×1
mediasession ×1
pagination ×1