Changeset 163
- Timestamp:
- 03/09/07 00:59:44 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dmp/trunk/gwt-windows-1.3.3/src/DMP/client/DMPWebsite.java
r158 r163 23 23 DeckPanel flashPanel; 24 24 25 int currentMusicDuration = 0;26 Date currentSongStart = null;27 25 String testString = "This is a test."; 26 boolean nowPlaying = false; 28 27 29 28 public void onClick(Widget w) … … 43 42 musicServ.addSongToPlaying(song, new AsyncCallback(){ 44 43 public void onSuccess(Object result) { 45 if( currentMusicDuration == 0)44 if(!nowPlaying) 46 45 { 47 46 playNextSong(); … … 106 105 // the panel containing the flash movie and html navigation links 107 106 flashPanel = new DeckPanel(); 108 Hyperlink nextSongLink = new Hyperlink("Next Song",false,"");109 nextSongLink.addClickListener(new ClickListener(){110 public void onClick(Widget w)111 {112 playNextSong();113 }114 });115 flashPanel.add(nextSongLink);116 GWT.log(nextSongLink.getElement().toString(), null);117 107 SimplePanel placeholder = new SimplePanel(); 108 SimplePanel placeholder2 = new SimplePanel(); 109 flashPanel.add(placeholder2); 118 110 flashPanel.add(placeholder); // add a blank panel as a placeholder 119 111 flashPanel.showWidget(flashPanel.getWidgetIndex(placeholder)); … … 160 152 }; 161 153 refreshTimer.scheduleRepeating(30000); 162 163 Timer testPlay = new Timer() {164 public void run()165 {166 playNextSong();167 }168 };169 154 } 170 155 … … 172 157 { 173 158 GWT.log("playNextSong in DMPWebsite", null); 174 final boolean firstSong = (currentMusicDuration == 0);175 159 musicServ.getNextSong(new AsyncCallback(){ 176 160 public void onSuccess(Object result) 177 161 { 178 162 HashMap song = (HashMap) result; 179 String path = (String) song.get("path"); 180 currentSongStart = new Date(); 181 if(path == null) // no more songs to play 163 if(song == null) // no more songs to play 182 164 { 183 currentMusicDuration = 0;165 nowPlaying = false; 184 166 Label noSongsLeft = new Label("Click a song to play it."); 185 flashPanel. clear();167 flashPanel.remove(flashPanel.getVisibleWidget()); 186 168 flashPanel.add(noSongsLeft); 169 flashPanel.showWidget(flashPanel.getWidgetIndex(noSongsLeft)); 187 170 return; 188 171 } 189 Widget lastFlash = flashPanel.getWidget(flashPanel.getVisibleWidget());190 flashPanel.remove( lastFlash); //remove the last flash movie191 HTML flash = new HTML("<object width=\" 50\" height=\"50\">" +172 String path = (String) song.get("path"); 173 flashPanel.remove(flashPanel.getVisibleWidget()); //remove the last flash movie 174 HTML flash = new HTML("<object width=\"150\" height=\"50\">" + 192 175 "<param name=\"movie\" value=\"" + path + "\"><PARAM NAME=loop VALUE=\"false\">" + 193 176 "<PARAM NAME=menu VALUE=\"true\">" + 194 177 "<embed src=\"" + path + 195 "\" width=\" 50\" height=\"50\" loop=\"false\" menu=\"true\">" +178 "\" width=\"150\" height=\"50\" loop=\"false\" menu=\"true\">" + 196 179 "</embed></object>"); 197 180 flashPanel.add(flash); 198 181 flashPanel.showWidget(flashPanel.getWidgetIndex(flash)); // make sure we're showing the movie 199 currentMusicDuration = Double.valueOf((String)song.get("duration")).intValue(); 200 if(firstSong) 201 { 202 //Timer nextSong = new NextSongTimer(); 203 //nextSong.schedule(currentMusicDuration); 204 } 182 nowPlaying = true; 205 183 playing.removeSong(song.get("id")); 206 184 } … … 211 189 flashPanel.clear(); 212 190 flashPanel.add(error); 191 flashPanel.showWidget(flashPanel.getWidgetIndex(error)); 213 192 } 214 193 }); … … 234 213 } 235 214 236 private class NextSongTimer extends Timer237 {238 public void run()239 {240 System.out.println("Playing next song.");241 playNextSong();242 if(currentMusicDuration == 0)243 {244 return;245 }246 this.schedule(currentMusicDuration);247 }248 }249 250 215 /** 251 216 * Javascript initialization method. dmp/trunk/gwt-windows-1.3.3/src/DMP/server/MusicServImpl.java
r158 r163 38 38 Vector song = new Vector(); 39 39 song.add(2); 40 serv.testFlashCreation();41 40 //System.out.println(serv.getSongsFromCollection()); 42 41 } … … 53 52 if(song == null) 54 53 { 55 song = new HashMap();56 song.put("duration",0);57 54 return song; 58 55 } … … 92 89 flashFileHandles.remove(song); 93 90 } 94 }95 96 /** Old method, kept for reference.97 * Makes a flash file from the input song.98 * @param song the song to make the flash file from99 */100 public void makeFlash2(Vector song)101 {102 Integer songID = Integer.parseInt(song.get(0).toString());103 String songURLString = client.getSongURL(songID.intValue());104 URL songURL;105 InputStream music;106 try {107 songURL = new URL(songURLString);108 } catch (MalformedURLException e) {109 e.printStackTrace();110 return;111 }112 try {113 music = songURL.openStream();114 } catch (IOException e) {115 e.printStackTrace();116 return;117 }118 byte[] musicBytes = new byte[5000000];119 try {120 music.read(musicBytes);121 } catch (IOException e) {122 e.printStackTrace();123 return;124 }125 //makeFlash2(musicBytes,song);126 91 } 127 92 … … 190 155 191 156 /** 192 * Testing method.193 */194 public void testFlashCreation()195 {196 File testMusic = new File("C:\\Dransik\\elves.mp3");197 FileInputStream music;198 byte[] musicBytes = new byte[new Long(testMusic.length()).intValue()];199 try {200 music = new FileInputStream(testMusic);201 music.read(musicBytes);202 } catch (FileNotFoundException e) {203 e.printStackTrace();204 return;205 } catch (IOException e) {206 e.printStackTrace();207 return;208 }209 //System.out.println(makeFlash(musicBytes));210 }211 212 /**213 157 * Creates a barebones flash file containing the specified sound file. 214 158 * @param inputFileName the sound file name … … 219 163 { 220 164 int framesPerSecond = 12; 221 FSMovie musicMov = new FSMovie(new FSBounds(0,0,1000,1000),new Float(framesPerSecond).floatValue()); 222 musicMov.add(new FSSetBackgroundColor(new FSColor(255,200,255))); // random color for testing 223 FSGetUrl nextSongAction = new FSGetUrl("javascript:nextSong()"); 165 FSMovie musicMov = new FSMovie(new FSBounds(0,0,3000,1000),new Float(framesPerSecond).floatValue()); 166 //musicMov.add(new FSSetBackgroundColor(new FSColor(255,200,255))); // random color for testing 224 167 225 168 // make the sound … … 242 185 } 243 186 244 // make the next button 245 FSImageConstructor imageMaker = new FSImageConstructor(); 246 FSDefineObject nextHover; 247 FSDefineObject nextNoHover; 248 FSDefineObject nextPressed; 249 try { 250 imageMaker.setImageFromFile(graphicsPath + "Next_hover.png"); 251 nextHover = imageMaker.defineImage(musicMov.newIdentifier()); 252 imageMaker.setImageFromFile(graphicsPath + "Next_nohover.png"); 253 nextNoHover = imageMaker.defineImage(musicMov.newIdentifier()); 254 imageMaker.setImageFromFile(graphicsPath + "Next_pressed.png"); 255 nextPressed = imageMaker.defineImage(musicMov.newIdentifier()); 256 } catch (IOException e2) { 257 e2.printStackTrace(); 258 return false; 259 } catch (DataFormatException e2) { 260 e2.printStackTrace(); 261 return false; 262 } 263 FSDefineShape3 nextNoHoverShape = imageMaker.defineEnclosingShape(musicMov.newIdentifier(), 264 nextNoHover.getIdentifier(), 0, 0, new FSSolidLine(1,new FSColor(0,0,10))); 265 FSDefineShape3 nextHoverShape = imageMaker.defineEnclosingShape(musicMov.newIdentifier(), 266 nextHover.getIdentifier(), 0, 0, new FSSolidLine(1,new FSColor(10,0,0))); 267 FSDefineShape3 nextPressedShape = imageMaker.defineEnclosingShape(musicMov.newIdentifier(), 268 nextPressed.getIdentifier(), 0, 0, new FSSolidLine(1,new FSColor(0,10,0))); 269 270 // make the buttons 271 ArrayList<FSButton> nextButtonParts = new ArrayList<FSButton>(); 272 nextButtonParts.add(new FSButton(FSButton.Up, nextNoHoverShape.getIdentifier(), 1)); 273 nextButtonParts.add(new FSButton(FSButton.Over, nextHoverShape.getIdentifier(), 2)); 274 nextButtonParts.add(new FSButton(FSButton.Down, nextPressedShape.getIdentifier(), 3)); 275 nextButtonParts.add(new FSButton(FSButton.Active, nextNoHoverShape.getIdentifier(),4)); 276 277 // button actions 278 ArrayList<FSActionObject> nextButtonActions = new ArrayList<FSActionObject>(); 279 nextButtonActions.add(new FSGetUrl("javascript:nextSong()")); 280 281 // define the button and add it to the movie 282 FSDefineButton nextButton = new FSDefineButton(musicMov.newIdentifier(), 283 nextButtonParts, nextButtonActions); 284 nextButton.setButtonRecords(nextButtonParts); 285 musicMov.add(nextHover); 286 musicMov.add(nextNoHover); 287 musicMov.add(nextPressed); 288 musicMov.add(nextNoHoverShape); 289 musicMov.add(nextHoverShape); 290 musicMov.add(nextPressedShape); 291 musicMov.add(nextButton); 292 musicMov.add(new FSPlaceObject(nextButton.getIdentifier(), 1, 0, 0)); 293 // done making the button and placing it in the movie 187 188 // next button 189 HashMap<Integer,String> buttonParts = new HashMap<Integer,String>(); 190 buttonParts.put(FSButton.Up, graphicsPath + "Next_nohover.png"); 191 buttonParts.put(FSButton.Down, graphicsPath + "Next_pressed.png"); 192 buttonParts.put(FSButton.Over, graphicsPath + "Next_hover.png"); 193 ArrayList<FSActionObject> buttonActions = new ArrayList<FSActionObject>(); 194 buttonActions.add(new FSGetUrl("javascript:nextSong()")); 195 buttonActions.add(new FSAction(FSAction.End)); 196 makeButton(buttonParts, buttonActions, 0, 0, 1, musicMov); 197 198 // pause button 199 buttonParts.clear(); 200 buttonParts.put(FSButton.Up, graphicsPath + "Pause_nohover.png"); 201 buttonParts.put(FSButton.Down, graphicsPath + "Pause_pressed.png"); 202 buttonParts.put(FSButton.Over, graphicsPath + "Pause_hover.png"); 203 buttonActions = new ArrayList<FSActionObject>(); 204 buttonActions.add(new FSAction(FSAction.Stop)); 205 buttonActions.add(new FSAction(FSAction.End)); 206 makeButton(buttonParts, buttonActions, 1000, 0, 2, musicMov); 207 208 // play button 209 buttonParts.clear(); 210 buttonParts.put(FSButton.Up, graphicsPath + "Play_nohover.png"); 211 buttonParts.put(FSButton.Down, graphicsPath + "Play_pressed.png"); 212 buttonParts.put(FSButton.Over, graphicsPath + "Play_hover.png"); 213 buttonActions = new ArrayList<FSActionObject>(); 214 buttonActions.add(new FSAction(FSAction.Play)); 215 buttonActions.add(new FSAction(FSAction.End)); 216 makeButton(buttonParts, buttonActions, 2000, 0, 3, musicMov); 217 294 218 295 219 int samplesPerBlock; … … 313 237 ArrayList<FSActionObject> actions = new ArrayList<FSActionObject>(); 314 238 actions.add(new FSAction(FSAction.Stop)); 315 actions.add(ne xtSongAction);239 actions.add(new FSGetUrl("javascript:nextSong()")); 316 240 FSDoAction action = new FSDoAction(actions); 317 241 musicMov.add(action); … … 335 259 } 336 260 } 261 262 public boolean makeButton(HashMap<Integer,String> buttonParts, ArrayList<FSActionObject> actions, int xPos, int yPos, int layer, FSMovie movie) 263 { 264 // make the next button 265 FSImageConstructor imageMaker = new FSImageConstructor(); 266 FSDefineObject hover; 267 FSDefineObject noHover; 268 FSDefineObject pressed; 269 try { 270 imageMaker.setImageFromFile(buttonParts.get(FSButton.Over)); 271 hover = imageMaker.defineImage(movie.newIdentifier()); 272 imageMaker.setImageFromFile(buttonParts.get(FSButton.Up)); 273 noHover = imageMaker.defineImage(movie.newIdentifier()); 274 imageMaker.setImageFromFile(buttonParts.get(FSButton.Down)); 275 pressed = imageMaker.defineImage(movie.newIdentifier()); 276 } catch (IOException e2) { 277 e2.printStackTrace(); 278 return false; 279 } catch (DataFormatException e2) { 280 e2.printStackTrace(); 281 return false; 282 } 283 FSDefineShape3 nextNoHoverShape = imageMaker.defineEnclosingShape(movie.newIdentifier(), 284 noHover.getIdentifier(), 0, 0, null); 285 FSDefineShape3 nextHoverShape = imageMaker.defineEnclosingShape(movie.newIdentifier(), 286 hover.getIdentifier(), 0, 0, null); 287 FSDefineShape3 nextPressedShape = imageMaker.defineEnclosingShape(movie.newIdentifier(), 288 pressed.getIdentifier(), 0, 0, null); 289 290 // make the buttons 291 ArrayList<FSButton> fsButtonParts = new ArrayList<FSButton>(); 292 fsButtonParts.add(new FSButton(FSButton.Up, nextNoHoverShape.getIdentifier(), 1)); 293 fsButtonParts.add(new FSButton(FSButton.Over, nextHoverShape.getIdentifier(), 2)); 294 fsButtonParts.add(new FSButton(FSButton.Down, nextPressedShape.getIdentifier(), 3)); 295 fsButtonParts.add(new FSButton(FSButton.Active, nextNoHoverShape.getIdentifier(),4)); 296 297 // define the button and add it to the movie 298 FSDefineButton button = new FSDefineButton(movie.newIdentifier(), 299 fsButtonParts, actions); 300 button.setButtonRecords(fsButtonParts); 301 movie.add(hover); 302 movie.add(noHover); 303 movie.add(pressed); 304 movie.add(nextNoHoverShape); 305 movie.add(nextHoverShape); 306 movie.add(nextPressedShape); 307 movie.add(button); 308 movie.add(new FSPlaceObject(button.getIdentifier(), layer, xPos, yPos)); 309 310 return true; 311 } 337 312 }
