android-VLC

android使用开源库VLC播放网络摄像头内容

添加必要so库文件

vlc-so库文件

将vlc源码文件拷贝到当前项目中

vlc源码文件

使用VLC播放rtsp流

package com.moyu.ipccamera

import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.SurfaceView
import org.videolan.libvlc.LibVLC
import org.videolan.libvlc.Media
import org.videolan.libvlc.MediaPlayer
import java.util.ArrayList



class MainActivity : AppCompatActivity() {

    private val TAG = "$\$MainActivity$$"
    private lateinit var mSurfaceView: SurfaceView
    private val mVideoWidth = 1280
    private val mVideoHeight = 800
    private var libVLC: LibVLC? = null
    private var mMediaPlayer: MediaPlayer? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        init()
    }

    private fun init() {
        mSurfaceView = findViewById(R.id.main_sv)
        createPlayer(500)
    }



    private fun createPlayer(nc: Int) {
        val options = ArrayList<String>()
        options.add("--network-caching=$nc")

        libVLC = LibVLC(applicationContext, options)

        mMediaPlayer = MediaPlayer(libVLC)
        mMediaPlayer?.setEventListener(mEventListener)

        // Set up video output
        val vout = mMediaPlayer!!.vlcVout
        vout.setVideoView(mSurfaceView)
        vout.setWindowSize(mVideoWidth, mVideoHeight)
        vout.attachViews()
        val media = Media(
            libVLC,
            Uri.parse("rtsp://admin:admin12345@192.168.88.196/:554/h264/ch1/main/av_stream")
        )
        media.setHWDecoderEnabled(false, false)
        mMediaPlayer!!.media = media
        mMediaPlayer!!.play()
    }

    private fun releasePlayer() {
        mMediaPlayer?.let {
            it.stop()
            it.vlcVout.detachViews()
            mMediaPlayer = null

        }
        libVLC?.let {
            it.release()
            libVLC = null
        }

    }

    private val mEventListener = MediaPlayer.EventListener {
        when (it.type) {
            MediaPlayer.Event.EndReached -> {
                Log.i(TAG, "onEvent: EndReached")
            }
            MediaPlayer.Event.Buffering -> {
                Log.i(TAG, "onEvent: Buffering")
            }
            MediaPlayer.Event.Opening -> {
                Log.i(TAG, "onEvent: Opening")
            }
            MediaPlayer.Event.Playing -> {
                Log.i(TAG, "onEvent: Playing")
            }
            MediaPlayer.Event.Stopped -> {
                Log.i(TAG, "onEvent: Stopped")
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        releasePlayer()
    }


}

附上rtsp流截图
rtsp流视频截图
VLC示例代码:https://code.videolan.org/videolan/libvlc-android-samples
本项目示例代码:https://gitee.com/cmy_mob_dllm/android/tree/master/IpcCamera

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值