0

Добрый день! два дня не могу справиться с проблемой(( При смене камеры с фронтальной на переднюю и наоборот через раз или реже или чаще, приложение вылетает.

09-23 18:21:15.006 271-271/? E/mm-camera: mct_pipeline_stop_session: left modules: 5
09-23 18:21:15.006 271-271/? E/mm-camera: mct_pipeline_stop_session: left modules: 4
09-23 18:21:15.006 271-3660/? D/mm-camera: mct_pipeline_stop_session_thread: Stop module name: imglib - E
09-23 18:21:15.006 271-3626/? D/mm-camera: c2d_thread_process_pipe_message:793, C2D_THREAD_MSG_ABORT: c2d_thread exiting..
09-23 18:21:15.010 271-3660/? D/mm-camera: mct_pipeline_stop_session_thread: Stop module name: imglib - X
09-23 18:21:15.010 271-271/? E/mm-camera: mct_pipeline_stop_session: left modules: 3
09-23 18:21:15.011 271-3659/? D/mm-camera: c2d_module_stop_session:488, info: session 1 stopped.
09-23 18:21:15.011 271-3659/? D/mm-camera: mct_pipeline_stop_session_thread: Stop module name: pproc - X
09-23 18:21:15.011 271-271/? E/mm-camera: mct_pipeline_stop_session: left modules: 2
09-23 18:21:15.012 271-3657/? D/mm-camera: mct_pipeline_stop_session_thread: Stop module name: isp - X
09-23 18:21:15.012 271-271/? E/mm-camera: mct_pipeline_stop_session: left modules: 1
09-23 18:21:15.074 1862-3867/? W/InputDispatcher: channel '325c16df com.alyaskaapps.spidyphotoeditor/com.unity3d.player.UnityPlayerActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
09-23 18:21:15.075 1862-4258/? I/WindowState: WIN DEATH: Window{325c16df u0 com.alyaskaapps.spidyphotoeditor/com.unity3d.player.UnityPlayerActivity}
09-23 18:21:15.075 1862-4538/? I/bsthal: <BST> disable sensor <BOSCH Acceleration Sensor>
09-23 18:21:15.081 1862-3867/? E/InputDispatcher: channel '325c16df com.alyaskaapps.spidyphotoeditor/com.unity3d.player.UnityPlayerActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
09-23 18:21:15.082 1862-4258/? W/InputDispatcher: Attempted to unregister already unregistered input channel '325c16df com.alyaskaapps.spidyphotoeditor/com.unity3d.player.UnityPlayerActivity (server)'
09-23 18:21:15.082 1862-4258/? W/WindowManager: Force-removing child win Window{18819df5 u0 SurfaceView} from container Window{325c16df u0 com.alyaskaapps.spidyphotoeditor/com.unity3d.player.UnityPlayerActivity}
09-23 18:21:15.122 270-270/? I/Zygote: Process 3441 exited due to signal (11)
09-23 18:21:15.136 1862-7773/? I/ActivityManager: Process com.alyaskaapps.spidyphotoeditor (pid 3441) has died
09-23 18:21:15.138 1862-1877/? W/WindowManager: Failed looking up window
                                                java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@fa7df2c does not exist
                                                    at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8758)
                                                    at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8749)
                                                    at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1140)
                                                    at android.os.BinderProxy.sendDeathNotice(Binder.java:551)
09-23 18:21:15.138 1862-1877/? I/WindowState: WIN DEATH: null
09-23 18:21:15.140 1862-7773/? W/ActivityManager: Force removing ActivityRecord{3763193 u0 com.alyaskaapps.spidyphotoeditor/com.unity3d.player.UnityPlayerActivity t2385}: app died, no saved state
09-23 18:21:15.201 1862-7776/? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 3441 uid 10361
09-23 18:21:15.215 271-3655/? D/mm-camera: mct_pipeline_stop_session_thread: Stop module name: sensor - X
09-23 18:21:15.216 271-3627/? E/mm-camera: Got some events
09-23 18:21:15.217 271-271/? E/mm-camera: mct_pipeline_stop_session: left modules: 0
09-23 18:21:15.217 271-271/? D/mm-camera: mct_pipeline_stop_session - X

введите сюда описание изображения

   using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

public class CameraWebCamTexture : MonoBehaviour {

    WebCamTexture wct = null;
    WebCamDevice[] devices;
    public RawImage image;
    // Device cameras
    WebCamDevice frontCameraDevice;
    WebCamDevice backCameraDevice;
    WebCamDevice activeCameraDevice;

    WebCamTexture frontCameraTexture;
    WebCamTexture backCameraTexture;
    WebCamTexture activeCameraTexture;

    // Use this for initialization
    void Start () {

        if (WebCamTexture.devices.Length == 0)
        {
            Debug.Log("No devices cameras found");
            return;
        }

        frontCameraDevice = WebCamTexture.devices.Last();
        backCameraDevice = WebCamTexture.devices.First();

        frontCameraTexture = new WebCamTexture(frontCameraDevice.name);
        backCameraTexture = new WebCamTexture(backCameraDevice.name);

        // Set camera filter modes for a smoother looking image
        frontCameraTexture.filterMode = FilterMode.Trilinear;
        backCameraTexture.filterMode = FilterMode.Trilinear;

        // Set the camera to use by default
        SetActiveCamera(frontCameraTexture);
        /*
        devices = WebCamTexture.devices;
        frontCameraDevice = WebCamTexture.devices.Last();
        backCameraDevice = WebCamTexture.devices.First();
        wct = new WebCamTexture();
        if (devices.Length > 0)
        {
            wct.deviceName = devices[0].name;
            Debug.Log("Device 0");
        }
        rawimage.texture = wct;
        rawimage.material.mainTexture = wct;
        wct.Play();
        */

    }

    public void SwitchCamera()
    {
        try { 

            SetActiveCamera(activeCameraTexture.Equals(frontCameraTexture) ?
                backCameraTexture : frontCameraTexture);
        }
        catch
        {
            Debug.Log("HUI HUI HUI HUI HUI");
        }


    }


    public void SetActiveCamera(WebCamTexture cameraToUse)
    {
        if (activeCameraTexture != null)
        {
            activeCameraTexture.Stop();
        }

        activeCameraTexture = cameraToUse;
        activeCameraDevice = WebCamTexture.devices.FirstOrDefault(device =>
            device.name == cameraToUse.deviceName);

        image.texture = activeCameraTexture;
        image.material.mainTexture = activeCameraTexture;

        activeCameraTexture.Play();
    }

    // Update is called once per frame
    void Update () {

    }
}
3
  • прикольно вы обрабатываете исключение в SwitchCamera :)
    – user194625
    23 сен 2017 в 19:07
  • 1
    Спасибо за внимательность)
    – GoodSoul
    23 сен 2017 в 20:00
  • Кстати, с код стайлом определитесь :D
    – user194625
    23 сен 2017 в 20:02

1 ответ 1

1

Если вы замечали, если просто открыть приложение Камера(встроенное), то переключение между камерами занимает от долей до нескольких секунд(и при этом экран становится черным). И что вы пытаетесь сделать, когда выключили текущую, включаете другую, система еще не получила доступ, а вы уже назначаете ее в image.texture. После команды Play, нужно цикл и проверять пока текстура не начнет проигрывать(isPlaying), и только тогда назначать в image.texture. И соответсвенно наоборот, когда stop вызываете, image.texture надо занулить, или вложить туда какой-нибудь черный квадрат или текстурку с надписью подождите, тут уже ваша фантазия.

p.s. И способ распознавания фронтальной и задней камеры у вас странный, у CamDevice есть функция для распознавания, является ли она фронтальной.

1
  • Спасибо большое!!! ДУмал об этом, а потом забыл!
    – GoodSoul
    23 сен 2017 в 19:54

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.