N
O
D
E
M
E
D
I
A
Thinking
首页
产品
文档
博客
订单
文档
快速接入-Objc
2026年 5月 20日 下午3:43
## Cocoapods 安装 ### 在项目目录下创建 Podfile 文件, 如果没有的话请执行 ``` pod init ``` ### 添加Pod ```ruby # Uncomment the next line to define a global platform for your project platform :ios, '9.0' target 'QLive' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks use_modular_headers! # Pods for QLive pod 'NodeMediaClient', '~> 4.0' end ``` ### 安装 ```shell pod install ``` ## 简单用法 ### 使用NodePlayer进行播放 ``` #import "PlayViewController.h" //引入头文件 #import <NodeMediaClient/NodeMediaClient.h> @interface PlayViewController () //定义播放器对象 @property (nonatomic, strong) NodePlayer *np; @end @implementation PlayViewController - (void)viewDidLoad { [super viewDidLoad]; // 初始化,如果有授权码请填入 _np = [[NodePlayer alloc] initWithLicense:@""]; //设置日志等级 [_np setLogLevel:1]; //开启硬件加速 [_np setHWAccelEnable:YES]; //如果需要视频内容解码,请填入16位密码 [_np setCryptoKey:@""]; //设置播放缓冲,单位毫秒 [_np setBufferTime:1000]; //设置视频缩放模式 [_np setScaleMode:1]; //设置音量 [_np setVolume:1.0f]; // 绑定视图 [_np attachView:self.view]; //开始播放 [_np start:@"rtmp://live.nodemedia.cn/live/b480_264"]; } -(void)viewWillDisappear:(BOOL)animated { // 移除视图 [_np detachView]; //停止播放 [_np stop]; //标记释放 _np = nil; } @end ``` ### 使用NodePublisher进行摄像头推流 **请确认描述条目'Privacy - Microphone Usage Description' 和 'Privacy - Camera Usage Description' 已经添加入info.plist** ``` #import "PublishViewController.h" //引入头文件 #import <NodeMediaClient/NodeMediaClient.h> @interface PublishViewController () //定义推流器对象 @property (nonatomic, strong) NodePublisher *np; @property (nonatomic) Boolean isStart; @end @implementation PublishViewController - (void)viewDidLoad { [super viewDidLoad]; //初始化对象,如果有授权码请填入 _np = [[NodePublisher alloc] initWithLicense:@""]; //设置日志等级 [_np setLogLevel:NM_LOGLEVEL_DEBUG]; //开启硬件加速 [_np setHWAccelEnable:YES]; //开启麦克风降噪 [_np setDenoiseEnable:YES]; //开启Enhanced Rtmp推流,仅对H265有效 [_np setEnhancedRtmp:YES]; //如果需要,设置推流内容加密,16位密码 [_np setCryptoKey:@""]; //设置音频参数 [_np setAudioParamWithCodec:NMC_CODEC_ID_AAC profile:NMC_PROFILE_AUTO samplerate:48000 channels:1 bitrate:64*1000]; //设置视频方向 [_np setVideoOrientation:VIDEO_ORIENTATION_PORTRAIT]; //设置视频关键帧间隔,单位秒 [_np setKeyFrameInterval:3]; //设置视频参数 [_np setVideoParamWithCodec:NMC_CODEC_ID_H264 profile:NMC_PROFILE_AUTO width:540 height:960 fps:30 bitrate:2000*1000]; //绑定摄像头预览视图 [_np attachView:self.view]; //打开摄像头预览 [_np openCamera:true]; } -(void)viewWillDisappear:(BOOL)animated { //关闭摄像头预览 [_np closeCamera]; //移除视图 [_np detachView]; //停止推流 [_np stop]; //标记释放 _np = nil; } - (IBAction)publishAction:(id)sender { if(_isStart) { [_np stop]; dispatch_async(dispatch_get_main_queue(), ^{ [sender setTitle:@"Start Publish" forState:UIControlStateNormal]; }); }else { [_np start:@"rtmp://live.nodemedia.cn/live/demo"]; dispatch_async(dispatch_get_main_queue(), ^{ [sender setTitle:@"Stop Publish" forState:UIControlStateNormal]; }); } _isStart = !_isStart; } @end ``` ## 用例demo [ObjcDemo.zip](https://www.nodemedia.cn/doc/server/index.php?s=/api/attachment/visitFile&sign=5782309fbcd1615dc1db45922e54f620 "[ObjcDemo.zip")
嘿,我是小R,需要帮助随时找我哦
QQ客服:281269007
邮件支持
扫码加微信
回到顶部