Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 铬铸。CastRemoteDisplayLocalService不';不要一次调用创建演示文稿_Android_Video Streaming_Chromecast - Fatal编程技术网

Android 铬铸。CastRemoteDisplayLocalService不';不要一次调用创建演示文稿

Android 铬铸。CastRemoteDisplayLocalService不';不要一次调用创建演示文稿,android,video-streaming,chromecast,Android,Video Streaming,Chromecast,我使用的应用程序显示实时视频流。我希望该应用程序能够在chromcast上播放视频。我不能使用,因为我必须动态地更改标题(为了安全,我没有找到如何做到这一点)。所以我不得不拒绝这种方法,我决定尝试在GlSurfaceView上播放我的视频。但我面对CastRemoteDisplayLocalService不调用onCreatePresentation,所以我的CastPresentation不创建。 根据日志,PresentationService创建,但不调用CreatePresentatio

我使用的应用程序显示实时视频流。我希望该应用程序能够在chromcast上播放视频。我不能使用,因为我必须动态地更改标题(为了安全,我没有找到如何做到这一点)。所以我不得不拒绝这种方法,我决定尝试在GlSurfaceView上播放我的视频。但我面对CastRemoteDisplayLocalService不调用onCreatePresentation,所以我的CastPresentation不创建。 根据日志,PresentationService创建,但不调用CreatePresentation,我不明白为什么。当我停止流媒体时,它还会调用onDismissPresentation

日志:

MediaRouterCallback.java

public class MediaRouterCallback extends MediaRouter.Callback {
public static final String TAG = MediaRouterCallback.class.getName();

private CastDevice mSelectedDevice;
private FragmentActivity activity;
private Context mContext;

public MediaRouterCallback(FragmentActivity activity, Context context){
    this.activity = activity;
    mContext = context;
}

@Override
public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo info) {
    Log.d(TAG, "onRouteSelected " + info.getName());
    Intent intent = new Intent(mContext,
            activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent notificationPendingIntent = PendingIntent.getActivity(
            mContext, 0, intent, 0);

    CastRemoteDisplayLocalService.NotificationSettings settings =
            new CastRemoteDisplayLocalService.NotificationSettings.Builder()
                    .setNotificationPendingIntent(notificationPendingIntent).build();

    CastRemoteDisplayLocalService.startService(
            CastApplication.getContext(),
            PresentationService.class, CastApplication.sApplicationId,
            mSelectedDevice, settings,
            new CastRemoteDisplayLocalService.Callbacks() {
                @Override
                public void onServiceCreated(CastRemoteDisplayLocalService castRemoteDisplayLocalService) {
                    Log.d(TAG, "CHROMECAST onServiceCreated");
                }

                @Override
                public void onRemoteDisplaySessionStarted(
                        CastRemoteDisplayLocalService service) {
                    Log.d(TAG, "CHROMECAST onRemoteDisplaySessionStarted");
                }

                @Override
                public void onRemoteDisplaySessionError(
                        Status errorReason){
                    Log.d(TAG, "CHROMECAST onRemoteDisplaySessionError");
                }
            });
}

@Override
public void onRouteUnselected(MediaRouter router, MediaRouter.RouteInfo info ) {
    Log.d(TAG, "onRouteUnselected " + info.getName());
}

}
PresentationService.java

public class PresentationService extends CastRemoteDisplayLocalService {
public static final String TAG = PresentationService.class.getName();

FirstScreenPresentation mPresentation;

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "CHROMECAST PresentationService onCreate" );
}

@Override
public void onCreatePresentation(Display display) {
    Log.d(TAG, "CHROMECAST onCreatePresentation");
    createPresentation(display);
}

@Override
public void onDismissPresentation() {
    Log.d(TAG, "CHROMECAST onDismissPresentation");
    dismissPresentation();
}

private void dismissPresentation() {
    if (mPresentation != null) {
        mPresentation.dismiss();
        mPresentation = null;
    }
}

private void createPresentation(Display display) {
    dismissPresentation();
    mPresentation = new FirstScreenPresentation(this, display);
    try {
        mPresentation.show();
    } catch (WindowManager.InvalidDisplayException ex) {
        Log.e(TAG, "CHROMECAST Unable to show presentation, display was " +
                "removed.", ex);
        dismissPresentation();
    }
}
}
FirstScreenPresentation.java

public class FirstScreenPresentation extends CastPresentation {

private GLSurfaceView mFirstScreenSurfaceView;

public FirstScreenPresentation(Context context,
                               Display display) {
    super(context, display);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first_screen_layout);
    mFirstScreenSurfaceView = (GLSurfaceView)
            findViewById(R.id.gl_surface_view);
    mFirstScreenSurfaceView.setRenderer(new ClearRenderer());
}


class ClearRenderer implements GLSurfaceView.Renderer {
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        // Do nothing special.
    }

    public void onSurfaceChanged(GL10 gl, int w, int h) {
        gl.glViewport(0, 0, w, h);
    }

    public void onDrawFrame(GL10 gl) {
        gl.glClearColor(1.0f, 0f, 0f, 1.0f);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    }

    public void setColor(float r, float g, float b) {
        mRed = r;
        mGreen = g;
        mBlue = b;
    }

    private float mRed = 1.0f;
    private float mGreen;
    private float mBlue;
}

}

问题是我的演员id有误

你们能分享一下Chromcast的样品吗。CastremotedDisplayLocalService
public class FirstScreenPresentation extends CastPresentation {

private GLSurfaceView mFirstScreenSurfaceView;

public FirstScreenPresentation(Context context,
                               Display display) {
    super(context, display);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first_screen_layout);
    mFirstScreenSurfaceView = (GLSurfaceView)
            findViewById(R.id.gl_surface_view);
    mFirstScreenSurfaceView.setRenderer(new ClearRenderer());
}


class ClearRenderer implements GLSurfaceView.Renderer {
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        // Do nothing special.
    }

    public void onSurfaceChanged(GL10 gl, int w, int h) {
        gl.glViewport(0, 0, w, h);
    }

    public void onDrawFrame(GL10 gl) {
        gl.glClearColor(1.0f, 0f, 0f, 1.0f);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    }

    public void setColor(float r, float g, float b) {
        mRed = r;
        mGreen = g;
        mBlue = b;
    }

    private float mRed = 1.0f;
    private float mGreen;
    private float mBlue;
}

}