nativescript-jwplayer
JW Player for nativescript
npm i --save nativescript-jwplayer

NativeScript JW Player

此插件提供了在 nativescript 中使用原生 jwplayer android/ios sdks 的接口。

jwplayer.com 注册并获取 android 和 ios 的 JWPlayer 许可证密钥。

对于 Android,在 AndroidManifest.xml 的 application 元数据文件中设置。

	<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">


<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
android:screenOrientation="portrait"
android:theme="@style/LaunchScreenTheme">


<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>

<!--TODO Set your license key-->
<meta-data
android:name="JW_LICENSE_KEY"
android:value="YOUR_JW_LICENSE_KEY" />


<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

</application>

对于 iOS,设置 JW_LICENSE_KEY。

<key>JWPlayerKey</key>
<string>YOUR_JW_LICENSE_KEY</string>

安装

从命令提示符进入您应用的根目录并执行

tns plugin add nativescript-jwplayer

用法

Typescript/Javascript 与 XML

<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:jw="nativescript-jwplayer">
<GridLayout>
<jw:JWPlayer src="{{src}}" videoPlayerEventsOnPlayEvent="{{VideoPlayerEventsOnPlayEvent}}"
videoPlayerEventsOnPauseEvent="{{VideoPlayerEventsOnPauseEvent}}">
</jw:JWPlayer>
</GridLayout>
</Page>

Angular

在 app.module.ts 中

import { registerElement } from "@nativescript/angular";
registerElement("JWPlayer", () => require("nativescript-jwplayer").JWPlayer);
<GridLayout>
<JWPlayer
[src]="src"
(videoPlayerEventsOnPlayEvent)="VideoPlayerEventsOnPlayEvent($event)"
(videoPlayerEventsOnPauseEvent)="VideoPlayerEventsOnPauseEvent($event)"
>
</JWPlayer>
</GridLayout>

插件 API

您可以为视频链接和其他详细信息传递 src 属性

选项 描述
URL 要播放的视频 URL
标题 视频标题
描述 视频描述

将这些属性包裹在一个对象中,并将其传递给 src。