⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmfextending.html

📁 奉献给多媒体java编程者们。JMF2.1.1最新版本的用户指南。JMF是java用于基于实时多媒体的开发工具
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</code><a name="105758"> </a>
<a name="105759"> </a><code>    int getInHeight() {
</code><a name="105760"> </a><code>	 return inHeight;
</code><a name="105761"> </a><code>    }
</code><a name="105762"> </a><code>    
</code><a name="105763"> </a><code>    private void newImage(Buffer buffer) {
</code><a name="105764"> </a><code>	 Object data = buffer.getData();
</code><a name="105765"> </a><code>	 if (!(data instanceof int[]))
</code><a name="105766"> </a><code>	     return;
</code><a name="105767"> </a><code>	 RGBFormat format = (RGBFormat) buffer.getFormat();
</code><a name="105768"> </a>
<a name="105769"> </a><code>	 DirectColorModel dcm = new 
</code><a name="106118"> </a><code>           DirectColorModel(format.getBitsPerPixel(),
</code><a name="105770"> </a><code>	 	 	 	 	 	     format.getRedMask(),
</code><a name="105771"> </a><code>	 	 	 	 	 	     format.getGreenMask(),
</code><a name="105772"> </a><code>	 	 	 	 	 	     format.getBlueMask());
</code></pre>
</font></td>
  </tr>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="105699"> </a><code>	 sourceImage = new MemoryImageSource(format.getLineStride(),
</code><a name="105700"> </a><code>	 	 	 	 	     format.getSize().height,
</code><a name="105701"> </a><code>	 	 	 	 	     dcm,
</code><a name="105702"> </a><code>	 	 	 	 	     (int[])data, 0,
</code><a name="105703"> </a><code>	 	 	 	 	     format.getLineStride());
</code><a name="105704"> </a><code>	 sourceImage.setAnimated(true);
</code><a name="105705"> </a><code>	 sourceImage.setFullBufferUpdates(true);
</code><a name="105706"> </a><code>	 if (component != null) {
</code><a name="105707"> </a><code>	     destImage = component.createImage(sourceImage);
</code><a name="105708"> </a><code>	     component.prepareImage(destImage, component);
</code><a name="105709"> </a><code>	 }
</code><a name="105710"> </a><code>    }
</code><a name="105712"> </a><code>}
</code></pre>
</font></td>
  </tr>
</table>



<br></font>


<h4>
  <a name="105794"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Registering a Custom Plug-In With the Plug-In Manager</font>
</h4>


<p>
  <a name="105795"> </a><font face="Palatino, Times New Roman, Times, serif">To make a custom plug-in available to a <code>Processor</code> through the <code>TrackControl </code>interface, you need to register it with the <code>PlugInManager</code>.<code> (</code>The default plug-ins are registered automatically.)</font>
</p>


<p>
  <a name="94881"> </a><font face="Palatino, Times New Roman, Times, serif">To register a new plug-in, you<code> </code>use the <code>PlugInManager addPlugIn</code> method. You must call <code>commit</code> to make the addition permanent. For example, to register the <code>GainEffect</code> plug-in from the example on <a href="JMFExtending.html#95527">page&nbsp;89</a>: </font>
</p>


<a name="103945"> </a><font  size="1" face="Palatino, Times New Roman, Times, serif">

<table border="1" bordercolorlight="#FFFFFF" bordercolordark="#000000"
       cellpadding="5" cellspacing="0">
  <caption><b><i><font face="Palatino, Times New Roman, Times, serif"><a name="105825"> </a>Example 6-6:  Registering a new plug-in.  (1 of 2)</font></i></b></caption>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="105874"> </a><code>// Name of the new plugin
</code><a name="105875"> </a><code>string GainPlugin = new String("COM.mybiz.media.GainEffect");
</code><a name="105876"> </a>
<a name="105877"> </a><code>// Supported input Formats
</code><a name="105878"> </a><code>Format[] supportedInputFormats = new Format[] {
</code><a name="105879"> </a><code>	     new AudioFormat(
</code><a name="105880"> </a><code>	         AudioFormat.LINEAR,
</code><a name="105881"> </a><code>                Format.NOT_SPECIFIED,
</code><a name="105882"> </a><code>                16,
</code><a name="105883"> </a><code>                Format.NOT_SPECIFIED,
</code><a name="105884"> </a><code>                AudioFormat.LITTLE_ENDIAN,
</code><a name="105885"> </a><code>                AudioFormat.SIGNED,
</code><a name="105886"> </a><code>                16,
</code><a name="105887"> </a><code>                Format.NOT_SPECIFIED,
</code><a name="105888"> </a><code>                Format.byteArray
</code></pre>
</font></td>
  </tr>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="105901"> </a><code>	     )
</code><a name="105902"> </a><code>};
</code><a name="105848"> </a>
<a name="105849"> </a><code>// Supported output Formats 
</code><a name="105850"> </a><code>Format[] supportedOutputFormats = new Format[] {
</code><a name="105851"> </a><code>	     new AudioFormat(
</code><a name="105852"> </a><code>	         AudioFormat.LINEAR,
</code><a name="105853"> </a><code>                Format.NOT_SPECIFIED,
</code><a name="105854"> </a><code>                16,
</code><a name="105855"> </a><code>                Format.NOT_SPECIFIED,
</code><a name="105856"> </a><code>                AudioFormat.LITTLE_ENDIAN,
</code><a name="105857"> </a><code>                AudioFormat.SIGNED,
</code><a name="105858"> </a><code>                16,
</code><a name="105859"> </a><code>                Format.NOT_SPECIFIED,
</code><a name="105860"> </a><code>                Format.byteArray
</code><a name="105861"> </a><code>	     )
</code><a name="105862"> </a><code>};
</code><a name="105863"> </a>
<a name="105864"> </a><code>// Add the new plug-in to the plug-in registry
</code><a name="105865"> </a><code>PlugInManager.addPlugIn(GainPlugin, supportedInputFormats, 
                          supportedOutputFormats, EFFECT);
</code><a name="105866"> </a>
<a name="105867"> </a><code>// Save the changes to the plug-in registry
</code><a name="105868"> </a><code>PlugInManager.commit();
</code></pre>
</font></td>
  </tr>
</table>



<br></font>


<p>
  <a name="103944"> </a><font face="Palatino, Times New Roman, Times, serif">If you want to make your plug-in available to other users, you should create an Java applet or application that performs this registration process and distribute it with your plug-in. </font>
</p>


<p>
  <a name="106152"> </a><font face="Palatino, Times New Roman, Times, serif">You can remove a plug-in either temporarily or permanently with the <code>removePlugIn</code> method. To make the change permanent, you call <code>commit</code>.</font>
</p>


<p>
  <a name="103935"> </a><font face="Palatino, Times New Roman, Times, serif">Note:  The reference implementation of JMF 2.0 provided by Sun Microsystems, Inc. and IBM Corporation provides a utility application, <code>JMFRegistry</code>, that you can use to register plug-ins interactively.</font>
</p>


<h3>
  <a name="95498"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Implementing Custom Data Sources and Media Handlers   </font>
</h3>


<p>
  <a name="101352"> </a><font face="Palatino, Times New Roman, Times, serif">Custom <code>DataSources</code> and <code>MediaHandlers</code> such as <code>Players</code> and <code>Processors</code> can be used seamlessly with JMF to support new formats and integrate existing media engines with JMF.</font>
</p>


<h4>
  <a name="95228"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Implementing a Protocol Data Source</font>
</h4>


<p>
  <a name="95230"> </a><font face="Palatino, Times New Roman, Times, serif">A <code>DataSource</code> is an abstraction of a media protocol-handler. You can implement new types of <code>DataSources</code> to support additional protocols by extending <code>PullDataSource</code>, <code>PullBufferDataSource</code>, <code>PushDataSource</code>, or <code>PushBufferDataSource</code>. If you implement a custom <code>DataSource</code>, you can implement <code>Demultiplexer</code> and <code>Multiplexer</code> plug-ins that work with your custom <code>DataSource</code> to enable playback through an existing <code>Processor</code>, or you can implement a completely custom <code>MediaHandler</code> for your <code>DataSource</code>.</font>
</p>


<p>
  <a name="95236"> </a><font face="Palatino, Times New Roman, Times, serif">A <code>DataSource</code> manages a collection of <code>SourceStreams</code> of the corresponding type. For example, a <code>PullDataSource</code> only supports pull data-streams; it manages a collection of <code>PullSourceStreams</code>. Similarly, a <code>PushDataSource</code> only supports push data-streams; it manages a collection of <code>PushSourceStreams</code>. When you implement a new <code>DataSource</code>, you also need to implement the corresponding source stream: <code>PullSourceStream</code>,<code> PullBufferStream</code>, <code>PushSourceStream</code>, or <code>PushBufferStream</code>.</font>
</p>


<p>
  <a name="101357"> </a><font face="Palatino, Times New Roman, Times, serif">If your <code>DataSource</code> supports changing the media position within the stream to a specified time, it should implement the <code>Positionable</code> interface. If the <code>DataSource</code> supports seeking to a particular point in the stream, the corresponding <code>SourceStream</code> should implement the <code>Seekable</code> interface.</font>
</p>


<p>
  <a name="96092"> </a><font face="Palatino, Times New Roman, Times, serif">So that the <code>Manager</code> can construct your custom <code>DataSource</code>, the name and package hierarchy for the <code>DataSource</code> must follow certain conventions. The fully qualified name of your custom <code>DataSource</code> should be: </font>
</p>

<pre>
<a name="96127"> </a><code>&lt;protocol package-prefix&gt;.media.protocol.&lt;protocol&gt;.DataSource 
</code></pre>

<p>
  <a name="96132"> </a><font face="Palatino, Times New Roman, Times, serif">The <em>protocol package-prefix</em> is a unique identifier for your code that you register with the JMF <code>PackageManager</code> (for example, <code>COM.mybiz</code>) as a protocol package-prefix. The protocol identifies the protocol for your new <code>DataSource</code>. For more information, see <a href="JMFExtending.html#96221">Integrating a Custom Data Source with JMF</a>.</font>
</p>


<h5>
  <a name="95240"> </a><i><font color="#003366" face="Palatino, Times New Roman, Times, serif">Example: Creating an FTP DataSource</font></i>
</h5>


<p>
  <a name="101372"> </a><font face="Palatino, Times New Roman, Times, serif">The example in <a href="JMFApp-DataSource.html#86181">Sample Data Source Implementation</a> demonstrates how to support an additional protocol by implementing a custom <code>DataSource</code> and <code>SourceStream</code>. This <code>DataSource</code>, <code>FTPDataSource</code>, implements <code>PullDataSource</code>.</font>
</p>


<h4>
  <a name="96221"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Integrating a Custom Data Source with JMF</font>
</h4>


<p>
  <a name="96222"> </a><font face="Palatino, Times New Roman, Times, serif">To integrate a custom <code>DataSource</code> implementation with JMF you need to:</font>
</p>

<ul>
  <li><a name="96223"> </a><font face="Palatino, Times New Roman, Times, serif">Install the package containing the new <code>DataSource</code> class, <code>&lt;protocol-prefix&gt;.media.protocol.&lt;protocol&gt;.DataSource.</code></font>
  <li><a name="96224"> </a><font face="Palatino, Times New Roman, Times, serif">Add your package prefix to the protocol package-prefix list controlled by the <code>PackageManager</code>. The <code>Manager</code> queries the <code>PackageManager</code> for the list of protocol package-prefixes it uses to search for a <code>DataSource</code>.</font>
</ul>

<p>
  <a name="96226"> </a><font face="Palatino, Times New Roman, Times, serif">For example, to integrate a new <code>DataSource</code> for the protocol type <em>xxx</em>, you would create and install a package called:</font>
</p>

<pre>
<a name="96227"> </a><code>&lt;protocol package-prefix&gt;.media.protocol.xxx.DataSource
</code></pre>

<p>
  <a name="101439"> </a><font face="Palatino, Times New Roman, Times, serif">that contains the new <code>DataSource</code> class. You also need to add your package prefix (an identifier for your code, such as <code>COM.mybiz</code>) to the protocol package-prefix list managed by the <code>PackageManager</code>.</font>
</p>


<a name="105910"> </a><font  size="1" face="Palatino, Times New Roman, Times, serif">

<table border="1" bordercolorlight="#FFFFFF" bordercolordark="#000000"
       cellpadding="5" cellspacing="0">
  <caption><b><i><font face="Palatino, Times New Roman, Times, serif"><a name="105916"> </a>Example 6-7:   Registering a protocol package-prefix. </font></i></b></caption>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -