Skip to content

Commit

Permalink
Merge pull request #46 from weiran/cleanup
Browse files Browse the repository at this point in the history
Removed VLCKit and native YouTube playback
  • Loading branch information
weiran authored Aug 20, 2022
2 parents 1665abc + 34b903f commit 068a25c
Show file tree
Hide file tree
Showing 21 changed files with 626 additions and 401 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ on:
jobs:

build:
runs-on: macos-latest
runs-on: macos-12

steps:
- uses: actions/checkout@v2
- name: Install Dependencies
run: pod install --repo-update
- name: Setup Config
run: mv 'App/Supporting Files/InstapaperConfiguration.defaults.plist' 'App/Supporting Files/InstapaperConfiguration.plist'
- name: Build
uses: sersoft-gmbh/xcodebuild-action@v1.1
uses: sersoft-gmbh/xcodebuild-action@v2
with:
workspace: WatchItLater.xcworkspace
project: WatchItLater.xcworkspace
scheme: WatchItLater
configuration: debug
sdk: appletvsimulator
Expand Down
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import AVFoundation
import SwiftyUserDefaults
import SwinjectStoryboard

Expand All @@ -17,6 +18,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
_ = Database.shared
SwinjectStoryboard.configure()

try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback)

return true
}

Expand Down
118 changes: 54 additions & 64 deletions App/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

119 changes: 25 additions & 94 deletions App/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import TVUIKit

import Nuke
import PromiseKit
import TVVLCPlayer
import SwiftyUserDefaults

class DetailViewController: UIViewController {
Expand All @@ -23,7 +22,6 @@ class DetailViewController: UIViewController {
private var videoProvider: VideoProviderProtocol?
private var videoStream: VideoStream?
private var duration: CMTime?
private var playerViewController: VLCPlayerViewController?

@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var domainLabel: UILabel!
Expand Down Expand Up @@ -54,7 +52,7 @@ class DetailViewController: UIViewController {
}

self.videoProvider = videoProvider
videoProvider.videoStream(preferredFormatType: Defaults[\.defaultVideoQualityKey]).done { [weak self] (videoStream) in
videoProvider.videoStream().done { [weak self] (videoStream) in
if let imageView = self?.thumbnailImageView, let url = videoStream.thumbnailURL {
let options = ImageLoadingOptions(placeholder: UIImage(named: "ThumbnailPlaceholder"))
Nuke.loadImage(with: url, options: options, into: imageView)
Expand Down Expand Up @@ -128,25 +126,20 @@ class DetailViewController: UIViewController {
}
}
}
activityIndicator.startAnimating()
view.isUserInteractionEnabled = false
videoProvider.videoStream(preferredFormatType: Defaults[\.defaultVideoQualityKey]).done { [weak self] videoStream -> Void in
guard let self = self, let video = self.video else {
return
}
self.videoStream = videoStream

if let alertController = self.playFromPositionAlertController(video) {
self.present(alertController, animated: true)
} else {
self.showVideoPlayer()

// play Vimeo using native player
if videoProvider is VimeoProvider {
activityIndicator.startAnimating()
view.isUserInteractionEnabled = false
videoProvider.videoStream().done { [weak self] videoStream -> Void in
self?.videoStream = videoStream
self?.showVideoPlayer()
}.ensure { [weak self] in
self?.activityIndicator.stopAnimating()
self?.view.isUserInteractionEnabled = true
}.catch { [weak self] error in
self?.showError(error)
}
}.ensure { [weak self] in
self?.activityIndicator.stopAnimating()
self?.view.isUserInteractionEnabled = true
}.catch { [weak self] error in
self?.showError(error)
}
}

Expand All @@ -164,47 +157,19 @@ class DetailViewController: UIViewController {
}

private func showVideoPlayer(startFrom: Int? = nil) {
if startFrom == nil || startFrom! <= 0 {
updateVideoProgress()
}
performSegue(withIdentifier: "ShowPlayerSegue", sender: self)
}

private func playFromPositionAlertController(_ video: Video) -> UIAlertController? {
guard video.progress > 0 else { return nil }
if let videoStream = videoStream {
let player = AVPlayer(url: videoStream.videoURL)

let progressInSeconds = video.progress / 1000
let formattedProgress = formatTimeInterval(duration: TimeInterval(progressInSeconds))
let alertController = UIAlertController(title: "", message: "Do you want to resume playback from your last saved position, or start from the beginning?", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Resume from \(formattedProgress)", style: .default, handler: { action in
self.showVideoPlayer(startFrom: video.progress)
}))
alertController.addAction(UIAlertAction(title: "Start from beginning", style: .default, handler: { action in
self.showVideoPlayer(startFrom: 0)
}))
if let startFrom = startFrom, startFrom > 0 {
let time = CMTimeMakeWithSeconds(Double(startFrom), preferredTimescale: 1)
player.seek(to: time)
}

return alertController
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ShowPlayerSegue" {
if let playerViewController = segue.destination as? VLCPlayerViewController,
let videoStream = self.videoStream {
let player = VLCMediaPlayer()
player.media = VLCMedia(url: videoStream.videoURL)
playerViewController.player = player

if let audioURL = videoStream.audioURL {
playerViewController.player.addPlaybackSlave(audioURL, type: .audio, enforce: true)
}

if let video = self.video, video.progress > 0 {
let time = VLCTime.init(number: NSNumber(value: video.progress))
playerViewController.player.time = time
}

playerViewController.player.delegate = self
self.playerViewController = playerViewController
let controller = AVPlayerViewController()
controller.player = player

present(controller, animated: true) {
player.play()
}
}
}
Expand Down Expand Up @@ -240,37 +205,3 @@ class DetailViewController: UIViewController {
return formatter.string(from: duration) ?? ""
}
}

extension DetailViewController: VLCMediaPlayerDelegate {
func mediaPlayerStateChanged(_ aNotification: Notification!) {
guard let playerViewController = self.playerViewController else { return }
if playerViewController.player.state == .ended {
updateVideoProgress()
} else if playerViewController.player.state == .stopped {
updateVideoProgress(Int(playerViewController.player.time.intValue))
}
}

func mediaPlayerTimeChanged(_ aNotification: Notification!) {
guard let player = self.playerViewController?.player else { return }
if player.state == .playing || player.state == .buffering {
updateVideoProgress(Int(player.time.intValue))
}
}

private func updateVideoProgress(_ duration: Int = 0) {
if let video = video {
Database.shared.updateVideoProgress(video, progress: duration)
}
}
}

extension VLCPlayerViewController {
public override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
if presses.first?.type == .menu {
// stop the player when quitting to trigger the delegate
player.stop()
}
super.pressesBegan(presses, with: event)
}
}
2 changes: 1 addition & 1 deletion App/FoldersTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2020 Weiran Zhang. All rights reserved.
//

import Foundation
import UIKit

class FoldersTabBarController: UITabBarController {
override func viewDidLoad() {
Expand Down
52 changes: 52 additions & 0 deletions App/Providers/HCVimeoVideoExtractor/HCVimeoVideo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// HCVimeoVideo.swift
// HCVimeoVideoExtractor
//
// Created by Mo Cariaga on 13/02/2018.
// Copyright (c) 2018 Mo Cariaga <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.


import UIKit

public enum HCVimeoThumbnailQuality: String {
case quality640 = "640"
case quality960 = "960"
case quality1280 = "1280"
case qualityBase = "base"
case qualityUnknown = "unknown"
}

public enum HCVimeoVideoQuality: String {
case quality360p = "360p"
case quality540p = "540p"
case quality640p = "640p"
case quality720p = "720p"
case quality960p = "960p"
case quality1080p = "1080p"
case qualityUnknown = "unknown"
}

public class HCVimeoVideo: NSObject {
public var title = ""
public var thumbnailURL = [HCVimeoThumbnailQuality: URL]()
public var videoURL = [HCVimeoVideoQuality: URL]()
public var duration = 0
}
Loading

0 comments on commit 068a25c

Please sign in to comment.