Source Code Cross Referenced for VideoTest.java in  » IDE-Netbeans » mobility » example » mmademo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » mobility » example.mmademo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2007, Sun Microsystems, Inc.
003:         * 
004:         * All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         * 
010:         *     * Redistributions of source code must retain the above copyright
011:         *       notice, this list of conditions and the following disclaimer.
012:         *     * Redistributions in binary form must reproduce the above copyright
013:         *       notice, this list of conditions and the following disclaimer in
014:         *       the documentation and/or other materials provided with the
015:         *       distribution.
016:         *     * Neither the name of Sun Microsystems, Inc. nor the names of its
017:         *       contributors may be used to endorse or promote products derived
018:         *       from this software without specific prior written permission.
019:         * 
020:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
023:         * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
024:         * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031:         */
032:        package example.mmademo;
033:
034:        import javax.microedition.midlet.*;
035:        import javax.microedition.lcdui.*;
036:        import java.util.Vector;
037:
038:        /**
039:         * An example MIDlet to demo MMAPI video features
040:         *
041:         */
042:        public class VideoTest extends MIDlet implements  CommandListener,
043:                Runnable {
044:
045:            private static VideoCanvas videoCanvas = null;
046:            private static VideoPlayer videoPlayer = null;
047:            private static Vector videoClips;
048:
049:            private Command exitCommand = new Command("Exit", Command.EXIT, 1);
050:            private Command playCommand = new Command("Play", Command.ITEM, 1);
051:            //private Command helpCommand = new Command("Help", Command.HELP, 1);
052:
053:            //private Alert helpScreen  = null;
054:            private Display display;
055:            private static List theList;
056:            private static VideoTest instance = null;
057:
058:            private static Vector urls;
059:
060:            static public VideoTest getInstance() {
061:                return instance;
062:            }
063:
064:            static public List getList() {
065:                return theList;
066:            }
067:
068:            public VideoTest() {
069:
070:                instance = this ;
071:                display = Display.getDisplay(this );
072:                theList = new List("MMAPI Video Player", Choice.IMPLICIT);
073:                fillList();
074:
075:                theList.addCommand(playCommand);
076:                theList.addCommand(exitCommand);
077:                theList.setCommandListener(this );
078:                display.setCurrent(theList);
079:            }
080:
081:            private void fillList() {
082:                videoClips = new Vector();
083:                urls = new Vector();
084:                for (int n = 1; n < 100; n++) {
085:                    String nthURL = "VideoTest-URL" + n;
086:                    String url = getAppProperty(nthURL);
087:                    if (url == null || url.length() == 0) {
088:                        break;
089:                    }
090:                    if (!SimplePlayer.isSupported(url))
091:                        continue;
092:                    String nthTitle = "VideoTest-" + n;
093:                    String title = getAppProperty(nthTitle);
094:                    if (title == null || title.length() == 0) {
095:                        title = url;
096:                    }
097:                    videoClips.addElement(title);
098:                    urls.addElement(url);
099:                    theList.append(title, null);
100:                }
101:            }
102:
103:            /**
104:             * Called when this MIDlet is started for the first time,
105:             * or when it returns from paused mode.
106:             * If there is currently a Form or Canvas displaying
107:             * video, call its startApp() method.
108:             */
109:            public void startApp() {
110:                //try {
111:                if (videoPlayer != null)
112:                    videoPlayer.startApp();
113:                if (videoCanvas != null)
114:                    videoCanvas.startApp();
115:                //} catch (Exception e) {
116:                //    System.out.println("DEBUG: GOT EXCEPTION in VideoTest.startApp()!");
117:                //    e.printStackTrace();
118:                //}
119:            }
120:
121:            /**
122:             * Called when this MIDlet is paused.
123:             * If there is currently a Form or Canvas displaying
124:             * video, call its startApp() method.
125:             */
126:            public void pauseApp() {
127:                //try {
128:                if (videoPlayer != null)
129:                    videoPlayer.pauseApp();
130:                if (videoCanvas != null)
131:                    videoCanvas.pauseApp();
132:                //} catch (Exception e) {
133:                //    System.out.println("DEBUG: GOT EXCEPTION in VideoTest.pauseApp()!");
134:                //    e.printStackTrace();
135:                //}
136:            }
137:
138:            /**
139:             * Destroy must cleanup everything not handled
140:             * by the garbage collector.
141:             */
142:            public synchronized void destroyApp(boolean unconditional) {
143:                //try {
144:                if (videoPlayer != null)
145:                    videoPlayer.close();
146:                if (videoCanvas != null)
147:                    videoCanvas.close();
148:                nullPlayer();
149:                //} catch (Exception e) {
150:                //    System.out.println("DEBUG: GOT EXCEPTION in VideoTest.destroyApp("+unconditional+")!");
151:                //    e.printStackTrace();
152:                //}
153:            }
154:
155:            public synchronized void nullPlayer() {
156:                videoPlayer = null;
157:                videoCanvas = null;
158:            }
159:
160:            int index = 0;
161:
162:            public void run() {
163:                //try {
164:                if (index % 2 == 0) {
165:                    videoPlayer = new VideoPlayer(display);
166:                    videoPlayer.open((String) urls.elementAt(index));
167:                    if (videoPlayer != null) {
168:                        display.setCurrent(videoPlayer);
169:                        videoPlayer.start();
170:                    }
171:                } else {
172:                    videoCanvas = new VideoCanvas(display);
173:                    videoCanvas.open((String) urls.elementAt(index));
174:                    if (videoCanvas != null) {
175:                        display.setCurrent(videoCanvas);
176:                        videoCanvas.start();
177:                    }
178:                }
179:                //} catch (Exception e) {
180:                //    System.out.println("DEBUG: GOT EXCEPTION in VideoTest.run()!");
181:                //    e.printStackTrace();
182:                //}
183:            }
184:
185:            /*
186:             * Respond to commands, including exit
187:             * On the exit command, cleanup and notify that the MIDlet has
188:             * been destroyed.
189:             */
190:            public void commandAction(Command c, Displayable s) {
191:                //try {
192:                if (c == exitCommand) {
193:                    synchronized (this ) {
194:                        if (videoPlayer != null || videoCanvas != null) {
195:                            new ExitThread().start();
196:                        } else {
197:                            destroyApp(false);
198:                            notifyDestroyed();
199:                        }
200:                    }
201:                } else if ((s == theList && c == List.SELECT_COMMAND)
202:                        || c == playCommand) {
203:                    synchronized (this ) {
204:                        if (videoPlayer != null || videoCanvas != null) {
205:                            return;
206:                        }
207:                        int i = theList.getSelectedIndex();
208:                        index = i;
209:                        // need to start the players in a separate thread to
210:                        // not block the command listener thread during
211:                        // Player.realize: if it requires a security
212:                        // dialog (like "is it OK to use airtime?"),
213:                        // it would block the VM
214:                        (new Thread(this )).start();
215:                    }
216:                }
217:                //} catch (Exception e) {
218:                //    System.out.println("DEBUG: GOT EXCEPTION in VideoTest.commandAction("+c.toString()+","+s.toString()+")!");
219:                //    e.printStackTrace();
220:                //}
221:            }
222:
223:            class ExitThread extends Thread {
224:                public void run() {
225:                    //try {
226:                    // this is stop()+deallocate(), but not close(), 
227:                    //which is done in destroyApp() ...
228:                    if (videoPlayer != null) {
229:                        videoPlayer.stopVideoPlayer();
230:                        //videoPlayer = null;
231:                    } else { //videoCanvas != null
232:                        videoCanvas.stopVideoCanvas();
233:                        //videoCanvas = null;
234:                    }
235:                    destroyApp(false);
236:                    notifyDestroyed();
237:                    //} catch (Exception e) {
238:                    //    System.out.println("DEBUG: GOT EXCEPTION in VideoTest.ExitThread.run()!");
239:                    //    e.printStackTrace();
240:                    //}
241:                }
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.