Playback reporting works now
This commit is contained in:
parent
208bec783a
commit
57b39c932b
|
@ -21,7 +21,7 @@ class GlobalData: ObservableObject {
|
||||||
|
|
||||||
extension UIDevice {
|
extension UIDevice {
|
||||||
var hasNotch: Bool {
|
var hasNotch: Bool {
|
||||||
let bottom = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
|
let bottom = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.safeAreaInsets.bottom ?? 0
|
||||||
return bottom > 0
|
return bottom > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
//me realizing i shouldve just written the whole app in the mvvm system bc it makes so much more sense
|
//me realizing i shouldve just written the whole app in the mvvm system bc it makes so much more sense
|
||||||
|
//Please don't touch this ifle
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import MobileVLCKit
|
import MobileVLCKit
|
||||||
|
@ -65,6 +66,7 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
var selectedAudioTrack: Int32 = 0;
|
var selectedAudioTrack: Int32 = 0;
|
||||||
var selectedCaptionTrack: Int32 = 0;
|
var selectedCaptionTrack: Int32 = 0;
|
||||||
var playSessionId: String = "";
|
var playSessionId: String = "";
|
||||||
|
var lastProgressReportTime: Double = 0;
|
||||||
|
|
||||||
var subtitleTrackArray: [Subtitle] = [];
|
var subtitleTrackArray: [Subtitle] = [];
|
||||||
var audioTrackArray: [AudioTrack] = [];
|
var audioTrackArray: [AudioTrack] = [];
|
||||||
|
@ -85,24 +87,21 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func exitButtonPressed(_ sender: Any) {
|
@IBAction func exitButtonPressed(_ sender: Any) {
|
||||||
print("exit tap")
|
sendStopReport()
|
||||||
delegate?.exitPlayer(self)
|
delegate?.exitPlayer(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func controlViewTapped(_ sender: Any) {
|
@IBAction func controlViewTapped(_ sender: Any) {
|
||||||
print("control view tap")
|
|
||||||
videoControlsView.isHidden = !videoControlsView.isHidden
|
videoControlsView.isHidden = !videoControlsView.isHidden
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func contentViewTapped(_ sender: Any) {
|
@IBAction func contentViewTapped(_ sender: Any) {
|
||||||
print("content view tap")
|
|
||||||
videoControlsView.isHidden = !videoControlsView.isHidden
|
videoControlsView.isHidden = !videoControlsView.isHidden
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@IBOutlet weak var mainActionButton: UIButton!
|
@IBOutlet weak var mainActionButton: UIButton!
|
||||||
@IBAction func mainActionButtonPressed(_ sender: Any) {
|
@IBAction func mainActionButtonPressed(_ sender: Any) {
|
||||||
print("mab press")
|
|
||||||
print(mediaPlayer.state.rawValue)
|
print(mediaPlayer.state.rawValue)
|
||||||
if(paused) {
|
if(paused) {
|
||||||
mediaPlayer.play()
|
mediaPlayer.play()
|
||||||
|
@ -120,6 +119,7 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
|
|
||||||
//View has loaded.
|
//View has loaded.
|
||||||
//Show loading screen
|
//Show loading screen
|
||||||
|
usleep(10000);
|
||||||
delegate?.showLoadingView(self)
|
delegate?.showLoadingView(self)
|
||||||
|
|
||||||
//Fetch max bitrate from UserDefaults depending on current connection mode
|
//Fetch max bitrate from UserDefaults depending on current connection mode
|
||||||
|
@ -166,7 +166,6 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stream["Type"].string == "Audio") {
|
if(stream["Type"].string == "Audio") {
|
||||||
let deliveryUrl = URL(string: "https://example.com")!
|
|
||||||
let subtitle = AudioTrack(name: stream["DisplayTitle"].string ?? "", id: Int32(stream["Index"].int ?? 0))
|
let subtitle = AudioTrack(name: stream["DisplayTitle"].string ?? "", id: Int32(stream["Index"].int ?? 0))
|
||||||
if(stream["IsDefault"].boolValue) {
|
if(stream["IsDefault"].boolValue) {
|
||||||
selectedAudioTrack = Int32(stream["Index"].int ?? 0);
|
selectedAudioTrack = Int32(stream["Index"].int ?? 0);
|
||||||
|
@ -201,7 +200,6 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stream["Type"].string == "Audio") {
|
if(stream["Type"].string == "Audio") {
|
||||||
let deliveryUrl = URL(string: "https://example.com")!
|
|
||||||
let subtitle = AudioTrack(name: stream["DisplayTitle"].string ?? "", id: Int32(stream["Index"].int ?? 0))
|
let subtitle = AudioTrack(name: stream["DisplayTitle"].string ?? "", id: Int32(stream["Index"].int ?? 0))
|
||||||
if(stream["IsDefault"].boolValue) {
|
if(stream["IsDefault"].boolValue) {
|
||||||
selectedAudioTrack = Int32(stream["Index"].int ?? 0);
|
selectedAudioTrack = Int32(stream["Index"].int ?? 0);
|
||||||
|
@ -220,6 +218,15 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
item.subtitles = subtitleTrackArray
|
item.subtitles = subtitleTrackArray
|
||||||
playbackItem = item;
|
playbackItem = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mediaPlayer.media = VLCMedia(url: playbackItem.videoUrl)
|
||||||
|
playbackItem.subtitles.forEach() { sub in
|
||||||
|
if(sub.id != -1 && sub.delivery == "External" && sub.codec != "subrip") {
|
||||||
|
mediaPlayer.addPlaybackSlave(sub.url, type: .subtitle, enforce: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mediaPlayer.play()
|
||||||
|
mediaPlayer.jumpForward(Int32(manifest.Progress/10000000))
|
||||||
} catch {
|
} catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -230,8 +237,6 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaPlayer.media = media
|
|
||||||
|
|
||||||
mediaPlayer.delegate = self
|
mediaPlayer.delegate = self
|
||||||
mediaPlayer.drawable = videoContentView
|
mediaPlayer.drawable = videoContentView
|
||||||
|
|
||||||
|
@ -240,7 +245,6 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
} else {
|
} else {
|
||||||
titleLabel.text = manifest.Name
|
titleLabel.text = manifest.Name
|
||||||
}
|
}
|
||||||
mediaPlayer.play()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
@ -255,12 +259,13 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
switch currentState {
|
switch currentState {
|
||||||
case .stopped :
|
case .stopped :
|
||||||
print("Video is done playing)")
|
print("Video is done playing)")
|
||||||
|
sendStopReport()
|
||||||
case .ended :
|
case .ended :
|
||||||
print("Video is done playing)")
|
print("Video is done playing)")
|
||||||
|
sendStopReport()
|
||||||
case .playing :
|
case .playing :
|
||||||
print("Video is playing")
|
print("Video is playing")
|
||||||
|
sendProgressReport(eventName: "unpause")
|
||||||
delegate?.hideLoadingView(self)
|
delegate?.hideLoadingView(self)
|
||||||
paused = false;
|
paused = false;
|
||||||
|
|
||||||
|
@ -273,6 +278,7 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
|
|
||||||
case .buffering :
|
case .buffering :
|
||||||
print("Video is buffering)")
|
print("Video is buffering)")
|
||||||
|
sendProgressReport(eventName: "pause")
|
||||||
delegate?.showLoadingView(self)
|
delegate?.showLoadingView(self)
|
||||||
mediaPlayer.pause()
|
mediaPlayer.pause()
|
||||||
usleep(10000)
|
usleep(10000)
|
||||||
|
@ -280,9 +286,8 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
|
|
||||||
case .error :
|
case .error :
|
||||||
print("Video has error)")
|
print("Video has error)")
|
||||||
|
sendStopReport()
|
||||||
case .esAdded:
|
case .esAdded:
|
||||||
print("Es Added")
|
|
||||||
mainActionButton.setImage(UIImage(systemName: "pause"), for: .normal)
|
mainActionButton.setImage(UIImage(systemName: "pause"), for: .normal)
|
||||||
@unknown default:
|
@unknown default:
|
||||||
break
|
break
|
||||||
|
@ -293,11 +298,29 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe
|
||||||
let time = mediaPlayer.position;
|
let time = mediaPlayer.position;
|
||||||
if(time != lastTime) {
|
if(time != lastTime) {
|
||||||
paused = false;
|
paused = false;
|
||||||
|
seekSlider.setValue(mediaPlayer.position, animated: true)
|
||||||
delegate?.hideLoadingView(self)
|
delegate?.hideLoadingView(self)
|
||||||
|
|
||||||
|
let remainingTime = abs(mediaPlayer.remainingTime.intValue)/1000;
|
||||||
|
let hours = remainingTime / 3600;
|
||||||
|
let minutes = (remainingTime % 3600) / 60;
|
||||||
|
let seconds = (remainingTime % 3600) % 60;
|
||||||
|
var timeTextStr = "";
|
||||||
|
if(hours != 0) {
|
||||||
|
timeTextStr = "\(Int(hours)):\(String(Int((minutes))).leftPad(toWidth: 2, withString: "0")):\(String(Int((seconds))).leftPad(toWidth: 2, withString: "0"))";
|
||||||
|
} else {
|
||||||
|
timeTextStr = "\(String(Int((minutes))).leftPad(toWidth: 2, withString: "0")):\(String(Int((seconds))).leftPad(toWidth: 2, withString: "0"))";
|
||||||
|
}
|
||||||
|
timeText.text = timeTextStr
|
||||||
} else {
|
} else {
|
||||||
paused = true;
|
paused = true;
|
||||||
}
|
}
|
||||||
lastTime = time;
|
lastTime = time;
|
||||||
|
|
||||||
|
if(CACurrentMediaTime() - lastProgressReportTime > 5) {
|
||||||
|
sendProgressReport(eventName: "timeupdate")
|
||||||
|
lastProgressReportTime = CACurrentMediaTime()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK: Jellyfin Playstate updates
|
//MARK: Jellyfin Playstate updates
|
||||||
|
|
Loading…
Reference in New Issue