Android 简明教程

Android - JetPlayer

Android 平台包含一个 JET 引擎,可让您在应用程序中添加 JET 音频内容的互动回放。Android 提供 JetPlayer 类来处理这些内容。

The Android platform includes a JET engine that lets you add interactive playback of JET audio content in your applications. Android provides JetPlayer class to handle this stuff.

为了获取 Jet 内容,您需要使用随 AndroidSDK 一起提供的 JetCreator 工具。已在示例中讨论 JetCreator 的用法。为了播放 JetCreator 创建的内容,您需要 android 支持的 JetPlayer 类。

In order to Jet Content , you need to use the JetCreator tool that comes with AndroidSDK. The usage of jetCreator has been discussed in the example. In order to play the content created by JetCreator, you need JetPlayer class supported by android.

要使用 JetPlayer,您需要实例化 JetPlayer 类的一个对象。其语法如下所示 −

In order to use JetPlayer , you need to instantiate an object of JetPlayer class. Its syntax is given below −

JetPlayer jetPlayer = JetPlayer.getJetPlayer();

接下来你需要做的是调用 loadJetFile 方法并传入 Jet 文件的路径。然后你需要将其添加到 JetPlayer 的队列中。其语法如下所示 -

The next thing you need to do is to call loadJetFile method and pass in the path of your Jet file. After that you have to add this into the Queue of JetPlayer. Its syntax is given below −

jetPlayer.loadJetFile("/sdcard/level1.jet");
byte segmentId = 0;

// queue segment 5, repeat once, use General MIDI, transpose by -1 octave
jetPlayer.queueJetSegment(5, -1, 1, -1, 0, segmentId++);

方法 queueJetSegment 将指定的片段排队添加到 JET 队列中。最后,你需要调用 play 方法来播放音乐。其语法如下所示 -

The method queueJetSegment Queues the specified segment in the JET Queue. The last thing you need to is to call the play method to start playing the music. Its syntax is given below −

jetPlayer.play();

除了这些方法以外,JetPlayer 类中还定义了其他方法。它们在下面定义 -

Apart from these methods, there are other methods defined in the JetPlayer class. They are defined below −

Sr.No

Method & description

1

clearQueue() Empties the segment queue, and clears all clips that are scheduled for playback

2

closeJetFile() Closes the resource containing the JET content

3

getJetPlayer() Factory method for the JetPlayer class

4

loadJetFile(String path) Loads a .jet file from a given path

5

pause() Pauses the playback of the JET segment queue

6

release() Stops the current JET playback, and releases all associated native resources

Example

以下示例演示了如何使用 JetCreator 工具创建 Jet 内容。一旦该内容创建,你可以通过 JetPlayer 播放它。

The following example demonstrates the use of JetCreator tool to create Jet content. Once that content is created, you can play it through JetPlayer.

要使用此示例,你需要在实际设备或模拟器上运行它。

To experiment with this example , you need to run this on an actual device or in an emulator.

Steps

Description

1

You will use Android studio IDE to create an Android application and name it as JetPlayer under a package com.example.jetplayer.

2

Install Python and WxPython on your computer from internet.

3

Run the jet creator from command prompt

4

Create Jet content and then save it

5

Run the application and verify the results

Using JetCreator

Installing python

使用 JetCreator 时所需的第一步是安装 python。可以从其官方网站 here 或互联网上其他任何地方安装 python。

The first step that you need while using JetCreator is to install the python. The python can be installed from its official website here or from any where else on the internet.

请记住,python 的版本号应为 2.6 或 2.7,因为本示例遵循该版本。

Please keep in mind the version number of the python should either be 2.6 or 2.7 because this example follows that.

下载 python 后安装它。安装后,你必须设置 python 的路径。打开命令提示符并键入以下命令。它显示在下面的图像中 -

Once you download python install it. After installing you have to set path to the python. Open your command prompt and type the following command.It is shown in the image below −

python0

设定路径后你可以通过输入 python 并按下回车键验证。如下图所示 -

Once path is set , you can verify it by typing python and hit enter. It is shown below −

python1

Installing WxPython

下一步你需要做的是安装 wxPython。可以 here 下载。下载之后,你会安装它。它会自动安装在 python 目录中。

The next thing you need to do is to install the wxPython. It can be downloaded here. Once downloaded , you will install it. It will be automatically installed in the python directory.

Ruuning JetCreator

下一步你需要做的是移动到 JetCreator 所在的路径。它在 android 工具的 SDK 文件夹中。如下图所示 -

The next thing you need to is to move to the path where JetCreator is present. It is in the tools,SDK folder of the android. It is shown below −

python

到文件夹后输入此命令并按下回车键。

Once in the folder type this command and hit enter.

python JetCreator.py

如下图所示 -

It is shown in the figure below −

python2

只要你按下回车键,Jet Creator 窗口就会打开。它会是这样的。

As soon as you hit enter, Jet Creator window will open. It would be something like this.

android jetplayer1

Creating JetContent

在上面的 Jet 窗口中,点击导入按钮。从 Jet 文件夹中选择 JetCreator_demo_1 或 2,在 Jet 文件夹的 demo 内容文件夹中。如下图所示:

In the above Jet Window, click on the import button. And select JetCreator_demo_1 or 2 from the JetFolder from the demo content folder in the Jet folder. It is shown in the image below:

android jetplayer2

一旦你导入内容,你就会在 JetCreator 窗口中看到内容。如下图所示 -

Once you import the content , you will see the content in the JetCreator window. It is shown below −

android jetplayer3

现在你可以通过访问 JetCreator 链接 here 探索 JetCreator 的不同选项。最后为了创建 .jet 文件,你需要从文件菜单中保存内容。

Now you can explore different options of JetCreator by visiting the JetCreator link here. Finally in order to create .jet file , you need to save the content from the file menu.

Verifying Results

一旦你得到 jet 文件,你可以使用 jet 播放器播放它。以下是播放它的主代码 -

Once you got the jet file, you can play it using jet player. The main code of playing it has been given below −

JetPlayer jetPlayer = JetPlayer.getJetPlayer();
jetPlayer.loadJetFile("/sdcard/level1.jet");
byte segmentId = 0;

// queue segment 5, repeat once, use General MIDI, transpose by -1 octave
jetPlayer.queueJetSegment(5, -1, 1, -1, 0, segmentId++);
jetPlayer.play();