2014-02-26 87 views
0

以下是我的代碼。有一個可用的googlecast設備,但我無法找到它。我已經按照SDK文檔一步一步重建了以下簡單項目,但仍然沒有得到修復解決方案,所以重新打開此問題。非常感謝你。沒有媒體路徑可以找到和媒體路由actionBar項目或媒體路由按鈕不可用

private MediaRouter mMediaRouter; 
    private MediaRouteSelector mMediaRouteSelector; 
    private MediaRouter.Callback mMediaRouterCallback; 
    private CastDevice mSelectedDevice; 
    private GoogleApiClient mApiClient; 
    private Cast.Listener mCastListener; 
    private ConnectionCallbacks mConnectionCallbacks; 
    // private ConnectionFailedListener mConnectionFailedListener; 
    // private HelloWorldChannel mHelloWorldChannel; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    mMediaRouter = MediaRouter.getInstance(getApplicationContext()); 
    mMediaRouteSelector = new MediaRouteSelector.Builder() 
      // .addControlCategory(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID) 
        /* .addControlCategory(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID) 
        .addControlCategory(CastMediaControlIntent.EXTRA_CAST_APPLICATION_ID) 
        .addControlCategory(CastMediaControlIntent.EXTRA_CAST_RELAUNCH_APPLICATION) 
        .addControlCategory(CastMediaControlIntent.EXTRA_CAST_STOP_APPLICATION_WHEN_SESSION_ENDS) 
        .addControlCategory(CastMediaControlIntent.EXTRA_CUSTOM_DATA) 
        .addControlCategory(CastMediaControlIntent.EXTRA_DEBUG_LOGGING_ENABLED) 
        .addControlCategory(CastMediaControlIntent.EXTRA_ERROR_CODE)*/ 
      .addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO) 
      .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO) 
      .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) 

        .build(); 
    mMediaRouterCallback = new MyMediaRouterCallback(); 
    //mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,MediaRouter.CALLBACK_FLAG_UNFILTERED_EVENTS); 

} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    super.onCreateOptionsMenu(menu); 
     getMenuInflater().inflate(R.menu.main, menu); 
     MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item); 
     MediaRouteActionProvider mediaRouteActionProvider = 
     (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem); 
     mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector); 
     return true; 


} 
@Override 
public boolean onPrepareOptionsMenu(Menu menu) 
{ 

    return true; 

} 
@Override 
public void onStart() { 
    mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, 
      MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY); 
    super.onStart(); 
} 

// Remove the selector on stop to tell the media router that it no longer 
// needs to discover routes for your app. 
@Override 
public void onStop() { 
    mMediaRouter.removeCallback(mMediaRouterCallback); 
    super.onStop(); 
} 
+1

你可以嘗試開源示例應用程序,看看你的設備是否被發現:https://github.com/googlecast/MediaRouter-Cast-Button-android –

+0

感謝Leon Nicholls。單擊應用程序中的MediaRouterDiscovery按鈕時,我的測試結果未找到任何設備。只是無法想出其他地方失蹤。 – cc5zhenhua

+0

嘗試重新下載android支持庫,但沒有奏效。 – cc5zhenhua

回答

0

查看內嵌評論。再次感謝Leon Nicholls。

相關問題