上图为拉流页面(即看直播页面)
最近刚刚做完直播项目,来总结一下,直播使用七牛云直播实现的,直播和看直播写了两个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