'From etoys2.1 of 26 July 2007 [latest update: #1664] on 27 September 2007 at 4:30:04 pm'! "Change Set: FileOpenFixes Date: 27 September 2007 Author: kks Media files are now opened in readonly mode instead of read/write for playing"! !AbstractSound class methodsFor: 'sound library-file in/out' stamp: 'kks 9/27/2007 16:25'! fileInSoundLibraryNamed: fileName "File in the sound library with the given file name, and add its contents to the current sound library." | s newSounds | s _ FileStream readOnlyFileNamed: fileName. newSounds _ s fileInObjectAndCode. s close. newSounds associationsDo: [:assoc | self storeFiledInSound: assoc value named: assoc key]. AbstractSound updateScorePlayers. Smalltalk garbageCollect. "Large objects may have been released" ! ! !BookMorph class methodsFor: 'fileIn/Out' stamp: 'kks 9/27/2007 16:25'! openFromFile: fullName "Reconstitute a Morph from the selected file, presumed to be represent a Morph saved via the SmartRefStream mechanism, and open it in an appropriate Morphic world" | book aFileStream | Smalltalk verifyMorphicAvailability ifFalse: [^ self]. aFileStream _ FileStream readOnlyFileNamed: fullName. book _ BookMorph new. book setProperty: #url toValue: aFileStream url. book fromRemoteStream: aFileStream. aFileStream close. Smalltalk isMorphic ifTrue: [ActiveWorld addMorphsAndModel: book] ifFalse: [book isMorph ifFalse: [^self inform: 'Can only load a single morph into an mvc project via this mechanism.']. book openInWorld]. book goToPage: 1! ! !MoviePlayerMorph methodsFor: 'private' stamp: 'kks 9/27/2007 16:26'! pvtOpenFileNamed: fName "Private - open on the movie file iof the given name" | f w h d n m | self stopRunning. fName = movieFileName ifTrue: [^ self]. "No reopen necessary on same file" movieFileName _ fName. "Read movie file parameters from 128-byte header... (records follow as {N=int32, N words}*)" f _ (FileStream readOnlyFileNamed: movieFileName) binary. f nextInt32. w _ f nextInt32. h _ f nextInt32. d _ f nextInt32. n _ f nextInt32. m _ f nextInt32. f close. pageSize _ frameSize _ w@h. frameDepth _ d. frameCount _ n. frameNumber _ 1. playDirection _ 0. msAtLastSync _ 0. msPerFrame _ m/1000.0. self makeMyPage. (SmalltalkImage current platformName = 'Mac OS') ifTrue:[ (SmalltalkImage current extraVMMemory < self fileByteCountPerFrame) ifTrue: [^ self inform: 'Playing movies in Squeak requires that extra memory be allocated for asynchronous file IO. This particular movie requires a buffer of ' , (self fileByteCountPerFrame printString) , ' bytes, but you only have ' , (SmalltalkImage current extraVMMemory printString) , ' allocated. You can evaluate ''SmalltalkImage current extraVMMemory'' to check your allocation, and ''SmalltalkImage current extraVMMemory: 485000'' or the like to increase your allocation. Note that raising your allocation in this way only marks your image as needing this much, so you must then save, quit, and start over again before you can run this movie. Good luck.']]. ! ! !SampledSound class methodsFor: 'instance creation' stamp: 'kks 9/27/2007 16:26'! fromWaveFileNamed: fileName "(SampledSound fromWaveFileNamed: 'c:\windows\media\chimes.wav') play" "| snd fd | fd := FileDirectory on:'c:\windows\media\'. fd fileNames do: [:n | (n asLowercase endsWith: '.wav') ifTrue: [ snd _ SampledSound fromWaveFileNamed: (fd pathName,n). snd play. SoundPlayer waitUntilDonePlaying: snd]]." ^self fromWaveStream: (FileStream readOnlyFileNamed: fileName) ! !