@ capgo/ 电容- jw- 玩家
在你的Capacitorapp中与本地的JW Player SDKs在iOS和Android上播放JW Player的视频和播放列表,在全屏播放器中播放.
🤖 建筑与AI编码代理? 安装 Capgo 技能 所以克劳德代码,代码,光标,副驾驶,或双子座CLI知道如何安装和使用
@capgo/capacitor-jw-player在您的电容应用程序中:npx skills add Cap-go/capgo-skills。然后问你的经纪人: 添加@capgo/capor-jw-player到我的Capacitor应用上,并把它接上" 代理设置指南 • 妇女 主机磁共振
主要特点
- 重播数字 :
initialize()拿着你的驾照钥匙play(), (中文(简体) ),pause(), (中文(简体) ),resume(), (中文(简体) ),stop()财务报告和审定财务报表seekTo()。 。 。 . - 播放列表数字 :
loadPlaylist(), (中文(简体) ),loadPlaylistWithItems()财务报告和审定财务报表setPlaylistIndex()。 。 。 . - 音轨: 音频音轨和标题选择.
- 控件数字 :
setVolume(), (中文(简体) ),setSpeed(), (中文(简体) ),getPosition()财务报告和审定财务报表getState()。 。 。 . - 平台:iOS,Android和Web. 在iOS上使用JWPlayerKit和JW玩家Android SDK. Web使用JW玩家网络播放器.
从jwplayer.com播放有全屏播放器界面的视频. 该插件为控制JW Player回放,播放列表,以及音轨提供了全面的API.
玩家的最新版本需要一分版本的 IOS 15
关键特性
- 总是全屏播放器
- 支持单个视频和播放列表
- 完整控制回放( 播放、 暂停、 搜索等)
- 音频音轨选择
- 标题/字幕支持
- 玩家状态变化的事件听众 从jwplayer.com播放视频
文档
这里有最完整的医生: https://capgo.app/docs/plugins/jw-player/ 页面存档备份,存于互联网档案馆
兼容性
| 插件版本 | 电容兼容性 | 维护 |
|---|---|---|
| 联合国 | 联合国 | ✅ |
| 页:1 | 页:1 | 应要求 |
| 页:1 | 页:1 | ❌ |
| 页:1 | 页:1 | ❌ |
说明: 此插件的主要版本沿用了Capacitor的主要版本. 使用匹配您的 Capacitor 安装的版本( 如 Capacitor 8 的插件 v8) 。 只有最新的主要版本得到积极维护.
安装
您可以使用我们的 AI 辅助设置安装插件 。 使用以下命令将 Capgo 技能添加到您的 AI 工具 :
npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins
然后使用下列提示:
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-jw-player` plugin in my project.
如果您更喜欢手动设置,请通过运行以下命令来安装插件,并遵循下面的平台特定指令:
npm install @capgo/capacitor-jw-player
npx cap sync
机器人
编辑 build.gradle 为了让插件工作:
allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://mvn.jwplayer.com/content/repositories/releases/'
}
}
}
用法实例
基本设置和播放
import { JwPlayer } from '@capgo/capacitor-jw-player';
// Initialize the player with your license key
await JwPlayer.initialize({
licenseKey: 'YOUR_JW_PLAYER_LICENSE_KEY'
});
// Play a video
await JwPlayer.play({
mediaUrl: 'https://example.com/video.mp4',
mediaType: 'video'
});
// Play a playlist
await JwPlayer.play({
mediaUrl: 'https://cdn.jwplayer.com/v2/playlists/PLAYLIST_ID',
mediaType: 'playlist'
});
播放控件
// Pause playback
await JwPlayer.pause();
// Resume playback
// Note: No need to call play() again with the URL, it resumes current content
await JwPlayer.play();
// Seek to a specific position (in seconds)
await JwPlayer.seekTo({ time: 30 });
// Set volume (0.0 to 1.0)
await JwPlayer.setVolume({ volume: 0.5 });
// Change playback speed
await JwPlayer.setSpeed({ speed: 1.5 });
// Stop and release the player
await JwPlayer.stop();
使用播放列表工作
// Load a playlist by URL
await JwPlayer.loadPlaylist({
playlistUrl: 'https://cdn.jwplayer.com/v2/playlists/PLAYLIST_ID'
});
// Load a playlist with custom items
await JwPlayer.loadPlaylistWithItems({
playlist: [
{ file: 'https://example.com/video1.mp4', title: 'Video 1' },
{ file: 'https://example.com/video2.mp4', title: 'Video 2' }
]
});
// Jump to a specific item in the playlist
await JwPlayer.setPlaylistIndex({ index: 2 });
// Get information about the current playlist
const playlistInfo = await JwPlayer.currentPlaylist();
console.log(playlistInfo.playlist);
音频和字幕音轨
// Get available audio tracks
const { tracks } = await JwPlayer.getAudioTracks();
console.log('Available audio tracks:', tracks);
// Get current audio track
const { index } = await JwPlayer.getCurrentAudioTrack();
console.log('Current audio track index:', index);
// Set audio track
await JwPlayer.setCurrentAudioTrack({ index: 1 });
// Get available captions
const { captions } = await JwPlayer.getCaptions();
console.log('Available captions:', captions);
// Set captions track (0 is usually "Off")
await JwPlayer.setCurrentCaptions({ index: 1 });
活动听众
import { JwPlayer } from '@capgo/capacitor-jw-player';
// Listen for player ready event
JwPlayer.addListener('ready', () => {
console.log('Player is ready');
});
// Listen for playback state changes
JwPlayer.addListener('play', () => {
console.log('Playback started');
});
JwPlayer.addListener('pause', (data) => {
console.log('Playback paused, reason:', data.reason);
});
JwPlayer.addListener('complete', () => {
console.log('Playback completed');
});
// Listen for time updates
JwPlayer.addListener('time', (data) => {
console.log(`Position: ${data.position}, Duration: ${data.duration}`);
});
// Listen for playlist changes
JwPlayer.addListener('playlist', (data) => {
console.log(`Playlist loaded with ${data.playlistSize} items`);
});
JwPlayer.addListener('playlistItem', (data) => {
console.log(`Now playing item at index ${data.index}`);
});
// Listen for errors
JwPlayer.addListener('error', (data) => {
console.error('Player error:', data.message);
});
// Clean up listeners when done
function cleanup() {
JwPlayer.removeAllListeners();
}
API 密码
initialize(...)play(...)pause()resume()stop()seekTo(...)setVolume(...)getPosition()getState()setSpeed(...)setPlaylistIndex(...)loadPlaylist(...)loadPlaylistWithItems(...)getAudioTracks()getCurrentAudioTrack()setCurrentAudioTrack(...)getCaptions()getCurrentCaptions()setCurrentCaptions(...)currentPlaylist()
初始化(...)
initialize(options: { licenseKey: string; playerUrl?: string; }) => Promise<void>
初始化 JW 播放器
| 参数 | 类型 | 说明 |
|---|---|---|
options | { licenseKey: string; playerUrl?: string; } | - JW玩家的选项 |
播放(...)
play(options: { mediaUrl: string; mediaType: 'video' | 'playlist'; autostart?: boolean; }) => Promise<void>
播放视频
| 参数 | 类型 | 说明 |
|---|---|---|
options | { mediaUrl: string; mediaType: 'video' | 'playlist'; autostart?: boolean; } | - JW玩家的选项 |
暂停( c)
pause() => Promise<void>
暂停当前播放的媒体
恢复( )
resume() => Promise<void>
恢复当前已暂停的媒体
停止( )
stop() => Promise<void>
停止当前播放媒体
请求(...)
seekTo(options: { time: number; }) => Promise<void>
寻找当前播放媒体中的特定位置
| 参数 | 类型 | 说明 |
|---|---|---|
options | { time: number; } | - 寻找办法 |
设置卷 (...)
setVolume(options: { volume: number; }) => Promise<void>
设置音量级别
| 参数 | 类型 | 说明 |
|---|---|---|
options | { volume: number; } | - 设置音量的选项 |
获取方案( )
getPosition() => Promise<{ position: number; }>
获取媒体目前的位置
回返情况: Promise<{ position: number; }>
获取状态( C)
getState() => Promise<{ state: number; }>
获取当前玩家状态
回返情况: Promise<{ state: number; }>
设置 speed (...)
setSpeed(options: { speed: number; }) => Promise<void>
设定播放速度
| 参数 | 类型 | 说明 |
|---|---|---|
options | { speed: number; } | - 设置速度的选项 |
设置PlaylistIndex(...)
setPlaylistIndex(options: { index: number; }) => Promise<void>
按索引设置播放列表中的当前项目
| 参数 | 类型 | 说明 |
|---|---|---|
options | { index: number; } | - 设置播放列表项的选项 |
加载列表(...)
loadPlaylist(options: { playlistUrl: string; }) => Promise<void>
装入播放列表
| 参数 | 类型 | 说明 |
|---|---|---|
options | { playlistUrl: string; } | - 装入播放列表的选项 |
用项目加载播放列表(...)
loadPlaylistWithItems(options: { playlist: any[]; }) => Promise<void>
装入播放列表中的项目
| 参数 | 类型 | 说明 |
|---|---|---|
options | { playlist: any[]; } | - 装入播放列表的选项 |
获得音频跟踪( )
getAudioTracks() => Promise<{ tracks: any[]; }>
获取可用的音轨
回返情况: Promise<{ tracks: any[]; }>
获取当前音频跟踪( C)
getCurrentAudioTrack() => Promise<{ index: number; }>
获取当前音轨
回返情况: Promise<{ index: number; }>
设置当前音频跟踪(...)
setCurrentAudioTrack(options: { index: number; }) => Promise<void>
设置当前音轨
| 参数 | 类型 | 说明 |
|---|---|---|
options | { index: number; } | - 设置音频音轨的选项 |
获取标题( )
getCaptions() => Promise<{ captions: any[]; }>
获取可用的标题/ 字幕
回返情况: Promise<{ captions: any[]; }>
获取当前标题( C)
getCurrentCaptions() => Promise<{ index: number; }>
获取当前标题/ 字幕音轨
回返情况: Promise<{ index: number; }>
设置当前标题(...)
setCurrentCaptions(options: { index: number; }) => Promise<void>
设定当前标题/ 字幕音轨
| 参数 | 类型 | 说明 |
|---|---|---|
options | { index: number; } | - 设置字幕音轨的选项 |
当前 playlist ()
currentPlaylist() => Promise<any>
获取当前播放列表
回返情况: Promise<any>
活动听众
该插件释放出您可以收听的以下事件 :
| 活动 | 说明 | 数据 |
|---|---|---|
ready | 玩家已准备好使用 | 无 |
play | 播放已经开始 | 无 |
pause | 播放暂停 | { reason: number } |
complete | 当前项目的回放完成 | 无 |
time | 播放时间已更新 | { position: number, duration: number } |
setupError | 设置时出错 | { code: number, message: string } |
error | 常规回放错误 | { code: number, message: string } |
warning | 玩家警告 | { code: number, message: string } |
playlist | 播放列表已装入 | { playlistSize: number } |
playlistItem | 当前播放列表项目已更改 | { index: number, file: string, title: string } |
playerDismissed | 玩家已关闭或解除 | 无 |