I have the following playground
import UIKit
import AVKit
import AVFoundation
import XCPlayground
let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let frame = CGRectMake(0, 0, 640, 480)
let player = AVPlayer(URL: videoURL!)
player.allowsExternalPlayback = false
let playerViewController = AVPlayerViewController()
XCPlaygroundPage.currentPage.liveView = playerViewController.view!
playerViewController.view!.frame = frame
playerViewController.player = player
playerViewController.player!.play()
But the time timeline output shows the following:
I can hear the audio, but no video plays.
What am I doing wrong. I am using the latest xCode release 7.3
Thanks,
Rob
Related
My image is not visible in Scenekit, I also tested while button is visible, image button or button with image background becomes invisible. Any idea?
I have finally showed an image over Scenekit View, but not using image view. I have checked out Fox2SceneKitWWDC2017 sample project and I see they used SpriteKit overlay. I used Fox2 sample codes to do so, as below. In case some body needs...
//
// Overlay.swift
// Remote
//
// Created by Mustafa Akkuzu on 14.12.2021.
//
import Foundation
import SceneKit
import SpriteKit
class Overlay: SKScene {
private var overlayNode: SKNode
// MARK: - Initialization
init(size: CGSize, controller: ViewController) {
overlayNode = SKNode()
super.init(size: size)
scaleMode = .resizeFill
addChild(overlayNode)
// Assign the SpriteKit overlay to the SceneKit view.
isUserInteractionEnabled = false
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func showImage() {
// Congratulation title
let congratulationsNode = SKSpriteNode(imageNamed: "circle.png")
overlayNode.addChild(congratulationsNode)
let w: CGFloat = size.width
let h: CGFloat = size.height
overlayNode.position = CGPoint(x: w/2, y: h/2)
// Animate
congratulationsNode.alpha = 0.0
congratulationsNode.xScale = 0
congratulationsNode.yScale = 0
congratulationsNode.run( SKAction.group([SKAction.fadeIn(withDuration: 0.25),
SKAction.sequence([SKAction.scale(to: 1.22, duration: 0.25),
SKAction.scale(to: 1.0, duration: 0.1)])]))
}
}
Usage:
let overlay = Overlay(size: sceneView.bounds.size, controller: self)
sceneView.overlaySKScene = overlay
overlay.showImage()
According to the Cocoa Drawing Guide documentation for Images, NSImage can load a Windows cursor .cur file.
But how do I obtain the hotspot needed for NSCursor - initWithImage:(NSImage *)newImage hotSpot:(NSPoint)point; ?
As the documentation also says,
In OS X v10.4 and later, NSImage supports many additional file formats using the Image I/O framework.
So let's grab a sample cursor file and experiment in a Swift playground:
import Foundation
import ImageIO
let url = Bundle.main.url(forResource: "BUSY_L", withExtension: "CUR")! as CFURL
let source = CGImageSourceCreateWithURL(url, nil)!
print(CGImageSourceCopyPropertiesAtIndex(source, 0, nil)!)
Output:
{
ColorModel = RGB;
Depth = 8;
HasAlpha = 1;
IsIndexed = 1;
PixelHeight = 32;
PixelWidth = 32;
ProfileName = "sRGB IEC61966-2.1";
hotspotX = 16;
hotspotY = 16;
}
So, to get the hotspot safely:
import Foundation
import ImageIO
if let url = Bundle.main.url(forResource: "BUSY_L", withExtension: "CUR") as CFURL?,
let source = CGImageSourceCreateWithURL(url, nil),
let properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [String: Any],
let x = properties["hotspotX"] as? CGFloat,
let y = properties["hotspotY"] as? CGFloat
{
let hotspot = CGPoint(x: x, y: y)
print(hotspot)
}
Output:
(16.0, 16.0)
I have tried many ways of writing the code to get it to rotate, but keep getting threads.
First way:
import UIKit
import SpriteKit
class PlayScene: SKScene {
let hero = SKSpriteNode(imageNamed: "hero.png")
let groundSpeed = 5
override func didMoveToView(view: SKView) {
// code
}
override func update(currentTime: NSTimeInterval) {
//rotate the hero (in shape of a ball)
let rotateAction = SKAction.rotateByAngle(5, duration: 1)
let repeatAction = SKAction.repeatActionForever(rotateAction)
hero.runAction(repeatAction)
}
}
Second way:
var degreeRotation = CDouble(self.groundSpeed) * M_PI / 180
//rotate the hero
self.hero.zRotation -= CGFloat(degreeRotation)
I have tried making an Int extension for degree to radians translation (like someone already suggested on Stackoverflow) but for some reason none of them worked. I am very new to Swift and I don't know what to try anymore, so if you can help me, please do.
Change your code to this...
import UIKit
import SpriteKit
class PlayScene: SKScene {
let hero = SKSpriteNode(imageNamed: "hero.png")
let groundSpeed = 5
override func didMoveToView(view: SKView) {
// code to add the hero sprite to the view.
// if the sprite is not added to the view then nothing will happen with actions.
// M_PI = half a turn. Work in radians, not degrees.
let rotateAction = SKAction.rotateByAngle((CGFloat)M_PI, duration: (NSTimeInterval)1)
let repeatAction = SKAction.repeatActionForever(rotateAction)
hero.runAction(repeatAction)
}
}
I'm unable to load a scene in XCode 7 beta 3 playground... although it was working with Xcode 6.4.... is it bug or something as changed ?
ps : SCNScene(named: "ship.dae") returns nil.
In my Resources folder is ship.dae and texture.png (from the SceneKit template), and here is my code :
//: Playground - noun: a place where people can play
import SceneKit
import XCPlayground
var view = SCNView(frame: NSRect(x: 0, y: 0, width: 500, height: 500))
var scene = SCNScene(named: "ship.dae")
view.scene = scene
XCPShowView("view", view: view)
In Xcode 7
import XCPlayground
let view = // your view
XCPlaygroundPage.currentPage.liveView = view
In Xcode 8
import PlaygroundSupport
let view = // your view
PlaygroundPage.current.liveView = view
I just wrote this code. You press a button and hear a sound. I imported AudioToolBox. It worked fine the first 10 times I opened and used my app, but now for some reason it sounds like my audio is very quiet, even though the volume on my phone is all the way up and the audio that is produced by AVFoundation sounds fine.
Anyone know how this would be possible?
import AVFoundation
import AudioToolBox
#IBAction func buttonOne(sender: UIButton) {
var soundID: SystemSoundID = 0
let soundURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), "C-note", "mp3", nil)
AudioServicesCreateSystemSoundID(soundURL, &soundID)
AudioServicesPlaySystemSound(soundID)
let wSize : CGFloat = 20
let hSize : CGFloat = 35
let yPosition : CGFloat = 40
let dot = UIImageView()
dot.image = UIImage(named: "drop")
dot.frame = CGRect(x: 33, y: yPosition, width: wSize, height: hSize)
self.view.addSubview(dot)
let duration = 0.7
let delay = 0.0
let options = UIViewAnimationOptions.CurveEaseIn
UIView.animateWithDuration(duration, delay: delay, options: options, animations: {
dot.frame = CGRect(x: 33, y: 360, width: wSize, height: hSize)
}, completion: { animationFinished in
dot.removeFromSuperview()
})
}