Digital media player

Report a typo

Daniel wants to create the DigitalPlayer interface that should implement the Play() and Stop() methods to play or stop an mp3 or mp4 file.

He has already created the AudioPlayer and VideoPlayer structs, as well as the Play() and Stop() methods. Now you need to help Daniel with the following tasks:

  1. Create the DigitalPlayer interface with the Play() and Stop() methods;
  2. Create the player variable of the DigitalPlayer type within the main function;
  3. Make the player variable an AudioPlayer or a VideoPlayer depending on the file extension mp3 or mp4;
  4. Finally, call the Play() and Stop() methods on the previously created player.

Sample Input 1:

coldplay_viva_la_vida.mp3

Sample Output 1:

Playing audio coldplay_viva_la_vida.mp3
Stop playing audio coldplay_viva_la_vida.mp3

Sample Input 2:

evolution_of_dance.mp4

Sample Output 2:

Playing video evolution_of_dance.mp4
Stop playing video evolution_of_dance.mp4
Write a program in Go
package main

import (
"fmt"
"strings"
)

type VideoPlayer struct {
File string
}

type AudioPlayer struct {
File string
}

func (v VideoPlayer) Play() {
fmt.Println("Playing video", v.File)
}

func (v VideoPlayer) Stop() {
fmt.Println("Stop playing video", v.File)
}

func (a AudioPlayer) Play() {
fmt.Println("Playing audio", a.File)
}

func (a AudioPlayer) Stop() {
fmt.Println("Stop playing audio", a.File)
}

// Create the `DigitalPlayer` interface that implements the `Play()` and `Stop()` methods.
type ? interface {
?
?
}
___

Create a free account to access the full topic