mirror of
https://github.com/oonyeje/Get-Hip.git
synced 2025-12-25 03:37:40 +00:00
Connection between peers working framework is kinda buggy, but that may just be development woes. Working on streaming now with TDAudioStreamer library
This commit is contained in:
parent
fb39de92cc
commit
8c4ae2e7e7
@ -121,17 +121,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate , CLLocationManagerDelegat
|
||||
|
||||
var query = PFQuery(className: "_User")
|
||||
var currentUser = PFUser.currentUser()
|
||||
|
||||
query.whereKey("username", equalTo: (currentUser?.username as String!))
|
||||
|
||||
query.getFirstObjectInBackgroundWithBlock({
|
||||
(object: PFObject?, error: NSError?) -> Void in
|
||||
if(currentUser != nil){
|
||||
query.whereKey("username", equalTo: (currentUser?.username as String!))
|
||||
|
||||
if(error == nil){
|
||||
object?.setObject(geo, forKey: "location")
|
||||
object?.saveInBackground()
|
||||
}
|
||||
})
|
||||
query.getFirstObjectInBackgroundWithBlock({
|
||||
(object: PFObject?, error: NSError?) -> Void in
|
||||
|
||||
if(error == nil){
|
||||
object?.setObject(geo, forKey: "location")
|
||||
object?.saveInBackground()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -9,15 +9,16 @@
|
||||
import UIKit
|
||||
import MediaPlayer
|
||||
import AVFoundation
|
||||
import MultipeerConnectivity
|
||||
|
||||
class CurrentlyPlayingViewController: UIViewController{
|
||||
class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDelegate{
|
||||
//persistant data
|
||||
var party: PartyServiceManager!
|
||||
var usr: [UserParseData] = []
|
||||
var frnds: [FriendData] = []
|
||||
var requestData: [FriendData] = []
|
||||
var audioPlayer: AVPlayer!
|
||||
var playing = true
|
||||
var playing = false
|
||||
var timer = NSTimer()
|
||||
|
||||
//controller data
|
||||
@ -57,24 +58,34 @@ class CurrentlyPlayingViewController: UIViewController{
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.audioPlayer = AVPlayer(URL: self.party.currentSong.valueForProperty(MPMediaItemPropertyAssetURL) as! NSURL)
|
||||
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
if(self.party.role == PeerType.Host_Creator){
|
||||
|
||||
self.audioPlayer = AVPlayer(URL: self.party.currentSong.valueForProperty(MPMediaItemPropertyAssetURL) as! NSURL)
|
||||
|
||||
self.songImg.image = self.party.currentSong.valueForProperty(MPMediaItemPropertyArtwork).imageWithSize(songImg.frame.size)
|
||||
self.titleLabel.text = (self.party.currentSong.valueForProperty(MPMediaItemPropertyTitle) as? String!)!
|
||||
self.artistAndAlbumLabel.text = (self.party.currentSong.valueForProperty(MPMediaItemPropertyArtist) as? String!)! + " - " + (self.party.currentSong.valueForProperty(MPMediaItemPropertyAlbumTitle) as? String!)!
|
||||
self.audioPlayer.volume = self.volCtrl.value
|
||||
self.maxLabel.text = String(stringInterpolationSegment: self.audioPlayer.currentItem.duration.value)
|
||||
self.audioPlayer.play()
|
||||
self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateLabels"), userInfo: nil, repeats: true)
|
||||
self.party.delegate = self
|
||||
//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){
|
||||
|
||||
self.songImg.image = self.party.currentSongIMG
|
||||
self.titleLabel.text = (self.party.currentSongTitle)
|
||||
println(self.party.currentSongTitle)
|
||||
println(self.titleLabel.text)
|
||||
self.artistAndAlbumLabel.text = (self.party.currentSongArtistAlbum)
|
||||
self.party.delegate = self
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -82,14 +93,17 @@ class CurrentlyPlayingViewController: UIViewController{
|
||||
}
|
||||
|
||||
func updateLabels(){
|
||||
var timeLeft = self.audioPlayer.currentItem.duration.value - self.audioPlayer.currentTime().value
|
||||
var interval = timeLeft
|
||||
var seconds = interval%60
|
||||
println(seconds)
|
||||
var minutes = (interval/60)%60
|
||||
println(minutes)
|
||||
//self.maxLabel.text
|
||||
//self.minLabel.text
|
||||
if (self.playing == true){
|
||||
var timeLeft = self.audioPlayer.currentItem.duration.value - self.audioPlayer.currentTime().value
|
||||
var interval = timeLeft
|
||||
var seconds = interval%60
|
||||
println(seconds)
|
||||
var minutes = (interval/60)%60
|
||||
println(minutes)
|
||||
//self.maxLabel.text
|
||||
//self.minLabel.text
|
||||
}
|
||||
|
||||
}
|
||||
override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
@ -127,3 +141,40 @@ class CurrentlyPlayingViewController: UIViewController{
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension CurrentlyPlayingViewController: PartyServiceManagerDelegate {
|
||||
|
||||
func foundPeer() {
|
||||
|
||||
}
|
||||
|
||||
func lostPeer() {
|
||||
|
||||
}
|
||||
|
||||
func invitationWasRecieved(peerID: MCPeerID, invitationHandler: ((Bool, MCSession!) -> Void)!) {
|
||||
|
||||
}
|
||||
|
||||
func connectedWithPeer(peerID: MCPeerID) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
func didRecieveInstruction(dictionary: Dictionary<String, AnyObject>){
|
||||
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{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -87,6 +87,7 @@ extension JoiningPartyViewController: PartyServiceManagerDelegate {
|
||||
}
|
||||
|
||||
if (instruction == "start_party"){
|
||||
println("mark 4")
|
||||
self.performSegueWithIdentifier("EnteringPartySegue", sender: self)
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
import UIKit
|
||||
import MediaPlayer
|
||||
import MultipeerConnectivity
|
||||
import AVFoundation
|
||||
|
||||
class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, PartyServiceManagerDelegate{
|
||||
//persistant data
|
||||
@ -127,7 +128,7 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource,
|
||||
}
|
||||
}
|
||||
}else{
|
||||
var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "start_Party"]
|
||||
var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "start_party"]
|
||||
self.party.sendInstruction(dictionary, toPeer: joinedPeer! )
|
||||
}
|
||||
|
||||
@ -200,6 +201,53 @@ extension LoadingPartyViewController: PartyServiceManagerDelegate {
|
||||
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(songImg.frame.size))]
|
||||
|
||||
self.party.sendInstruction(dictionary, toPeer: fromPeer)
|
||||
|
||||
//open stream with peer
|
||||
let stream = self.party.outputStreamForPeer(fromPeer)
|
||||
self.party.outputStreamer = TDAudioOutputStreamer(outputStream: stream)
|
||||
|
||||
|
||||
/*
|
||||
let asset: AVURLAsset? = AVURLAsset(URL: (self.party.currentSong.valueForProperty(MPMediaItemPropertyAssetURL) as! NSURL), options: nil)
|
||||
|
||||
var error: NSError?
|
||||
|
||||
let assetReader: AVAssetReader = AVAssetReader(asset: asset, error: &error)
|
||||
|
||||
let assetOutput: AVAssetReaderTrackOutput = AVAssetReaderTrackOutput(track: asset!.tracks[0] as! AVAssetTrack, outputSettings: nil)
|
||||
|
||||
if error != nil {
|
||||
|
||||
}else{
|
||||
//for peer in self.party.session.connectedPeers {
|
||||
assetReader.addOutput(assetOutput)
|
||||
assetReader.startReading()
|
||||
|
||||
let sampleBuffer:CMSampleBuffer! = assetOutput.copyNextSampleBuffer()
|
||||
|
||||
var audioBufferList = AudioBufferList(mNumberBuffers: 1, mBuffers: AudioBuffer(mNumberChannels: 0, mDataByteSize: 0, mData: nil))
|
||||
|
||||
var blockBuffer: Unmanaged<CMBlockBuffer>? = nil
|
||||
|
||||
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, nil, &audioBufferList, Int(sizeof(audioBufferList.dynamicType)), nil, nil, UInt32(kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment), &blockBuffer)
|
||||
|
||||
let stream = self.party.outputStreamForPeer(fromPeer) //self.party.session.startStreamWithName("music", toPeer: peer as! MCPeerID, error: &error)
|
||||
|
||||
if error != nil {
|
||||
print("Error stream: \(error?.localizedDescription)")
|
||||
}
|
||||
|
||||
for (var i: UInt32 = 0; i < audioBufferList.mNumberBuffers; i++){
|
||||
var audioBuffer = AudioBuffer(mNumberChannels: audioBufferList.mBuffers.mNumberChannels, mDataByteSize: audioBufferList.mBuffers.mDataByteSize, mData: audioBufferList.mBuffers.mData)
|
||||
stream.write(UnsafeMutablePointer<UInt8>(audioBuffer.mData), maxLength: Int(audioBuffer.mDataByteSize))
|
||||
}
|
||||
//}
|
||||
|
||||
//CFRelease(blockBuffer)
|
||||
//CFRelease(sampleBuffer)
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1306,7 +1306,7 @@
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sFb-YR-QlX">
|
||||
<rect key="frame" x="138" y="505" width="44" height="43"/>
|
||||
<state key="normal" backgroundImage="Pause-52.png">
|
||||
<state key="normal" backgroundImage="Play-52.png">
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
@ -1635,7 +1635,7 @@
|
||||
<image name="Lower.png" width="7" height="10"/>
|
||||
<image name="No Friend Requests i5.png" width="320" height="568"/>
|
||||
<image name="Party.png" width="81" height="41"/>
|
||||
<image name="Pause-52.png" width="52" height="52"/>
|
||||
<image name="Play-52.png" width="52" height="52"/>
|
||||
<image name="Raise.png" width="14" height="13"/>
|
||||
<image name="Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2.png" width="203" height="153"/>
|
||||
<image name="Send Invites Button.png" width="375" height="46"/>
|
||||
|
||||
@ -59,11 +59,14 @@ class PartyServiceManager: NSObject {
|
||||
|
||||
//party-creator variables
|
||||
var currentSong: MPMediaItem! = nil
|
||||
var outputStreamer: TDAudioOutputStreamer!
|
||||
|
||||
//party-guest variables
|
||||
var currentSongTitle: String!
|
||||
var currentSongArtistAlbum: String!
|
||||
var currentSongIMG: UIImage!
|
||||
var songStream: NSInputStream!
|
||||
var inputStreamer: TDAudioInputStreamer!
|
||||
|
||||
|
||||
|
||||
@ -130,6 +133,7 @@ class PartyServiceManager: NSObject {
|
||||
if(instruction == "set_up_song"){
|
||||
self.currentSongTitle = dataDictionary["songTitle"] as! String
|
||||
self.currentSongArtistAlbum = dataDictionary["songArtistAndAlbum"] as! String
|
||||
println(self.currentSongTitle)
|
||||
self.currentSongIMG = UIImage(data: (dataDictionary["songImage"] as! NSData))
|
||||
}
|
||||
return (instruction!, fromPeer)
|
||||
@ -197,7 +201,9 @@ class PartyServiceManager: NSObject {
|
||||
}
|
||||
|
||||
func outputStreamForPeer(peer: MCPeerID) -> NSOutputStream {
|
||||
println("attempted to start stream with" + peer.displayName)
|
||||
return session.startStreamWithName("music", toPeer: peer, error: nil)
|
||||
|
||||
}
|
||||
|
||||
//Host Methods
|
||||
@ -321,6 +327,16 @@ extension PartyServiceManager: MCSessionDelegate{
|
||||
|
||||
func session(session: MCSession!, didReceiveStream stream: NSInputStream!, withName streamName: String!, fromPeer peerID: MCPeerID!) {
|
||||
NSLog("%@", "didRecieveStream: \(streamName) from peer: \(peerID)")
|
||||
|
||||
if streamName == "music" {
|
||||
self.songStream = stream
|
||||
self.inputStreamer = TDAudioInputStreamer(inputStream: stream)
|
||||
self.songStream.delegate = self
|
||||
self.songStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
|
||||
//self.songStream.open()
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func session(session: MCSession!, didFinishReceivingResourceWithName resourceName: String!, fromPeer peerID: MCPeerID!, atURL localURL: NSURL!, withError error: NSError!) {
|
||||
@ -334,6 +350,18 @@ extension PartyServiceManager: MCSessionDelegate{
|
||||
|
||||
}
|
||||
|
||||
extension PartyServiceManager: NSStreamDelegate {
|
||||
func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {
|
||||
if(eventCode == NSStreamEvent.HasBytesAvailable){
|
||||
println("data available in stream")
|
||||
}else if(eventCode == NSStreamEvent.EndEncountered) {
|
||||
println("stream ended")
|
||||
}else if(eventCode == NSStreamEvent.ErrorOccurred) {
|
||||
println("stream error occured")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//state extensions
|
||||
|
||||
extension MCSessionState{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user