📄 simpleplayer.java
字号:
/* * @(#)SimplePlayer.java 1.2 03/01/22 * * Copyright (c) 2000-2003 Sun Microsystems, Inc. All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms */package example.mmademo;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.media.*;import javax.microedition.media.control.*;import java.util.*;import java.io.*;/** * An example MIDlet for a generic Player for audio, MIDI media * The top-level URLs are configured in the jad file:<br> * <code>PlayerURL-n</code> defines the n'th URL<br> * <code>PlayerTitle-n</code> defines the n'th title * <p> * Special URL "protocols" can be used:<br> * <code>resource:</code> for media data from the jar<br> * <code>rms:</code> for media data from RMS memory<br> * <p> * Examples:<br> * <code> * PlayerURL-1: http://server.com/ <br> * PlayerTitle-1: Browse server.com <br> * PlayerURL-2: resource:/audio/hello.wav <br> * PlayerTitle-2: hello.wav from jar <br> * PlayerURL-3: http://localhost/movie.mpg <br> * PlayerTitle-3: Funny movie <br> * PlayerURL-4: rms:/ <br> * PlayerTitle-4: Browse Record Stores<br> * </code> * * @author Florian Bomers * @version 1.7 */public class SimplePlayer extends BaseListMidlet implements Utils.BreadCrumbTrail, Utils.QueryListener { private static final String manualEnterURL="manual"; private static final String manualEnterTitle="[enter URL]"; private String lastManualURL = ""; private Vector titles; private Vector urls; // SimplePlayerCanvas is the default player private SimplePlayerCanvas simplePlayerCanvas = new SimplePlayerCanvas("MMA Player", this); private Utils.ContentHandler[] handlers = { new SimpleHttpBrowser("MMA HTTP Browser", this), new SimpleRmsBrowser("MMA RMS Browser", this), simplePlayerCanvas, //new SimplePlayerForm("MMA Player", this), // will be instanciated by SimplePlayer }; public SimplePlayer() { super("MMA Player"); } protected void fillList(List list) { titles = new Vector(); urls = new Vector(); for (int n = 1; n < 100; n++) { String nthURL = "PlayerURL-"+ n; String url = getAppProperty(nthURL); if (url == null || url.length() == 0) { break; } String nthTitle = "PlayerTitle-" + n; String title = getAppProperty(nthTitle); if (title == null || title.length() == 0) { title = url; } titles.addElement(title); urls.addElement(url); list.append(title, null); } // TODO: add MRU list here // manual enter of URL titles.addElement(manualEnterTitle); urls.addElement(manualEnterURL); list.append(manualEnterTitle, null); list.addCommand(exitCommand); list.addCommand(selectCommand); } /** * Main function that decides which class to display * dependant on the url. */ public void handle(String title, String url) {System.err.println("title: " + title + "url: " + url); try { InputStream is = null; String ct = ""; // first magic URL's if (url.equals(manualEnterURL)) { enterURL(); return; } else if (url.startsWith("resource:")) { is = getClass().getResourceAsStream(url.substring(9)); System.err.println("is: " + is); } else if (SimpleRmsBrowser.isRmsFile(url)) { is = SimpleRmsBrowser.getRecordStoreStream(url); }
ct = Utils.guessContentType(url); // ringtone text file ? if (ct.equals("audio/x-txt")) { RingToneConverter rtc; if (is != null) { rtc = new RingToneConverter(is, title); } else { rtc = new RingToneConverter(url, title); } Player tonePlayer = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR); tonePlayer.realize(); ToneControl tc = (ToneControl) tonePlayer.getControl("ToneControl"); tc.setSequence(rtc.getSequence()); // do NOT prefetch this player. Otherwise SimplePlayerGUI will not initialize this player go(simplePlayerCanvas); simplePlayerCanvas.handle(rtc.getName(), tonePlayer); return; } if (is != null) { go(simplePlayerCanvas); simplePlayerCanvas.handle(title, is, ct); return; } else { for (int i=0; i<handlers.length; i++) { if (handlers[i].canHandle(url)) { go((Displayable) handlers[i]); handlers[i].handle(title, url); return; } } } Utils.error("No handler available!", this); } catch (Exception e) { Utils.error(e, this); } } protected void selectCommand(int index) { if (index>=0) { if (index<titles.size()) { handle((String) titles.elementAt(index), (String) urls.elementAt(index)); } } } /** * Display a prompt for a new URL */ private void enterURL() { Utils.query("Enter a URL", lastManualURL, 300, TextField.URL, this, this); } ////////////////////// interface Utils.QueryListener ///////////////////// public void queryOK(String text) { handle(text, text); lastManualURL = text; } public void queryCancelled() { // don't do anything if query is cancelled. // the previous visible Displayable will be // displayed automatically } public void destroyApp(boolean unconditional) { Utils.ContentHandler p = getCurrentHandler(); if (p != null) { p.close(); } } private Utils.ContentHandler getCurrentHandler() { Displayable d = getDisplay().getCurrent(); if (d instanceof Utils.ContentHandler) { return (Utils.ContentHandler) d; } return null; } // for debugging public String toString() { return "SimplePlayer"; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -