如何在Android Studio中集成JWPlayer

3

大家好,我正在做一个项目,想要播放一个从json中获取的视频。我想使用Jwplayer来实现这个目的,请告诉我如何在Android Studio中集成JWPlayer。

1个回答

6

下面开始翻译:

将JW Player SDK导入您的项目

有两种方法可以将JW Player SDK导入到您的Android Studio项目中。一种是通过我们的Maven存储库,另一种是从您的仪表板下载.aar文件并从本地机器导入它。

  1. Import using Maven

    To add the SDK to your Android project using Maven. You must first edit your project's build.gradle file and add our Maven repository url

    allprojects {
        repositories {
            ...
            maven {
                url 'https://mvn.jwplayer.com/content/repositories/releases/'
            }
        }
    }
    

    Next, edit your application's build.gradle file and add the JW Player SDK dependency:

    dependencies {
      ...
      compile 'com.longtailvideo.jwplayer:jwplayer-android-sdk:+'
    }
    

    After syncing Gradle you should be able to use all JW Player SDK classes in your application.

  2. Import from your local file system

    If you do not wish to use our Maven repository you can always download our SDK package from your Dashboard and import the SDK from your local file system.

    Downloading the JW Player SDK from your Dashboard

    1. Sign in to your JW Player dashboard at https://account.jwplayer.com
    2. Navigate to the Players section, center of the left navigation bar, then click on Tools
    3. In the Downloads section, locate the Android SDK and click on the download button
    4. Unzip the SDK package to your local hard drive.

    Importing the SDK to your Android Studio Project

    1. Go to File > New > New Module… > Import .JAR / .AAR Package
    2. Navigate to the location where you unzipped the AAR file, select it, then click Finish
    3. Go to File > Project Structure…
    4. Make sure your app is selected in the left-hand pane, then click the Dependencies tab
    5. Click the plus sign in the lower left-hand corner of the dialog and choose Module Dependency
    6. Select the jwplayer-android-sdk module then click OK
    7. Click OK again to close the dialog, the JW Player SDK is now available in your project

初始项目配置

为了确保播放器正常运行,需要在AndroidManifest.xml文件中添加以下条目:

首先,您必须添加您的JW许可证密钥并将其嵌套在 <application> 元素中。

<meta-data 
    android:name="JW_LICENSE_KEY"
    android:value="{YOUR_LICENSE_KEY}" />

{YOUR_LICENSE_KEY} 应替换为您仪表板中工具页面显示的JW Player许可证密钥。

有效的许可版本包括广告、企业和试用版。如果提供了无效的许可密钥,应用程序将崩溃并抛出AssertionError。

接下来,修改所有将包含JW Player的标签,并添加

<activity
    ...
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize" >

这将允许您以编程方式处理方向更改,并防止Android在旋转时销毁Activity。 其他功能 如果您计划使用Google IMA广告,请将以下行添加到应用程序的build.gradle文件的依赖项部分:
compile 'com.google.android.gms:play-services-ads:8.1.0'

如果您计划使用Google IMA广告,请将以下行添加为应用程序AndroidManifest.xml中标签的子级:
<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

顺便提一下,这里是源代码


花了一些时间才弄明白,所以想分享一下。要锁定版本,您需要使用类似于compile 'com.longtailvideo.jwplayer:jwplayer-android-sdk:2.5.3+164'的语法,将**+替换为2.5.3+164**。此外,jwplayer已经从jwplayer-android-sdk转移到了jwplayer-core、jwplayer-common,详见文档。他们在版本2.6中采用了这种新布局。 - lockwobr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接