Comments (4)
@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.
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.
@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:
- The player (like you showed above)
- The API strategy (what API to use to fetch either Video, Songs, or Podcasts)
- 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.
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)
- Architecture Question (Follow-Up to #69) HOT 4
- is there a react-native bridge for this package? HOT 1
- Question about AVPlayerItemDidPlayToEndTime HOT 2
- does your lib support rtsp/rtmp? HOT 1
- Vimeo Video Not Playing. HOT 1
- How to play private vimeo video link? HOT 1
- UIWebview is deprecated HOT 4
- Sutitles HOT 3
- Swift version bump. HOT 2
- TextTracks are empty
- Example project is not playing the video HOT 2
- Video not playing: https://vimeo.com/30371570 HOT 4
- Play a video HOT 4
- How to show video in fullscreen? which function needs to call?
- Does the SDK support 360 video?
- Can't find documentation on captioning
- Playback speed HOT 1
- Chapter markers
- Distribute PlayerKit as Swift Package
- Full Screen View
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playerkit.