安卓用七牛云做直播

本文介绍了如何在安卓应用中使用七牛云服务进行直播。直播功能分为主播和观看者两个Activity,共用同一Fragment。当遇到网络问题导致直播中断时,程序会判断网络状态并尝试重连。同时,直播页面还包括了聊天、禁言、切换摄像头等交互功能。观看直播的实现同样简洁,通过注释详细说明了拉流过程。目前只展示了主要逻辑,剩余部分后续更新。
摘要由CSDN通过智能技术生成

上图为拉流页面(即看直播页面)

最近刚刚做完直播项目,来总结一下,直播使用七牛云直播实现的,直播和看直播写了两个Activiy,公用同一个Fragment,大致结构是这样的。下面先来说主播页面(前期引入sak省略):

  CameraPreviewFrameView cameraPreviewFrameView =
                (CameraPreviewFrameView) findViewById(R.id.cameraPreview_surfaceView);
        cameraPreviewFrameView.setListener(this);

        streamingProfile = new StreamingProfile();

        try {

//            // audio sample rate is 44100, audio bitrate is 96 * 1024 bps
//            StreamingProfile.AudioProfile aProfile = new StreamingProfile.AudioProfile(44100, 96 * 1024);
 fps is 30, video bitrate is 1000 * 1024 bps, maxKeyFrameInterval is 48
//            StreamingProfile.VideoProfile vProfile = new StreamingProfile.VideoProfile(30, 1000 * 1024, 48);
//            StreamingProfile.AVProfile avProfile = new StreamingProfile.AVProfile(vProfile, aProfile);
            streamingProfile
//                    .setAVProfile(avProfile)
                    .setVideoQuality(StreamingProfile.VIDEO_QUALITY_MEDIUM2)//视频的 fps 为 30,码率为 1000 kbps
                    .setAudioQuality(StreamingProfile.AUDIO_QUALITY_MEDIUM2)//音频的采样率为 44100 HZ,码率为 48 kbps。

                    .setEncodingSizeLevel(StreamingProfile.VIDEO_ENCODING_HEIGHT_480)//使用内置的 encoding size level
                    .setBitrateAdjustMode(StreamingProfile.BitrateAdjustMode.Auto)
//                    .setAudioQuality(StreamingProfile.AUDIO_QUALITY_LOW1)
//                .setPreferredVideoEncodingSize(960, 544)
                    //.setEncodingSizeLevel(StreamingProfile.VIDEO_ENCODING_HEIGHT_480)
                    .setEncoderRCMode(StreamingProfile.EncoderRCModes.QUALITY_PRIORITY)//质量优先,实际的码率可能高于设置的码率
//                .setAVProfile(avProfile)
//                    .setDnsManager(getMyDnsManager())
//                    .setAdaptiveBitrateEnable(true)
                    .setFpsControllerEnable(true)
                    .setStreamStatusConfig(new
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值