قالب وردپرس درنا توس
Home / IOS Development / ios – can't get the video in your browser using GCDWebServer in quick

ios – can't get the video in your browser using GCDWebServer in quick



I created a small demo app where the app accesses the image and videos from the iPhone using the UIImagePickerController.
When choosing an image or video, the app creates a copy of it (image or video) in the document folder.
And create a web server on the iPhone using the GCDWeb server and have to display the selected image or video.
But it doesn't work.

Here's the test code, not sure where I could go wrong.

  class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak was btnselect: UIButton!
leave videoPicker = UIImagePickerController ()

@IBAction func btnSelect (_ sender: Any) {

if UIImagePickerController.isSourceTypeAvailable (.photoLibrary) {
leave myPickerController = UIImagePickerController ()
myPickerController.delegate = self;
myPickerController.sourceType = .photoLibrary
myPickerController.allowsEditing = false
self.present (myPickerController, animated: true, completion: null)
}

}

func imagePickerControllerDidCancel (_ picker: UIImagePickerController) {
self.dismiss (animated: true, completion: null)
}

func imagePickerController (_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

// 1
. save video to document directory let videoURL = info [UIImagePickerController.InfoKey.mediaURL] like! NSURL leave videoData = NSData (content of: videoURL as URL) let the path = try! FileManager.default.url (for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask, appropriateFor: null, create: false) la newPath = path.appendingPathComponent ("/ myTestVideo.mp4") do { try videoData? .write (to: newPath) } catch { print (wrong) } // 2. Create web server on iPhone using GCDWebServer la webServer = GCDWebServer () webServer.addDefaultHandler (forMethod: "GET" request: GCDWebServerRequest.self, processBlock: {request in return GCDWebServerDataResponse (newPath) }) webServer.start (withPort: 8080, bonjourName: "GCD Web Server") } }

I need this selected (image or video) to be hosted / available by this GCD Web Server.


Source link