Refactored some force unwraps

This commit is contained in:
Stephen Byatt 2021-06-23 12:11:33 +10:00
parent 77e6777b91
commit 099e138eb5
5 changed files with 26 additions and 120 deletions

View File

@ -33,16 +33,6 @@ class AudioViewController: UIViewController {
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
struct AudioView: View {

View File

@ -72,15 +72,10 @@ class InfoTabBarViewController: UITabBarController, UIGestureRecognizerDelegate
return
}
print(item.title!)
switch item.title {
case "Audio":
if var height = audioViewController?.height {
print(height)
height += tabBarHeight
UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseOut) { [self] in
videoPlayer?.infoViewContainer.frame = CGRect(x: pos.minX, y: pos.minY, width: pos.width, height: height)
@ -91,8 +86,6 @@ class InfoTabBarViewController: UITabBarController, UIGestureRecognizerDelegate
break
case "Info":
if var height = mediaInfoController?.height {
print(height)
height += tabBarHeight
UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseOut) { [self] in
videoPlayer?.infoViewContainer.frame = CGRect(x: pos.minX, y: pos.minY, width: pos.width, height: height)
@ -103,8 +96,6 @@ class InfoTabBarViewController: UITabBarController, UIGestureRecognizerDelegate
break
case "Subtitles":
if var height = subtitleViewController?.height{
print(height)
height += tabBarHeight
UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseOut) { [self] in
videoPlayer?.infoViewContainer.frame = CGRect(x: pos.minX, y: pos.minY, width: pos.width, height: height)

View File

@ -45,7 +45,8 @@ struct MediaInfoView: View {
HStack(spacing: 30) {
VStack {
ImageView(src: item.type == "Episode" ? item.getSeriesPrimaryImage(maxWidth: 200) : item.getPrimaryImage(maxWidth: 200), bh: item.type == "Episode" ? item.getSeriesPrimaryImageBlurHash() : item.getPrimaryImageBlurHash()) .frame(width: 200, height: 300)
ImageView(src: item.type == "Episode" ? item.getSeriesPrimaryImage(maxWidth: 200) : item.getPrimaryImage(maxWidth: 200), bh: item.type == "Episode" ? item.getSeriesPrimaryImageBlurHash() : item.getPrimaryImageBlurHash())
.frame(width: 200, height: 300)
.cornerRadius(10)
Spacer()
}
@ -68,7 +69,7 @@ struct MediaInfoView: View {
if item.type == "Episode" {
Text("S\(item.parentIndexNumber ?? 0) • E\(item.indexNumber ?? 0)")
if let date = item.premiereDate! {
if let date = item.premiereDate {
Text("")
Text(formatDate(date: date))
}

View File

@ -21,7 +21,6 @@ class SubtitlesViewController: UIViewController {
}
func prepareSubtitleView(subtitleTracks: [Subtitle], selectedTrack: Int32, delegate: VideoPlayerSettingsDelegate)
{
let contentView = UIHostingController(rootView: SubtitleView(selectedTrack: selectedTrack, subtitleTrackArray: subtitleTracks, delegate: delegate))
@ -33,86 +32,6 @@ class SubtitlesViewController: UIViewController {
contentView.view.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
}
//
//
// func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// return subtitleTrackArray.count
// }
//
// func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// let cell = UITableViewCell()
// let subtitle = subtitleTrackArray[indexPath.row]
// cell.textLabel?.text = subtitle.name
//
// let image = UIImage(systemName: "checkmark", withConfiguration: UIImage.SymbolConfiguration(pointSize: (27), weight: .bold))?.withRenderingMode(.alwaysOriginal).withTintColor(.white)
// cell.imageView?.image = image
//
// if selectedTrack != subtitle.id {
// cell.imageView?.isHidden = true
// }
// else {
// selectedTrackCellRow = indexPath.row
// }
//
// return cell
// }
//
// func tableView(_ tableView: UITableView, didUpdateFocusIn context: UITableViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
//
// if let path = context.nextFocusedIndexPath {
// if path.row == selectedTrackCellRow {
// let cell : UITableViewCell = tableView.cellForRow(at: path)!
// cell.imageView?.image = cell.imageView?.image?.withTintColor(.black)
// }
// }
//
// if let path = context.previouslyFocusedIndexPath {
// if path.row == selectedTrackCellRow {
// let cell : UITableViewCell = tableView.cellForRow(at: path)!
// cell.imageView?.image = cell.imageView?.image?.withTintColor(.white)
// }
// }
//
// }
//
//
// func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// let oldPath = IndexPath(row: selectedTrackCellRow, section: 0)
// if let oldCell : UITableViewCell = tableView.cellForRow(at: oldPath) {
// oldCell.imageView?.isHidden = true
// }
//
// let cell : UITableViewCell = tableView.cellForRow(at: indexPath)!
// cell.imageView?.isHidden = false
// cell.imageView?.image = cell.imageView?.image?.withTintColor(.black)
//
// selectedTrack = Int32(subtitleTrackArray[indexPath.row].id)
// selectedTrackCellRow = indexPath.row
//// infoTabBar?.videoPlayer?.subtitleTrackChanged(newTrackID: selectedTrack)
// print("setting new subtitle")
// tableView.deselectRow(at: indexPath, animated: false)
//
// }
//
// func numberOfSections(in tableView: UITableView) -> Int {
// return 1
// }
//
//
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
struct SubtitleView: View {

View File

@ -140,6 +140,7 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
setupNowPlayingCC()
// Adjust subtitle size
mediaPlayer.perform(Selector(("setTextRendererFontSize:")), with: 16)
}
@ -154,10 +155,14 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
builder.setMaxBitrate(bitrate: maxBitrate)
let profile = builder.buildProfile()
let playbackInfo = PlaybackInfoDto(userId: SessionManager.current.user.user_id!, maxStreamingBitrate: Int(maxBitrate), startTimeTicks: manifest.userData?.playbackPositionTicks ?? 0, deviceProfile: profile, autoOpenLiveStream: true)
guard let currentUser = SessionManager.current.user else {
return
}
let playbackInfo = PlaybackInfoDto(userId: currentUser.user_id ?? "", maxStreamingBitrate: Int(maxBitrate), startTimeTicks: manifest.userData?.playbackPositionTicks ?? 0, deviceProfile: profile, autoOpenLiveStream: true)
DispatchQueue.global(qos: .userInitiated).async { [self] in
MediaInfoAPI.getPostedPlaybackInfo(itemId: manifest.id!, userId: SessionManager.current.user.user_id!, maxStreamingBitrate: Int(maxBitrate), startTimeTicks: manifest.userData?.playbackPositionTicks ?? 0, autoOpenLiveStream: true, playbackInfoDto: playbackInfo)
MediaInfoAPI.getPostedPlaybackInfo(itemId: manifest.id!, userId: currentUser.user_id ?? "", maxStreamingBitrate: Int(maxBitrate), startTimeTicks: manifest.userData?.playbackPositionTicks ?? 0, autoOpenLiveStream: true, playbackInfoDto: playbackInfo)
.sink(receiveCompletion: { result in
print(result)
}, receiveValue: { [self] response in
@ -167,16 +172,17 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
playSessionId = response.playSessionId ?? ""
let mediaSource = response.mediaSources!.first.self!
guard let mediaSource = response.mediaSources?.first.self else {
return
}
let item = PlaybackItem()
let streamURL : URL?
let streamURL : URL
// Item is being transcoded by request of server
if mediaSource.transcodingUrl != nil
{
if let transcodiungUrl = mediaSource.transcodingUrl {
item.videoType = .transcode
streamURL = URL(string: "\(ServerEnvironment.current.server.baseURI!)\(mediaSource.transcodingUrl!)")
streamURL = URL(string: "\(ServerEnvironment.current.server.baseURI!)\(transcodiungUrl)")!
}
// Item will be directly played by the client
else
@ -185,7 +191,7 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
streamURL = URL(string: "\(ServerEnvironment.current.server.baseURI!)/Videos/\(manifest.id!)/stream?Static=true&mediaSourceId=\(manifest.id!)&deviceId=\(SessionManager.current.deviceID)&api_key=\(SessionManager.current.accessToken)&Tag=\(mediaSource.eTag!)")!
}
item.videoUrl = streamURL!
item.videoUrl = streamURL
let disableSubtitleTrack = Subtitle(name: "None", id: -1, url: nil, delivery: .embed, codec: "")
subtitleTrackArray.append(disableSubtitleTrack)
@ -223,7 +229,7 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
}
// If no default audio tracks select the first one
if selectedAudioTrack == -1 && !audioTrackArray.isEmpty{
if selectedAudioTrack == -1 && !audioTrackArray.isEmpty {
selectedAudioTrack = audioTrackArray.first!.id
}
@ -349,8 +355,8 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
}
var nowPlayingInfo = [String: Any]()
nowPlayingInfo[MPMediaItemPropertyTitle] = manifest.name!
nowPlayingInfo[MPMediaItemPropertyTitle] = manifest.name ?? "Jellyfin Video"
nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = 0.0
nowPlayingInfo[MPNowPlayingInfoPropertyMediaType] = AVMediaType.video
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = runTicks
@ -359,10 +365,9 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
if let imageData = NSData(contentsOf: manifest.getPrimaryImage(maxWidth: 200)) {
if let artworkImage = UIImage(data: imageData as Data) {
let artwork = MPMediaItemArtwork.init(boundsSize: artworkImage.size, requestHandler: { (size) -> UIImage in
return artworkImage
return artworkImage
})
nowPlayingInfo[MPMediaItemPropertyArtwork] = artwork
print("set artwork")
nowPlayingInfo[MPMediaItemPropertyArtwork] = artwork
}
}
@ -571,14 +576,14 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
switch swipe.direction {
case .left:
print("swiped left")
mediaPlayer.pause()
// mediaPlayer.pause()
// player.seek(to: CMTime(value: Int64(self.currentSeconds) + 10, timescale: 1))
mediaPlayer.play()
// mediaPlayer.play()
case .right:
print("swiped right")
mediaPlayer.pause()
// mediaPlayer.pause()
// player.seek(to: CMTime(value: Int64(self.currentSeconds) + 10, timescale: 1))
mediaPlayer.play()
// mediaPlayer.play()
case .up:
break
case .down: