Files
Woka_Native_iOS/WOKA/Theme/ViewModel/ThemeTwoVM.swift
BilalKhanWDI 1d6add0322 - Added DropDown
- Added api for show listing , made data model, updated the dropdown
- Added api for category, made data model
- Made the dynamic height tableview to show all the shows
- On fav add remove , will refresh the mylist screen
- Added default load on hindi
- On category selection change, updating the show list data
- Handled the fav category id as int, string , string seeprated with “,”
- Modifying my list with bookmark id with above
2024-06-19 20:07:47 +05:30

192 lines
6.5 KiB
Swift

//
// ThemeTwoVM.swift
// WOKA
//
// Created by MacBook Pro on 27/05/24.
//
import UIKit
import AVFoundation
import JWPlayerKit
struct Theme2Struct{
let imageName : String
let text : String
}
class ThemeTwoVM{
weak var vc : ThemeTwoVC!
var liveStreamURL = "https://d3volyx7jx7oal.cloudfront.net/master.m3u8"
var avPlayer : AVPlayer!
var playerLayer: AVPlayerLayer!
var cellData = [Theme2Struct(imageName: "WokaFMT2", text: "WOKA FM"),
Theme2Struct(imageName: "LiveTVT2", text: "LIVE TV"),
Theme2Struct(imageName: "WebSeriesT2", text: "WEB SERIES"),
Theme2Struct(imageName: "GamesT2", text: "GAMES"),
Theme2Struct(imageName: "AudioBooksT2", text: "AUDIO BOOKS"),
Theme2Struct(imageName: "KaraokeT2", text: "KARAOKE"),
Theme2Struct(imageName: "ShopT2", text: "SHOP")]
func initView(){
setupCell()
NotificationCenter.default.addObserver(self, selector: #selector(self.reloadTheme), name: NSNotification.Name(rawValue: K.NotificationCenterReloads.reloadTheme), object: nil)
setupAvPlayer()
setUserData()
}
func playLiveTV(){
Utilities.startProgressHUD(msg: "Loading...")
print("tapped")
let vc = self.vc.storyboard?.instantiateViewController(identifier: "PlayerVC") as! PlayerVC
DispatchQueue.main.async {
do {
// Create a JWMediaTrack with the thumbnails .vtt file
// let thumbnailTrack = try JWThumbnailTrackBuilder()
// .file(URL(string:"https://content.jwplatform.com/videos/Agy4RIje-Ysj2G4DQ.mp4")!)
// .build()
// Create a JWPlayerItem
let item = try JWPlayerItemBuilder()
.file(URL(string: self.liveStreamURL)!)
.title("Testing Title")
// .posterImage(URL(string: "https://img.freepik.com/free-photo/painting-mountain-lake-with-mountain-background_188544-9126.jpg")!)
// .mediaTracks([thumbnailTrack])
.build()
// Create a config, and give it the item as a playlist.
let config = try JWPlayerConfigurationBuilder()
.playlist(items: [item])
.autostart(true)
// .preload(.auto)
// .repeatContent(true)
.build()
vc.config = config
vc.dismissTapped = self.tapped
vc.modalPresentationStyle = .overFullScreen
Utilities.dismissProgressHUD()
self.vc.present(vc, animated: false) {
self.stopLiveStream()
vc.transitionToFullScreen(animated: true) {
print("FullScreen")
}
// vc.setDeviceOrientation(orientation: .landscapeRight)
}
// Utilities.dismissProgressHUD()
// self.vc.navigationController?.pushViewController(vc, animated: true)
// self.stopLiveStream()
}
catch {
// Handle Error
}
}
}
func tapped(){
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { _ in
self.startLiveStream()
self.vc.liveTvView.layoutIfNeeded()
}
print("Sadasd")
}
func startLiveStream(){
avPlayer.play()
avPlayer.volume = 0
}
func stopLiveStream(){
avPlayer.pause()
}
func setUserData(){
guard let data = AuthFunc.shareInstance.userData else{return}
//set the first name as the name
/*
Check User Type,
Dont show username if the user type is guest
*/
switch data.userType{
case "1": // child
vc.nameLabel.text = data.fullname?.components(separatedBy: " ").first
vc.notificationBtn.isHidden = false
case "2" : // adult
vc.nameLabel.text = data.fullname?.components(separatedBy: " ").first
vc.notificationBtn.isHidden = false
case "3": // Guest
vc.nameLabel.text = ""
vc.notificationBtn.isHidden = true
break
default:
break
}
if let avatar = data.avtar{
//https://wokaland.com/admin/storage/app/public/uploads/avtar/avatar2.png?d=1716889852
vc.avatarImage.imageURL("https://wokaland.com/admin/storage/app/public/uploads/avtar/avatar6.png")
}
}
func setupAvPlayer(){
/*
Av Player Setup
*/
let streamURL = URL(string: liveStreamURL)
// Create AVPlayer with the stream URL
avPlayer = AVPlayer(url: streamURL!)
// avPlayer.isMuted = true
// Create AVPlayerLayer
playerLayer = AVPlayerLayer(player: avPlayer)
playerLayer.videoGravity = .resizeAspectFill // You can set different videoGravity as per your need
playerLayer.frame = self.vc.liveTvView.bounds
self.vc.liveTvView.layer.addSublayer(playerLayer)
avPlayer.play()
avPlayer.volume = 0
}
func setData(){
playerLayer.frame = self.vc.liveTvView.bounds
guard let data = AuthFunc.shareInstance.userData else{return}
//set the first name as the name
/*
Check User Type,
Dont show username if the user type is guest
*/
switch data.userType{
case "1": // child
vc.nameLabel.text = data.fullname?.components(separatedBy: " ").first
case "2" : // adult
vc.nameLabel.text = data.fullname?.components(separatedBy: " ").first
case "3": // Guest
vc.nameLabel.text = ""
break
default:
break
}
}
// MARK: - Notification Center Handlers
@objc func reloadTheme(){
self.vc.delegate?.didPressSwitchButton(from: self.vc)
}
func setupCell(){
vc.collectionView.register(UINib(nibName: K.CellIdentifier.Theme.homeExploreCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Theme.homeExploreCell)
vc.collectionView.delegate = vc.self
vc.collectionView.dataSource = vc.self
}
}