DA2008

Member

Last active last year

  1. last year
    Thu 22 Jun 2017 06:21:33 PM CEST
    DA2008 started the conversation Multi Buttons to url Videos.

    Hello,
    I hope you can help me.

    Im a beginner on Xcode using Swift language. I'm trying to build a simple app.
    Im struggle to create a button that link to URL videos. The only ONE button is working to play the videos but i can't create more than 1 buttons to play videos.

    See the script below:
    As you see there are three buttons but they all playing same video... Can you code it that each button can play different URL videos please.

    //
    // ViewController.swift
    //
    // Created by Thomas Maher on 22/06/2017.
    // Copyright © 2017 Thomas Maher. All rights reserved.
    //
    import UIKit
    import AVFoundation
    import AVKit

    class ViewController: UIViewController {

    let avPlayerViewController = AVPlayerViewController()
    var avPlayer:AVPlayer?

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let movieUrl:NSURL? = NSURL(string: "http://www.discoverycamp.co.uk/BT_Video/Alphabet.mp4")

    if let url = movieUrl {

    self.avPlayer = AVPlayer(url: url as URL)
    self.avPlayerViewController.player = self.avPlayer

    }


    }

    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.


    }

    @IBAction func Alphabet(_ sender: UIButton) {
    self.present(self.avPlayerViewController, animated: true) { () -> Void in
    self.avPlayerViewController.player?.play() }

    }

    @IBAction func Colours(_ sender: UIButton) {
    self.present(self.avPlayerViewController, animated: true) { () -> Void in
    self.avPlayerViewController.player?.play() }

    }
    @IBAction func Family(_ sender: UIButton) {
    self.present(self.avPlayerViewController, animated: true) { () -> Void in
    self.avPlayerViewController.player?.play() }

    }

    }

    As you see there are three buttons but they all playing same video... Can you code it that each button can play different URL videos please.

    Hope this make sense,
    Looking forward from you.
    Thanks
    Thomas.

  2. Thu 22 Jun 2017 06:20:00 PM CEST
    DA2008 joined the forum.