Chromecast Sender v2.7.0锁屏图像 [英] Chromecast Sender v2.7.0 lockscreen image
问题描述
我们如何为运行 v2.7.0
的 chromecast发送器
应用显示锁屏插图。我花了大约2天的最好的时间来解决这个问题。
How do we go about showing the lockscreen artwork for a chromecast sender
app running v2.7.0
. I have spent the best part of about 2 days on this without any resolution.
v2.7.0
库当前在 VideoCastManager.java <中具有以下方法/ code>类:
The v2.7.0
library currently has the following method in the VideoCastManager.java
class:
private void setBitmapForLockScreen(MediaInfo video) {
if (video == null || mMediaSessionCompat == null) {
return;
}
Uri imgUrl = null;
Bitmap bm = null;
List<WebImage> images = video.getMetadata().getImages();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (images.size() > 1) {
imgUrl = images.get(1).getUrl();
} else if (images.size() == 1) {
imgUrl = images.get(0).getUrl();
} else if (mContext != null) {
// we don't have a url for image so get a placeholder image from resources
bm = BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.album_art_placeholder_large);
}
} else if (!images.isEmpty()) {
imgUrl = images.get(0).getUrl();
} else {
// we don't have a url for image so get a placeholder image from resources
bm = BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.album_art_placeholder);
}
if (bm != null) {
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null
? new MediaMetadataCompat.Builder()
: new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder
.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bm)
.build());
} else {
if (mLockScreenFetchTask != null) {
mLockScreenFetchTask.cancel(true);
}
mLockScreenFetchTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (mMediaSessionCompat != null) {
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController()
.getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null
? new MediaMetadataCompat.Builder()
: new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder
.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
.build());
}
mLockScreenFetchTask = null;
}
};
mLockScreenFetchTask.execute(imgUrl);
}
}
我尝试过交换 album_art_placeholder_large
可绘制,带有我自己的自定义图像,没有结果。还尝试通过以下行添加位图:
I have tried swaping the album_art_placeholder_large
drawable with my own custom image, no results. Also tried adding a bitmap via the following line:
putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bm)
,但没有任何效果。我在这里到底想念什么?需要使用什么 MediaMetadataCompat
键显示锁屏图稿??
还是我在寻找错误的开始位置?
but nothing works. What exactly am i missing here? What MediaMetadataCompat
key needs to be used to show the lockscreen artwork??
Or i am looking at the wrong place to begin with?
我尝试过一些其他链接但无济于事:
Some other links i have tried but to no avail:
锁定屏幕上的Android MediaMetadata图片已缩放
截至目前,在线文档非常差且无济于事。
The document online as of now is incredibly poor and does not help much.
谢谢!
编辑:经过进一步调查,锁定设备似乎需要15-20分钟才能显示锁屏图像。不知道为什么。
EDIT: On further investigation, it seems to be taking 15-20 minutes after locking the device to show the lockscreen image. Not sure why.
编辑2 :setupMediaSession方法。
EDIT 2: setupMediaSession method.
private void setUpMediaSession(final MediaInfo info) {
if (!isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
return;
}
if (mMediaSessionCompat == null) {
ComponentName mediaEventReceiver = new ComponentName(mContext,
VideoIntentReceiver.class.getName());
mMediaSessionCompat = new MediaSessionCompat(mContext, "TAG", mediaEventReceiver,
null);
mMediaSessionCompat.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mMediaSessionCompat.setActive(true);
mMediaSessionCompat.setCallback(new MediaSessionCompat.Callback() {
@Override
public boolean onMediaButtonEvent(Intent mediaButtonIntent) {
KeyEvent keyEvent = mediaButtonIntent
.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (keyEvent != null && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PAUSE
|| keyEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY)) {
toggle();
}
return true;
}
@Override
public void onPlay() {
toggle();
}
@Override
public void onPause() {
toggle();
}
private void toggle() {
try {
togglePlayback();
} catch (CastException | TransientNetworkDisconnectionException |
NoConnectionException e) {
LOGE(TAG, "MediaSessionCompat.Callback(): Failed to toggle playback", e);
}
}
});
}
mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
PendingIntent pi = getCastControllerPendingIntent();
if (pi != null) {
mMediaSessionCompat.setSessionActivity(pi);
}
if (info == null) {
mMediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_NONE, 0, 1.0f).build());
} else {
mMediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PLAYING, 0, 1.0f)
.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE).build());
}
// Update the media session's image
updateLockScreenImage(info);
// update the media session's metadata
updateMediaSessionMetadata();
mMediaRouter.setMediaSessionCompat(mMediaSessionCompat);
}
推荐答案
您是否定义了较大定义MediaInfo时的专辑封面? CCL假定您有一个较小的窗口(设置为index = 0),它将用于通知,小型控制器和媒体路由器控制器对话框,而较大的窗口(MediaInfo中的第二个图像,index = 1)将用于锁屏。和全屏遥控器。如果这些图像在那里,CCL将自动使用它们。作为测试,请运行CastVideos-android(v2),看看是否适合您。
Have you defined a "larger" album arts when you defined your MediaInfo? CCL assumes you have a smaller one, set as index=0, which will be used in notification and mini-controller and media router controller dialog and a larger one (second image in MediaInfo, index=1) that will be used for the lockscreen and the fullscreen remote controller. If these images are there, CCL automatically uses them. As a test, run CastVideos-android (v2) and see if that works for you.
这篇关于Chromecast Sender v2.7.0锁屏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!