Call Encore now on +44 (0) 1273 722 544 or contact us
Monday 6th, February 2012

A small glitch in the new Xcode

Posted by Lenka on February 9, 2011

Those who downloaded Xcode 3.2.5 might experience a problem with updating their old projects. Each app that used an older base SDK needs its Info.plist changed to use the newest SDK. Previously, doing so worked but the 3.2.5 Xcode is not happy after you close the “Project Info” pane and keeps showing “Base SDK missing” message. Before you spend too much time googling what else needs to be done to have your project compile properly, just close it and open it again. All should be fine now.

UILabel size to fit text

Posted by Lenka on December 17, 2010

If you create your UI programatically for iOS (as is good practice), you might come across a problem with the UILabel: what size should it be to fit the text perfectly? You might get away with just making the label very large, but this will not work if you need to use the text size in some calculations later in your code.

To instantiate a UILabel with a fitting frame, you can do the following:

NSString * myText = [NSString stringWithString:@"some text"];
//get size of the text:
CGFloat constrainedSize = 265.0f; //or any other size
UIFont * myFont = [UIFont fontWithName:@"Arial" size:19]; //or any other font that matches what you will use in the UILabel
CGSize textSize = [myText sizeWithFont: myFont
                       constrainedToSize:CGSizeMake(constrainedSize, CGFLOAT_MAX)
                           lineBreakMode:UILineBreakModeWordWrap];

//create a label:
CGRect labelFrame = CGRectMake (0, 0, textSize.width, textSize.height);
UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
[label setFont:myFont];
[label setText:myText];
...
[label release];

Custom video player on the iPad / iPhone

Posted by Lenka on November 8, 2010

In Cocoa, you can use the MPMoviePlayerController to play .mov videos. The player controller provides you with standard video controls which are fine until you need to build something that is visually suitable for you application. Fortunately, you can hide the controls and build your own from scratch.

Play / Pause buttons

These buttons are pretty easy to make. As MPMoviePlayerController implements the MPMediaPlayback protocol, you can simply call MPMediaPlayback‘s:

- (void)play

and:

- (void)pause
Progress indicator A progress indicator can be built using a simple UISlider. To calculate its current value, you can use formula:
value = currentPlaybackTime / totalVideoTime;

The value needs to be updated every N milliseconds in a method e.g.:

- (void) monitorPlaybackTime
{
        self.progressIndicator.value = self.mpMoviePlayerController.currentPlaybackTime / self.totalVideoTime;
        //constantly keep checking if at the end of video:
        if (self.totalVideoTime != 0 && videoPlayer.currentPlaybackTime >= totalVideoTime - 0.1)
        {
             //-------- rewind code:
             self.mpMoviePlayerController.currentPlaybackTime = 0;
             [self.mpMoviePlayerController pause];
        }
        else
        {
             [self performSelector:@selector(monitorPlaybackTime) withObject:nil afterDelay:kVideoPlaybackUpdateTime];
        }
}

Apart from constantly updating the indicator, this method also solves a problem that a number of people reported: the video would not play for the second time once it got to the end. To solve this problem, you can constantly keep checking whether video is about to finish, in which case you rewind and pause it (the latter being non-compulsory action to do).

Where do you get the self.totalVideoTime value from? The total video time is not available immediately after the video has been instantiated. Therefore, you need to subscribe for the notification:

... [ video instantiating code ] ....
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleDurationAvailableNotification)
        name:MPMovieDurationAvailableNotification
        object:self.mpMoviePlayerController];

And then implement the handler method to save the video time and start playing the video (this method is usually called about a second or less after the video controller has been instantiated:

- (void) handleDurationAvailableNotification
{
       self.totalVideoTime = self.mpMoviePlayerController.duration;
       [self.mpMoviePlayerController.currentPlaybackTime = 0;
       [self.mpMoviePlayerController play];
}

Implementing a timeline control

We can use the same UISlider to be able to jump through the video. The method tied to the value change of the slider bar is really simple:

- (IBAction) onTimeSliderChange: (UISlider*)sender
{
       self.mpMoviePlayerController.currentPlaybackTime = totalVideoTime*timeLineSlider.value;
       [self monitorPlaybackTime];
}

Using of your own video controls gives you an absolute control of the playback and the UI. Among other things, you can provide a filtered amount of functionality and add effects that are not possible to do with the standard controls. Creating the controls from scratch is not that lengthy or difficult and shows users of your app that you care a bit more about their perfect experience.

Is it Xmas yet – iPhone?

Posted by Jethro Grassie on November 8, 2010

Well its that time of year fast approaching us again!

For all of you that are just not quite sure how many days are left to go and have an iPhone, we at Encore have created you the perfect solution.

Enjoy!


Is It Xmas Yet iPhone screenshot


View in iTunes


[hint: shake to reset!]

Just a flash in the pan then

Posted by Jethro Grassie on April 21, 2010

Just a quick follow-up to a post I made a while back iPhlash or just a flash in the pan.

Well as I suspected Apple were not going to let this happen blindly!
Mike Chambers has just announced Adobe will be removing this feature due to Apple’s latest SDK terms.

In fact what is almost humorous about this is that Apple have forced Adobe into removing this functionality just before Adobe publicly release their upcoming “give me another $1000″ (CS5).

Like what you see? Then get in touch;
t. +44 (0) 1273 722 544   e. contact us