From 8bf0c603b0b8d9ecb80141f4c422f00bf2c2ee5b Mon Sep 17 00:00:00 2001 From: Jens Timmerman Date: Fri, 25 Sep 2020 01:35:12 +0200 Subject: [PATCH] added example video player in the view --- vrtnu/vrtnu.xcodeproj/project.pbxproj | 4 +++ vrtnu/vrtnu/ContentView.swift | 11 +++++-- vrtnu/vrtnu/video.swift | 43 +++++++++++++++++++++++++++ vrtnu/vrtnu/vrtnuApp.swift | 13 ++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 vrtnu/vrtnu/video.swift diff --git a/vrtnu/vrtnu.xcodeproj/project.pbxproj b/vrtnu/vrtnu.xcodeproj/project.pbxproj index b90970b..d1608d8 100644 --- a/vrtnu/vrtnu.xcodeproj/project.pbxproj +++ b/vrtnu/vrtnu.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ B4F0CC82251BE62F00E9EA74 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B4F0CC81251BE62F00E9EA74 /* Preview Assets.xcassets */; }; B4F0CC8D251BE62F00E9EA74 /* vrtnuTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4F0CC8C251BE62F00E9EA74 /* vrtnuTests.swift */; }; B4F0CC98251BE62F00E9EA74 /* vrtnuUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4F0CC97251BE62F00E9EA74 /* vrtnuUITests.swift */; }; + B4F0CCAA251BFD6F00E9EA74 /* video.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4F0CCA9251BFD6F00E9EA74 /* video.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -45,6 +46,7 @@ B4F0CC93251BE62F00E9EA74 /* vrtnuUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = vrtnuUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B4F0CC97251BE62F00E9EA74 /* vrtnuUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = vrtnuUITests.swift; sourceTree = ""; }; B4F0CC99251BE62F00E9EA74 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B4F0CCA9251BFD6F00E9EA74 /* video.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = video.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -100,6 +102,7 @@ B4F0CC7E251BE62F00E9EA74 /* Assets.xcassets */, B4F0CC83251BE62F00E9EA74 /* Info.plist */, B4F0CC80251BE62F00E9EA74 /* Preview Content */, + B4F0CCA9251BFD6F00E9EA74 /* video.swift */, ); path = vrtnu; sourceTree = ""; @@ -261,6 +264,7 @@ files = ( B4F0CC7D251BE62B00E9EA74 /* ContentView.swift in Sources */, B4F0CC7B251BE62B00E9EA74 /* vrtnuApp.swift in Sources */, + B4F0CCAA251BFD6F00E9EA74 /* video.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/vrtnu/vrtnu/ContentView.swift b/vrtnu/vrtnu/ContentView.swift index 018ff8a..2148b24 100644 --- a/vrtnu/vrtnu/ContentView.swift +++ b/vrtnu/vrtnu/ContentView.swift @@ -6,14 +6,19 @@ // import SwiftUI +import AVKit +import AVFoundation struct ContentView: View { + private let player = AVPlayer(url: URL(string: "https://remix-cf.lwc.vrtcdn.be/remix/ecd69313-4a39-4297-95b1-aede167725b7/remix.ism/.m3u8")!) + var body: some View { - Text("Hello, world!") - .padding() - } + VideoPlayer(player: player) + }; + } + struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() diff --git a/vrtnu/vrtnu/video.swift b/vrtnu/vrtnu/video.swift new file mode 100644 index 0000000..ff2a6c1 --- /dev/null +++ b/vrtnu/vrtnu/video.swift @@ -0,0 +1,43 @@ +// +// video.swift +// vrtnu +// +// Created by Jens Timmerman on 24/09/2020. +// + +/* +See LICENSE folder for this sample’s licensing information. + +Abstract: +Video is a simple struct that provides the title, url, and timing information about the app's videos. +*/ + +//import UIKit +import AVFoundation + +struct Video: Hashable { + + let hlsUrl: URL + let title: String + let duration: TimeInterval + var resumeTime: TimeInterval + + init(hlsUrl: URL, title: String, duration: TimeInterval, resumeTime: TimeInterval = 0) { + self.hlsUrl = hlsUrl + self.title = title + self.duration = duration + self.resumeTime = resumeTime + } +} + +extension Video { + + static func makeVideos() -> [Video] { + return [ + Video(hlsUrl: URL(string: "https://remix-cf.lwc.vrtcdn.be/remix/ecd69313-4a39-4297-95b1-aede167725b7/remix.ism/.m3u8")!, + title: "best of dinges", + duration: 2946), + + ] + } +} diff --git a/vrtnu/vrtnu/vrtnuApp.swift b/vrtnu/vrtnu/vrtnuApp.swift index dc29442..1012020 100644 --- a/vrtnu/vrtnu/vrtnuApp.swift +++ b/vrtnu/vrtnu/vrtnuApp.swift @@ -6,6 +6,7 @@ // import SwiftUI +import AVFoundation @main struct vrtnuApp: App { @@ -14,4 +15,16 @@ struct vrtnuApp: App { ContentView() } } + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { + let audioSession = AVAudioSession.sharedInstance() + do { + try audioSession.setCategory(.playback, mode: .moviePlayback) + } + catch { + print("Setting category to AVAudioSessionCategoryPlayback failed.") + } + return true + } }