### Configure Swifty360View via Code with Storyboard Setup Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md Shows how to configure a Swifty360View that has been added to a view controller via Storyboard. This involves connecting the IBOutlets and then setting the player and motion manager, followed by starting playback. ```swift let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "google-help-vr", ofType: "mp4")!) let player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared swifty360View.setup(player: player, motionManager: motionManager) player.play() ``` -------------------------------- ### Initialize Swifty360View Programmatically Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md Demonstrates programmatic initialization of Swifty360View. It requires an AVPlayer instance and a Swifty360MotionManager instance. The view is configured and added to the view hierarchy, and video playback is started. ```swift let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "google-help-vr", ofType: "mp4")!) let player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared let swifty360View = Swifty360View(withFrame: view.bounds, player: player, motionManager: motionManager) swifty360View.setup(player: player, motionManager: motionManager) view.addSubview(swifty360View) player.play() ``` -------------------------------- ### Swifty360ViewController Subclass for Storyboard Usage Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md An example of a custom UIViewController subclass that inherits from Swifty360ViewController. This allows for custom setup within the `viewDidLoad` method, such as starting video playback. ```swift import UIKit import Swifty360Player class TestViewController: Swifty360ViewController { override func viewDidLoad() { super.viewDidLoad() player.play() } } ``` -------------------------------- ### Initialize Swifty360ViewController from Storyboard Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md Shows how to instantiate Swifty360ViewController from a Storyboard and set its player and motion manager properties. This approach is useful when using Interface Builder for UI setup. The view controller is then presented modally. ```swift guard let swifty360ViewController = self.storyboard?.instantiateViewController(withIdentifier: "TestViewController") as? TestViewController else { return } let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "google-help-vr", ofType: "mp4")!) let player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared swifty360ViewController.player = player swifty360ViewController.motionManager = motionManager self.present(swifty360ViewController, animated: true, completion: nil) ``` -------------------------------- ### Install Swifty360Player with Carthage Source: https://context7.com/abdullahselek/swifty360player/llms.txt Instructions for adding the Swifty360Player library to an iOS project using Carthage. This involves adding the dependency to the Cartfile and running `carthage update`. ```ruby # Cartfile github "abdullahselek/Swifty360Player" ~> 0.2.7 ``` ```bash carthage update ``` -------------------------------- ### Install Swifty360Player with CocoaPods Source: https://context7.com/abdullahselek/swifty360player/llms.txt Instructions for adding the Swifty360Player library to an iOS project using CocoaPods. This involves updating the Podfile and running `pod install`. ```ruby source 'https://github.com/CocoaPods/Specs.git' platform :ios, '11.0' use_frameworks! target 'YourApp' do pod 'Swifty360Player', '0.2.7' end ``` ```bash pod install ``` -------------------------------- ### Install Swifty360Player with Swift Package Manager Source: https://context7.com/abdullahselek/swifty360player/llms.txt Instructions for adding the Swifty360Player library to an iOS project using Swift Package Manager. This involves specifying the package URL and version in the Package.swift file. ```swift // Package.swift dependencies: [ .package(url: "https://github.com/abdullahselek/Swifty360Player.git", from: "0.2.7") ] ``` -------------------------------- ### Integrate Swifty360Player with CocoaPods Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md This snippet shows how to add Swifty360Player to your Xcode project using CocoaPods. Ensure you have CocoaPods installed and specify the library in your Podfile. ```ruby source 'https://github.com/CocoaPods/Specs.git' platform :ios, '11.0' use_frameworks! target '' do pod 'Swifty360Player', '0.2.7' end ``` -------------------------------- ### Implement Swifty360ViewDelegate for Compass and User Events (Swift) Source: https://context7.com/abdullahselek/swifty360player/llms.txt This example shows how to implement the Swifty360ViewDelegate protocol for receiving compass angle updates and initial user interaction events. It requires UIKit, AVKit, and Swifty360Player. The delegate methods log the current compass angle in degrees and the method of user interaction. ```swift import UIKit import AVKit import Swifty360Player class ViewDelegateExampleViewController: UIViewController, Swifty360ViewDelegate { var swifty360View: Swifty360View! override func viewDidLoad() { super.viewDidLoad() let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "360-video", ofType: "mp4")!) let player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared swifty360View = Swifty360View(withFrame: view.bounds, player: player, motionManager: motionManager) swifty360View.setup(player: player, motionManager: motionManager) swifty360View.delegate = self view.addSubview(swifty360View) player.play() } // MARK: - Swifty360ViewDelegate func didUpdateCompassAngle(withViewController: Swifty360View, compassAngle: Float) { // Handle compass angle updates let degrees = compassAngle * 180 / .pi print("Current compass angle: (degrees)°") } func userInitallyMovedCameraViaMethod(withView: Swifty360View, method: Swifty360UserInteractionMethod) { // Handle initial user interaction print("User started interacting via: (method)") } } ``` -------------------------------- ### Integrate Swifty360View with Storyboard in Swift Source: https://context7.com/abdullahselek/swifty360player/llms.txt Connect a UIView to the Swifty360View class in Interface Builder to integrate 360 video playback. This involves creating an IBOutlet, initializing an AVPlayer, obtaining the Swifty360MotionManager, and setting up the view. Playback is then started using the AVPlayer. ```swift import UIKit import AVKit import Swifty360Player class StoryboardVideo360ViewController: UIViewController { // Connect this outlet to a UIView with class set to Swifty360View in Interface Builder @IBOutlet weak var swifty360View: Swifty360View! var player: AVPlayer! override func viewDidLoad() { super.viewDidLoad() // Create AVPlayer let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "360-video", ofType: "mp4")!) player = AVPlayer(url: videoURL) // Get motion manager let motionManager = Swifty360MotionManager.shared // Setup the view (required when using storyboard) swifty360View.setup(player: player, motionManager: motionManager) // Start playback player.play() } @IBAction func resetCameraTapped(_ sender: Any) { swifty360View.reorientVerticalCameraAngleToHorizon(animated: true) } } ``` -------------------------------- ### Implement Swifty360ViewControllerDelegate for Compass and User Events (Swift) Source: https://context7.com/abdullahselek/swifty360player/llms.txt This example demonstrates how to implement the Swifty360ViewControllerDelegate protocol to receive compass angle updates and initial user interaction events. It requires UIKit, AVKit, and Swifty360Player. The delegate methods process compass angles in radians and identify the user interaction method (gyroscope or touch). ```swift import UIKit import AVKit import Swifty360Player class DelegateExampleViewController: UIViewController, Swifty360ViewControllerDelegate { var swifty360ViewController: Swifty360ViewController! var compassLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "360-video", ofType: "mp4")!) let player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared swifty360ViewController = Swifty360ViewController(withAVPlayer: player, motionManager: motionManager) swifty360ViewController.delegate = self addChild(swifty360ViewController) view.addSubview(swifty360ViewController.view) swifty360ViewController.didMove(toParent: self) // Add compass label overlay compassLabel = UILabel(frame: CGRect(x: 20, y: 50, width: 200, height: 30)) compassLabel.textColor = .white view.addSubview(compassLabel) player.play() } // MARK: - Swifty360ViewControllerDelegate func didUpdateCompassAngle(withViewController: Swifty360ViewController, compassAngle: Float) { // Called frequently during camera movement // compassAngle is in radians let degrees = compassAngle * 180 / .pi compassLabel.text = String(format: "Compass: %.1f°", degrees) } func userInitallyMovedCameraViaMethod(withViewController: Swifty360ViewController, method: Swifty360UserInteractionMethod) { // Called once when user first interacts with the camera switch method { case .gyroscope: print("User moved camera using device motion") case .touch: print("User moved camera using touch gesture") } } } ``` -------------------------------- ### Subclass Swifty360ViewController for Storyboard Use in Swift Source: https://context7.com/abdullahselek/swifty360player/llms.txt Create a custom subclass of Swifty360ViewController to integrate with storyboards. This allows for custom setup and presentation logic. The video player and motion manager are configured before presenting the view controller. ```swift import UIKit import AVKit import Swifty360Player // Custom subclass for storyboard integration class Custom360ViewController: Swifty360ViewController { override func viewDidLoad() { super.viewDidLoad() // Start video playback player.play() // Custom setup code here setupUI() } private func setupUI() { // Add custom overlays, controls, etc. } } // Presenting the storyboard-based 360 view controller class MainViewController: UIViewController { func present360Video() { // Instantiate from storyboard guard let vc = storyboard?.instantiateViewController(withIdentifier: "Custom360ViewController") as? Custom360ViewController else { return } // Configure before presentation let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "360-video", ofType: "mp4")!) let player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared vc.player = player vc.motionManager = motionManager // Present modally present(vc, animated: true, completion: nil) } } ``` -------------------------------- ### Embed 360 Video with Swifty360View (Swift) Source: https://context7.com/abdullahselek/swifty360player/llms.txt Demonstrates how to embed a 360-degree video within an existing view hierarchy using `Swifty360View`. It initializes an AVPlayer, creates and configures the `Swifty360View`, adds it to the view, starts playback, and sets up a tap gesture for camera reset. It also includes logic to stop motion updates when the view disappears. ```swift import UIKit import AVKit import Swifty360Player class EmbeddedVideo360ViewController: UIViewController { var swifty360View: Swifty360View! var player: AVPlayer! override func viewDidLoad() { super.viewDidLoad() // Create AVPlayer let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "360-video", ofType: "mp4")!) player = AVPlayer(url: videoURL) // Get motion manager let motionManager = Swifty360MotionManager.shared // Initialize Swifty360View with frame swifty360View = Swifty360View(withFrame: CGRect(x: 0, y: 100, width: view.bounds.width, height: 300), player: player, motionManager: motionManager) // Setup is required after initialization swifty360View.setup(player: player, motionManager: motionManager) // Add to view hierarchy view.addSubview(swifty360View) // Start playback player.play() // Add tap gesture for camera reset let tapGesture = UITapGestureRecognizer(target: self, action: #selector(resetCamera)) swifty360View.addGestureRecognizer(tapGesture) } @objc func resetCamera() { swifty360View.reorientVerticalCameraAngleToHorizon(animated: true) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) // Stop motion updates when view disappears swifty360View.stopMotionUpdates() } } ``` -------------------------------- ### Initialize Swifty360ViewController Programmatically Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md Demonstrates how to initialize and present Swifty360ViewController programmatically. It requires an AVPlayer instance with a video URL and a Swifty360MotionManager instance. The view is added as a child view controller and then to the main view. A tap gesture recognizer is added for camera reorientation. ```swift let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "google-help-vr", ofType: "mp4")!) let player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared swifty360ViewController = Swifty360ViewController(withAVPlayer: player, motionManager: motionManager) addChildViewController(swifty360ViewController) view.addSubview(swifty360ViewController.view) swifty360ViewController.didMove(toParentViewController: self) player.play() let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(reorientVerticalCameraAngle)) view.addGestureRecognizer(tapGestureRecognizer) ``` -------------------------------- ### Integrate Swifty360Player with Carthage Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md This snippet demonstrates how to integrate Swifty360Player using Carthage. After specifying the dependency in your Cartfile, run 'carthage update' and drag the framework into your project. ```plaintext github "abdullahselek/Swifty360Player" ~> 0.2.7 ``` -------------------------------- ### Integrate Swifty360Player with Swift Package Manager Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md This snippet shows how to add Swifty360Player as a dependency in your Package.swift file for use with Swift Package Manager. After adding the dependency, run 'swift package resolve'. ```swift .package(url: "https://github.com/abdullahselek/Swifty360Player.git", from: "0.2.7") ``` -------------------------------- ### Control Video Playback with Play and Pause in Swift Source: https://context7.com/abdullahselek/swifty360player/llms.txt Demonstrates how to control video playback using the `play()` and `pause()` methods provided by `Swifty360ViewController`. This snippet initializes the player, sets up the 360 view controller, and includes a button to toggle between playing and pausing the video. ```swift import UIKit import AVKit import Swifty360Player class PlaybackControlViewController: UIViewController { var swifty360ViewController: Swifty360ViewController! var player: AVPlayer! var isPlaying = true override func viewDidLoad() { super.viewDidLoad( let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "360-video", ofType: "mp4")!) player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared swifty360ViewController = Swifty360ViewController(withAVPlayer: player, motionManager: motionManager) addChild(swifty360ViewController) view.addSubview(swifty360ViewController.view) swifty360ViewController.didMove(toParent: self) // Start playing player.play() // Add play/pause button let playPauseButton = UIButton(frame: CGRect(x: 20, y: view.bounds.height - 80, width: 100, height: 44)) playPauseButton.setTitle("Pause", for: .normal) playPauseButton.backgroundColor = .systemBlue playPauseButton.addTarget(self, action: #selector(togglePlayback), for: .touchUpInside) view.addSubview(playPauseButton) } @objc func togglePlayback(_ sender: UIButton) { if isPlaying { // Pause using the view controller method swifty360ViewController.pause() sender.setTitle("Play", for: .normal) } else { // Play using the view controller method swifty360ViewController.play() sender.setTitle("Pause", for: .normal) } isPlaying.toggle() } } ``` -------------------------------- ### Play 360 Video Full-Screen with Swifty360ViewController (Swift) Source: https://context7.com/abdullahselek/swifty360player/llms.txt Demonstrates how to use `Swifty360ViewController` to play a 360-degree video in a full-screen view controller. It initializes an AVPlayer, sets up the `Swifty360ViewController` with motion management, adds it as a child view controller, and configures a tap gesture for camera reset. ```swift import UIKit import AVKit import Swifty360Player class Video360ViewController: UIViewController { var swifty360ViewController: Swifty360ViewController! override func viewDidLoad() { super.viewDidLoad() // Create AVPlayer with local or remote video URL let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "360-video", ofType: "mp4")!) // For remote: let videoURL = URL(string: "https://example.com/360-video.mp4")! let player = AVPlayer(url: videoURL) // Get shared motion manager (handles gyroscope) let motionManager = Swifty360MotionManager.shared // Initialize the 360 view controller // Pass nil for motionManager to disable gyroscope control swifty360ViewController = Swifty360ViewController(withAVPlayer: player, motionManager: motionManager) // Add as child view controller addChild(swifty360ViewController) view.addSubview(swifty360ViewController.view) swifty360ViewController.didMove(toParent: self) // Start playback player.play() // Add tap gesture to reset camera orientation let tapGesture = UITapGestureRecognizer(target: self, action: #selector(resetCamera)) swifty360ViewController.view.addGestureRecognizer(tapGesture) } @objc func resetCamera() { // Smoothly animate camera back to horizontal position swifty360ViewController.reorientVerticalCameraAngleToHorizon(animated: true) } } ``` -------------------------------- ### Manage Device Motion with Swifty360MotionManager in Swift Source: https://context7.com/abdullahselek/swifty360player/llms.txt Utilize the Swifty360MotionManager singleton to manage device motion updates efficiently. It handles multiple observers and adjusts update intervals automatically. You can check for availability, active status, access motion data, and manually control updates. ```swift import Swifty360Player import CoreMotion // Use the shared instance throughout your app let motionManager = Swifty360MotionManager.shared // Check if device motion is available if motionManager.deviceMotionAvailable { print("Device motion is available") } // Check if motion updates are currently active if motionManager.deviceMotionActive { print("Motion updates are running") } // Access current device motion data if let deviceMotion = motionManager.deviceMotion { print("Rotation rate: (deviceMotion.rotationRate)") print("Attitude: (deviceMotion.attitude)") } // Manual motion update control (typically handled internally) // Start updates with preferred interval (returns a token for stopping) let token = motionManager.startUpdating(preferredUpdateInterval: 1.0 / 60.0) // Stop updates using the token motionManager.stopUpdating(token: token) ``` -------------------------------- ### Tap Gesture Handler for Swifty360ViewController Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md Provides the Objective-C selector function to handle tap gestures for reorienting the Swifty360ViewController's camera angle to the horizon. This function is typically called by a UITapGestureRecognizer. ```swift @objc func reorientVerticalCameraAngle() { swifty360ViewController.reorientVerticalCameraAngleToHorizon(animated: true) } ``` -------------------------------- ### Tap Gesture Handler for Swifty360View Source: https://github.com/abdullahselek/swifty360player/blob/master/README.md Provides the Objective-C selector function to handle tap gestures for reorienting the Swifty360View's camera angle to the horizon. This function is typically called by a UITapGestureRecognizer attached to the view controller's main view. ```swift @objc func reorientVerticalCameraAngle() { swifty360View.reorientVerticalCameraAngleToHorizon(animated: true) } ``` -------------------------------- ### Access Compass Angle and Pan Gesture Recognizer in Swift Source: https://context7.com/abdullahselek/swifty360player/llms.txt Shows how to retrieve the current compass angle in radians from both `Swifty360ViewController` and `Swifty360View` instances. It also demonstrates how to access and modify the pan gesture recognizer for custom touch interactions. ```swift import Swifty360Player // From Swifty360ViewController let compassAngle = swifty360ViewController.compassAngle // Returns Float in radians // From Swifty360View let viewCompassAngle = swifty360View.compassAngle // Returns Float in radians // Convert to degrees let degrees = compassAngle * 180 / .pi // Access the pan gesture recognizer for customization let panRecognizer = swifty360ViewController.panRecognizer panRecognizer?.isEnabled = true // Enable/disable pan gestures ``` -------------------------------- ### Configure Swifty360 Panning Axes in Swift Source: https://context7.com/abdullahselek/swifty360player/llms.txt Control the panning axes for camera movement using device motion and touch gestures with Swifty360Player. You can restrict panning to horizontal, vertical, or allow both axes for device motion and touch input independently. ```swift import Swifty360Player class ConfigurablePanningViewController: UIViewController { var swifty360ViewController: Swifty360ViewController! override func viewDidLoad() { super.viewDidLoad() let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "360-video", ofType: "mp4")!) let player = AVPlayer(url: videoURL) let motionManager = Swifty360MotionManager.shared swifty360ViewController = Swifty360ViewController(withAVPlayer: player, motionManager: motionManager) // Configure panning axes // Allow only horizontal panning via device motion (disable vertical tilt) swifty360ViewController.allowedDeviceMotionPanningAxes = .horizontal // Allow only vertical panning via touch gestures swifty360ViewController.allowedPanGesturePanningAxes = .vertical // Allow both axes (default) swifty360ViewController.allowedDeviceMotionPanningAxes = [.horizontal, .vertical] swifty360ViewController.allowedPanGesturePanningAxes = [.horizontal, .vertical] addChild(swifty360ViewController) view.addSubview(swifty360ViewController.view) swifty360ViewController.didMove(toParent: self) player.play() } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.