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

📄 scriptplayer.java

📁 j2me 上面flash播放器。非常值得研究。就是版本只到2.0
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.jflashme;/*  This library is free software; you can redistribute it and/or modify it *  under the terms of the GNU Lesser General Public License, version 2, as *  published by the Free Software Foundation. * *  This library is distributed in the hope that it will be useful, but *  WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License (the accompanying file named LGPL.txt) *  for more details. */import java.io.*;import javax.microedition.lcdui.*;final class ScriptPlayer    extends SParser implements Runnable {  static final boolean debug = true;  static final int MAX_CHARACTER_NUM = 64;  static final int TAG_SHOWFRAME = 1;  static final int TAG_DEFINESHAPE = 2;  static final int TAG_FREE = 3;  static final int TAG_PLACEOBJECT = 4;  static final int TAG_REMOVEOBJECT = 5;  static final int TAG_DEFINEBITS = 6;  static final int TAG_DEFINEBUTTON = 7;  static final int TAG_JPEGTABLES = 8;  static final int TAG_SETBACKGROUNDCOLOR = 9;  static final int TAG_DEFINEFONT = 10;  static final int TAG_DEFINETEXT = 11;  static final int TAG_DOACTION = 12;  static final int TAG_DEFINEFONTINFO = 13;  static final int TAG_DEFINESOUND = 14;  static final int TAG_STARTSOUND = 15;  static final int TAG_DEFINEBUTTONSOUND = 17;  static final int TAG_SOUNDSTREAMHEAD = 18;  static final int TAG_SOUNDSTREAMBLOCK = 19;  static final int TAG_DEFINEBITSJPEG2 = 21;  static final int TAG_DEFINESHAPE2 = 22;  static final int TAG_DEFINEBUTTONCXFORM = 23;  static final int TAG_PROTECT = 24;  static final int TAG_PLACEOBJECT2 = 26;  static final int TAG_REMOVEOBJECT2 = 28;  static final int TAG_DEFINESHAPE3 = 32;  static final int TAG_DEFINETEXT2 = 33;  static final int TAG_FRAMELABEL = 43;  static final int TAG_DEFINEFONTINFO2 = 62;  static final int noErr = 0;  static final int badHeaderErr = -1;  static final int noMemErr = -2;  static final int noScriptErr = -3;  static final int playOK = 0;  static final int playNeedData = 1;  static final int playAtEnd = 2;  /*   static final int soundHasInPoint = 1;     static final int soundHasOutPoint = 2;     static final int soundHasLoops = 4;     static final int soundHasEnvelope = 8;*/  static final int syncNoMultiple = 1;  static final int syncStop = 2;  int nextPos;  int startPos;  int scriptErr;  int len;  int scriptLen;  Rect frame;  int frameRate;  int frameDelay;  int numFrames;  int version;  int headerLen;  byte headerBuf[];  boolean gotHeader;  boolean atEnd;  int curFrame;  Semaphore gotData;  DisplayList display;  static final int maxActions = 16;  public int actionList[];  public int nActions;  static final int charIndexSize = 64;  static final int charIndexMask = 63;  SCharacter charIndex[];  FlashPane flash;//   Sound streamSound;  int mixFormat;  boolean mute;  static final int START_MARKER = 216;  static final int END_MARKER = 217;  static final int TAG_MARKER = 255;  private int jpegTablePos;  private int jpegTableLen;  private static int imageClassToUse;  /*    private static final int IMAGE_NOT_INITIALIZED = 0;     private static final int IMAGE_TOOLKIT = 1;     private static final int IMAGE_SUN = 2;     private static final int IMAGE_NONE = 3;*/  private int numFramesComplete;  private int numFramesCompletePos;  private InputStream scriptStream;  private boolean scriptComplete;  ScriptPlayer() {    headerBuf = new byte[8];    gotData = new Semaphore(false);    actionList = new int[16];    charIndex = new SCharacter[MAX_CHARACTER_NUM];//      streamSound = new Sound(0, 0, null, 0,flash);    frame = new Rect(0, 0, 600, 600);    ClearScript();  }  ScriptPlayer(FlashPane flash1) {    this();    flash = flash1;  }  public final boolean ScriptComplete() {    return super.script != null && len >= scriptLen;  }  public final boolean GotHeader() {    return gotHeader;  }  public final int GetFrame() {    return curFrame;  }  public final boolean AtEnd() {    return atEnd;  }  /*    void PlayButtonSound(SObject sobject, int i)      {          int j = sobject.buttonState;          if(j == i || i != 1 && j > i)              return;          if(sobject.character.soundPos > 0)          {              SParser sparser = new SParser();              byte abyte0[] = super.script;              int l = sobject.character.soundPos;              sparser.script = abyte0;              sparser.pos = l;              for(int k = 1; k < i; k <<= 1)              {                  l = sparser.GetWord();                  if(l > 0)                      sparser.GetSoundInfo(null, null, true);              }              l = sparser.GetWord();              if(l > 0)              {                  SCharacter scharacter = findCharacter(l);                  if(scharacter == null || scharacter.type != 5)                      return;                  int ai[] = new int[1];                  int ai1[] = new int[1];                  Sound sound = (Sound)scharacter.object;                  sparser.GetSoundInfo(ai, ai1, false);                  if(sound.ConvertToMulaw())                  {                      if((ai1[0] & 2) != 0)                      {                          sound.stop();                          return;                      }                      if((ai1[0] & 1) != 0 && !mute)                      {                          sound.playNoMultiple(ai[0]);                          return;                      }                      if(!mute)                          sound.playMultiple(ai[0]);                  }              }          }      }      void SoundStreamHead()      {          mixFormat = super.script[super.pos++] & 0xff;          streamSound.SetFormat(super.script[super.pos++] & 0xff);          streamSound.SetSamples(GetWord());      }      void SoundStreamBlock()      {      }      void stopAllSounds()      {          for(Sound sound = streamSound; sound != null; sound = sound.next)              sound.stop();          streamSound.soundMixer.stopAllStreams();      }      void StartSound()      {          int i = GetWord();          SCharacter scharacter = findCharacter(i);          if(scharacter == null || scharacter.type != 5)              return;          int ai[] = new int[1];          int ai1[] = new int[1];          Sound sound = (Sound)scharacter.object;          GetSoundInfo(ai, ai1, false);          if(sound.ConvertToMulaw())          {              if((ai1[0] & 2) != 0)              {                  sound.stop();                  return;              }              if((ai1[0] & 1) != 0 && !mute)              {                  sound.playNoMultiple(ai[0]);                  return;              }              if(!mute)                  sound.playMultiple(ai[0]);          }      }*/  public void FreeAll() {    if (display != null)      display.FreeAll();    super.pos = startPos;    curFrame = -1;    atEnd = false;  }  public void ClearScript() {    FreeAll();    gotHeader = false;    curFrame = -1;    atEnd = false;    len = headerLen = 0;    scriptLen = -1;    super.pos = 0;    super.script = null;    scriptErr = 0;    nActions = 0;  }  SCharacter findCharacter(int i) {    SCharacter scharacter;    for (scharacter = charIndex[i & 0x3f];         scharacter != null && scharacter.tag != i;         scharacter = scharacter.next);    return scharacter;  }  SCharacter findCharacterAtDepth(int depth) {    SCharacter scharacter;    if (debug) System.out.println("findCharacterAtDepth(" + depth + ")");    for (int i = 0; i < MAX_CHARACTER_NUM; i++) {      scharacter = charIndex[i];//         if (debug) System.out.println("charIndex["+i+"]="+scharacter);      while ( (scharacter != null) && (scharacter.depth != depth)) {//            if (debug) System.out.println("   depth: "+scharacter.depth+"!="+depth);        scharacter = scharacter.next;      }      if ( (scharacter != null) && (scharacter.depth == depth))return          scharacter;    }    return null;  }  void removeCharacter(int ID, int depth) {    SCharacter scharacter, prevSChar;    scharacter = charIndex[ID & 0x3F];    if (scharacter == null)return;    prevSChar = scharacter;    if (scharacter.depth == depth) {      charIndex[ID & 0x3F] = null;      return;    }    else scharacter = scharacter.next;    while ( (scharacter != null) && (scharacter.depth != depth)) scharacter =        scharacter.next;    if ( (scharacter != null) && (scharacter.depth == depth))      prevSChar = scharacter.next;  }  private SCharacter createCharacter(int ID, int depth) {    SCharacter scharacter = new SCharacter();    if (scharacter != null) {      scharacter.next = charIndex[ID & 0x3f];      charIndex[ID & 0x3f] = scharacter;      scharacter.player = this;      scharacter.tag = ID;      scharacter.depth = depth;    }    return scharacter;  }  private void freeCharacter(int i) {    Object obj = null;    SCharacter scharacter = charIndex[i & 0x3f];  }  private void defineShape() {    SCharacter scharacter;    int ID = GetWord();    scharacter = findCharacter(ID);    if (scharacter == null) scharacter = createCharacter(ID, -1);    if (debug) System.out.println("defineShape() " + ID + ", -1");    scharacter.type = 0;    scharacter.bounds = GetRect();    scharacter.dataPos = super.pos;    return;  }  private void placeObject() {    int ID = GetWord();    int depth = GetWord();    if (debug) System.out.println("placeObject() " + ID + ", " + depth);    SCharacter scharacter = findCharacter(ID);    scharacter.depth = depth;    Matrix matrix = GetMatrix();    if (super.pos < super.end) {      ColorTransform colortransform = new ColorTransform(flash);      GetColorTransform(colortransform);      display.placeObject(scharacter, ID, depth, matrix, colortransform);      return;    }    else {      display.placeObject(scharacter, ID, depth, matrix, null);      return;    }  }  private void placeObject2() {    final int PF_MOVE = 0x01;    final int PF_HAS_CHARACTER = 0x02;    final int PF_HAS_MATRIX = 0x04;    final int PF_HAS_COLORTRANS = 0x08;    int ID = -1, flags, depth;    Matrix matrix = null;    SCharacter scharacter = null;    ColorTransform colortransform = null;    flags = GetByte();    depth = GetWord();    if ( (flags & PF_HAS_CHARACTER) == PF_HAS_CHARACTER) ID = GetWord();    if ( (flags & PF_HAS_MATRIX) == PF_HAS_MATRIX) matrix = GetMatrix();    if ( (flags & PF_HAS_COLORTRANS) == PF_HAS_COLORTRANS) {      colortransform = new ColorTransform(flash);      GetColorTransform(colortransform);    }    if (debug) System.out.println("placeObject2() " + ID + ", " + depth + ", " +                                  flags);    if ( (flags & PF_MOVE | PF_HAS_CHARACTER) == (PF_MOVE | PF_HAS_CHARACTER)) {      removeCharacter(ID, depth);    }    if ( (flags & /*PF_MOVE|*/ PF_HAS_CHARACTER) == PF_HAS_CHARACTER) {      scharacter = findCharacter(ID);      if (scharacter == null) {        scharacter = createCharacter(ID, depth);        scharacter.type = 0;        scharacter.dataPos = super.pos;        scharacter.bounds = new Rect();      }    }    else { //if ((flags & PF_MOVE|PF_HAS_CHARACTER)==PF_MOVE)      scharacter = findCharacterAtDepth(depth);      if (scharacter == null) {        System.err.println("Character at depth " + depth +                           " not found at ScriptPlayer.placeObject2()");        return;      }    }    /*      else             {             System.err.println("Script error at ScriptPlayer.placeObject2(): PF_MOVE|PF_HAS_CHARACTER not set");             return;             }*/    scharacter.depth = depth;    display.placeObject(scharacter, ID, depth, matrix, colortransform);  }  private void removeObject() {    int ID = GetWord();    int depth = GetWord();    display.removeObject(ID, depth);  }  private void removeObject2() {    int depth = GetWord();    display.removeObject2(depth);  }  private void defineButton() {    int i = GetWord();    if (findCharacter(i) != null)return;    else {      SCharacter scharacter = createCharacter(i, -1);      scharacter.type = 2;      scharacter.dataPos = super.pos;      scharacter.bounds = new Rect();      return;    }  }  void defineButtonExtra(boolean flag) {    int i = GetWord();    SCharacter scharacter = findCharacter(i);    if (scharacter == null || scharacter.type != 2)return;    if (flag) {//         scharacter.soundPos = super.pos;      return;    }    else {      scharacter.cxformPos = super.pos;      return;    }  }  /*   void defineSound(int i)

⌨️ 快捷键说明

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