Skip to content

Instantly share code, notes, and snippets.

@zapsleep
zapsleep / UIKitScreenShot
Created December 7, 2012 13:15
UIKit screenshot snippet
- (UIImage*)screenshotFromView:(UIView *)view
{
CGSize imageSize = [view bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
@zapsleep
zapsleep / OpentGLESScreenShot.m
Created December 7, 2012 13:18
OpenGL ES Scene Screenshot snippet
- (UIImage*)snapshot:(UIView*)eaglview
{
GLint backingWidth, backingHeight;
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _colorRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES,
GL_RENDERBUFFER_WIDTH_OES,
&backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES,
GL_RENDERBUFFER_HEIGHT_OES,
@zapsleep
zapsleep / cameraVideoScreenShot.m
Created December 7, 2012 13:20
AVFoundation Camera ScreenShot snippet
- (void)setupCaptureSession
{
NSError *error = nil;
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;
AVCaptureDevice *device = [AVCaptureDevice
defaultDeviceWithMediaType:AVMediaTypeVideo];
@zapsleep
zapsleep / AVAssetImageGenScreenShot.m
Created December 7, 2012 13:40
Getting a screenshot with AVAssetImageGenerator
- (UIImage *)screenshotFromFileURL:(NSURL *)url {
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url];
AVURLAsset *asset = (AVURLAsset *)item.asset;
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]
initWithAsset:asset];
CGImageRef thumb = [imageGenerator
copyCGImageAtTime:CMTimeMakeWithSeconds(10.0, 1.0)
actualTime:NULL
error:NULL];
- (CVImageBufferRef)getImageBufferFromURL:(NSURL *)url {
AVAsset *asset = [AVAsset assetWithURL:url];
AVAssetTrack *track = [[asset
tracksWithMediaType:AVMediaTypeVideo]
objectAtIndex:0];
AVAssetReaderTrackOutput
*readerTrack = [AVAssetReaderTrackOutput
assetReaderTrackOutputWithTrack:track
outputSettings:nil];
AVAssetReader *reader = [AVAssetReader assetReaderWithAsset:asset
@zapsleep
zapsleep / AirPlayButtonAdd.mm
Created December 13, 2012 07:36
AirPlay button adding to player's interface
-(void)addAirPlayButtonToPlayerView:(UIView *)playerView {
//change the rectForAirPlay below to whatever you need
MPVolumeView *airPlayButton = [[MPVolumeView alloc]
initWithFrame:rectForAirPlay];
airPlayButton.showsVolumeSlider = NO;
[playerView addSubview:airPlayButton];
}
@zapsleep
zapsleep / AirPlayButtonRef.mm
Created December 13, 2012 07:47
Obtain a reference to AirPlay button
- (UIButton *)getButtonFromVolumeView:(MPVolumeView *)volumeView {
UIButton *button;
for (button in volumeView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
break;
}
return button;
}
@zapsleep
zapsleep / AirPlayButtonAlpha.mm
Created December 13, 2012 07:57
Observe AirPlay button's alpha
//setting the observer
-(void)observeAirPlayFromView:(MPVolumeView *)voluemView {
for (UIButton *button in volumeView.subviews) {
if([button isKindOfClass:[UIButton class]]) {
[button addObserver:self
forKeyPath:@"alpha"
options:NSKeyValueObservingOptionNew
context:nil];
}
}
@zapsleep
zapsleep / CheckScreensMirroring.mm
Created December 13, 2012 08:01
Check multiple screens and mirroring
for (UIScreen *screen in [UIScreen screens])
{
if ([screen respondsToSelector:@selector(mirroredScreen)] &&
[screen mirroredScreen] == [UIScreen mainScreen])
{
// The main screen is being mirrored.
}
else
{
// The main screen is not being mirrored, or
@zapsleep
zapsleep / ScreenNotify.mm
Created December 13, 2012 08:04
Obtain notifies of connecting and disconnecting screens
//setting notifiers
- (void)setupScreenConnectionNotificationHandlers {
NSNotificationCenter* center = [NSNotificationCenter
defaultCenter];
[center addObserver:self selector:@selector(
handleScreenConnect:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(
handleScreenDisconnect:)