Skip to content

Instantly share code, notes, and snippets.

@alibahaaa
Created February 5, 2023 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alibahaaa/c43050b50f6893a1d404e55c68033ebd to your computer and use it in GitHub Desktop.
Save alibahaaa/c43050b50f6893a1d404e55c68033ebd to your computer and use it in GitHub Desktop.
class MusicPlayerFacade {
private val player = MediaPlayer()
private val playlist = Playlist()
fun play(song: Song) {
playlist.clear()
playlist.addSong(song)
player.reset()
player.setDataSource(song.filePath)
player.prepare()
player.start()
}
fun stop() {
player.stop()
}
}
class Song(val filePath: String)
class MediaPlayer {
fun reset() {
// Implementation for resetting the media player
}
fun setDataSource(filePath: String) {
// Implementation for setting the data source for the media player
}
fun prepare() {
// Implementation for preparing the media player
}
fun start() {
// Implementation for starting the media player
}
fun stop() {
// Implementation for stopping the media player
}
}
class Playlist {
private val songs = mutableListOf<Song>()
fun clear() {
songs.clear()
}
fun addSong(song: Song) {
songs.add(song)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment