Android - JetPlayer Tutorial

<p >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.</p> <p >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.</p> <p >In order to use JetPlayer , you need to instantiate an object of JetPlayer class. Its syntax is given below &minus;</p> <pre class="result notranslate" > JetPlayer jetPlayer = JetPlayer.getJetPlayer(); </pre> <p >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 &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pln" >jetPlayer</span><span class="pun" >.</span><span class="pln" >loadJetFile</span><span class="pun" >(</span><span class="str" >&quot;/sdcard/level1.jet&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >byte</span><span class="pln" > segmentId </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > </span><span class="com" >// queue segment 5, repeat once, use General MIDI, transpose by -1 octave</span><span class="pln" > jetPlayer</span><span class="pun" >.</span><span class="pln" >queueJetSegment</span><span class="pun" >(</span><span class="lit" >5</span><span class="pun" >,</span><span class="pln" > </span><span class="pun" >-</span><span class="lit" >1</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >1</span><span class="pun" >,</span><span class="pln" > </span><span class="pun" >-</span><span class="lit" >1</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >,</span><span class="pln" > segmentId</span><span class="pun" >++);</span></pre> <p >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 &minus;</p> <pre class="result notranslate" > jetPlayer.play(); </pre> <p >Apart from these methods, there are other methods defined in the JetPlayer class. They are defined below &minus;</p> <table class="table table-bordered" > <tbody > <tr > <th >Sr.No</th> <th >Method &amp; description</th> </tr> <tr > <td >1</td> <td ><b >clearQueue()</b> <p >Empties the segment queue, and clears all clips that are scheduled for playback</p> </td> </tr> <tr > <td >2</td> <td ><b >closeJetFile()</b> <p >Closes the resource containing the JET content</p> </td> </tr> <tr > <td >3</td> <td ><b >getJetPlayer()</b> <p >Factory method for the JetPlayer class</p> </td> </tr> <tr > <td >4</td> <td ><b >loadJetFile(String path)</b> <p >Loads a .jet file from a given path</p> </td> </tr> <tr > <td >5</td> <td ><b >pause()</b> <p >Pauses the playback of the JET segment queue</p> </td> </tr> <tr > <td >6</td> <td ><b >release()</b> <p >Stops the current JET playback, and releases all associated native resources</p> </td> </tr> </tbody> </table> <h2 >Example</h2> <p >The following example demonstrates the use of JetCreator tool to create Jet content. Once that content is created, you can play it through JetPlayer.</p> <p >To experiment with this example , you need to run this on an actual device or in an emulator.</p> <table class="table table-bordered" > <tbody > <tr > <th >Steps</th> <th >Description</th> </tr> <tr > <td >1</td> <td >You will use Android studio IDE to create an Android application and name it as JetPlayer under a package com.example.jetplayer. While creating this project, make sure you Target SDK and Compile With at the latest version of Android SDK to use higher levels of APIs.</td> </tr> <tr > <td >2</td> <td >Install Python and WxPython on your computer from internet.</td> </tr> <tr > <td >3</td> <td >Run the jet creator from command prompt</td> </tr> <tr > <td >4</td> <td >Create Jet content and then save it</td> </tr> <tr > <td >5</td> <td >Run the application and verify the results</td> </tr> </tbody> </table> <h2 >Using JetCreator</h2> <h3 >Installing python</h3> <p >The first step that you need while using JetCreator is to install the python. The python can be installed from its official website<a href="http://python.org/" >here</a>or from any where else on the internet.</p> <p >Please keep in mind the version number of the python should either be 2.6 or 2.7 because this example follows that.</p> <p >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:</p> <p><img alt="Android Jet Player Tutorial" src="http://www.tutorialspoint.com/android/images/python0.jpg" /></p> <p >Once path is set , you can verify it by typing python and hit enter. It is shown below:</p> <p><img alt="Android Jet Player Tutorial" src="http://www.tutorialspoint.com/android/images/python1.jpg" /></p> <h3 >Installing WxPython</h3> <p >The next thing you need to do is to install the wxPython. It can be downloaded<a href="http://www.wxpython.org/download.php" rel="nofollow" target="_blank">here</a>. Once downloaded , you will install it. It will be automatically installed in the python directory.</p> <h3 >Ruuning JetCreator</h3> <p >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 &minus;</p> <p><img alt="Android Jet Player Tutorial" src="http://www.tutorialspoint.com/android/images/python.jpg" /></p> <p >Once in the folder type this command and hit enter.</p> <pre class="prettyprint prettyprinted" > <span class="pln" >python </span><span class="typ" >JetCreator</span><span class="pun" >.</span><span class="pln" >py</span></pre> <p >It is shown in the figure below:</p> <p><img alt="Android Jet Player Tutorial" src="http://www.tutorialspoint.com/android/images/python2.jpg" /></p> <p >As soon as you hit enter, Jet Creator window will open. It would be something like this.</p> <p><img alt="Android Jet Player Tutorial" src="http://www.tutorialspoint.com/android/images/android_jetplayer1.jpg" /></p> <h3 >Creating JetContent</h3> <p >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:</p> <p><img alt="Android Jet Player Tutorial" src="http://www.tutorialspoint.com/android/images/android_jetplayer2.jpg" /></p> <p >Once you import the content , you will see the content in the JetCreator window. It is shown below:</p> <p><img alt="Android Jet Player Tutorial" src="http://www.tutorialspoint.com/android/images/android_jetplayer3.jpg" /></p> <p >Now you can explore different options of JetCreator by visiting the JetCreator link<a href="http://developer.android.com/guide/topics/media/jet/jetcreator_manual.html" rel="nofollow" target="_blank">here</a>. Finally in order to create .jet file , you need to save the content from the file menu.</p> <h2 >Verifying Results</h2> <p >Once you got the jet file, you can play it using jet player. The main code of playing it has been given below &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="typ" >JetPlayer</span><span class="pln" > jetPlayer </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >JetPlayer</span><span class="pun" >.</span><span class="pln" >getJetPlayer</span><span class="pun" >();</span><span class="pln" > jetPlayer</span><span class="pun" >.</span><span class="pln" >loadJetFile</span><span class="pun" >(</span><span class="str" >&quot;/sdcard/level1.jet&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >byte</span><span class="pln" > segmentId </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > </span><span class="com" >// queue segment 5, repeat once, use General MIDI, transpose by -1 octave</span><span class="pln" > jetPlayer</span><span class="pun" >.</span><span class="pln" >queueJetSegment</span><span class="pun" >(</span><span class="lit" >5</span><span class="pun" >,</span><span class="pln" > </span><span class="pun" >-</span><span class="lit" >1</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >1</span><span class="pun" >,</span><span class="pln" > </span><span class="pun" >-</span><span class="lit" >1</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >,</span><span class="pln" > segmentId</span><span class="pun" >++);</span><span class="pln" > jetPlayer</span><span class="pun" >.</span><span class="pln" >play</span><span class="pun" >();</span></pre>
RangeTime:0.008045s
RangeMem:215.56 KB
返回顶部 留言