...
In the following example, the adapter has been implemented for the media player
from the standard API.
Code Block |
---|
// // KMA_MediaPlayerAdapter.m // KMA_SpringStreams // // Created by Frank Kammann on 26.08.11. // Copyright 2011 spring GmbH & Co. KG. All rights reserved. // #import <MediaPlayer/MediaPlayer.h> #import <UIKit/UIKit.h> #import "KMA_SpringStreams.h" @class MediaPlayerMeta; @implementation MediaPlayerAdapter MPMoviePlayerController"KMA_SpringStreams.h" /** * Implementation of a KMA_StreamAdapter. * * @see KMA_StreamAdapter */ @implementation KMA_MediaPlayerAdapter AVPlayerViewController *controller; NSObject<Meta>KMA_Player_Meta *meta; - (id)adapter:(MPMoviePlayerController/** *)player {Initialize the adapter with the selfMPMoviePlayerController = [super init:player]; if (self) { meta = [[MediaPlayerMeta alloc] meta:player];* * @see http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html * */ - (KMA_MediaPlayerAdapter*)adapter:(AVPlayerViewController *)player { } //if (self) { return self; } - (NSObject<Meta>*) getMeta { return meta; } - (int) getPosition meta = [[KMA_Player_Meta alloc] init]; meta.playername = @"AVPlayerViewController"; controller = player; //} return [super init]; } /** * Returns the meta object. * * @see MediaPlayerMeta */ - (KMA_Player_Meta*) getMeta { return meta; } /** * Returns the current position on the KMA_Stream in seconds by calling * the method MPMediaPlayback.currentPlaybackTime * * @see http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMediaPlayback_protocol/Reference/Reference.html#//apple_ref/occ/intf/MPMediaPlayback# */ - (int) getPosition { int position = CMTimeGetSeconds(controller.player.currentItem.currentTime); // in initialize phase in controller this value is set to -2^31 if(position < 0) position = 0; return position; } /** * Returns the duration of the KMA_Stream in seconds by calling * the method MPMediaPlayback.duration. * */ - (int) getDuration { return CMTimeGetSeconds(controller.player.currentItem.duration); } /** * Returns the width by the controller view. * * @return contoller.view.bound.size.width */ - (int) getWidth { return controller.view.bounds.size.width; } /** * Returns the height by the controller view. * * @return contoller.view.bound.size.height */ - (int) getHeight { return controller.view.bounds.size.height; } @end @implementation KMA_Player_Meta /** * Returns the player name * * @return the string "MediaPlayer" */ @synthesize playername; /** * Returns the player version. * The itselfs has no version so the system version is delivered. * * @see http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html * * @return The version my calling [UIDevice currentDevice].systemVersion */ @synthesize playerversion; /** * Returns the screen width my calling the method * [[UIScreen mainScreen] bounds].screenRect.size.width * * @see http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html * * @return the width */ @synthesize screenwidth; /** * Returns the screen width my calling the method * [[UIScreen mainScreen] bounds].screenRect.size.height * * @see http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html * * @return the height */ @synthesize screenheight; - (id) init { intself position = (int)round([controllersuper currentPlaybackTimeinit]); if (self) { // in initialize phase in controller this valueself.playername is= set to -2^31@"iOS Player"; if(position < 0) positionself.playerversion = 0;[UIDevice currentDevice].systemVersion; return position; } - (int) getDuration { CGRect screenRect return (int)round([controller duration]); } - (int) getWidth {= [[UIScreen mainScreen] bounds]; return controller.view.bounds.self.screenwidth = screenRect.size.width; } - (int) getHeight { self.screenheight return controller.view.bounds= screenRect.size.height; } return self; } - (id) copyWithZone:(voidNSZone *)dealloczone { id copy = [meta release];[[self class] alloc] init]; [super dealloc]; }if (copy) { @end @implementation MediaPlayerMeta MPMoviePlayerController *controller;// Copy -NSObject (id) meta:(MPMoviePlayerController *)player {subclasses self =[copy setPlayername:[super initself.playername copyWithZone:zone]]; if (self) { [copy setPlayerversion:[self.playerversion copyWithZone:zone]]; if(player == nil) // Set @throw [NSException exceptionWithName:@"IllegalArgumentException"primitives [copy setScreenwidth:self.screenwidth]; [copy setScreenheight:self.screenheight]; } return copy; } - (NSString *)description { return [NSString reasonstringWithFormat:@"playerMeta may not be null" pl=%@ plv=%@ sx=%ld sy=%ld", self.playername, self.playerversion, userInfo:nil]; (long)self.screenwidth, controller = player; (long)self.screenheight]; } - (void)encodeWithCoder:(NSCoder *)encoder return{ self; } - (NSString*) getPlayerName {[encoder encodeObject:self.playername forKey:@"playername"]; return [encoder encodeObject:self.playerversion forKey:@"MediaPlayerplayerversion"]; } - (NSString*) getPlayerVersion { [encoder encodeInt:self.screenwidth forKey:@"screenwidth"]; return [UIDevice currentDevice].systemVersion[encoder encodeInt:self.screenheight forKey:@"screenheight"]; } - (intid) getScreenWidthinitWithCoder:(NSCoder *)decoder { CGRectself.playername screenRect = [[UIScreen mainScreen] boundsdecoder decodeObjectForKey:@"playername"]; self.playerversion = [decoder decodeObjectForKey:@"playerversion"]; return screenRect.size.width; } - (int) getScreenHeight { CGRect screenRectself.screenwidth = [decoder decodeIntForKey:@"screenwidth"]; self.screenheight = [[UIScreen mainScreen] bounds]decoder decodeIntForKey:@"screenheight"]; return screenRect.size.heightself; } @end |
Implementation of the URL Scheme in iOS
...