0

The title summarized my problem. I'm new to coding and I don't understand how to solve the problem.

I've tried pretty much all I know.

import UIKit import AVKit import AVFoundation class ViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) } @IBOutlet weak var PowerLVLlabel: UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @IBAction func randomNumber(_ sender: Any) { let randomNumber = Int.random(in: 1000...10000) PowerLVLlabel.text = String(randomNumber) if case { randomNumber; >=9000 == (true); func playVideo() { guard let path = Bundle.main.path(forResource: "over 9000", ofType:"mp4") else { debugPrint("over 9000.mp4 not found") return } {let player = AVPlayer(url: URL(fileURLWithPath: path)) let playerController = AVPlayerViewController() playerController.player = player present(playerController, animated: true) } {player.play() } 
1
  • start var names PowerLVLlabel with small letter powerLVLlabel Commented Jun 27, 2019 at 10:35

2 Answers 2

1

try this:

func playVideo(){ guard let path = Bundle.main.path(forResource: "over 9000", ofType:"mp4") else { debugPrint("over 9000.mp4 not found") return } let player = AVPlayer(url: URL(fileURLWithPath: path)) let playerController = AVPlayerViewController() playerController.player = player present(playerController, animated: true) player.play() } @IBAction func randomNumber(_ sender: Any) { let randomNumber = Int.random(in: 1000...10000) PowerLVLlabel.text = String(randomNumber) if randomNumber >= 9000{ playVideo() } } 
Sign up to request clarification or add additional context in comments.

1 Comment

@Sh_Khan thanks for the information. Will keep that in mind. though I just only cleared the code.
0

You need to get playVideo function out of randomNumber and remove some un needed ; and {}

import UIKit import AVKit import AVFoundation class ViewController: UIViewController { @IBOutlet weak var powerLVLlabel: UILabel! override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } func playVideo() { guard let path = Bundle.main.path(forResource: "over 9000", ofType:"mp4") else { debugPrint("over 9000.mp4 not found") return } let player = AVPlayer(url: URL(fileURLWithPath: path)) let playerController = AVPlayerViewController() playerController.player = player present(playerController, animated: true) player.play() } @IBAction func randomNumber(_ sender: Any) { let randomNumber = Int.random(in: 1000...10000) powerLVLlabel.text = String(randomNumber) if randomNumber >= 9000 { playVideo() } } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.