Post

Replies

Boosts

Views

Activity

Building a json app that plays videos (troubleshooting and better ways)
I've been watching various tutorials and have managed to come up with the following code: import SwiftUI import AVKit struct ContentView: View {     @State private var wolData = [Main]()          var body: some View {                  NavigationView{List(wolData, id: \.id) { item in             NavigationLink(destination: MainDetail(json: item)) {                                  HStack() {                     Text(item.name)                         .font(.headline)                     Text(item.date)                         .font(.footnote)                     if #available(iOS 15.0, *) {                         AsyncImage(url: URL(string: item.thumbnail))                         { image in                             image                                 .resizable()                                 .scaledToFill()                         } placeholder: {                             Color.purple.opacity(0.1)                         }                         .frame(width: 20, height: 20)                     } else {                         // Fallback on earlier versions                     }                 }                              }                      }.onAppear(perform: loadData)}              }           } extension ContentView {     func loadData() {                  guard let url = URL(string: "https://wolvideos.firebaseapp.com/Simple.json") else {             return         }                  let request = URLRequest(url: url)         URLSession.shared.dataTask(with: request) { data, response, error in                          if let data = data {                 if let response_obj = try? JSONDecoder().decode([Main].self, from: data) {                                          DispatchQueue.main.async {                         self.wolData = response_obj                     }                 }             }                      }.resume()     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } import Foundation struct Main: Decodable {     var id: Int     var name: String     var interactive: String     var thumbnail: String     var date: String     var videolink: String     var sharelink: String } import SwiftUI import AVKit struct MainDetail: View {     var json: Main    private let player = AVPlayer(url: URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!)        var body: some View {      VideoPlayer(player: player)             .onAppear() {                 // Start the player going, otherwise controls don't appear                 player.play()             }             .onDisappear() {                 // Stop the player when the view disappears                 player.pause()             }    } } Now that I've shared that, the intent is to when the user clicks an option load the corresponding video (from the json not the current test file) via HLS in a default player (like the one in safari)... should I be going about this in a different way? I'm starting to think committing to SwiftUI is a mistake.
0
0
918
Jun ’22
passing json video link to avplayer
I'm attempting to simply pass the video link inside the json to the navigation menu... my brain is fried as I'm lost in why I can't do this view the navigation link protocol. import SwiftUI import AVKit struct MainDetail: View {          var json: Main         private let player = AVPlayer(url: URL(string: item.interactive))        var body: some View {      VideoPlayer(player: player)             .onAppear() {                 // Start the player going, otherwise controls don't appear                 player.play()             }             .onDisappear() {                 // Stop the player when the view disappears                 player.pause()             }    } } this returns a "Cannot find 'item' in scope" despite being declared back on the main content view. the intended action is loading the "interactive" link (m3u8 file) in a player view when clicked on. I apologize for not understanding what's going on here.
0
0
715
Jun ’22
Is it possible to convert this to using just play view for links in 16?
here is the code: struct LiveView: View {      @State var allowsInlineMediaPlayback: Bool = false      var body: some View {            VStack {                  VideoView(videoID:"vimeo.com/event/000000/embed")                  }                }            } struct VideoView: UIViewRepresentable {      let videoID: String      func makeUIView(context: Context) -> WKWebView {       let configuration = WKWebViewConfiguration()       configuration.allowsInlineMediaPlayback = true       let WKWebView = WKWebView(frame: .zero, configuration: configuration)       return WKWebView        }      func updateUIView(_ uiView: WKWebView, context: Context) {     guard let youtubeURL = URL(string: "https://\(videoID)") else     {return}     uiView.load(URLRequest (url: youtubeURL))   } } Is their a better way to accomplish feeding a live event link into a playerview instead of needing a WKWebView?
0
0
898
Jul ’22
NLtagger not filtering words such as "And, to, a, in"
what am I not understanding here. in short the view loads text from the jsons descriptions and then should filter out the words. and return and display a list of most used words, debugging shows words being identified by the code but does not filter them out private func loadWordCounts() { DispatchQueue.global(qos: .background).async { let fileManager = FileManager.default guard let documentsDirectory = try? fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) else { return } let descriptions = loadDescriptions(fileManager: fileManager, documentsDirectory: documentsDirectory) var counts = countWords(in: descriptions) let tagsToRemove: Set<NLTag> = [ .verb, .pronoun, .determiner, .particle, .preposition, .conjunction, .interjection, .classifier ] for (word, _) in counts { let tagger = NLTagger(tagSchemes: [.lexicalClass]) tagger.string = word let (tag, _) = tagger.tag(at: word.startIndex, unit: .word, scheme: .lexicalClass) if let unwrappedTag = tag, tagsToRemove.contains(unwrappedTag) { counts[word] = 0 } } DispatchQueue.main.async { self.wordCounts = counts } } }
0
0
580
Oct ’24
Where is documentation, demos or implementation of this?
This video session is essentially a consumer facing video, there isn't even a single line of code shown. VideoPlayer(player: player) doesn't give the shown "new features" by default, an example / implementation should be expected of a WWDC session.
Replies
0
Boosts
0
Views
807
Activity
Jun ’22
Building a json app that plays videos (troubleshooting and better ways)
I've been watching various tutorials and have managed to come up with the following code: import SwiftUI import AVKit struct ContentView: View {     @State private var wolData = [Main]()          var body: some View {                  NavigationView{List(wolData, id: \.id) { item in             NavigationLink(destination: MainDetail(json: item)) {                                  HStack() {                     Text(item.name)                         .font(.headline)                     Text(item.date)                         .font(.footnote)                     if #available(iOS 15.0, *) {                         AsyncImage(url: URL(string: item.thumbnail))                         { image in                             image                                 .resizable()                                 .scaledToFill()                         } placeholder: {                             Color.purple.opacity(0.1)                         }                         .frame(width: 20, height: 20)                     } else {                         // Fallback on earlier versions                     }                 }                              }                      }.onAppear(perform: loadData)}              }           } extension ContentView {     func loadData() {                  guard let url = URL(string: "https://wolvideos.firebaseapp.com/Simple.json") else {             return         }                  let request = URLRequest(url: url)         URLSession.shared.dataTask(with: request) { data, response, error in                          if let data = data {                 if let response_obj = try? JSONDecoder().decode([Main].self, from: data) {                                          DispatchQueue.main.async {                         self.wolData = response_obj                     }                 }             }                      }.resume()     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } import Foundation struct Main: Decodable {     var id: Int     var name: String     var interactive: String     var thumbnail: String     var date: String     var videolink: String     var sharelink: String } import SwiftUI import AVKit struct MainDetail: View {     var json: Main    private let player = AVPlayer(url: URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!)        var body: some View {      VideoPlayer(player: player)             .onAppear() {                 // Start the player going, otherwise controls don't appear                 player.play()             }             .onDisappear() {                 // Stop the player when the view disappears                 player.pause()             }    } } Now that I've shared that, the intent is to when the user clicks an option load the corresponding video (from the json not the current test file) via HLS in a default player (like the one in safari)... should I be going about this in a different way? I'm starting to think committing to SwiftUI is a mistake.
Replies
0
Boosts
0
Views
918
Activity
Jun ’22
passing json video link to avplayer
I'm attempting to simply pass the video link inside the json to the navigation menu... my brain is fried as I'm lost in why I can't do this view the navigation link protocol. import SwiftUI import AVKit struct MainDetail: View {          var json: Main         private let player = AVPlayer(url: URL(string: item.interactive))        var body: some View {      VideoPlayer(player: player)             .onAppear() {                 // Start the player going, otherwise controls don't appear                 player.play()             }             .onDisappear() {                 // Stop the player when the view disappears                 player.pause()             }    } } this returns a "Cannot find 'item' in scope" despite being declared back on the main content view. the intended action is loading the "interactive" link (m3u8 file) in a player view when clicked on. I apologize for not understanding what's going on here.
Replies
0
Boosts
0
Views
715
Activity
Jun ’22
is there any way allow video player to rotate in a portrait locked app (SwiftUI)?
I can only find UIKit examples that don't work when used... I would prefer to never use appdelgate again.
Replies
0
Boosts
0
Views
1.1k
Activity
Jul ’22
Is it possible to convert this to using just play view for links in 16?
here is the code: struct LiveView: View {      @State var allowsInlineMediaPlayback: Bool = false      var body: some View {            VStack {                  VideoView(videoID:"vimeo.com/event/000000/embed")                  }                }            } struct VideoView: UIViewRepresentable {      let videoID: String      func makeUIView(context: Context) -> WKWebView {       let configuration = WKWebViewConfiguration()       configuration.allowsInlineMediaPlayback = true       let WKWebView = WKWebView(frame: .zero, configuration: configuration)       return WKWebView        }      func updateUIView(_ uiView: WKWebView, context: Context) {     guard let youtubeURL = URL(string: "https://\(videoID)") else     {return}     uiView.load(URLRequest (url: youtubeURL))   } } Is their a better way to accomplish feeding a live event link into a playerview instead of needing a WKWebView?
Replies
0
Boosts
0
Views
898
Activity
Jul ’22
NLtagger not filtering words such as "And, to, a, in"
what am I not understanding here. in short the view loads text from the jsons descriptions and then should filter out the words. and return and display a list of most used words, debugging shows words being identified by the code but does not filter them out private func loadWordCounts() { DispatchQueue.global(qos: .background).async { let fileManager = FileManager.default guard let documentsDirectory = try? fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) else { return } let descriptions = loadDescriptions(fileManager: fileManager, documentsDirectory: documentsDirectory) var counts = countWords(in: descriptions) let tagsToRemove: Set<NLTag> = [ .verb, .pronoun, .determiner, .particle, .preposition, .conjunction, .interjection, .classifier ] for (word, _) in counts { let tagger = NLTagger(tagSchemes: [.lexicalClass]) tagger.string = word let (tag, _) = tagger.tag(at: word.startIndex, unit: .word, scheme: .lexicalClass) if let unwrappedTag = tag, tagsToRemove.contains(unwrappedTag) { counts[word] = 0 } } DispatchQueue.main.async { self.wordCounts = counts } } }
Replies
0
Boosts
0
Views
580
Activity
Oct ’24