Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@
F79B645F26CA661600838ACA /* UIControl+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIControl+Extension.swift"; sourceTree = "<group>"; };
F79B869A265E19D40085C0E0 /* NSMutableAttributedString+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMutableAttributedString+Extension.swift"; sourceTree = "<group>"; };
F79EDA9F26B004980007D134 /* NCPlayerToolBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPlayerToolBar.swift; sourceTree = "<group>"; };
F79EDAA126B004980007D134 /* NCPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPlayer.swift; sourceTree = "<group>"; };
F79EDAA126B004980007D134 /* NCPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = NCPlayer.swift; sourceTree = "<group>"; };
F79FFB252A97C24A0055EEA4 /* NCNetworkingE2EEMarkFolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCNetworkingE2EEMarkFolder.swift; sourceTree = "<group>"; };
F7A03E2E2D425A14007AA677 /* NCFavoriteNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCFavoriteNavigationController.swift; sourceTree = "<group>"; };
F7A03E322D426115007AA677 /* NCMoreNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMoreNavigationController.swift; sourceTree = "<group>"; };
Expand Down
31 changes: 18 additions & 13 deletions iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NextcloudKit
import UIKit
import MobileVLCKit

class NCPlayer: NSObject {
class NCPlayer: NSObject, VLCMediaDelegate {
internal var url: URL?
internal var player = VLCMediaPlayer()
internal var dialogProvider: VLCDialogProvider?
Expand Down Expand Up @@ -65,18 +65,21 @@ class NCPlayer: NSObject {
self.url = url
self.singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didSingleTapWith(gestureRecognizer:)))

print("Play URL: \(url)")
player.media = VLCMedia(url: url)
print("Playing URL: \(url)")
let media = VLCMedia(url: url)

media.parse(options: url.isFileURL ? .fetchLocal : .fetchNetwork)

player.media = media
Comment on lines +69 to +73

This comment was marked as off-topic.

player.delegate = self

dialogProvider = VLCDialogProvider(library: VLCLibrary.shared(), customUI: true)
dialogProvider?.customRenderer = self

// player?.media?.addOption("--network-caching=500")
player.media?.addOption(":http-user-agent=\(userAgent)")

if let result = self.database.getVideo(metadata: metadata),
let resultPosition = result.position {
let resultPosition = result.position {
position = resultPosition
}

Expand Down Expand Up @@ -213,11 +216,12 @@ extension NCPlayer: VLCMediaPlayerDelegate {

NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterPlayerStoppedPlaying)

print("Played mode: STOPPED")
print("Player mode: STOPPED")
case .opening:
print("Played mode: OPENING")
playerToolBar?.playbackSliderEvent = .began
print("Player mode: OPENING")
case .buffering:
print("Played mode: BUFFERING")
print("Player mode: BUFFERING")
case .ended:
self.database.addVideo(metadata: self.metadata, position: 0)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
Expand All @@ -226,9 +230,9 @@ extension NCPlayer: VLCMediaPlayerDelegate {
}
}
playerToolBar?.playButtonPlay()
print("Played mode: ENDED")
print("Player mode: ENDED")
case .error:
print("Played mode: ERROR")
print("Player mode: ERROR")
case .playing:
guard let playerToolBar = playerToolBar else { return }
if playerToolBar.playerButtonView.isHidden {
Expand Down Expand Up @@ -256,24 +260,25 @@ extension NCPlayer: VLCMediaPlayerDelegate {
}
self.width = Int(size.width)
self.height = Int(size.height)
playerToolBar.updatePlaybackPosition()
playerToolBar.updateTopToolBar(videoSubTitlesIndexes: player.videoSubTitlesIndexes, audioTrackIndexes: player.audioTrackIndexes)
self.database.addVideo(metadata: metadata, width: self.width, height: self.height, length: self.length)

NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterPlayerIsPlaying)

print("Played mode: PLAYING")
print("Player mode: PLAYING")
case .paused:
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterPlayerStoppedPlaying)

playerToolBar?.playButtonPlay()
print("Played mode: PAUSED")
print("Player mode: PAUSED")
default: break
}
}

func mediaPlayerTimeChanged(_ aNotification: Notification) {
activityIndicator.stopAnimating()
playerToolBar?.update()
playerToolBar?.updatePlaybackPosition()
}
}

Expand Down
30 changes: 21 additions & 9 deletions iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,32 @@ class NCPlayerToolBar: UIView {
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = position
}

public func update() {
guard let ncplayer = self.ncplayer, let length = ncplayer.player.media?.length.intValue else { return }
public func updatePlaybackPosition() {
guard let ncplayer = self.ncplayer,
let media = ncplayer.player.media else {
return
}

let length = media.length.intValue

let position = ncplayer.player.position
let positionInSecond = position * Float(length / 1000)

// SLIDER & TIME
let currentSeconds = Double(position) * (Double(length) / 1000.0)

let currentTimeObj = VLCTime(int: Int32(currentSeconds * 1000))
let remainingTimeObj = VLCTime(int: Int32((Double(length) / 1000.0) - currentSeconds) * 1000)

labelCurrentTime.text = currentTimeObj.stringValue == "--:--" ? "00:00" : currentTimeObj.stringValue

let remaining = remainingTimeObj.stringValue
labelLeftTime.text = "-\(remaining)"

if playbackSliderEvent == .ended {
playbackSlider.value = position
}
labelCurrentTime.text = ncplayer.player.time.stringValue
labelLeftTime.text = ncplayer.player.remainingTime?.stringValue

MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPMediaItemPropertyPlaybackDuration] = length / 1000
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = positionInSecond
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentSeconds
}

public func updateTopToolBar(videoSubTitlesIndexes: [Any], audioTrackIndexes: [Any]) {
Expand Down Expand Up @@ -407,7 +419,7 @@ extension NCPlayerToolBar {
guard let metadata = self.metadata else { return }
let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
if let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController,
let viewController = navigationController.topViewController as? NCSelect {
let viewController = navigationController.topViewController as? NCSelect {

viewController.delegate = self
viewController.typeOfCommandView = .nothing
Expand Down Expand Up @@ -490,7 +502,7 @@ extension NCPlayerToolBar: NCSelectDelegate {

// swiftlint:disable inclusive_language
func addPlaybackSlave(type: String, metadata: tableMetadata) {
// swiftlint:enable inclusive_language
// swiftlint:enable inclusive_language
let fileNameLocalPath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileName: metadata.fileNameView, userId: metadata.userId, urlBase: metadata.urlBase)

if type == "subtitle" {
Expand Down
Loading