'From Squeak2.9alpha of 13 June 2000 [latest update: #2518] on 19 November 2000 at 6:50:23 pm'! !MPEGPlayer methodsFor: 'access' stamp: 'JMM 11/19/2000 11:52'! external [external hasVideo] on: Error do: [(MPEGFile isFileValidMPEG: external fileName) ifFalse: [^self error: 'Mpeg File is invalid']. external _ MPEGFile openFile: external fileName]. ^external! ! !MPEGPlayer methodsFor: 'audio' stamp: 'JMM 11/19/2000 18:03'! privatePlayAudioStream: aStream | number | number _ 5. self soundQueue: (QueueSound new startTime: 0). [number + 2 timesRepeat: [self soundQueue add: (self createSoundFrom: aStream)]. self soundQueue play. semaphoreForSound signal. [[self soundQueue sounds size > number] whileTrue: [(Delay forMilliseconds: 100) wait]. self soundQueue add: (self createSoundFrom: aStream). (self endOfAudio: aStream) ifTrue: [self audioPlayerProcess: nil. ^self]] repeat] on: Error do: [self audioPlayerProcess: nil. ^self]! ! !MPEGPlayer methodsFor: 'audio' stamp: 'JMM 11/19/2000 18:02'! readSoundChannel: aChannel stream: aStream | buffer result samples | samples _ (self sampleRate // 10) min: ((self audioSamples: aStream) - (self currentAudioSampleForStream: aStream)). (samples == 0) ifTrue: [self error: 'Mpeg at end of stream, toss error, catch up high']. buffer _ SoundBuffer newMonoSampleCount: samples. aChannel = 0 ifTrue: [result _ self external audioReadBuffer: buffer stream: aStream channel: aChannel] ifFalse: [result _ self external audioReReadBuffer: buffer stream: aStream channel: aChannel]. ^SampledSound samples: buffer samplingRate: self sampleRate. ! ! !MPEGPlayer methodsFor: 'play controls' stamp: 'JMM 11/19/2000 12:50'! isPlaying ^((self audioPlayerProcess isNil) and: [self videoPlayerProcess isNil]) not! ! !MPEGPlayer methodsFor: 'play controls' stamp: 'JMM 11/19/2000 11:44'! seekVideoAudioBasedOnFrame: aFrame forStream: aStream self external hasVideo ifTrue: [self currentVideoFrameForStream: aStream put: aFrame]. self recalculateNewSampleLocationForStream: aStream givenFrame: aFrame! ! !MPEGPlayer methodsFor: 'video' stamp: 'JMM 11/19/2000 12:47'! privatePlayVideoStream: aStream | location | self hasVideo ifFalse: [self timeCheck: 0@0. ^self]. self checkForm: aStream. self frameRate: (self videoFrameRate: aStream). location _ self currentVideoFrameForStream: aStream. self clockBiasForStream: aStream put: (1/self frameRate*location*1000) asInteger. self videoLoop: aStream. self timeCheck: ((Time millisecondClockValue + (self clockBiasForStream: aStream) - (self startTimeForStream: aStream))/1000.0) @ ((self videoFrames: aStream) / self frameRate). self videoPlayerProcess: nil! ! !MPEGPlayer methodsFor: 'video' stamp: 'JMM 11/19/2000 12:45'! videoLoop: aStream | location oneTime | oneTime _ true. [self form depth = 16 ifTrue: [self external videoReadNext16BitFrameInto: self form bits width: self form width height: self form height stream: aStream] ifFalse: [self external videoReadNextFrameInto: self form bits width: self form width height: self form height stream: aStream]. oneTime ifTrue: [oneTime _ false. self noSound ifFalse: [self playAudioStreamNoSeek: aStream. semaphoreForSound wait. (Delay forMilliseconds: errorForSoundStart) wait]. self startTimeForStream: aStream put: (Time millisecondClockValue)]. self morph ifNil: [self form == Display ifTrue: [Display forceToScreen] ifFalse: [self form displayOn: Display]]. self changed. location _ (self currentVideoFrameForStream: aStream)+1. true ifTrue: [self calculateDelayGivenFrame: location stream: aStream] ifFalse: [self calculateDelayToSoundGivenFrame: location stream: aStream]. (self endOfVideo: aStream) ifTrue: [^self]] repeat.! ! !MPEGPlayerMorph methodsFor: 'as yet unclassified' stamp: 'JMM 11/19/2000 12:52'! step foo ifNil: [^ self]. (isPlaying and: [foo isPlaying]) ifTrue: [progress setValue: (foo currentLocationInPercent: 0)] ifFalse: [isPlaying _ false. foo setLocation: progress value forStream: 0]. foo volume: volume value! !