bugId 17316
Added 4 demo pluglets a = laa@sparc.spb.su r = idk@eng.sun.com git-svn-id: svn://10.0.0.236/trunk@51965 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
163
mozilla/java/plugins/examples/MediaPlayer/JMPlayer.java
Normal file
163
mozilla/java/plugins/examples/MediaPlayer/JMPlayer.java
Normal file
@@ -0,0 +1,163 @@
|
||||
import javax.media.*;
|
||||
import javax.media.util.*;
|
||||
import javax.media.format.*;
|
||||
import javax.media.bean.playerbean.*;
|
||||
import javax.media.control.*;
|
||||
|
||||
|
||||
import org.mozilla.pluglet.*;
|
||||
import org.mozilla.pluglet.mozilla.*;
|
||||
import org.mozilla.pluglet.mozilla.PlugletTagInfo2;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.print.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class JMPlayer implements Pluglet {
|
||||
public JMPlayer() {
|
||||
}
|
||||
|
||||
public PlugletInstance createPlugletInstance(String mimeType) {
|
||||
return new JMPlayerInstance();
|
||||
}
|
||||
|
||||
public void initialize(PlugletManager manager) {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
}
|
||||
}
|
||||
|
||||
class JMPlayerInstance implements PlugletInstance, ControllerListener {
|
||||
PlugletInstancePeer peer;
|
||||
Dimension defaultSize;
|
||||
Frame frm;
|
||||
int w, h;
|
||||
MediaPlayer player = null;
|
||||
|
||||
Panel panel;
|
||||
|
||||
public synchronized void controllerUpdate(ControllerEvent ce) {
|
||||
if(ce instanceof RealizeCompleteEvent) {
|
||||
player.prefetch();
|
||||
}
|
||||
if(ce instanceof PrefetchCompleteEvent) {
|
||||
Dimension dim = player.getPreferredSize();
|
||||
frm.pack();
|
||||
panel.setSize(dim);
|
||||
// player.setBounds(0, 0, w, h);
|
||||
frm.setSize(defaultSize);
|
||||
player.start();
|
||||
frm.show();
|
||||
}
|
||||
}
|
||||
|
||||
public JMPlayerInstance() {
|
||||
}
|
||||
|
||||
public void initialize(PlugletInstancePeer peer) {
|
||||
PlugletTagInfo2 info = (PlugletTagInfo2)peer.getTagInfo();
|
||||
w = info.getWidth();
|
||||
h = info.getHeight();
|
||||
defaultSize = new Dimension(w, h);
|
||||
this.peer = peer;
|
||||
}
|
||||
|
||||
public boolean playFile(String url) {
|
||||
player.setMediaLocator(new MediaLocator(url));
|
||||
if(player.getPlayer() == null) {
|
||||
return false;
|
||||
} else {
|
||||
player.addControllerListener(this);
|
||||
player.realize();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
player = new MediaPlayer();
|
||||
panel = new Panel();
|
||||
panel.add(player);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
(new Exception()).printStackTrace();
|
||||
player.stop();
|
||||
player.deallocate();
|
||||
player.close();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public PlugletStreamListener newStream() {
|
||||
org.mozilla.util.Debug.print("--TestInstance.newStream\n");
|
||||
JMPlayerStreamListener listener = new JMPlayerStreamListener();
|
||||
listener.setPlayer(this);
|
||||
return listener;
|
||||
}
|
||||
|
||||
public void setWindow(Frame frame) {
|
||||
if(frame == null) {
|
||||
return;
|
||||
}
|
||||
if(panel == null) {
|
||||
System.out.println("++ Initialize failed.");
|
||||
return;
|
||||
}
|
||||
// PlugletTagInfo2 info = (PlugletTagInfo2)peer.getTagInfo();
|
||||
// defaultSize = new Dimension(info.getWidth(), info.getHeight());
|
||||
frame.setSize(defaultSize);
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.add(panel);
|
||||
frm=frame;
|
||||
}
|
||||
|
||||
public void print(PrinterJob printerJob) {
|
||||
}
|
||||
}
|
||||
|
||||
class JMPlayerStreamListener implements PlugletStreamListener {
|
||||
JMPlayerInstance jmp;
|
||||
int total=0;
|
||||
|
||||
public JMPlayerStreamListener() {
|
||||
}
|
||||
|
||||
public void onStartBinding(PlugletStreamInfo streamInfo) {
|
||||
|
||||
|
||||
if(!jmp.playFile(streamInfo.getURL())) {
|
||||
System.out.println("++ Error starting player ");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setPlayer(JMPlayerInstance jmp) {
|
||||
this.jmp = jmp;
|
||||
}
|
||||
|
||||
public void onDataAvailable(PlugletStreamInfo streamInfo, InputStream input,int length) {
|
||||
}
|
||||
|
||||
public void onFileAvailable(PlugletStreamInfo plugletInfo, String fileName) {
|
||||
}
|
||||
|
||||
public void onStopBinding(PlugletStreamInfo plugletInfo,int status) {
|
||||
System.out.println("++ On stop binding.");
|
||||
}
|
||||
|
||||
public int getStreamType() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
43
mozilla/java/plugins/examples/MediaPlayer/README
Normal file
43
mozilla/java/plugins/examples/MediaPlayer/README
Normal file
@@ -0,0 +1,43 @@
|
||||
MediaPlayer Pluglet Example.
|
||||
================================
|
||||
|
||||
This directory contains the source code for MediaPlayer pluglet example.
|
||||
Pluglet is using Java Media Frameworks 2.0b MediaPlayer bean.
|
||||
|
||||
========================================================================
|
||||
Win32 Build Directions:
|
||||
========================================================================
|
||||
Requirements:
|
||||
|
||||
* built latest mozilla tree for WinNT4.0
|
||||
|
||||
* JDK1.3
|
||||
|
||||
* built Java-Implemented Plugins.
|
||||
|
||||
* JMF2.0b installed.
|
||||
|
||||
How To Build:
|
||||
|
||||
* add jmf.jar to classpath
|
||||
|
||||
* type "nmake /f makefile.win"
|
||||
|
||||
|
||||
How to Run:
|
||||
|
||||
* Follow the directions in ..\..\README
|
||||
|
||||
* Add jmf.jar to classpath
|
||||
|
||||
* Set PLUGLET environment to the directory you have JMPlayer.jar
|
||||
|
||||
* Run mozilla and load page play.html from this directory and you will see
|
||||
sample avi file. (In addition you need to download some avi file and
|
||||
name it test.avi.)
|
||||
|
||||
Warning: JMF MediaPlayer does not support all the video formats so you can
|
||||
see some errors from player when loading unsupported format file.
|
||||
|
||||
|
||||
|
||||
26
mozilla/java/plugins/examples/MediaPlayer/makefile.win
Normal file
26
mozilla/java/plugins/examples/MediaPlayer/makefile.win
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.0 (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS"
|
||||
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
# the License for the specific language governing rights and limitations
|
||||
# under the License.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Sun Microsystems,
|
||||
# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
|
||||
# Inc. All Rights Reserved.
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
.java.class:
|
||||
$(JDKHOME)\bin\javac -classpath "../../classes;$(CLASSPATH)" $<
|
||||
default: JMPlayer.jar
|
||||
JMPlayer.jar: JMPlayer.class manifest
|
||||
$(JDKHOME)\bin\jar cvfm JMPlayer.jar manifest *.class
|
||||
|
||||
clobber:
|
||||
-del *.class *.jar
|
||||
export: JMPlayer.jar
|
||||
copy *.jar $(PLUGLET)
|
||||
2
mozilla/java/plugins/examples/MediaPlayer/manifest
Normal file
2
mozilla/java/plugins/examples/MediaPlayer/manifest
Normal file
@@ -0,0 +1,2 @@
|
||||
MIMEDescription: video/mpeg;video/quicktime;video/avi:avi;mpg;mpeg;mov:Pluglet JMPlayer
|
||||
Pluglet-Class: JMPlayer
|
||||
5
mozilla/java/plugins/examples/MediaPlayer/play.html
Normal file
5
mozilla/java/plugins/examples/MediaPlayer/play.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<EMBED type="video/avi" name=JMPlayer SRC="test.avi" width=400 height=400>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user