处理流媒体视频外部屏幕

时间:2014-07-17 07:31:30

标签: android android-activity

我再次遇到一个新问题,基本上现在我有一个应用程序需要在移动设备(Android)上传输视频的要求,但它不应该在任何其他外部输出中显示应用程序内容或视频(如果应用程序有第二个输出,它应该显示不同的布局),我一直在尝试使用Android中的一些示例,并查看API。

如果显示另一个输出,我无法显示外部图像。任何想法我怎么能实现这一目标。我错过了什么吗?

目前我正在尝试使用MediaRouter,DisplayManager Presentation。

来实现我的目标

1选项 - 使用MediaRouter

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MediaRouter mediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
        MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();

        if (route != null) {
             Display presentationDisplay = route.getPresentationDisplay();
             if (presentationDisplay != null) {
                 Presentation presentation = new DemoPresentation(this, presentationDisplay);
                 presentation.show();
             }
         }
         // Keep going here because theresnt presentation (secundary output) available

         setContentView(R.layout.video_player); 
        } 

2选项 - 使用DisplayManager

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
    Display[] presentationDisplays = mDisplayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
    if (presentationDisplays.length > 0) {
        // If there is more than one suitable presentation display, then we could consider
        // giving the user a choice.  For this example, we simply choose the first display
        // which is the one the system recommends as the preferred presentation display.
        Display display = presentationDisplays[0];
        Presentation presentation = new DemoPresentation(this, display);
        presentation.show();
    }
    // Keep going here because theresnt presentation (secundary output) available

    setContentView(R.layout.video_player); 
} 

这是演示文稿

  private final class DemoPresentation extends Presentation {
   final PresentationContents mContents = null;

   public DemoPresentation(Context context, Display display) {
       super(context, display);

   }

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       // Be sure to call the super class.
       super.onCreate(savedInstanceState);
       // Get the resources for the context of the presentation.
       // Notice that we are getting the resources from the context of the presentation.
       // Inflate the layout.
       setContentView(R.layout.show_layout_external_screen);

  }
来自http://developer.android.com/reference/android/app/Presentation.html

示例

0 个答案:

没有答案