Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
nto committed Jan 18, 2011
0 parents commit bcbd956
Show file tree
Hide file tree
Showing 72 changed files with 19,175 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
/build/
/*.xcodeproj/
!/*.xcodeproj/project.pbxproj
62 changes: 62 additions & 0 deletions AirView-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleDocumentTypes</key>
<array/>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIconFiles</key>
<array>
<string>AirView iPhone Icon.png</string>
<string>AirView iPhone Retina Icon.png</string>
<string>AirView iPad Icon.png</string>
</array>
<key>CFBundleIdentifier</key>
<string>com.github.nto.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array/>
<key>CFBundleVersion</key>
<string>0.9</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow_iPhone</string>
<key>NSMainNibFile~ipad</key>
<string>MainWindow_iPad</string>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UTExportedTypeDeclarations</key>
<array/>
<key>UTImportedTypeDeclarations</key>
<array/>
</dict>
</plist>
14 changes: 14 additions & 0 deletions AirView-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Prefix header for all source files of the 'AirView' target in the 'AirView' project
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
16 changes: 16 additions & 0 deletions AirView-main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AirView-main.m
// AirView
//
// Created by Clément Vasseur on 12/18/10.
// Copyright 2010 Clément Vasseur. All rights reserved.
//

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
634 changes: 634 additions & 0 deletions AirView.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions Classes/AirPlayController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// AirPlayController.h
// AirView
//
// Created by Clément Vasseur on 12/16/10.
// Copyright 2010 Clément Vasseur. All rights reserved.
//

#import <UiKit/UIWindow.h>
#import <MediaPlayer/MPMoviePlayerController.h>
#import <MediaPlayer/MPMoviePlayerViewController.h>
#import "AirPlayHTTPServer.h"

@interface AirPlayController : NSObject {
AirPlayHTTPServer *httpServer;
MPMoviePlayerViewController *playerView;
MPMoviePlayerController *player;
UIWindow *window;
}

- (id)initWithWindow:(UIView *)uiWindow;
- (void)startServer;
- (void)stopServer;
- (void)stopPlayer;
- (void)play:(NSURL *)location atPosition:(NSTimeInterval)position;
- (void)stop;
- (void)setPosition:(float)position;
- (float)position;
- (void)setRate:(float)value;
- (NSTimeInterval)duration;
- (void)dealloc;

@end
185 changes: 185 additions & 0 deletions Classes/AirPlayController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
//
// AirPlayController.m
// AirView
//
// Created by Clément Vasseur on 12/16/10.
// Copyright 2010 Clément Vasseur. All rights reserved.
//

#import "AirPlayController.h"
#import "AirPlayHTTPConnection.h"
#import "DeviceInfo.h"
#import "DDLog.h"

// Log levels: off, error, warn, info, verbose
static const int ddLogLevel = LOG_LEVEL_INFO;

@implementation AirPlayController

- (id)initWithWindow:(UIWindow *)uiWindow
{
if ((self = [super init])) {
window = uiWindow;

DDLogVerbose(@"AirPlayController: init");

// Create server using our custom AirPlayHTTPServer class
httpServer = [[AirPlayHTTPServer alloc] init];
httpServer.airplay = self;

// Tell the server to broadcast its presence via Bonjour.
[httpServer setType:@"_airplay._tcp."];
[httpServer setTXTRecordDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
@"0x7", @"features",
[DeviceInfo platform], @"model",
[DeviceInfo deviceId], @"deviceid",
nil]];

// We're going to extend the base HTTPConnection class with our AirPlayHTTPConnection class.
[httpServer setConnectionClass:[AirPlayHTTPConnection class]];

// Set a dummy document root
[httpServer setDocumentRoot:@"/dummy"];

// [httpServer setPort:7000];

playerView = [[MPMoviePlayerViewController alloc] initWithContentURL:nil];
player = playerView.moviePlayer;
}

return self;
}

- (void)startServer
{
NSError *error;

DDLogVerbose(@"AirPlayController: startServer");

// Start the server (and check for problems)
if(![httpServer start:&error])
DDLogError(@"Error starting HTTP Server: %@", error);
}

- (void)stopServer
{
DDLogVerbose(@"AirPlayController: stopServer");

[httpServer stop];
}

- (void)play:(NSURL *)location atPosition:(NSTimeInterval)position
{
DDLogVerbose(@"AirPlayController: play %@", location);

dispatch_async(dispatch_get_main_queue(), ^{
if (playerView == nil) {
playerView = [[MPMoviePlayerViewController alloc] initWithContentURL:location];
player = playerView.moviePlayer;
} else {
[player setContentURL:location];
}
// if (position > 0) {
// DDLogVerbose(@"AirPlayController: set initial playback time to %f", position);
// player.initialPlaybackTime = position;
// }
[window addSubview:playerView.view];
player.fullscreen = YES;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];

[player play];
});
}

- (void)movieFinishedCallback:(NSNotification *)notification
{
DDLogVerbose(@"AirPlayController: movie finished");

[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:[notification object]];

[self stopPlayer];
}

- (void)stopPlayer
{
DDLogVerbose(@"AirPlayController: stop player");

[playerView.view removeFromSuperview];
[player stop];
player.initialPlaybackTime = 0;
}

- (void)stop
{
DDLogVerbose(@"AirPlayController: stop");

dispatch_sync(dispatch_get_main_queue(), ^{
[self stopPlayer];
});
}

- (void)setPosition:(float)position
{
DDLogVerbose(@"AirPlayController: set position %f", position);

dispatch_async(dispatch_get_main_queue(), ^{
if (player.playbackState == MPMoviePlaybackStateStopped)
player.initialPlaybackTime = position;
else
player.currentPlaybackTime = position;
});
}

- (float)position
{
__block float position;

if (player == nil)
return 0;

dispatch_sync(dispatch_get_main_queue(), ^{
position = player.currentPlaybackTime;
});

return position;
}

- (NSTimeInterval)duration
{
__block NSTimeInterval duration;

if (player == nil)
return 0;

dispatch_sync(dispatch_get_main_queue(), ^{
duration = player.duration;
});

return duration;
}

- (void)setRate:(float)value
{
DDLogVerbose(@"AirPlayController: rate %f", value);

dispatch_async(dispatch_get_main_queue(), ^{
player.currentPlaybackRate = value;
});
}

- (void)dealloc
{
DDLogVerbose(@"AirPlayController: release");

[playerView release];
[httpServer release];
[super dealloc];
}

@end
27 changes: 27 additions & 0 deletions Classes/AirPlayHTTPConnection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// AirPlayHTTPConnection.h
// AirView
//
// Created by Clément Vasseur on 12/15/10.
// Copyright 2010 Clément Vasseur. All rights reserved.
//

#import "HTTPConnection.h"
#import "AirPlayController.h"

@interface AirPlayHTTPConfig : HTTPConfig {
AirPlayController *airplay;
}

- (id)initWithServer:(HTTPServer *)server documentRoot:(NSString *)documentRoot queue:(dispatch_queue_t)q airplay:(AirPlayController *)airplay;

@property (nonatomic, readonly) AirPlayController *airplay;

@end

@interface AirPlayHTTPConnection : HTTPConnection {
}

- (AirPlayController *)airplay;

@end
Loading

0 comments on commit bcbd956

Please sign in to comment.