Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
updated for Xcode 8 and Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorpatras committed Sep 15, 2016
1 parent eb52806 commit e29580f
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 251 deletions.
1 change: 1 addition & 0 deletions .swift-version
@@ -0,0 +1 @@
3.0
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -3,20 +3,20 @@
# * https://github.com/supermarin/xcpretty#usage

language: objective-c
osx_image: xcode7.3
osx_image: xcode8
env:
global:
- WORKSPACE=Jukebox.xcworkspace
- FRAMEWORK_NAME=Jukebox
- PROJECT=Jukebox.xcodeproj
- SCHEME=Jukebox
- SDK=iphonesimulator9.3
- SDK=iphonesimulator10
install:
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
before_deploy:
- carthage build --no-skip-current
- carthage archive $FRAMEWORK_NAME
script:
- set -o pipefail
- xcodebuild test -workspace $WORKSPACE -scheme $SCHEME -sdk $SDK ONLY_ACTIVE_ARCH=NO | xcpretty -c
- xcodebuild -scheme $SCHEME -workspace $WORKSPACE -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.0' build test
- pod lib lint --quick
17 changes: 14 additions & 3 deletions Example/Example.xcodeproj/project.pbxproj
Expand Up @@ -145,11 +145,13 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = teodorpatras;
TargetAttributes = {
137DF0851D2043F400C15E86 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 752CFWL5Y4;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -261,8 +263,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -307,8 +311,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -327,6 +333,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -336,21 +343,25 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 752CFWL5Y4;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.teodorpatras.Example;
PRODUCT_BUNDLE_IDENTIFIER = com.teodorpatras.jukebox.example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
137DF09A1D2043F400C15E86 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 752CFWL5Y4;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.teodorpatras.Example;
PRODUCT_BUNDLE_IDENTIFIER = com.teodorpatras.jukebox.example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
14 changes: 7 additions & 7 deletions Example/Example/AppDelegate.swift
Expand Up @@ -14,31 +14,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
application.statusBarHidden = true
application.isStatusBarHidden = true
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
18 changes: 9 additions & 9 deletions Example/Example/Info.plist
Expand Up @@ -22,6 +22,15 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -36,15 +45,6 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
81 changes: 41 additions & 40 deletions Example/Example/ViewController.swift
Expand Up @@ -31,23 +31,23 @@ class ViewController: UIViewController, JukeboxDelegate {
configureUI()

// begin receiving remote events
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
UIApplication.shared.beginReceivingRemoteControlEvents()

// configure jukebox
jukebox = Jukebox(delegate: self, items: [
JukeboxItem(URL: NSURL(string: "http://www.kissfm.ro/listen.pls")!),
JukeboxItem(URL: NSURL(string: "http://www.noiseaddicts.com/samples_1w72b820/2514.mp3")!),
JukeboxItem(URL: NSURL(string: "http://www.noiseaddicts.com/samples_1w72b820/2958.mp3")!)
JukeboxItem(URL: URL(string: "http://www.kissfm.ro/listen.pls")!),
JukeboxItem(URL: URL(string: "http://www.noiseaddicts.com/samples_1w72b820/2514.mp3")!),
JukeboxItem(URL: URL(string: "http://www.noiseaddicts.com/samples_1w72b820/2958.mp3")!)
])!

/// Later add another item
let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(3 * Double(NSEC_PER_SEC)))
dispatch_after(delay, dispatch_get_main_queue()) {
self.jukebox.append(item: JukeboxItem (URL: NSURL(string: "http://www.noiseaddicts.com/samples_1w72b820/2228.mp3")!), loadingAssets: true)
let delay = DispatchTime.now() + Double(Int64(3 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: delay) {
self.jukebox.append(item: JukeboxItem (URL: URL(string: "http://www.noiseaddicts.com/samples_1w72b820/2228.mp3")!), loadingAssets: true)
}
}

override func prefersStatusBarHidden() -> Bool {
override var prefersStatusBarHidden : Bool {
return true
}

Expand All @@ -58,27 +58,27 @@ class ViewController: UIViewController, JukeboxDelegate {
let color = UIColor(red:0.84, green:0.09, blue:0.1, alpha:1)

indicator.color = color
slider.setThumbImage(UIImage(named: "sliderThumb"), forState: .Normal)
slider.setThumbImage(UIImage(named: "sliderThumb"), for: UIControlState())
slider.minimumTrackTintColor = color
slider.maximumTrackTintColor = UIColor.blackColor()
slider.maximumTrackTintColor = UIColor.black

volumeSlider.minimumTrackTintColor = color
volumeSlider.maximumTrackTintColor = UIColor.blackColor()
volumeSlider.maximumTrackTintColor = UIColor.black
volumeSlider.thumbTintColor = color

titleLabel.textColor = color

centerContainer.layer.cornerRadius = 12
view.backgroundColor = UIColor.blackColor()
view.backgroundColor = UIColor.black
}

// MARK:- JukeboxDelegate -

func jukeboxDidLoadItem(jukebox: Jukebox, item: JukeboxItem) {
func jukeboxDidLoadItem(_ jukebox: Jukebox, item: JukeboxItem) {
print("Jukebox did load: \(item.URL.lastPathComponent)")
}

func jukeboxPlaybackProgressDidChange(jukebox: Jukebox) {
func jukeboxPlaybackProgressDidChange(_ jukebox: Jukebox) {

if let currentTime = jukebox.currentItem?.currentTime, let duration = jukebox.currentItem?.meta.duration {
let value = Float(currentTime / duration)
Expand All @@ -90,51 +90,51 @@ class ViewController: UIViewController, JukeboxDelegate {
}
}

func jukeboxStateDidChange(jukebox: Jukebox) {
func jukeboxStateDidChange(_ jukebox: Jukebox) {

UIView.animateWithDuration(0.3, animations: { () -> Void in
self.indicator.alpha = jukebox.state == .Loading ? 1 : 0
self.playPauseButton.alpha = jukebox.state == .Loading ? 0 : 1
self.playPauseButton.enabled = jukebox.state == .Loading ? false : true
UIView.animate(withDuration: 0.3, animations: { () -> Void in
self.indicator.alpha = jukebox.state == .loading ? 1 : 0
self.playPauseButton.alpha = jukebox.state == .loading ? 0 : 1
self.playPauseButton.isEnabled = jukebox.state == .loading ? false : true
})

if jukebox.state == .Ready {
playPauseButton.setImage(UIImage(named: "playBtn"), forState: .Normal)
} else if jukebox.state == .Loading {
playPauseButton.setImage(UIImage(named: "pauseBtn"), forState: .Normal)
if jukebox.state == .ready {
playPauseButton.setImage(UIImage(named: "playBtn"), for: UIControlState())
} else if jukebox.state == .loading {
playPauseButton.setImage(UIImage(named: "pauseBtn"), for: UIControlState())
} else {
volumeSlider.value = jukebox.volume
let imageName: String
switch jukebox.state {
case .Playing, .Loading:
case .playing, .loading:
imageName = "pauseBtn"
case .Paused, .Failed, .Ready:
case .paused, .failed, .ready:
imageName = "playBtn"
}
playPauseButton.setImage(UIImage(named: imageName), forState: .Normal)
playPauseButton.setImage(UIImage(named: imageName), for: UIControlState())
}

print("Jukebox state changed to \(jukebox.state)")
}

func jukeboxDidUpdateMetadata(jukebox: Jukebox, forItem: JukeboxItem) {
func jukeboxDidUpdateMetadata(_ jukebox: Jukebox, forItem: JukeboxItem) {
print("Item updated:\n\(forItem)")
}


override func remoteControlReceivedWithEvent(event: UIEvent?) {
if event?.type == .RemoteControl {
override func remoteControlReceived(with event: UIEvent?) {
if event?.type == .remoteControl {
switch event!.subtype {
case .RemoteControlPlay :
case .remoteControlPlay :
jukebox.play()
case .RemoteControlPause :
case .remoteControlPause :
jukebox.pause()
case .RemoteControlNextTrack :
case .remoteControlNextTrack :
jukebox.playNext()
case .RemoteControlPreviousTrack:
case .remoteControlPreviousTrack:
jukebox.playPrevious()
case .RemoteControlTogglePlayPause:
if jukebox.state == .Playing {
case .remoteControlTogglePlayPause:
if jukebox.state == .playing {
jukebox.pause()
} else {
jukebox.play()
Expand All @@ -160,7 +160,8 @@ class ViewController: UIViewController, JukeboxDelegate {
}

@IBAction func prevAction() {
if jukebox.currentItem?.currentTime > 5 || jukebox.playIndex == 0 {

if let time = jukebox.currentItem?.currentTime, time > 5.0 || jukebox.playIndex == 0 {
jukebox.replayCurrentItem()
} else {
jukebox.playPrevious()
Expand All @@ -173,11 +174,11 @@ class ViewController: UIViewController, JukeboxDelegate {

@IBAction func playPauseAction() {
switch jukebox.state {
case .Ready :
case .ready :
jukebox.play(atIndex: 0)
case .Playing :
case .playing :
jukebox.pause()
case .Paused :
case .paused :
jukebox.play()
default:
jukebox.stop()
Expand All @@ -197,7 +198,7 @@ class ViewController: UIViewController, JukeboxDelegate {

// MARK:- Helpers -

func populateLabelWithTime(label : UILabel, time: Double) {
func populateLabelWithTime(_ label : UILabel, time: Double) {
let minutes = Int(time / 60)
let seconds = Int(time) - minutes * 60

Expand Down
2 changes: 1 addition & 1 deletion Jukebox.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Jukebox"
s.version = "0.1.5"
s.version = "0.2.0"
s.summary = "Jukebox is an iOS audio player written in Swift."

s.homepage = "https://github.com/teodorpatras/Jukebox"
Expand Down

0 comments on commit e29580f

Please sign in to comment.