mirror of
https://github.com/oonyeje/Get-Hip.git
synced 2025-12-25 11:47:41 +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 query = PFQuery(className: "_User")
|
||||||
var currentUser = PFUser.currentUser()
|
var currentUser = PFUser.currentUser()
|
||||||
|
if(currentUser != nil){
|
||||||
|
query.whereKey("username", equalTo: (currentUser?.username as String!))
|
||||||
|
|
||||||
query.whereKey("username", equalTo: (currentUser?.username as String!))
|
query.getFirstObjectInBackgroundWithBlock({
|
||||||
|
(object: PFObject?, error: NSError?) -> Void in
|
||||||
|
|
||||||
query.getFirstObjectInBackgroundWithBlock({
|
if(error == nil){
|
||||||
(object: PFObject?, error: NSError?) -> Void in
|
object?.setObject(geo, forKey: "location")
|
||||||
|
object?.saveInBackground()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if(error == nil){
|
|
||||||
object?.setObject(geo, forKey: "location")
|
|
||||||
object?.saveInBackground()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -9,15 +9,16 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import MediaPlayer
|
import MediaPlayer
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
|
import MultipeerConnectivity
|
||||||
|
|
||||||
class CurrentlyPlayingViewController: UIViewController{
|
class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDelegate{
|
||||||
//persistant data
|
//persistant data
|
||||||
var party: PartyServiceManager!
|
var party: PartyServiceManager!
|
||||||
var usr: [UserParseData] = []
|
var usr: [UserParseData] = []
|
||||||
var frnds: [FriendData] = []
|
var frnds: [FriendData] = []
|
||||||
var requestData: [FriendData] = []
|
var requestData: [FriendData] = []
|
||||||
var audioPlayer: AVPlayer!
|
var audioPlayer: AVPlayer!
|
||||||
var playing = true
|
var playing = false
|
||||||
var timer = NSTimer()
|
var timer = NSTimer()
|
||||||
|
|
||||||
//controller data
|
//controller data
|
||||||
@ -57,24 +58,34 @@ class CurrentlyPlayingViewController: UIViewController{
|
|||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
self.audioPlayer = AVPlayer(URL: self.party.currentSong.valueForProperty(MPMediaItemPropertyAssetURL) as! NSURL)
|
|
||||||
|
|
||||||
// Do any additional setup after loading the view.
|
// Do any additional setup after loading the view.
|
||||||
|
|
||||||
if(self.party.role == PeerType.Host_Creator){
|
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.songImg.image = self.party.currentSong.valueForProperty(MPMediaItemPropertyArtwork).imageWithSize(songImg.frame.size)
|
||||||
self.titleLabel.text = (self.party.currentSong.valueForProperty(MPMediaItemPropertyTitle) as? String!)!
|
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.artistAndAlbumLabel.text = (self.party.currentSong.valueForProperty(MPMediaItemPropertyArtist) as? String!)! + " - " + (self.party.currentSong.valueForProperty(MPMediaItemPropertyAlbumTitle) as? String!)!
|
||||||
self.audioPlayer.volume = self.volCtrl.value
|
self.audioPlayer.volume = self.volCtrl.value
|
||||||
self.maxLabel.text = String(stringInterpolationSegment: self.audioPlayer.currentItem.duration.value)
|
self.maxLabel.text = String(stringInterpolationSegment: self.audioPlayer.currentItem.duration.value)
|
||||||
self.audioPlayer.play()
|
self.party.delegate = self
|
||||||
self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateLabels"), userInfo: nil, repeats: true)
|
//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){
|
}else if (self.party.role == PeerType.Guest_Invited){
|
||||||
|
|
||||||
self.songImg.image = self.party.currentSongIMG
|
self.songImg.image = self.party.currentSongIMG
|
||||||
self.titleLabel.text = (self.party.currentSongTitle)
|
self.titleLabel.text = (self.party.currentSongTitle)
|
||||||
|
println(self.party.currentSongTitle)
|
||||||
|
println(self.titleLabel.text)
|
||||||
self.artistAndAlbumLabel.text = (self.party.currentSongArtistAlbum)
|
self.artistAndAlbumLabel.text = (self.party.currentSongArtistAlbum)
|
||||||
|
self.party.delegate = self
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,14 +93,17 @@ class CurrentlyPlayingViewController: UIViewController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateLabels(){
|
func updateLabels(){
|
||||||
var timeLeft = self.audioPlayer.currentItem.duration.value - self.audioPlayer.currentTime().value
|
if (self.playing == true){
|
||||||
var interval = timeLeft
|
var timeLeft = self.audioPlayer.currentItem.duration.value - self.audioPlayer.currentTime().value
|
||||||
var seconds = interval%60
|
var interval = timeLeft
|
||||||
println(seconds)
|
var seconds = interval%60
|
||||||
var minutes = (interval/60)%60
|
println(seconds)
|
||||||
println(minutes)
|
var minutes = (interval/60)%60
|
||||||
//self.maxLabel.text
|
println(minutes)
|
||||||
//self.minLabel.text
|
//self.maxLabel.text
|
||||||
|
//self.minLabel.text
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
override func didReceiveMemoryWarning() {
|
override func didReceiveMemoryWarning() {
|
||||||
super.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"){
|
if (instruction == "start_party"){
|
||||||
|
println("mark 4")
|
||||||
self.performSegueWithIdentifier("EnteringPartySegue", sender: self)
|
self.performSegueWithIdentifier("EnteringPartySegue", sender: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import MediaPlayer
|
import MediaPlayer
|
||||||
import MultipeerConnectivity
|
import MultipeerConnectivity
|
||||||
|
import AVFoundation
|
||||||
|
|
||||||
class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, PartyServiceManagerDelegate{
|
class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, PartyServiceManagerDelegate{
|
||||||
//persistant data
|
//persistant data
|
||||||
@ -127,7 +128,7 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}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! )
|
self.party.sendInstruction(dictionary, toPeer: joinedPeer! )
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +202,53 @@ extension LoadingPartyViewController: PartyServiceManagerDelegate {
|
|||||||
|
|
||||||
self.party.sendInstruction(dictionary, toPeer: fromPeer)
|
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>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sFb-YR-QlX">
|
<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"/>
|
<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"/>
|
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
@ -1635,7 +1635,7 @@
|
|||||||
<image name="Lower.png" width="7" height="10"/>
|
<image name="Lower.png" width="7" height="10"/>
|
||||||
<image name="No Friend Requests i5.png" width="320" height="568"/>
|
<image name="No Friend Requests i5.png" width="320" height="568"/>
|
||||||
<image name="Party.png" width="81" height="41"/>
|
<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="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="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"/>
|
<image name="Send Invites Button.png" width="375" height="46"/>
|
||||||
|
|||||||
@ -59,11 +59,14 @@ class PartyServiceManager: NSObject {
|
|||||||
|
|
||||||
//party-creator variables
|
//party-creator variables
|
||||||
var currentSong: MPMediaItem! = nil
|
var currentSong: MPMediaItem! = nil
|
||||||
|
var outputStreamer: TDAudioOutputStreamer!
|
||||||
|
|
||||||
//party-guest variables
|
//party-guest variables
|
||||||
var currentSongTitle: String!
|
var currentSongTitle: String!
|
||||||
var currentSongArtistAlbum: String!
|
var currentSongArtistAlbum: String!
|
||||||
var currentSongIMG: UIImage!
|
var currentSongIMG: UIImage!
|
||||||
|
var songStream: NSInputStream!
|
||||||
|
var inputStreamer: TDAudioInputStreamer!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -130,6 +133,7 @@ class PartyServiceManager: NSObject {
|
|||||||
if(instruction == "set_up_song"){
|
if(instruction == "set_up_song"){
|
||||||
self.currentSongTitle = dataDictionary["songTitle"] as! String
|
self.currentSongTitle = dataDictionary["songTitle"] as! String
|
||||||
self.currentSongArtistAlbum = dataDictionary["songArtistAndAlbum"] as! String
|
self.currentSongArtistAlbum = dataDictionary["songArtistAndAlbum"] as! String
|
||||||
|
println(self.currentSongTitle)
|
||||||
self.currentSongIMG = UIImage(data: (dataDictionary["songImage"] as! NSData))
|
self.currentSongIMG = UIImage(data: (dataDictionary["songImage"] as! NSData))
|
||||||
}
|
}
|
||||||
return (instruction!, fromPeer)
|
return (instruction!, fromPeer)
|
||||||
@ -197,7 +201,9 @@ class PartyServiceManager: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func outputStreamForPeer(peer: MCPeerID) -> NSOutputStream {
|
func outputStreamForPeer(peer: MCPeerID) -> NSOutputStream {
|
||||||
|
println("attempted to start stream with" + peer.displayName)
|
||||||
return session.startStreamWithName("music", toPeer: peer, error: nil)
|
return session.startStreamWithName("music", toPeer: peer, error: nil)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Host Methods
|
//Host Methods
|
||||||
@ -321,6 +327,16 @@ extension PartyServiceManager: MCSessionDelegate{
|
|||||||
|
|
||||||
func session(session: MCSession!, didReceiveStream stream: NSInputStream!, withName streamName: String!, fromPeer peerID: MCPeerID!) {
|
func session(session: MCSession!, didReceiveStream stream: NSInputStream!, withName streamName: String!, fromPeer peerID: MCPeerID!) {
|
||||||
NSLog("%@", "didRecieveStream: \(streamName) from peer: \(peerID)")
|
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!) {
|
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
|
//state extensions
|
||||||
|
|
||||||
extension MCSessionState{
|
extension MCSessionState{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user