2016-09-25 10 views
10

Mam problem z miejscem, w którym po emisji mojego ekranu na żywo próbuję nagrać ekran, ale to nie działa. To samo dzieje się, gdy nagrywam swój ekran, a potem próbuję transmitować na żywo ekran. Nie próbuję robić ich razem btw. To jest po jednym, a ja próbuję użyć drugiego. Daj mi znać, jeśli chcesz zobaczyć kod lub więcej informacji. Jestem w Swift 3 i korzystam z nowej struktury zestawu powtórek. Dzięki!Czy replaykit umożliwia nagrywanie ekranu, a następnie emisję ekranu?

EDIT: Jest to kod za pomocą IM

//LIVE STREAM REPLAYKIT===================================================================== 
func broadcastActivityViewController(_ broadcastAVC: RPBroadcastActivityViewController, didFinishWith broadcastController: RPBroadcastController?, error: Error?) { 
    print("=====hello delegate \(broadcastController?.broadcastURL) (error)") 

    self.broadcastController = broadcastController 
    self.broadcastController?.delegate = self 

    broadcastAVC.dismiss(animated: true) { 
     self.broadcastController?.startBroadcast(handler: { error in 

      print("start broadcast \(error)") 
      print("\(broadcastController?.broadcastExtensionBundleID)") 
      print("==url=\(broadcastController?.broadcastURL)") 
      print("==serviceInfo=\(broadcastController?.serviceInfo)") 

    //This is called when the broadcast is live 

    }) 
    } 
} 


func broadcastController(_ broadcastController: RPBroadcastController, didFinishWithError error: Error?) { 
    print("broadcastController====delegate") 

    let alert = UIAlertController(title: "Alert", message: "There was an error broadcasting your screen. Please try again", preferredStyle: UIAlertControllerStyle.alert) 

    // show the alert 
    self.view!.window?.rootViewController!.present(alert, animated: true, completion: nil) 

    alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.destructive, handler: { action in 

     // add action 
    })) 
} 



func broadcastController(_ broadcastController: RPBroadcastController, didUpdateServiceInfo serviceInfo: [String : NSCoding & NSObjectProtocol]) { 
    print("broadcastController====didUpdateServiceInfo") 
    } 

    //LIVE STREAM REPLAYKIT========================================================= 


//RECORD SCREEN REPLAYKIT------------------------------------------------------------------- 
func startRecoding() { 
    let recorder = RPScreenRecorder.shared() 
    if recorder.isAvailable { 
     recorder.startRecording(handler: { (error) in 


    if error == nil { // Recording has started 


    } else { 
       // Handle error 
       print("Dont Allow Recording") 

    } 
}) 

    } else { 
     print("Did not record screen") 

     //if iphone or ipad doesnt support replaykit 

     // create the alert 
     let alert = UIAlertController(title: "Alert", message: "Please make sure your device supports ReplayKit!", preferredStyle: UIAlertControllerStyle.alert) 


     // show the alert 
     self.view!.window?.rootViewController!.present(alert, animated: true, completion: nil) 

     alert.addAction(UIAlertAction(title: "Try Again!", style: UIAlertActionStyle.destructive, handler: { action in 
      // add action 

    })) 
    } 
} 


func stopRecording() { 

    let sharedRecorder = RPScreenRecorder.shared() 
    sharedRecorder.stopRecording(handler: { (previewViewController: RPPreviewViewController?, error) in 

if previewViewController != nil { 
      print("stopped recording") 

      previewViewController!.previewControllerDelegate = self 

      let alertController = UIAlertController(title: "Recording", message: "Tap view to watch, edit, share, or save your screen recording!", preferredStyle: .alert) 

      let viewAction = UIAlertAction(title: "View", style: .default, handler: { (action: UIAlertAction) -> Void in 

       self.view?.window?.rootViewController?.present(previewViewController!, animated: true, completion: nil) 

}) 

      alertController.addAction(viewAction) 
      self.previewViewController = previewViewController! 
      self.previewViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen 
      self.view?.window?.rootViewController!.present(alertController, animated: true, completion: nil) 
} 


else { 
      print("recording stopped working") 

      //create the alert================================ 

      let alert = UIAlertController(title: "Alert", message: "Sorry, there was an error recording your screen. Please Try Again!", preferredStyle: UIAlertControllerStyle.alert) 

      // show the alert 
      self.view!.window?.rootViewController!.present(alert, animated: true, completion: nil) 

      alert.addAction(UIAlertAction(title: "Try Again!", style: UIAlertActionStyle.destructive, handler: { action in 
       // add action 

      })) 
     } 
    }) 
} 


func previewControllerDidFinish(_ previewViewController: RPPreviewViewController) { 

print("cancel and save button pressed") 

previewViewController.dismiss(animated: true, completion: nil) 
//dismiss preview view controller when save or cancel button pressed 

} 
+0

Proszę wyjaśnić, wyświetlasz ekran, odtwarzacz się kończy, a następnie chcesz zapisać wideo, które zostało nadane na dysk? – Lance

+0

Problem jest po tym, jak skończyłem nadawać ekran, na którym naciskam stop, a następnie spróbuj nagrać ekran i to nie działa. Nie chcę zapisać wideo, które zostało nadane. Po prostu chcę móc nagrać ekran, a kiedy to się skończy, nadaj ekran. Nie wiem, czy widziałeś nową strukturę zestawu powtórek, ale możesz nagrać ekran, a także transmitować na żywo ekran. Po prostu nie wiem, czy można używać obu aplikacji. – coding22

+0

Oboje działają dobrze, ale jeśli robię to z powrotem do tyłu. Np. Jeśli najpierw nagrywam ekran, to działa, a potem chcę transmitować na żywo ekran, który nie zadziała. To samo dzieje się, gdy robię to w odwrotnej kolejności, w której transmituję ekran na żywo, po pierwsze działa, ale kiedy wtedy spróbuję nagrać ekran, to nie zadziała. Nie jestem pewien, dlaczego tak się dzieje. – coding22

Odpowiedz

1

wierzę, że jest to błąd w ReplayKit, nie jestem pewien, czy to zostało rozwiązane z dniem 10.1 lub nie, ale warto spróbować 10.1 beta, aby sprawdzić, czy rozwiązuje twój problem.