Giter Site home page Giter Site logo

abdullahselek / swifty360player Goto Github PK

View Code? Open in Web Editor NEW
174.0 12.0 46.0 21.6 MB

iOS 360-degree video player streaming from an AVPlayer.

License: MIT License

Objective-C 2.07% Swift 94.00% Ruby 1.44% Shell 2.49%
360-video uiview uiviewcontroller scenekit avplayer cocoapods carthage media video streaming

swifty360player's Introduction

Build Status CocoaPods Compatible Carthage Compatible License

Swifty360Player Swifty360Player

iOS 360-degree video player streaming from an AVPlayer.

Demo

Swifty360Player Demo

Requirements

Swifty360Player Version Minimum iOS Target Swift Version
0.2.7 11.0 5.x
0.2.2 11.0 4.2
0.2.1 10.0 4.1
0.2 10.0 4.0

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Swifty360Player into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Swifty360Player', '0.2.7'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

brew update
brew install carthage

To integrate Swifty360Player into your Xcode project using Carthage, specify it in your Cartfile:

github "abdullahselek/Swifty360Player" ~> 0.2.7

Run carthage update to build the framework and drag the built Swifty360Player.framework into your Xcode project.

Swift Package Manager

Modify your Package.swift file to include the following dependency:

.package(url: "https://github.com/abdullahselek/Swifty360Player.git", from: "0.2.7")

Run swift package resolve

XCFramework

XCFrameworks require Xcode 11 or later and integration is very similar to integration of .framework format. Please use script scripts/build-framework.sh to generate binary Swifty360Player.xcframework archive that you can use as a dependency in Xcode.

Swifty360Player.xcframework is a Release (Optimized) binary that offer best available Swift code performance.

Example Usage

You just need an AVPlayer instance created with a valid video url and a Swifty360MotionManager instance. You can use these code snippets in a UIViewController instance.

Video url can be either local or remote.

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)

Tap Gesture Handler

@objc func reorientVerticalCameraAngle() {
    swifty360ViewController.reorientVerticalCameraAngleToHorizon(animated: true)
}

Using storyboard and Swifty360ViewController as parent class

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)
import UIKit
import Swifty360Player

class TestViewController: Swifty360ViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        player.play()
    }

}

Example use of Swifty360View with using code commands

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()

Using Swifty360View with Storyboard

  • Add a UIView to your viewcontroller and change it's class as Swifty360View
  • Connect via IBOutlets

and

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()

Tap gesture recognizers for Swifty360View, create one recognizer for your viewcontroller's view

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(reorientVerticalCameraAngle))
view.addGestureRecognizer(tapGestureRecognizer)

and selector function

@objc func reorientVerticalCameraAngle() {
    swifty360View.reorientVerticalCameraAngleToHorizon(animated: true)
}

License

Swifty360Player is released under the MIT license. See LICENSE for details.

swifty360player's People

Contributors

abdullahselek avatar and01 avatar danialepaco avatar dependabot[bot] avatar mikado2005 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swifty360player's Issues

Stereoscopic view

Hi,
is there any way to use stereoscopic view when playing the video?

I used something of a hack and added two views
with the same motionManager in a horizontal stack.
Is there a better way ?

    player = AVPlayer(url: fileURL)
    
    let motionManager = Swifty360MotionManager.shared
    swifty360ViewController = Swifty360ViewController(withAVPlayer: player, motionManager: motionManager)
    
    addChildViewController(swifty360ViewController)
    //view.addSubview(swifty360ViewController.view)
    swifty360ViewController.didMove(toParentViewController: self)
    
    
    swifty360ViewController1 = Swifty360ViewController(withAVPlayer: player, motionManager: motionManager)
    addChildViewController(swifty360ViewController1)
    //view.addSubview(swifty360ViewController1.view)
    swifty360ViewController1.didMove(toParentViewController: self)
    
    
    // Create a stack
    let stackView = UIStackView(arrangedSubviews: [swifty360ViewController1.view,swifty360ViewController.view])
    stackView.axis = .horizontal
    stackView.distribution = .fillEqually
    stackView.alignment = .fill
    stackView.spacing = 0
    stackView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(stackView)
    let stackView_H = NSLayoutConstraint.constraints(
        withVisualFormat: "H:|-0-[stackView]-0-|",  //horizontal constraint 0 points from left and right side
        options: NSLayoutFormatOptions(rawValue: 0),
        metrics: nil,
        views: ["stackView":stackView])
    let stackView_V = NSLayoutConstraint.constraints(
        withVisualFormat: "V:|-0-[stackView]-0-|", //vertical constraint 0 points from top and bottom
        options: NSLayoutFormatOptions(rawValue:0),
        metrics: nil,
        views: ["stackView":stackView])
    view.addConstraints(stackView_H)
    view.addConstraints(stackView_V)

Thanks

How to Mute Audio

Can we loop the video and as well as how to mute video please advice

Pan inertia

The player works perfect and would be nice if can have some inertia when panning finishes

Cannot find type 'UIPanGestureRecognizer' in scope

Hi,
when using XCode 13 and SPM as dependency manager there is error in Swifty360CameraPanGestureRecognizer, saying Cannot find type 'UIPanGestureRecognizer' in scope.
There is no import UIKit in file

FairPlay Streaming

First of all, congratulations for the amazing work!

Is it possible to play FairPlay content on your player?

My greetings.

Load video orienting the camera to the real world horizon

What should I do to have the loaded video oriented to the real world horizon?

Everything works fine and I see that by calling reorientVerticalCameraAngleToHorizon(animated:) the video is getting re-oriented to where the device is currently looking at.
But what if I want the video initial state orientation to match the real-world orientation, so as the first thing I see when I have the phone pointing to the ceiling is the sky?

Thanks in advance!

How to disable motion

I have an app running perfectly with your code (huge thanks btw), but I am unable to disable motion control from my main ViewController.

How to come about this?

Distorted straight lines in video

When loading a 360° video, horizontal lines that are supposed to be straight are wavy. This seems to apply to all videos I load in the player. In a different 360 video player app they appear straight, so it does not appear to be a problem with the encoding.

Do you have any ideas what might cause this behavior?

Best,
Kai

Suggestion: Give access to the UIPanGestureRecognizer handler in Swifty360View

Hi, great package! One easy-to-implement suggestion: In Swifty360View, create some access to the internal function, Swifty360CameraController.handlePan(). Right now, while Swifty360CameraController is an "open class", Swifty360View's cameraController var is private. Hence it doesn't matter that an app can create and modify a Swifty360CameraController, I don't see any way of then using it.

What I'm currently trying to do is control panning from touches made on a device whilst projecting the Swifty360View onto an AirPlay screen. I'm blocked from forwarding gestures made on the iOS device to Swifty360View, which only wants to accept gestures directly from its own view.

Video not showing on OpenGL

Hi

I have this sample project running just fine with the default settings. I am trying to understand how to make ti work when using openGL instead of metal (by adding the "PrefersOpenGL" flag to "YES" in info.plist . When i do this, however, i can no longer see the video (just a flat gray sphere). I can, however, listen to it.

I'm building on XCode 11.1 and all the defaults on the workspace (other than the variable of info.plist)

Is this something that happens to you as well? Do you know what might cause it or how to fix? Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.