iphone - playing a song on another device using bluetooth -
i have playlist of songs in app.i want play song playlist on anther device (iphone) using bluetooth.
this have done
#import "browsestationsviewcontroller.h" @interface browsestationsviewcontroller (){ gksession *gksession; } @end @implementation browsestationsviewcontroller - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } #pragma mark - - (void)viewdidload { [super viewdidload]; // additional setup after loading view [self setupsession]; nsnotificationcenter *defaultcenter = [nsnotificationcenter defaultcenter]; // register notifications when application leaves background state // on way becoming active application. [defaultcenter addobserver:self selector:@selector(setupsession) name:uiapplicationwillenterforegroundnotification object:nil]; // register notifications when when application enters background. [defaultcenter addobserver:self selector:@selector(teardownsession) name:uiapplicationdidenterbackgroundnotification object:nil]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - gksession setup , teardown - (void)setupsession { gksession = [[gksession alloc] initwithsessionid:nil displayname:nil sessionmode:gksessionmodepeer]; gksession.delegate = self; gksession.disconnecttimeout = kdisconnecttimeout; gksession.available = yes; self.title = [nsstring stringwithformat:@"gksession: %@", gksession.displayname]; } - (void)teardownsession { [gksession disconnectfromallpeers]; gksession.available = no; gksession.delegate = nil; } #pragma mark - gksessiondelegate protocol conformance - (void)session:(gksession *)session peer:(nsstring *)peerid didchangestate: (gkpeerconnectionstate)state { switch (state) { case gkpeerstateavailable: { nslog(@"didchangestate: peer %@ available", [session displaynameforpeer:peerid]); [nsthread sleepfortimeinterval:ksleeptimeinterval]; [session connecttopeer:peerid withtimeout:kconnectiontimeout]; break; } case gkpeerstateunavailable: { nslog(@"didchangestate: peer %@ unavailable", [session displaynameforpeer:peerid]); break; } case gkpeerstateconnected: { nslog(@"didchangestate: peer %@ connected", [session displaynameforpeer:peerid]); break; } case gkpeerstatedisconnected: { nslog(@"didchangestate: peer %@ disconnected", [session displaynameforpeer:peerid]); break; } case gkpeerstateconnecting: { nslog(@"didchangestate: peer %@ connecting", [session displaynameforpeer:peerid]); break; } } [self.tableview reloaddata]; } - (void)session:(gksession *)session didreceiveconnectionrequestfrompeer:(nsstring *)peerid { nslog(@"didreceiveconnectionrequestfrompeer: %@", [session displaynameforpeer:peerid]); [session acceptconnectionfrompeer:peerid error:nil]; [self.tableview reloaddata]; } - (void)session:(gksession *)session connectionwithpeerfailed:(nsstring *)peerid witherror:(nserror *)error { nslog(@"connectionwithpeerfailed: peer: %@, error: %@", [session displaynameforpeer:peerid], error); [self.tableview reloaddata]; } - (void)session:(gksession *)session didfailwitherror:(nserror *)error { nslog(@"didfailwitherror: error: %@", error); [session disconnectfromallpeers]; [self.tableview reloaddata]; } #pragma mark - uitableviewdatasource protocol conformance - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // have 5 sections in our grouped table view, // 1 each gkpeerconnectionstate return 3; } - (nsinteger)tableview:(uitableview *)table numberofrowsinsection:(nsinteger)section { nsinteger rows; nsinteger peerconnectionstate = section; switch (peerconnectionstate) { case gkpeerstateavailable: { nsarray *availablepeers = [gksession peerswithconnectionstate:gkpeerstateavailable]; rows = availablepeers.count; break; } case gkpeerstateconnected: { nsarray *connectedpeers = [gksession peerswithconnectionstate:gkpeerstateconnected]; rows = connectedpeers.count; break; } case gkpeerstateunavailable: { nsarray *unavailablepeers = [gksession peerswithconnectionstate:gkpeerstateunavailable]; rows = unavailablepeers.count; break; } } // show @ least 1 row each gkpeerconnectionstate. if (rows < 1) { rows = 1; } return rows; } - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section { nsstring *headertitle = nil; nsinteger peerconnectionstate = section; switch (peerconnectionstate) { case gkpeerstateavailable: { headertitle = @"available peers"; break; } case gkpeerstateconnected: { headertitle = @"connected peers"; break; } case gkpeerstateunavailable: { headertitle = @"unavailable peers"; break; } } return headertitle; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsstring * cellid = @"cell"; uitableviewcell * cell = [tableview dequeuereusablecellwithidentifier:cellid]; if(!cell){ cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellid]; } nsinteger peerconnectionstate = indexpath.section; nsarray *peers = nil; switch (peerconnectionstate) { case gkpeerstateavailable: { peers = [gksession peerswithconnectionstate:gkpeerstateavailable]; break; } case gkpeerstateconnected: { peers = [gksession peerswithconnectionstate:gkpeerstateconnected]; break; } case gkpeerstateunavailable: { peers = [gksession peerswithconnectionstate:gkpeerstateunavailable]; break; } } nsinteger peerindex = indexpath.row; if ((peers.count > 0) && (peerindex < peers.count)) { nsstring *peerid = [peers objectatindex:peerindex]; if (peerid) { cell.textlabel.text = [gksession displaynameforpeer:peerid]; } } return cell; } @end
now have no idea how proceed.could please me out??by selecting song can played on device??
gamekit meant inter-device games. this, you'd want @ cbperipheralmanager or cbcentralmanager depending on device you're interacting with. it's lower level, you'll have more work set connection, there's tons of tutorials , sample code out.
Comments
Post a Comment