Commit e564db69 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

MacOSX/Framework/Example: Initial creation of a nice application that does iPod exporting.

parent 836f9311
/* Controller */
#import <Cocoa/Cocoa.h>
#import <VLCKit/VLCKit.h>
#import <VLCKit/VLCMediaPlayer.h>
@interface Controller : NSObject
{
IBOutlet NSView * conversionView;
IBOutlet NSWindow * window;
IBOutlet NSButton * openConvertedFileButton;
NSNumber * selectedStreamOutput;
VLCMedia * media;
VLCStreamSession * streamSession;
}
- (void)awakeFromNib;
@property (retain) VLCMedia * media;
@property (retain) VLCStreamSession * streamSession;
@property (assign) NSNumber * selectedStreamOutput;
@property (retain,readonly) NSString * outputFilePath;
- (IBAction)convert:(id)sender;
- (IBAction)openConvertedFile:(id)sender;
- (IBAction)openConvertedEnclosingFolder:(id)sender;
@end
#import "Controller.h"
/**********************************************************
* First off, some value transformer to easily play with
* bindings
*/
@interface VLCFloat10000FoldTransformer : NSObject
@end
@implementation VLCFloat10000FoldTransformer
+ (Class)transformedValueClass
{
return [NSNumber class];
}
+ (BOOL)allowsReverseTransformation
{
return YES;
}
- (id)transformedValue:(id)value
{
if( !value ) return nil;
if(![value respondsToSelector: @selector(floatValue)])
{
[NSException raise: NSInternalInconsistencyException
format: @"Value (%@) does not respond to -floatValue.",
[value class]];
return nil;
}
return [NSNumber numberWithFloat: [value floatValue]*10000.];
}
- (id)reverseTransformedValue:(id)value
{
if( !value ) return nil;
if(![value respondsToSelector: @selector(floatValue)])
{
[NSException raise: NSInternalInconsistencyException
format: @"Value (%@) does not respond to -floatValue.",
[value class]];
return nil;
}
return [NSNumber numberWithFloat: [value floatValue]/10000.];
}
@end
/**********************************************************
* @implementation Controller
*/
@implementation Controller
- (id)init
{
if(self = [super init])
{
VLCFloat10000FoldTransformer *float100fold;
float100fold = [[[VLCFloat10000FoldTransformer alloc] init] autorelease];
[NSValueTransformer setValueTransformer:(id)float100fold forName:@"Float10000FoldTransformer"];
self.media = nil;
self.streamSession = nil;
selectedStreamOutput = [[NSNumber alloc] initWithInt:0];
}
return self;
}
@synthesize streamSession;
@synthesize selectedStreamOutput;
- (void)awakeFromNib
{
[window setShowsResizeIndicator:NO];
[NSApp setDelegate: self];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[VLCLibrary sharedLibrary];
}
- (VLCMedia *)media
{
return media;
}
- (void)setMedia:(VLCMedia *)newMedia
{
[media release];
media = [newMedia retain];
NSRect newFrame = [window frameRectForContentRect:[conversionView frame]];
[[window animator] setFrame:NSMakeRect([window frame].origin.x, [window frame].origin.y+NSHeight([window frame])-NSHeight(newFrame), NSWidth(newFrame), NSHeight(newFrame)) display:YES];
[[window animator] setContentView:conversionView];
[window setMinSize:newFrame.size];
[window setMaxSize:NSMakeSize(10000., NSHeight(newFrame))];
[window setShowsResizeIndicator:YES];
}
+ (NSSet *)keyPathsForValuesAffectingOutputFilePath
{
return [NSSet setWithObjects:@"media.metaDictionary.title", nil];
}
- (NSString *)outputFilePath
{
return [NSString stringWithFormat:[@"~/Movies/iPod Converted/%@.mp4" stringByExpandingTildeInPath],
[[self.media metaDictionary] objectForKey:@"title"]];
}
- (IBAction)convert:(id)sender
{
self.streamSession = [VLCStreamSession streamSession];
if([selectedStreamOutput intValue] == 0)
{
[self.streamSession setStreamOutput:
[VLCStreamOutput ipodStreamOutputWithFilePath:
[self outputFilePath]
]];
}
else
{
/* This doesn't really is useful for the iPod/iPhone...
* But one day we'll figure that out */
NSRunAlertPanelRelativeToWindow(@"Warning", @"We can't really stream to the iPod/iPhone for now...\n\nSo we're just streaming using the RTP protocol, and annoucing it via SAP.\n\n(Launch the SAP VLC service discovery module to see it).", @"OK", nil, nil, window);
[self.streamSession setStreamOutput:
[VLCStreamOutput rtpBroadcastStreamOutput]];
}
NSLog(@"Using %@", self.streamSession.streamOutput );
[self.streamSession setMedia:self.media];
[self.streamSession startStreaming];
[openConvertedFileButton setImage:[[NSWorkspace sharedWorkspace] iconForFile:[self outputFilePath]]];
}
- (IBAction)openConvertedFile:(id)sender
{
[[NSWorkspace sharedWorkspace] openFile:[self outputFilePath]];
}
- (IBAction)openConvertedEnclosingFolder:(id)sender
{
[[NSWorkspace sharedWorkspace] openFile:[[self outputFilePath] stringByDeletingLastPathComponent]];
}
@end
<?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>IBClasses</key>
<array>
<dict>
<key>CLASS</key>
<string>GradientBackgroundView</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>SUPERCLASS</key>
<string>NSImageView</string>
</dict>
<dict>
<key>CLASS</key>
<string>FirstResponder</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
<dict>
<key>ACTIONS</key>
<dict>
<key>convert</key>
<string>id</string>
<key>openConvertedEnclosingFolder</key>
<string>id</string>
<key>openConvertedFile</key>
<string>id</string>
</dict>
<key>CLASS</key>
<string>Controller</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>OUTLETS</key>
<dict>
<key>conversionView</key>
<string>NSView</string>
<key>openConvertedFileButton</key>
<string>NSButton</string>
<key>window</key>
<string>NSWindow</string>
</dict>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
<dict>
<key>CLASS</key>
<string>MovieReceiver</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>OUTLETS</key>
<dict>
<key>controller</key>
<string>Controller</string>
</dict>
<key>SUPERCLASS</key>
<string>NSView</string>
</dict>
</array>
<key>IBVersion</key>
<string>1</string>
</dict>
</plist>
<?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>IBFramework Version</key>
<string>629</string>
<key>IBLastKnownRelativeProjectPath</key>
<string>../../iPodConverter.xcodeproj</string>
<key>IBOldestOS</key>
<integer>5</integer>
<key>IBOpenObjects</key>
<array>
<integer>317</integer>
</array>
<key>IBSystem Version</key>
<string>9B18</string>
<key>targetFramework</key>
<string>IBCocoaFramework</string>
</dict>
</plist>
//
// GradientBackgroundView.h
// iPodConverter
//
// Created by Pierre d'Herbemont on 1/12/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface GradientBackgroundView : NSImageView {
}
@end
//
// GradientBackgroundView.m
// iPodConverter
//
// Created by Pierre d'Herbemont on 1/12/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "GradientBackgroundView.h"
/**********************************************************
* Why not drawing something nice?
*/
@implementation GradientBackgroundView
- (void)awakeFromNib
{
/* Buggy nib files... Force us to be on the back of the view hierarchy */
NSView * superView;
[self retain];
superView = [self superview];
[self removeFromSuperview];
[superView addSubview:self positioned: NSWindowBelow relativeTo:nil];
}
- (void)drawRect:(NSRect)rect
{
NSColor * topGradient = [NSColor colorWithCalibratedWhite:.12f alpha:1.0];
NSColor * bottomGradient = [NSColor colorWithCalibratedWhite:0.55f alpha:0.9];
NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations:bottomGradient, 0.f, bottomGradient, 0.1f, topGradient, 1.f, nil];
[gradient drawInRect:self.bounds angle:90.0];
[super drawRect:rect];
}
@end
<?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>English</string>
<key>CFBundleExecutable</key>
<string>iPodConverter</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>org.videolan.ipodconverter</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>CFBundleVersion</key>
<string>1.0</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
//
// MovieReceiver.h
// iPodConverter
//
// Created by Pierre d'Herbemont on 1/12/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "Controller.h"
@interface MovieReceiver : NSView {
IBOutlet Controller * controller;
}
@end
//
// MovieReceiver.m
// iPodConverter
//
// Created by Pierre d'Herbemont on 1/12/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "MovieReceiver.h"
/**********************************************************
* This handles drag-and-drop in the main window
*/
@implementation MovieReceiver
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSURLPboardType, nil]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (NSDragOperation)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] )
{
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
for( NSString * filename in files )
{
[controller setMedia:[VLCMedia mediaWithPath:filename]];
}
}
return YES;
return NSDragOperationGeneric;
}
@end
//
// Prefix header for all source files of the 'test' target in the 'test' project
//
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
//
// main.m
// test
//
// Created by Pierre d'Herbemont on 13/04/07.
// Copyright __MyCompanyName__ 2007. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <VLCKit/VLCKit.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment