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

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!]


Weekly tech ramblings

Posted by Jethro Grassie on November 2, 2010

Well its been another busy week or two of heated tech ramblings in the office.

Hottest discussion was probably Apple “deprecating” Java in OS X.

Apple's Java coffee cup

There was no surprise here really. Apple have been slow to keep the Apple built JRE (Java Runtime Environment) up-to-date. Anyone remember how long it took them to update to Java 6?! But the big questions were ‘Why?’ and ‘Where does this leave Java desktop apps on OS X?’

I think the ‘Why?’ comes down to the typical Jobsian control factor. If you look at the App Store model and lock-down of development of iPhone and iPad applications, no surprise Apple would want to start locking down technologies on their desktop platform really.

The more important question is where it leaves Java apps in OS X. There is still after all the OpenJDK project which has superb support for many platforms – including OS X. The single biggest issue however is the GUI implementation. This is based on the X windowing system under OpenJDK and quite frankly, under OS X these windows look awful and integrate very poorly into the rest of the OS X windowing system – Aqua. The problem for OpenJDK, as Apple have always kept the Aqua windowing system closed source, is its never going to be an easy or desirable option to integrate directly with it. In fact it would be a huge effort. Yet without that level of core integration (things like window behaviour, key-bindings, localisation etc), Java apps running on OS X will look and feel very dated compared to more standard (eg Cocoa developed) apps. There have already been calls from the community to Apple asking [pleading] for them to release the Apple developed JRE. No replies as yet and I wouldn’t hold my breath either.

Another hot topic has been the notice from Adobe they will be closing the source for the latest and greatest version of the Flex SDK for an estimated 2 release versions.

Flex closed source

Consensus in the Encore dev team is that this is simply a means to hide the prototype [crappy] code the Adobe “developers” have rushed out in the Flex 4.5 “HERO” SDK (which includes lots of features targeting mobile devices among other things) in time for the Adobe MAX conference. Reasons cited were the release cycle of the player runtimes and burdensome patch submission process. The latter particularly odd given that Adobe need as much help as possible fixing their flaky code!

Lastly much discussion around some up-and-coming cross-device/platform frameworks for native mobile applications. My personal favourite is libnui. But thats for another post (when I can get it building on my PowerPC Gentoo box!).

libnui logo

Refresh

Posted by Jethro Grassie on October 14, 2010

Luckily we have been very busy over the last 6 months.
Unluckily this means there have been very few site/blog updates!

We have now managed to take a little time to publicise a few things that have been happening here as there have been quite a few changes implemented in our organisation.

A few months ago the board was restructured and now it consist solely of Billy Johal and myself, Jethro Grassie, both directors and between us, now the full share-holders of the company. This streamlining has enabled us to achieve a much stronger direction and focus of the business, which in turn has led to the massive growth in both revenue and staff levels.

In terms of our technical resource capability, we have also slightly restructured the development team and refined our practices to help facilitate all this growth and achieve a high standard of software being developed.

One aspect I am particularly pleased with is the adoption of our new testing suite. We now have all code run under continuous integration testing and also have automated functionality testing implemented across a number of platforms and browsers. This of course does not negate the need for real human testing but it does help us find software defects early in the development cycle and also in turn yields a higher quality output.

Another aspect I am very proud of is that of our dedicated R&D time. This enables us to stay right at the forefront of technology whilst also having the benefit of creating some very cool and interesting software products. More on some of these very soon.


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