Allow for use of audio data
This commit is contained in:
		
							parent
							
								
									56d44e6f23
								
							
						
					
					
						commit
						3a8807101e
					
				
					 1 changed files with 25 additions and 13 deletions
				
			
		|  | @ -50,6 +50,7 @@ type player struct { | |||
| 	fps            int | ||||
| 	paused         bool | ||||
| 	frameCount     int64 | ||||
| 	audioProcessor func([2]float64) | ||||
| } | ||||
| 
 | ||||
| // readVideoAndAudio reads video and audio frames | ||||
|  | @ -178,6 +179,18 @@ func (p *player) readVideoAndAudio(media *reisen.Media) (<-chan *image.RGBA, <-c | |||
| 	return frameBuffer, sampleBuffer, errs, nil | ||||
| } | ||||
| 
 | ||||
| func (p *player) SetAudioProcessorFunc(f func(data [2]float64)) { | ||||
| 	p.audioProcessor = f | ||||
| } | ||||
| 
 | ||||
| func (p *player) processAudioFrame(data [2]float64) { | ||||
| 	if p.audioProcessor != nil { | ||||
| 		p.audioProcessor(data) | ||||
| 	} else { | ||||
| 		_ = data | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // Starts reading samples and frames | ||||
| // of the media file. | ||||
| func (p *player) open(fname string) error { | ||||
|  | @ -294,12 +307,11 @@ func (w *BufferedVidPlayback) Play() { | |||
| 				fmt.Printf("Error %s\n", err.Error()) | ||||
| 			} | ||||
| 			w.fpsTimer.Reset(frameDuration) | ||||
| 			go func() { | ||||
| 				// empty the audio buffer in case that's what's jamming things up. | ||||
| 			go func(p player) { | ||||
| 				for { | ||||
| 					_ = <-w.playerStruct.audioBuffer | ||||
| 					p.processAudioFrame(<-w.playerStruct.audioBuffer) | ||||
| 				} | ||||
| 			}() | ||||
| 			}(w.playerStruct) | ||||
| 			w.FillBuffer() | ||||
| 			w.videoOpened = true | ||||
| 		} | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue