n1mda / sonos-objc Goto Github PK
View Code? Open in Web Editor NEWAn Objective-C API for controlling Sonos Devices
License: MIT License
An Objective-C API for controlling Sonos Devices
License: MIT License
Hi @n1mda,
I am willing to use this SDK to play the songs from my clients streaming server, Is it possible with using SDK.
Thanks
Since AFNetworking
is used to execute a simple HTTP GET, I suggest to remove any dependencies of AFNetworking and replacing it with NSURLConnection
:
(SonosController.m)
- (void)upnp:(NSString *)url soap_service:(NSString *)soap_service soap_action:(NSString *)soap_action soap_arguments:(NSString *)soap_arguments completion:(void (^)(NSDictionary *, NSError *))block {
like
// Set Body
[request setHTTPBody:[post_xml dataUsingEncoding:NSUTF8StringEncoding]];
[self getRequest:request completionBlock:^(NSData *responseObject, NSError *error) {
if(responseObject) {
NSDictionary *response = [XMLReader dictionaryForXMLData:responseObject error:nil];
block(response, nil);
} else {
if(block) block(nil, error);
}
}];
where
- (void)getRequest:(NSURLRequest *)request completionBlock:(void (^)(NSData *data, NSError *error))completionBlock
{
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
completionBlock(data,error);
}];
}
I got crash on
int minutes = [[times objectAtIndex:1] intValue] * 60;
Fatal Exception: NSRangeException
*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]
Hello,
I am facing a crash on line 401 of SonosController.m. I am not doing anything special to get this crash. I guess it comes directly from the sharedInstance that initializes the devices.
So it crashes on:
NSDictionary *returnData = @{@"CurrentTransportState" : response[@"s:Envelope"][@"s:Body"][@"u:GetTransportInfoResponse"][@"CurrentTransportState"][@"text"]};
It crashes because 'response' is nil.
Martin
I have a Sonos Play:1 on the same WiFi network.
I registered the observer and waited for changes, but nothing happened:
Code snippet:
-(IBAction)discover:(id)sender {
[[SonosManager sharedInstance] addObserver:self forKeyPath:@"allDevices" options:NSKeyValueObservingOptionNew context:NULL];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
SonosController *controller = [[SonosManager sharedInstance] currentDevice];
[controller trackInfo:^(NSString *artist, NSString *title, NSString *album, NSURL *albumArt, NSInteger time, NSInteger duration, NSInteger queueIndex, NSString *trackURI, NSString *protocol, NSError *error){
NSLog(@"Artist: %@", artist);
NSLog(@"Title: %@", title);
NSLog(@"Album: %@", album);
NSLog(@"Album Art: %@", albumArt);
NSLog(@"Time: %d", (int)time);
NSLog(@"Duration: %d", (int)duration);
NSLog(@"Place in queue: %d", (int)queueIndex);
NSLog(@"Track URI: %@", trackURI);
NSLog(@"Protocol: %@", protocol);
}];
}
I can see the Sonos PLAY:1 from the Sonos app and from DLNA compatible devices.
The newest version according to cocoapods.org is 0.1.1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.