我有Chromecast应用程序工作正常,但我现在已经使用Actionbar实现了Material Design,我将Chromecast MediaRoute图标显示为操作。问题是我在ActionBarActivity中获得了视频列表视图,其中我显示了视频列表以及视频缩略图。当我尝试在线程中加载视频缩略图时,Cast图标会消失。但是当我不使用在线程中设置视频缩略图的代码时,会出现“转换”按钮。
Cast MediaRoute Icon的代码作为操作栏上的操作:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.cast_menu, menu);
MenuItem media_route_menu_item = menu.findItem(R.id.media_route_menu_item);
MediaRouteActionProvider provider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider(media_route_menu_item);
provider.setRouteSelector(mediaRouteSelector);
return true;
}
显示缩略图的代码:
public void UpdateThumbnailImageForListItem()
{
try {
boolean started = false;
MyViewItem myViewItem = (MyViewItem)myViewItemQueue.poll();
if(myViewItem != null && myViewItem.getView() != null){
ViewHolder holder;
holder = (ViewHolder) myViewItem.getView().getTag(); //getViewHolderFromView(myViewItem.getView());
Bitmap bmThumbnail,fixedSizeThumbnail;
List<VideoListItem> items = MyCastSampleGlobals.getInstance().getVideoListItems();
if(items != null && holder != null)
{
//lets use title for now as key
String viewTitle = getVideoTitle(holder);
VideoListItem vItem = getVideoListItemForTitle(viewTitle);
if(vItem != null)
{
String path = vItem.getFilePath();
bmThumbnail = getVideoFrame(path);//ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MINI_KIND);
fixedSizeThumbnail = ThumbnailUtils.extractThumbnail(bmThumbnail, 150, 100);
holder.imageview.setImageBitmap(fixedSizeThumbnail);
}
}
}
else
{
//Thread.sleep(2000);
}
// RunOnUIThreadUpdateUIThumbnailView();
}
catch (Exception e) {
}
}
在OnCreate中:
Thread myThread;
Runnable runnable = new StatusRunner();
myThread = new Thread(runnable);
logVIfEnabled(TAG, "Starting statusRunner thread");
myThread.start();
Runnable代码:
private class StatusRunner implements Runnable {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
updateStatus();
updateProgressBar();
doThumbnailLoad();
Thread.sleep(1000);
} catch (Exception e) {
Log.e(TAG, "Thread interrupted: " + e);
}
}
}
}
doThumbnailload功能代码:
private void doThumbnailLoad()
{
if(castSampleNewAdapter != null)
{
castSampleNewAdapter.UpdateThumbnailImageForListItem();
}
}
解决这个问题的任何帮助都会非常棒。
答案 0 :(得分:0)
请参阅示例应用中的setupactionbar方法,并通过替换&#34;工具栏&#34;完成MD迁移。对于较旧的操作栏,你应该在toolBar的视图中使用强制转换图标的外观。