Polyv Help Center

Help Center

7 Video Casting

Updated: 2026-05-21 18:34:06

The video casting feature is used to cast on-demand videos to large-screen devices for playback. In the old on-demand iOS SDK, the casting capability was provided by the Demo layer. Developers can refer to the casting module source code in the Demo to integrate it into their own projects.

7.1 Applicable Versions and Limitations

  • The current Demo has integrated a self-developed casting SDK, with the casting dependency being PLVDLNA.
  • The casting module source code is located in the Demo's PolyvVodSDKDemo/PolyvVodSDKDemo/Classes/Cast directory.
  • The current Demo's casting example does not support casting encrypted videos. When playing encrypted videos, the casting entry will prompt that encrypted videos do not support casting.
  • After enabling screen recording prevention videoCaptureProtect=YES, the casting module is disabled by default.
  • The casting sender and receiver must be on an interoperable network environment, and the receiver must support the corresponding casting capability.

7.2 Integrating Casting Dependencies

Add the casting dependency in Podfile:

# 投屏 SDK
pod 'PLVDLNA'

After executing pod install, reopen the project.

7.3 Importing Demo Casting Source Code

Import the casting-related source code from the Demo's Classes/Cast directory into the project.

Cast
├── PLVCastBusinessManager.h // 投屏业务管理器,封装投屏 UI 与 PLVCastManager 的调用
├── PLVCastBusinessManager.m
├── PLVCastManager.h // 投屏管理器,封装设备搜索、连接、播放控制和状态回调
├── PLVCastManager.m
├── PLVCastControllView.h // 投屏控制视图
├── PLVCastControllView.m
├── PLVCastServiceListView.h // 投屏设备选择列表视图
└── PLVCastServiceListView.m

If the project uses the Demo's player skin PLVVodSkinPlayerController, the pre-packaged casting button and interaction logic in the Demo can be reused. If the project uses a custom player UI, refer to PLVCastBusinessManager and PLVCastManager to integrate the casting entry on your own.

7.4 Initializing the Casting Module

Import the casting business manager in the playback page:

#import "PLVCastBusinessManager.h"

Declare the casting business manager:

@property (nonatomic, strong) PLVCastBusinessManager *castBM;

After the player initialization is complete, initialize and enable the casting module:

if ([PLVCastBusinessManager authorizationInfoIsLegal]) {
    self.castBM = [[PLVCastBusinessManager alloc] initCastBusinessWithListPlaceholderView:self.view
                                                                                  player:self.player];
    [self.castBM setup];
}

Where:

  • self.view is the parent view of the device list view.
  • self.player is the on-demand player PLVVodPlayerViewController instance.
  • authorizationInfoIsLegal is currently used for backward compatibility; PLVDLNA does not require additional configuration of AppId or AppSecret.

7.5 Displaying the Casting Entry

If the project uses PLVVodSkinPlayerController, refer to the casting button logic in the Demo's player skin. PLVCastBusinessManager sets the click event for the casting button in the player skin within setup.

After clicking the casting button, the casting module will:

  1. Determine whether the current video supports casting.
  2. Display the device list view.
  3. Search for casting devices when Wi-Fi is available.
  4. Initiate casting playback after selecting a device.

If the project uses a custom player UI, you can create your own casting button and refer to the button click logic in PLVCastBusinessManager to call the device list display and device search capabilities.

7.6 Searching for and Connecting to Casting Devices

If you need to directly use PLVCastManager to interface with a custom UI, you can search for and connect to devices using the following methods.

// 开始搜索设备
[[PLVCastManager shareManager] startSearchService];

// 停止搜索设备
[[PLVCastManager shareManager] stopSearchService];

// 根据设备列表下标连接设备
PLVCastServiceModel *serviceModel = [[PLVCastManager shareManager] connectServiceWithIndex:index];

// 根据设备模型连接设备
[[PLVCastManager shareManager] connectServiceWithModel:serviceModel];

// 断开当前连接
[[PLVCastManager shareManager] disconnect];

The results of device search and connection will be returned via the PLVCastManagerDelegate callback.

// 发现投屏设备
- (void)plvCastManager_findServices:(NSArray<PLVCastServiceModel *> *)servicesArray;

// 设备搜索状态变化
- (void)plvCastManager_searchStateHadChanged:(BOOL)searchIsStart;

// 设备连接结果
- (void)plvCastManager_connectServicesResult:(BOOL)isConnected
                                serviceModel:(PLVCastServiceModel *)serviceModel
                           passiveDisconnect:(BOOL)isPassiveDisconnect;

// 投屏错误
- (void)plvCastManager_castError:(NSError *)error;

7.7 Initiating Casting Playback

After connecting to a device, call startPlayWithVideo:quality:startPosition: to initiate casting playback.

[[PLVCastManager shareManager] startPlayWithVideo:self.player.video
                                          quality:self.player.quality
                                    startPosition:self.player.currentPlaybackTime];

Parameter Description:

Parameter Description
video Current playback video model
quality Casting resolution
startPosition Casting start position, in seconds

7.8 Playback Control

After casting playback starts, use PLVCastManager to control playback on the receiver.

// 暂停播放
[[PLVCastManager shareManager] pause];

// 恢复播放
[[PLVCastManager shareManager] resume];

// 停止播放
[[PLVCastManager shareManager] stop];

// 跳转到指定进度,单位为秒
[[PLVCastManager shareManager] seekTo:seekTime];

// 增加音量
[[PLVCastManager shareManager] addVolume];

// 减少音量
[[PLVCastManager shareManager] reduceVolume];

// 设置音量,范围 0~100
[[PLVCastManager shareManager] setVolume:volume];

Playback status and progress can be obtained through the following delegate methods:

// 播放状态变化
- (void)plvCastManager_playStatusChangedWithStatus:(PLVCastPlayStatus)status;

// 播放进度变化
- (void)plvCastManager_playTimeChangedWithCurrentTime:(NSInteger)currentTime
                                             duration:(NSInteger)duration;

Common playback statuses are as follows:

Status Description
PLVCastPlayStatusLoading Casting loading
PLVCastPlayStatusPlaying Casting playing
PLVCastPlayStatusPause Casting paused
PLVCastPlayStatusStopped Casting stopped
PLVCastPlayStatusCommpleted Casting playback completed
PLVCastPlayStatusError Casting playback error

7.9 Destroying the Casting Module

When exiting the playback page, call quitAllFuntionc to stop casting-related functionality.

- (void)dealloc {
    [self.castBM quitAllFuntionc];
}

7.10 Frequently Asked Questions

Do I still need to configure the AppId and AppSecret for Lebo or Muxiang?

No. The current Demo uses PLVDLNA, so there is no need to configure the AppId or AppSecret for Lebo or Muxiang.

Does casting support encrypted videos?

The current Demo's casting example does not support casting encrypted videos. When playing encrypted videos, the casting entry will prompt that encrypted videos do not support casting.

Why can't I cast after enabling screen recording prevention?

After enabling screen recording prevention videoCaptureProtect=YES, PLVCastBusinessManager will not continue to initialize the casting module by default, making the casting entry unavailable.

Can I integrate casting without using the Demo's player skin?

Yes. If the project uses a custom player UI, you can create your own casting button and refer to PLVCastBusinessManager to interface with PLVCastManager's device search, device connection, casting playback, and playback control methods.

联系客服,在线咨询