From all the examples I have seen related to the library the only way to set a source ID or URL is by hard coding it into the swift program. It would be nice to be able to have the ability to enter a URL via a text field or something and then use that when creating a YouTubePlayerView. Here is a basic example of how I would like to create a YouTubePlayerView by passing it a variable instead of hard coding the URL into the app:
From all the examples I have seen related to the library the only way to set a source ID or URL is by hard coding it into the swift program. It would be nice to be able to have the ability to enter a URL via a text field or something and then use that when creating a YouTubePlayerView. Here is a basic example of how I would like to create a YouTubePlayerView by passing it a variable instead of hard coding the URL into the app:
// // ContentView.swift // YouTubePlayer-Example
import SwiftUI import YouTubePlayerKit
// Would ultimately like to get the string from a TextField input. var MyURL: String = "https://youtube.com/watch?v=psL_5RIBqnY"
struct ContentView: View { var body: some View { VStack { //YouTubePlayerView("https://youtube.com/watch?v=psL_5RIBqnY") YouTubePlayerView(MyURL) } .padding() } }
struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }