java.io.IOException:准备失败:status = 0x64 - 无法加载视频流

时间:2018-03-30 13:48:39

标签: android kotlin video-streaming surfaceview

我尝试显示视频流,但我的链接无法在Android应用中运行,尽管在iOS和Web应用上运行良好。链接看起来像"rtsp://192.168.8.73/cdb6e5a0-23af-40e8-8da8-54a21af9cba3/cdb6e5a0-23af-40e8-8da8-54a21af9cba3_vs1?token=cdb6e5a0-23af-40e8-8da8-54a21af9cba3^LVEBAMPZOTDGU|admin|1522055956266|0|0^50^26^26^1522315156^3394fa4fd8888fcca38c10bcf5fa74748b5b58a1&username=admin"。

当我使用下面的链接进行测试时,效果很好:

"https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4"

"rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov"

可能我做错了什么......

在我的Kotlin代码中,如果需要所有代码,我可以重构它:

class VideoFragment : RootFragment(), VideoContract.View, VideoAdapter.Listener, SurfaceHolder.Callback, OnPreparedListener, MediaPlayer.OnCompletionListener {

    @Inject
    lateinit var presenter: VideoContract.Presenter

    private val url = "rtsp://192.168.8.73/cdb6e5a0-23af-40e8-8da8-54a21af9cba3/cdb6e5a0-23af-40e8-8da8-54a21af9cba3_vs1?token=cdb6e5a0-23af-40e8-8da8-54a21af9cba3^LVEBAMPZOTDGU|admin|1522055956266|0|0^50^26^26^1522315156^3394fa4fd8888fcca38c10bcf5fa74748b5b58a1&username=admin" // it link not work
    private val url2 = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4"
    private val url3 = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov"
    var videoUrl = ""
    var contractId: Int = 0
    private lateinit var player: MediaPlayer

    companion object {
        val TAG = VideoFragment::class.java.simpleName!!
    }

    fun newInstance(idContract: Int?): VideoFragment {
        val bundle = Bundle()
        bundle.putInt(ID_CONTRACT, idContract!!)
        val fragment = VideoFragment()
        fragment.arguments = bundle
        return fragment
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater!!.inflate(R.layout.fragment_video, container, false)
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        App.appComponent.inject(this)
        presenter.attachView(this)
        retainInstance = true

        contractId = arguments.getInt(ID_CONTRACT)
        presenter.showContractById(contractId, activity)

        surfaceViewFrame.setOnClickListener(this)
        surfaceViewFrame.isClickable = false
        val holder = surfaceViewFrame.holder
        holder.addCallback(this)
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS)

        player = MediaPlayer()
        player.setOnPreparedListener(this)
        player.setOnCompletionListener(this)
        player.setScreenOnWhilePlaying(true)
    }

    override fun passUrl(url: String) {
        videoUrl = url
//        prepareToPlayingVideo(url2) // it works
        prepareToPlayingVideo(videoUrl)
    }

    private fun prepareToPlayingVideo(url: String) {
        Thread(Runnable {
            try {
                player.setDataSource(url)
                player.prepare() // here get error
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }).start()
    }

    override fun surfaceCreated(holder: SurfaceHolder?) {
        player.setDisplay(holder)
        presenter.showVideoByPosition(contractId, 1, activity)
        imgPlay.visibility = View.GONE
    }

    override fun onPrepared(mp: MediaPlayer?) {
        frameLoading?.visibility = View.GONE
        setOrignalScreen()
        videoProgressBar.visibility = View.GONE
        imgPlay.visibility = View.VISIBLE
    }

    override fun surfaceChanged(holder: SurfaceHolder?, format: Int, width: Int, height: Int) {
        //do nothing
    }

    override fun onCompletion(mp: MediaPlayer?) {
        mp?.stop()
    }

    override fun surfaceDestroyed(holder: SurfaceHolder?) {
        //do nothing
    }

    //....

}

当我player.prepare()时 - 我收到错误java.io.IOException: Prepare failed.: status=0x64

请帮我解决..

0 个答案:

没有答案