@@ -606,39 +606,34 @@ def endTime(self, packet):
606606
607607
608608class MediaRecorderTest (MediaTestCase ):
609- @ asynctest
610- async def test_audio_mp3 ( self ):
611- path = self .temporary_path ("test.mp3" )
609+ async def check_audio_recording ( self , filename , codec_names ):
610+ # Record audio.
611+ path = self .temporary_path (filename )
612612 recorder = MediaRecorder (path )
613613 recorder .addTrack (AudioStreamTrack ())
614614 await recorder .start ()
615615 await asyncio .sleep (2 )
616616 await recorder .stop ()
617617
618- # check output media
618+ # Check audio recording.
619619 container = av .open (path , "r" )
620620 self .assertEqual (len (container .streams ), 1 )
621- self .assertIn (container .streams [0 ].codec .name , ( "mp3" , "mp3float" ) )
621+ self .assertIn (container .streams [0 ].codec .name , codec_names )
622622 self .assertGreater (
623623 float (container .streams [0 ].duration * container .streams [0 ].time_base ), 0
624624 )
625625
626626 @asynctest
627- async def test_audio_wav (self ):
628- path = self .temporary_path ("test.wav" )
629- recorder = MediaRecorder (path )
630- recorder .addTrack (AudioStreamTrack ())
631- await recorder .start ()
632- await asyncio .sleep (2 )
633- await recorder .stop ()
627+ async def test_audio_mp3 (self ):
628+ await self .check_audio_recording ("test.mp3" , ("mp3" , "mp3float" ))
634629
635- # check output media
636- container = av . open ( path , "r" )
637- self .assertEqual ( len ( container . streams ), 1 )
638- self . assertEqual ( container . streams [ 0 ]. codec . name , "pcm_s16le" )
639- self . assertGreater (
640- float ( container . streams [ 0 ]. duration * container . streams [ 0 ]. time_base ), 0
641- )
630+ @ asynctest
631+ async def test_audio_ogg ( self ):
632+ await self .check_audio_recording ( "test.ogg" , ( "opus" ,) )
633+
634+ @ asynctest
635+ async def test_audio_wav ( self ):
636+ await self . check_audio_recording ( "test.wav" , ( "pcm_s16le" ,) )
642637
643638 @asynctest
644639 async def test_audio_wav_ended (self ):
0 commit comments