1

I just need to use screen mirroring on enabled device when I click the button on my app screen. There is an airplay button in my app, clicking on which will check for available mirroring devices such as tv or laptop but I don't think it is for screen mirroring. I want to call screen mirroring in my app (I want to use mirroring not casting) on that screen.

1

I don't know Objective-c well, so please use swift if you use example code. Thanks.

udi
  • 3,672
  • 2
  • 12
  • 33
jane kim
  • 11
  • 1
  • 4

1 Answers1

0

Please check below, this might help you to understand how currently apps are achieving this.

Screen Mirroring iPhone to smart TV

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    let routePickerView = AVRoutePickerView(frame: CGRect(x: 0.0, y: 30.0, width: 30.0, height: 30.0))
    routePickerView.backgroundColor = UIColor.lightGray
    self.view.addSubview(routePickerView)

    let avAsset = AVAsset(url: URL(string: "https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4")!)
    let avPlayerItem = AVPlayerItem(asset: avAsset)
    let avPlayer = AVPlayer(playerItem: avPlayerItem)
    let avPlayerLayer = AVPlayerLayer(player: avPlayer)
    avPlayerLayer.frame = CGRect(x: 0.0, y: 40.0, width: self.view.frame.size.width, height: self.view.frame.size.height - 40.0)
    self.view.layer.addSublayer(avPlayerLayer)
    avPlayer.seek(to: CMTime.zero)
    avPlayer.play()
}

This code shows a player and adds the ability to mirror ONLY the player into the Mac screen.

You can check below as well.

how-to-do-screen-mirroring-using-airplay-from-the-application-not-from-control

  • 1
    I meant screen mirroring not streaming. I think that is streaming. https://support.apple.com/en-us/HT204289 This site explains the difference between mirroring and streaming. Thanks :) – jane kim Feb 17 '22 at 00:08