Coder Social home page Coder Social logo

Question about Architecture about playerkit HOT 4 CLOSED

spike-hue avatar spike-hue commented on September 28, 2024
Question about Architecture

from playerkit.

Comments (4)

spike-hue avatar spike-hue commented on September 28, 2024 1

@rpassis Got it, thanks for your opinion, that helps. Also, thanks for the quick reply! And great library, it helps a lot in terms of architecture

from playerkit.

rpassis avatar rpassis commented on September 28, 2024

Hey @johnswifttt,

Please don't take the example too literally, that's just a simple exercise in order to get you going and using the player quickly. For a more testable, reusable and extendable solution I'd definitely recommend you inject the player into the view controller.

How you do that will generally depend on the general architecture of your app, how your controllers are instantiated and where from but as a general rule I personally prefer having static factory methods that take dependencies as parameters and return a configured view controller to the calling site.

Here's one possible implementation following your example above and using the same view controller for different player types.

protocol Player { // Omitted for brevity }
protocol ProvidesView { // Omitted for brevity }

class MusicPlayer: Player, ProvidesView { // Omitted for brevity }
class AudioBookPlayer: Player, ProvidesView { // Omitted for brevity }

class MyViewController<T: Player & ProvidesView>: UIViewController {

    var player: T!
    
    static func configured(with player: T) -> MyViewController {
        let vc = MyViewController()
        vc.player = player
        return vc
    }
}

let musicPlayer = MusicPlayer()
let musicVc = MyViewController.configured(with: musicPlayer)

let audioBookPlayer = AudioBookPlayer()
let audioBookPlayerVc = MyViewController.configured(with: audioBookPlayer)

I hope that helps!

from playerkit.

spike-hue avatar spike-hue commented on September 28, 2024

@rpassis Oh I see, that's a very clean approach! Thank you for such a quick reply and sample code!

I have one more question, if you don't mind 🙂 (it's kind of related to this library)

Right now, our app only has Video’s. We are expanding to Song’s and soon other media such as Podcast’s, etc. Also, right now, there is a PlayerViewController. This is coupled with Video objects tightly. The configure property for this view controller is like so:

func inject(videos: [Video], currentVideoIndex: Int, videoPlayer: VideoPlaybackManager) { … }

PlayerViewController has playback controls such as a play button, pause button, next/previous button, and others. We want to use this same layout of controls for Song’s and other media. There is a XIB for this: PlaybackControlsView. This is the only thing in common of how we would display these objects to the user. Basically, for Videos we would show videos, but as for Songs/Podcasts we would instead show an image.

I'm not sure if I should have only 1 view controller PlayerViewController that plays all types of media. So I would use dependency injection to inject:

  1. The player (like you showed above)
  2. The API strategy (what API to use to fetch either Video, Songs, or Podcasts)
  3. View strategy (what view to display: a video or image).. depends on if its is a Video or Song/Podcast

Or should I have a VideoPlayerViewController and AudioPlayerViewController instead of just 1 PlayerViewController?

from playerkit.

rpassis avatar rpassis commented on September 28, 2024

I can't answer those questions for you without knowing a lot more about your project and codebase but if you are looking for an opinion based on what you described above, it feels like a single view controller should be able to handle all of those asset types without having any knowledge of what their concrete types are.

from playerkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.