From b6378b35e7a117559f5f3ae3b535602090abae35 Mon Sep 17 00:00:00 2001 From: Okechi Date: Sun, 20 Mar 2016 22:55:19 -0400 Subject: [PATCH] resized view controllers --- GetHip/CurrentlyPlayingViewController.swift | 67 +- GetHip/Main.storyboard | 988 +++++++++++++++----- GetHip/NextUpViewController.swift | 49 +- GetHip/SongSelectionViewController.swift | 37 +- 4 files changed, 879 insertions(+), 262 deletions(-) diff --git a/GetHip/CurrentlyPlayingViewController.swift b/GetHip/CurrentlyPlayingViewController.swift index 38108a7..1f77e4d 100644 --- a/GetHip/CurrentlyPlayingViewController.swift +++ b/GetHip/CurrentlyPlayingViewController.swift @@ -38,7 +38,7 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg self.audioPlayer.volume = sender.value } @IBAction func playPauseFav(sender: UIButton){ - if (self.party.role == PeerType.Host_Creator){ + if (self.party.role == PeerType.Host_Creator || self.party.role == PeerType.Guest_Creator){ if(playing == true){ for peer in self.party.session.connectedPeers { var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "pause_stream"] @@ -76,7 +76,7 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg // Do any additional setup after loading the view. self.progressBar.setProgress(0, animated: true) - if(self.party.role == PeerType.Host_Creator){ + if(self.party.role == PeerType.Host_Creator || self.party.role == PeerType.Guest_Creator){ self.audioPlayer = AVPlayer(URL: self.party.currentSong.valueForProperty(MPMediaItemPropertyAssetURL) as! NSURL) self.songImg.image = self.party.currentSong.valueForProperty(MPMediaItemPropertyArtwork).imageWithSize(songImg.frame.size) @@ -90,7 +90,16 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg } self.audioPlayer.play() self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateLabels"), userInfo: nil, repeats: true) - }else if (self.party.role == PeerType.Guest_Invited){ + + //sets the next host of the party once the party starts + self.party.chooseNextHost() + print(self.party.currentHost) + + //used to notify for end of song and initiate next host loop + + //NSNotificationCenter.defaultCenter().addObserver(self, selector: "songDidEnd:", name: "AVPlayerItemDidPlayToEndTimeNotification", object: nil) + + }else if (self.party.role == PeerType.Guest_Invited || self.party.role == PeerType.Host_Invited){ self.songImg.image = self.party.currentSongIMG self.titleLabel.text = (self.party.currentSongTitle) @@ -102,21 +111,28 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg } - //sets the next host of the party once the party starts - if(self.party.role == PeerType.Guest_Creator || self.party.role == PeerType.Host_Creator){ - - self.party.chooseNextHost() - print(self.party.currentHost) - NSNotificationCenter.defaultCenter().addObserver(self, selector: "songDidEnd:", name: "gotDisplayID", object: nil) - - } - } func songDidEnd(notification: NSNotification){ - self.performSegueWithIdentifier("NextUpSegue", sender: nil) + if(self.party.role == PeerType.Host_Creator){ + self.party.role == PeerType.Host_Invited + }else if (self.party.role == PeerType.Guest_Creator){ + self.party.role == PeerType.Guest_Invited + } + + for peer in self.party.connectedPeers() as! [MCPeerID]{ + if (peer.displayName == self.party.currentHost){ + var dictionary: [String: AnyObject] = ["sender": self.party.myPeerID, "instruction": "start_picking_a_song"] + self.party.sendInstruction(dictionary, toPeer: peer) + }else{ + var dictionary: [String: AnyObject] = ["sender": self.party.myPeerID, "instruction": "wait_in_nextUp_Scene"] + self.party.sendInstruction(dictionary, toPeer: peer) + } + } + + self.performSegueWithIdentifier("NextUpSegue", sender: self) } func timeFormat(value: Float) -> String{ @@ -195,6 +211,18 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg if segue.identifier == "NextUpSegue" { let vc: NextUpViewController = (segue.destinationViewController as? NextUpViewController)! vc.setData(self.party, user: self.usr, friends: self.frnds, request: self.requestData) + + + } + if segue.identifier == "NextSongSelectionSegue" { + + let vc: SongSelectionViewController = (segue.destinationViewController as? SongSelectionViewController)! + vc.setData(self.party, user: self.usr, friends: self.frnds, request: self.requestData) + + + + + } } @@ -238,7 +266,7 @@ extension CurrentlyPlayingViewController: PartyServiceManagerDelegate { }else if(instruction == "want_to_be_host"){ - let alert = UIAlertController(title: "Host Request", message: "Would you like to be the next host for the party and pick a song?", preferredStyle: .Alert) + let alert = UIAlertController(title: "Hosting Request", message: "Would you like to be the next host for the party and pick a song?", preferredStyle: .Alert) alert.addAction(UIAlertAction(title: "Accept", style: .Default, handler:{ (action: UIAlertAction!) -> Void in @@ -255,6 +283,17 @@ extension CurrentlyPlayingViewController: PartyServiceManagerDelegate { })) self.presentViewController(alert, animated: true, completion: nil) + + }else if(instruction == "start_picking_a_song"){ + if(self.party.role == PeerType.Host_Invited){ + self.party.role == PeerType.Host_Creator + } + if(self.party.role == PeerType.Guest_Invited){ + self.party.role == PeerType.Guest_Creator + } + self.performSegueWithIdentifier("NextSongSelectionSegue", sender: self) + }else if(instruction == "wait_in_nextUp_Scene"){ + self.performSegueWithIdentifier("NextUpSegue", sender: self) } } diff --git a/GetHip/Main.storyboard b/GetHip/Main.storyboard index 257d9c4..e4ea74b 100644 --- a/GetHip/Main.storyboard +++ b/GetHip/Main.storyboard @@ -3,6 +3,9 @@ + + + @@ -17,21 +20,20 @@ - - - - - + + + + + - - - - - - - - + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + @@ -82,7 +126,7 @@ - + @@ -96,45 +140,39 @@ - - + + + + + - - + + + + + - - + + - - + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -204,27 +287,50 @@ - + + + + + + + + + + + + + + @@ -243,17 +349,31 @@ - - + + + + + - + + + + + + + + @@ -276,53 +396,90 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -347,35 +504,61 @@ - - + + + + - + + + + + + + + + + + + + + @@ -403,17 +586,17 @@ - - + + + + - - + + + + + + + + + + + + + + + @@ -466,11 +675,20 @@ - + + + + + + + + + + @@ -507,9 +725,12 @@ - + + + + @@ -573,6 +794,12 @@ + + + + + + @@ -638,44 +865,73 @@ - - + + + + + - - - - + + + + + + + + + + + + + + + @@ -716,9 +972,12 @@ - - - + + + + + @@ -839,6 +1101,15 @@ + + + + + + + + + @@ -890,18 +1161,12 @@ - - - + + + + + @@ -917,22 +1182,41 @@ - - + + + + - + + + + + + + + + + @@ -942,8 +1226,29 @@ + + + + + + + + + + @@ -985,12 +1290,49 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1121,28 +1492,24 @@ - - - + + + + @@ -1169,8 +1536,32 @@ + + + + + + + + + + + + @@ -1220,26 +1611,35 @@ - - - + + + + + + + + + @@ -1268,24 +1677,27 @@ - + - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1367,6 +1816,7 @@ + @@ -1385,9 +1835,12 @@ - + + + + @@ -1480,6 +1933,12 @@ + + + + + + @@ -1494,6 +1953,7 @@ + @@ -1521,27 +1981,36 @@ - + + + + + + + + + + + @@ -1575,27 +2055,36 @@ - + + + + + + + + + + + @@ -1659,36 +2159,36 @@ - - + + - - - - - - - - + + + + + + + + - + - + - - - - - - - + + + + + + + + + + - - - diff --git a/GetHip/NextUpViewController.swift b/GetHip/NextUpViewController.swift index 333d891..ba85cf8 100644 --- a/GetHip/NextUpViewController.swift +++ b/GetHip/NextUpViewController.swift @@ -7,8 +7,9 @@ // import UIKit +import MultipeerConnectivity -class NextUpViewController: UIViewController { +class NextUpViewController: UIViewController, PartyServiceManagerDelegate { var party: PartyServiceManager! var usr: [UserParseData] = [] var frnds: [FriendData] = [] @@ -17,6 +18,7 @@ class NextUpViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + self.party.delegate = self self.userImages.layer.cornerRadius = self.userImages.frame.size.width/2 self.userImages.clipsToBounds = true // Do any additional setup after loading the view. @@ -35,14 +37,55 @@ class NextUpViewController: UIViewController { self.requestData = request } - /* + // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. + + if(segue.identifier == "NextSongSegue"){ + let vc: CurrentlyPlayingViewController = (segue.destinationViewController as? CurrentlyPlayingViewController)! + + vc.setData(self.party, user: self.usr, friends: self.frnds, request: self.requestData) + } } - */ + } + +extension NextUpViewController: PartyServiceManagerDelegate { + + func foundPeer() { + + } + + func lostPeer() { + } + + func invitationWasRecieved(peerID: MCPeerID, invitationHandler: ((Bool, MCSession!) -> Void)!) { + + } + + func connectedWithPeer(peerID: MCPeerID) { + + } + + func didRecieveInstruction(dictionary: Dictionary){ + let (instruction, fromPeer) = self.party.decodeInstruction(dictionary) + + if self.party.disconnectedPeersDictionary[fromPeer.displayName] != nil { + + var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "disconnect"] + self.party.sendInstruction(dictionary, toPeer: fromPeer) + }else{ + if (instruction == "start"){ + self.performSegueWithIdentifier("NextSongSegue", sender: self) + } + } + + } + + +} diff --git a/GetHip/SongSelectionViewController.swift b/GetHip/SongSelectionViewController.swift index 1f0c61f..f8dcac0 100644 --- a/GetHip/SongSelectionViewController.swift +++ b/GetHip/SongSelectionViewController.swift @@ -8,6 +8,7 @@ import UIKit import MediaPlayer +import MultipeerConnectivity class SongSelectionViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var party: PartyServiceManager! @@ -167,7 +168,12 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl var songs = songsQuery.items var rowItem: MPMediaItem = songs[indexPath.row - 1] as! MPMediaItem self.party.setSong(rowItem) - self.performSegueWithIdentifier("LoadingPartySegue", sender: nil) + if(self.party.role == PeerType.Host_Creator){ + self.performSegueWithIdentifier("LoadingPartySegue", sender: self) + }else{ + self.performSegueWithIdentifier("NextSongCurrentlyPlayingSegue", sender: self) + } + } } @@ -287,6 +293,35 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl } + } + + if(segue.identifier == "NextSongCurrentlyPlayingSegue"){ + + let vc: CurrentlyPlayingViewController = (segue.destinationViewController as? CurrentlyPlayingViewController)! + vc.setData(self.party, user: self.usr, friends: self.frnds, request: self.requestData) + + //sends music info incuding, title, artist, album, and image + var dictionary: [String: AnyObject] = ["sender": self.party.myPeerID.displayName, "instruction": "set_up_song", "songTitle": (self.party.currentSong.valueForProperty(MPMediaItemPropertyTitle) as? String!)!, "songArtistAndAlbum": (self.party.currentSong.valueForProperty(MPMediaItemPropertyArtist) as? String!)! + " - " + (self.party.currentSong.valueForProperty(MPMediaItemPropertyAlbumTitle) as? String!)!, "songImage": UIImagePNGRepresentation(self.party.currentSong.valueForProperty(MPMediaItemPropertyArtwork).imageWithSize(CGSize(width: 320, height: 320)) )] + + + for peer in self.party.connectedPeers() as! [MCPeerID] { + self.party.sendInstruction(dictionary, toPeer: peer) + + //open stream with peer + let stream = self.party.outputStreamForPeer(peer) + self.party.outputStreamers[peer.displayName] = TDAudioOutputStreamer(outputStream: stream) + self.party.outputStreamers[peer.displayName]!.streamAudioFromURL((self.party.currentSong.valueForProperty(MPMediaItemPropertyAssetURL) as! NSURL)) + } + + dictionary = ["sender": self.party.myPeerID.displayName, "instruction": "start"] + + for peer in self.party.connectedPeers() as! [MCPeerID] { + self.party.sendInstruction(dictionary, toPeer: peer) + } + + + + } }