The 73-year-old screen legend wasn't a fan of the 31-year-old actor's choice of music when they were in the make-up trailer together, so had to find a compromise which worked for them both.
McKellen told Empire magazine: 'We brokered a deal, where he could have 15 minutes of music, then I could have 15 minutes of no music.'
The star had a great time reprising his role as Gandalf the wizard for the movie - a prequel to the 'Lord of the Rings' trilogy - but admits some of the modern shooting techniques left him in tears.
In the film, Gandalf is a huge man and in order to make the scenes with the diminutive hobbits and dwarves look convincing McKellen had to film his scenes on his own, and the process depressed him.
He said: 'In order to shoot the dwarves and a large Gandalf we couldn't be in the same set. So they were all in one and I was all alone in a different green screen. All I had for company were 13 photographs of the dwarves, on top of stands, with little lights - whoever's talking flashes up.
'Pretending you're with 13 other people when you're on your own, it stretches your technical ability to the absolute limits. And I cried, actually. I cried. Then I said out loud, 'This is not why I became an actor.' Unfortunately the microphone was on, so and the whole studio heard.'
The first instalment of the new trilogy, 'The Hobbit: An Unexpected Journey', is in cinemas this December and also stars Martin Freeman as Bilbo Baggins, Orlando Bloom as Elven Prince Legolas and Richard Armitage as dwarf leader Thorin Oakenshield.