日期:2014-05-20 浏览次数:20847 次
package com.mopietek; import java.io.IOException; import java.io.InputStream; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Item; import javax.microedition.media.Manager; import javax.microedition.media.MediaException; import javax.microedition.media.Player; import javax.microedition.media.control.VideoControl; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class GifPlayer extends MIDlet{ private Display display; private Player player = null; protected void destroyApp(boolean unconditional) throws MIDletStateChangeException { // TODO Auto-generated method stub if(player != null){ player.close(); player = null; } } protected void pauseApp() { // TODO Auto-generated method stub } protected void startApp() throws MIDletStateChangeException { // TODO Auto-generated method stub if(display == null){ display = Display.getDisplay(this); } Form form = new Form("gif Player"); InputStream is = getClass().getResourceAsStream("/12.gif"); createPlayer(is); if(player == null){ form.append("can not play image/gif"); }else{ VideoControl vc = (VideoControl)player.getControl("VideoControl"); if(vc != null){ form.append((Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null)); } } display.setCurrent(form); try{ player.start(); }catch(MediaException ex){ ex.printStackTrace(); } } private void createPlayer(InputStream is){ String [] contents = Manager.getSupportedContentTypes(null); for(int i=0;i<contents.length;i++){ if(contents[i].toLowerCase().indexOf("image/gif") != -1){ try{ player = Manager.createPlayer(is,"image/gif"); player.realize(); }catch(IOException e){ e.printStackTrace(); }catch(MediaException me){ me.printStackTrace(); } } } } }