soundplayer wrapper to make mediaplayer easier to work with
This commit is contained in:
		
							parent
							
								
									4519bf2e30
								
							
						
					
					
						commit
						4a04a703db
					
				
					 2 changed files with 29 additions and 4 deletions
				
			
		|  | @ -0,0 +1,29 @@ | ||||||
|  | package be.ugent.sel.studeez.screens.session | ||||||
|  | 
 | ||||||
|  | import android.content.Context | ||||||
|  | import android.media.MediaPlayer | ||||||
|  | import android.media.RingtoneManager | ||||||
|  | 
 | ||||||
|  | class SoundPlayer(private val context: Context) { | ||||||
|  | 
 | ||||||
|  |     var oldValue: Boolean = false | ||||||
|  |     var mediaPlayer: MediaPlayer = initPlayer() | ||||||
|  | 
 | ||||||
|  |     fun playOn(newValue: Boolean) { | ||||||
|  |         if (oldValue != newValue) { | ||||||
|  |             mediaPlayer.start() | ||||||
|  |             mediaPlayer.setOnCompletionListener { | ||||||
|  |                 mediaPlayer = initPlayer() | ||||||
|  |             } | ||||||
|  |             oldValue = newValue | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     private fun initPlayer(): MediaPlayer { | ||||||
|  |         return  MediaPlayer.create( | ||||||
|  |             context, | ||||||
|  |             RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -1,4 +0,0 @@ | ||||||
| package be.ugent.sel.studeez.screens.session.sessionScreens |  | ||||||
| 
 |  | ||||||
| class SoundPlayer { |  | ||||||
| } |  | ||||||
		Reference in a new issue
	
	 lbarraga
						lbarraga