Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Bug related to the preview.

Aperta
#1,689 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
15/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
android, kotlin

Direzione di ricerca

Start with the reporter's surfaceCreated, surfaceChanged and surfaceDestroyed callbacks, which call prepareVideo, startStream, switchCamera, startPreview and stopPreview on RtspServerCamera2. The attached log file is not in the payload, so it must be fetched from the issue page. Done means identifying why the preview intermittently stays black on Android 11 and either fixing the lifecycle ordering or confirming it is a device issue, with a reproduction note.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hi!

Could you please help me with an issue? I'm encountering an intermittent bug related to the preview.

About 3 out of 10 times, the preview shows a "black screen." I've attached the logs and code for reference.

Android 11
Hardware acceleration is enabled by default.


class RTSPFragment : Fragment(), ConnectChecker, ClientListener,
    SurfaceHolder.Callback {

    private lateinit var binding: FragmentRTSPBinding
    private lateinit var surfaceView: OpenGlView
    private lateinit var rtspServerCamera: RtspServerCamera2
    private var clickCount = 0

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentRTSPBinding.inflate(inflater, container, false)
        return binding.root
    }

    @SuppressLint("SimpleDateFormat")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        surfaceView = binding.surfaceViewCam2
        surfaceView.holder.addCallback(this)
        rtspServerCamera = RtspServerCamera2(surfaceView, this, 8554)
        rtspServerCamera.streamClient.setOnlyVideo(true)
        rtspServerCamera.streamClient.setClientListener(this)
        rtspServerCamera.streamClient.setAuthorization("admin", "admin")
        rtspServerCamera.setVideoCodec(VideoCodec.H264)
        surfaceView.setIsStreamHorizontalFlip(true)
        lifecycleScope.launch {
            try {
                while (true) {
                    binding.overlayTimeRtsp.text = SimpleDateFormat("HH:mm:ss").format(Date())
                    delay(500)
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }

        binding.logoCameraActivity.setOnClickListener{
            clickCount++
            if (clickCount >= 20) {
                findNavController().navigate(R.id.action_rtsp_to_login)
                clickCount = 0
            }
        }
    }

    private fun prepare(): Boolean {
        Log.d("CameraActivity", "prepare: front ${rtspServerCamera.resolutionsFront} back ${rtspServerCamera.resolutionsBack}")
        val prepared = rtspServerCamera.prepareVideo(1280, 720, 24, 2000 * 1024, 90)
        return prepared
    }

    override fun onAuthError() {
        Log.i("@@@@", "Auth error")
    }

    override fun onAuthSuccess() {
        Log.i("@@@@", "Auth success")
    }

    override fun onConnectionFailed(reason: String) {
        Log.i("@@@@", "Connection failed")
    }

    override fun onConnectionStarted(url: String) {
        Log.i("@@@@", "Connection started")
    }

    override fun onConnectionSuccess() {
        Log.i("@@@@", "Connection success")
    }

    override fun onDisconnect() {
        Log.i("@@@@", "Client disconnect")
    }

    override fun onClientConnected(client: ServerClient) {
        Log.i("@@@@", "Client connected")
    }

    override fun onClientDisconnected(client: ServerClient) {
        Log.i("@@@@", "Client disconnected")
    }

    override fun surfaceCreated(holder: SurfaceHolder) {
        if(prepare())
            rtspServerCamera.startStream()
        rtspServerCamera.switchCamera("0")
    }

    override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
        if (!holder.surface.isValid)
            Log.e("@@@@", "Surface is invalid!")
        if (!rtspServerCamera.isOnPreview)
            rtspServerCamera.startPreview()
    }

    override fun surfaceDestroyed(holder: SurfaceHolder) {
        Log.i("@@@@", "Surface destroyed")
        if (rtspServerCamera.isStreaming) {
            rtspServerCamera.stopStream()
        }
        if (rtspServerCamera.isOnPreview)
            rtspServerCamera.stopPreview()
    }
}

18_12_24.txt

Lingua principale
Kotlin
Stelle
3k
Fork
946
Merge medio
4g 6h
PR unite (30g)
9

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pedroSG94/RootEncoder

Tutte le issue di pedroSG94/RootEncoder

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.