官方提供的会议场景示例,这个场景如何实现ppt视频播放、暂停状态同步。我使用该示例的demo,反反复复测试就是实现不了ppt中视频播放状态的同步.demo 中同步视频播放状态执行的是如下api,即 SetMediaObj().
case this.optionType.SLIDEMEDIACHANGED.name:
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.SetMediaObj({ Data: optionInfo.value.Data });
break;
如上示例中完整代码如下
// 演示对象
export class Presentation {
cacheInfo = {}; // 文档操作缓存
optionType = {
SLIDESHOWONNEXT: { name: 'SlideShowOnNext' }, // 播放模式下一步触发
SLIDESHOWONPREVIOUS: { name: 'SlideShowOnPrevious' }, // 播放模式上一步触发
SLIDEMEDIACHANGED: { name: 'SlideMediaChanged' }, // 视频播放状态改变时触发
SLIDEPLAYERCHANGE: { name: 'SlidePlayerChange' }, // 播放状态改变时触发
SLIDELASERPENINKPOINTSCHANGED: { name: 'SlideLaserPenInkPointsChanged' }, // 发送激光笔的墨迹
SLIDESHOWBEGIN: { name: 'SlideShowBegin' }, // 进入播放
SLIDESHOWEND: { name: 'SlideShowEnd' }, // 退出播放
SLIDEINKVISIBLE: { name: 'SlideInkVisible' }, // 是否显示标注
SLIDEINKTOOLBARVISIBLE: { name: 'SlideInkToolbarVisible' }, // 是否使用激光笔和标注
SLIDESELECTIONCHANGED: { name: 'SlideSelectionChanged' } // 文档选中切换,非播放模式下文档同步
};
constructor(wsServer = {}, meetingInfo = {}, wpsApplication) {
this.wsServer = wsServer;
this.meetingInfo = meetingInfo;
this.wpsApplication = wpsApplication;
}
// 初始化主讲人演示事件监听
speakerInit() {
Object.keys(this.optionType).forEach((key) => {
this.wpsApplication.Sub[this.optionType[key].name] = async (e) => {
this.postMessage({ type: this.optionType[key].name, value: e });
this.cacheInfo[this.optionType[key].name] = e;
// 播放模式隐藏右键菜单\hover\链接
if (this.optionType[key].name === this.optionType.SLIDESHOWBEGIN.name) {
delete this.cacheInfo[this.optionType.SLIDESHOWEND.name];
await this._setMenusVisible(false);
} else if (this.optionType[key].name === this.optionType.SLIDESHOWEND.name) {
delete this.cacheInfo[this.optionType.SLIDESHOWBEGIN.name];
await this._setMenusVisible(true);
}
};
});
}
/**
* 主讲人初始化消息推送至听众
* @param isPlay 是否开启播放模式
*/
async sendInitInfo(isPlay) {
// 演示文档初始化后自动进入播放模式
const params = {};
if (isPlay) {
params[this.optionType.SLIDESHOWBEGIN.name] = {};
this.cacheInfo[this.optionType.SLIDESHOWBEGIN.name] = {};
await this.wpsApplication.ActivePresentation.SlideShowSettings.Run();
}
// 除页面页码、动画设置外,其它初始化根据缓存设置
const filterKey = [
this.optionType.SLIDESHOWONNEXT.name,
this.optionType.SLIDESHOWONPREVIOUS.name,
this.optionType.SLIDEPLAYERCHANGE.name
];
Object.keys(this.cacheInfo).forEach(key => {
if (filterKey.indexOf(key) < 0) {
params[key] = this.cacheInfo[key];
}
});
this.postMessage({ type: 'init', value: params });
}
// 初始化听众响应操作
async listenerInit(optionInfo) {
switch (optionInfo.type) {
case this.optionType.SLIDESHOWONNEXT.name: {
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.GotoNextClick();
break;
}
case this.optionType.SLIDESHOWONPREVIOUS.name: {
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.GotoPreClick();
break;
}
case this.optionType.SLIDEPLAYERCHANGE.name: {
if (optionInfo.value.Data.action === 'switchTo' || optionInfo.value.Data.action === 'effectFinish' || optionInfo.value.Data.action === 'changeMediaPlay' || optionInfo.value.Data.action === 'trigger') {
this._setPageAndAnimate(optionInfo);
}
break;
}
case this.optionType.SLIDESHOWBEGIN.name:
await this.wpsApplication.ActivePresentation.SlideShowSettings.Run();
await this._setMenusVisible(false);
break;
case this.optionType.SLIDESHOWEND.name:
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.Exit();
await this._setMenusVisible(true);
break;
case this.optionType.SLIDESELECTIONCHANGED.name: {
const playMode = await this.wpsApplication.ActivePresentation.SlideShowWindow.View.State;
if (playMode !== 'play') {
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.GotoSlide(optionInfo.value);
}
break;
}
case this.optionType.SLIDEINKVISIBLE.name:
this.wpsApplication.ActivePresentation.SlideShowWindow.View.PointerVisible = optionInfo.value.Data.showmark;
break;
case this.optionType.SLIDELASERPENINKPOINTSCHANGED.name:
// 当监听到激光笔的墨迹事件时拿到回调数据后直接调用
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.SetLaserPenData({ Data: optionInfo.value.Data });
break;
case this.optionType.SLIDEINKTOOLBARVISIBLE.name:
this.wpsApplication.ActivePresentation.SlideShowWindow.View.MarkerEditVisible = optionInfo.value.Data.show;
break;
case this.optionType.SLIDEMEDIACHANGED.name: // 视频播放状态改变
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.SetMediaObj({ Data: optionInfo.value.Data });
break;
default:
break;
}
}
/**
* 消息推送
* @param data 推送信息
*/
postMessage = (data) => {
const { meetId, id } = this.meetingInfo;
const params = JSON.stringify({ id: id, meetId, data });
this.wsServer.send(params);
}
// 播放设置右键\hover\链接是否显示
async _setMenusVisible(flag) {
const linkTip = this.wpsApplication.Enum.PpToolType.pcPlayHoverLink; // hover超链接
const imageTip = this.wpsApplication.Enum.PpToolType.pcImageHoverTip; // hover 图片
const menu = this.wpsApplication.Enum.PpToolType.pcPlayingMenu; // 右键菜单
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.SetToolVisible(linkTip, flag);
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.SetToolVisible(imageTip, flag);
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.SetToolVisible(menu, flag);
}
/**
* 设置slide与animate信息同步
* @param optionInfo 同步信息
*/
_setPageAndAnimate = async (optionInfo) => {
try {
const slideIndex = await this.wpsApplication.ActivePresentation.SlideShowWindow.View.Slide.SlideIndex;
const clickIndex = await this.wpsApplication.ActivePresentation.SlideShowWindow.View.GetClickIndex();
if (slideIndex !== optionInfo.value.Data.slideIndex + 1) {
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.GotoSlide(optionInfo.value.Data.slideIndex + 1);
}
if (clickIndex !== optionInfo.value.Data.animateIndex + 1) {
await this.wpsApplication.ActivePresentation.SlideShowWindow.View.GotoClick(optionInfo.value.Data.animateIndex + 2);
}
} catch (e) {
console.error(e);
}
}
}
请提供能同步 ppt 视频播放状态的api和实现逻辑。感谢感谢!