【发布时间】:2015-03-19 02:38:13
【问题描述】:
我有运行良好的 chromecast 应用程序,但我现在已经使用 Actionbar 实现了 Material Design,我在其中将 Chromecast MediaRoute 图标显示为操作。问题是我在 ActionBarActivity 中有视频列表视图,我在其中显示视频列表以及视频缩略图。当我尝试在线程中加载视频缩略图时,Cast 图标会消失。但是当我不使用在线程中设置视频缩略图的代码时,会出现 Cast 按钮。
将 MediaRoute 图标转换为操作栏上的操作的代码:
@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();
可运行代码:
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();
}
}
对解决这个问题的任何帮助都会非常棒。
【问题讨论】:
-
android-developers.blogspot.com/2014/10/…您现在是否按照推荐使用“工具栏”?
标签: android chromecast google-cast material-design android-actionbaractivity