Salve a tutti, sto provando ad usare streamaxia per fare contribuzioni video su un'app android.
Sulla base dell'app di demo (java) ho provato ad utilizzare la libreria in un progetto Kotlin ma noto due cose piuttosto strane:
- sono obbligato a chiamare il metodo switchCamera() altrimenti mi parte con la telecamera dei selfies
- lo streamVideo risulta mal codificato e su VLC vedo un valore di 1000 frame per secondo che non capisco da dove li prende.
Il codice del Fragment (esclusi import e metodi di callback di streamaxia dove per ora loggo solo) è il seguente:
codice:class StreamingFragment(val protocol: String): Fragment(), RtmpHandler.RtmpListener, RecordHandler.RecordListener, EncoderHandler.EncodeListener { private val logTag = "StreamingFragment" var mCameraView: CameraPreview? = null var mPublisher: StreamaxiaPublisher? = null override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { // requireActivity().requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE val rootView: View = inflater.inflate(R.layout.video_stream, container, false) return rootView } private fun hideStatusBar() { val decorView: View = MyApplication.instance.mainActivity?.getWindow()!!.getDecorView() // Hide the status bar. val uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN decorView.systemUiVisibility = uiOptions } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) try { // hideStatusBar() mCameraView = view.findViewById(R.id.preview) as CameraPreview mPublisher = StreamaxiaPublisher(mCameraView, MyApplication.instance.mainActivity) mPublisher?.setRtmpHandler(RtmpHandler(this)) mPublisher?.setEncoderHandler(EncoderHandler(this)); mPublisher?.setRecordEventHandler(RecordHandler(this)); mPublisher?.switchCamera() // mPublisher?.setVideoBitRate(500*1000) mPublisher?.framerate = 30 mPublisher?.keyframeInterval = 5 mCameraView?.startCamera() requireActivity().requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE MyLog.d(logTag, "onViewCreated -> end...") } catch (e: Exception) { MyLog.e(logTag, "onViewCreated -> errore: " + e.localizedMessage) e.stackTrace } } private fun avvioContribuzione() { mPublisher?.startPublish("rtmp://rtmp.streamaxia.com/streamaxia/demo") } @OptIn(DelicateCoroutinesApi::class) override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) MyLog.d(logTag, "onConfigurationChanged -> start...") //Update the orientation for stream mPublisher?.setScreenOrientation(newConfig.orientation) //The new orientation might not support the current resolution /* val supportedRes: Size = mPublisher?.getSupportedPictureSizes(newConfig.orientation)!![0] */ mPublisher?.setVideoOutputResolution( 1920, 1080, newConfig.orientation ) // mPublisher?.switchToHardEncoder() GlobalScope.launch(Dispatchers.Default) { delay(10000) MyLog.d(logTag, "onConfigurationChanged -> avvioContribuzione...") avvioContribuzione() } } private fun stopPublisher() { // stoppo il publisher try { mPublisher?.stopPublish() } catch (e: Exception) { MyLog.e(logTag, "stopPublisher -> error stopping publisher: " + e.localizedMessage) } } private fun stopCamera() { // stoppo la camera try { mCameraView?.stopCamera() } catch (e: Exception) { MyLog.e(logTag, "stopCamera -> error stopping camera: " + e.localizedMessage) } } }

Rispondi quotando