Changeset 107

Show
Ignore:
Timestamp:
03/02/07 16:43:53 (2 years ago)
Author:
bfitzpa2
Message:

Webpage creates music flash files.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmp/trunk/Bridge/Bridge.cs

    r104 r107  
    135135        /// <param name="id">The id of the requested song</param> 
    136136        /// <returns>A stream of the requested song</returns> 
    137         public Stream getSongStream(int id
     137        public Stream getSongStream(int id, out long length
    138138        { 
    139139            int libraryId = this.db.getRemoteLibraryId(id); 
     
    143143            //Track song = clientList[libraryId].Database.LookupTrackById(remoteSongId); 
    144144                        Track song = db.getRemoteTrack(id); 
    145             return clientList[libraryId].Database.StreamTrack(song, out songSize); 
     145            Stream musicStream = clientList[libraryId].Database.StreamTrack(song, out length); 
     146                        return musicStream; 
    146147            //return null; 
    147148        } 
  • dmp/trunk/XmLRpcBridgeServer/BridgeXmlRpcServer.cs

    r99 r107  
    1616                const int port = 6666; 
    1717                private Bridge bridge; 
     18                private int bufferChunkSize = 8192; 
    1819 
    1920                public BridgeXmlRpcServer() 
     
    5859 
    5960                /// <summary> 
     61                /// Gets a song's URL using the song's ID number. 
     62                /// </summary> 
     63                /// <param name="songID">the song's integer id number</param> 
     64                /// <returns>a string to the song's location</returns> 
     65                [XmlRpcExposed] 
     66                public String getSongURL(int songID) 
     67                { 
     68                        return bridge.getSongURL(songID); 
     69                } 
     70 
     71                /// <summary> 
     72                /// Gets a song using the song's ID number. 
     73                /// </summary> 
     74                /// <param name="songID">the song's id number</param> 
     75                /// <returns>a byte array containing the song's data</returns> 
     76                [XmlRpcExposed] 
     77                public byte[] getSong(int songID) 
     78                { 
     79                        Console.WriteLine("getSong " + songID + " in BridgeXmlRpcServer"); 
     80                        long length; 
     81                        Stream musicStream = bridge.getSongStream(songID, out length); 
     82                        int lengthInt = (int)length; 
     83 
     84                        MemoryStream musicStreamBuffer = new MemoryStream(lengthInt); 
     85 
     86                        int count = 0; 
     87                        byte[] buf = new byte[bufferChunkSize]; 
     88 
     89                        do { 
     90                        count = musicStream.Read(buf, 0, bufferChunkSize); 
     91                        musicStreamBuffer.Write(buf, 0, count); 
     92                        } while (count != 0); 
     93 
     94                        byte[] finalMusic = musicStreamBuffer.GetBuffer(); 
     95                        return finalMusic; 
     96                } 
     97 
     98                /* Old method, kept for reference. 
     99                /// <summary> 
    60100                /// Gets a song using the song's ID number. 
    61101                /// </summary> 
     
    63103                /// <returns>a byte array containing the song's data</returns> 
    64104                [XmlRpcExposed] 
    65                 public byte[] getSong(int songID) 
     105                public byte[] getSong2(int songID) 
    66106                { 
    67                         Console.WriteLine("getSong " + songID + " in BridgeXmlRpcServer"); 
    68                         Stream musicStream = bridge.getSongStream(songID); 
     107                        long length; 
     108                        Console.WriteLine("getSong2 " + songID + " in BridgeXmlRpcServer"); 
     109                        Stream musicStream = bridge.getSongStream(songID, out length); 
     110                        //musicStream.ReadTimeout = (int) 4268032; 
    69111                        Track song = bridge.getTrackInfo(songID); 
    70112                        byte[] musicBytes = new byte[song.Size]; 
    71                         musicStream.Read(musicBytes, 0, song.Size); 
     113                        IAsyncResult result =  
     114                                musicStream.BeginRead(musicBytes,0,musicBytes.Length,null,10); 
     115                        //System.Threading.Thread.Sleep(6000); 
     116                        result.AsyncWaitHandle.WaitOne(); 
     117                        musicStream.Flush(); 
     118                        int bytesRead = musicStream.EndRead(result); 
     119                        if (bytesRead < song.Size) 
     120                        { 
     121                                //throw new IOException("Not enough bytes read."); 
     122                        } 
    72123                        return musicBytes; 
     124                        //musicStream.Read(musicBytes, 0, musicBytes.Length); 
     125                        //return musicBytes; 
    73126                } 
     127                 * */ 
    74128 
    75129                /// <summary> 
  • dmp/trunk/gwt-windows-1.3.3/src/DMP/DMPXmlRpcClient.java

    r78 r107  
    5252        public byte[] getSong(int songID) 
    5353        { 
    54                 System.out.println("getSong on DMPXmlRpcClient"); 
     54                System.out.println("getSong " + songID + " on DMPXmlRpcClient"); 
    5555                byte[] response = null; 
    5656                ArrayList<Object> params = new ArrayList<Object>(); 
     
    5959                { 
    6060                        response = (byte[]) client.execute("server.getSong", params); 
     61                } 
     62                catch (XmlRpcException e) { 
     63                        e.printStackTrace(); 
     64                } 
     65                return response; 
     66        } 
     67         
     68        /** 
     69         * Gets the URL to the song with the specified ID. 
     70         * @param songID the song's ID 
     71         * @return the song's URL 
     72         */ 
     73        public String getSongURL(int songID) 
     74        { 
     75                String response = null; 
     76                ArrayList<Object> params = new ArrayList<Object>(); 
     77                params.add(songID); 
     78                try 
     79                { 
     80                        response = (String) client.execute("server.getSongURL",params); 
    6181                } 
    6282                catch (XmlRpcException e) { 
  • dmp/trunk/gwt-windows-1.3.3/src/DMP/server/MusicServImpl.java

    r78 r107  
    55 
    66import java.io.*; 
     7import java.net.*; 
    78 
    89import com.google.gwt.user.server.rpc.RemoteServiceServlet; 
     
    6566                        flashFileHandles.remove(song); 
    6667                } 
     68        } 
     69         
     70        /** Old method, kept for reference. 
     71         * Makes a flash file from the input song. 
     72         * @param song the song to make the flash file from 
     73         */ 
     74        public void makeFlash2(Vector song) 
     75        { 
     76                Integer songID = Integer.parseInt(song.get(0).toString()); 
     77                String songURLString = client.getSongURL(songID.intValue()); 
     78                URL songURL; 
     79                InputStream music; 
     80                try { 
     81                        songURL = new URL(songURLString); 
     82                } catch (MalformedURLException e) { 
     83                        e.printStackTrace(); 
     84                        return; 
     85                } 
     86                try { 
     87                        music = songURL.openStream(); 
     88                } catch (IOException e) { 
     89                        e.printStackTrace(); 
     90                        return; 
     91                } 
     92                byte[] musicBytes = new byte[5000000]; 
     93                try { 
     94                        music.read(musicBytes); 
     95                } catch (IOException e) { 
     96                        e.printStackTrace(); 
     97                        return; 
     98                } 
     99                //makeFlash2(musicBytes,song); 
    67100        } 
    68101         
     
    76109        public void makeFlash(Vector song) 
    77110        { 
    78                 Integer songID = Integer.parseInt(song.get(0).toString()); 
     111                Integer songID = Integer.parseInt((song.get(0).toString())); 
    79112                byte[] musicBytes = client.getSong(songID.intValue()); 
    80113                if(musicBytes == null) 
     
    82115                        return; 
    83116                } 
     117                // create music and flash temp files 
    84118                File tempMusicFile; 
    85119                File tempFlashFile; 
     
    108142                        return; 
    109143                } 
     144                // use temp files to create flash movie 
    110145                createFlashMovie(tempMusicFile.getPath(),tempFlashFile.getPath()); 
    111146                tempMusicFile.delete();