Apple chief executive Steve Jobs was ordered by a U.S. judge to testify in an antitrust lawsuit that alleges the company prevented music files sold by competitors from playing on its iPods.

Jobs, who has been on medical leave from Apple since January, can be deposed for no more than two hours, according to the court order issued by U.S. Magistrate Judge Howard R. Lloyd in San Jose. Attorneys who filed the class-action complaint on behalf of consumers can ask him only about changes the company made to its software format, which made it impossible for ­iPods to play songs that were not from Apple’s iTunes store.

The court ruled that Jobs has “unique, non-repetitive, firsthand knowledge” of the issues and must testify. The magistrate denied requests from the plaintiffs to question Jobs on other matters related to the case.

After the success of the iTunes store, a company called RealNetworks created music files that could be played on the iPod without iTunes. Apple then reworked its software to keep RealNetworks’ songs and others off its devices.

Apple says the software change was ostensibly a measure against piracy. But plaintiffs contend that it allowed Apple to have dual monopolies in the markets for digital media players and audio downloads.

Sheldon Klein, a shareholder at Butzel Long who specializes in antitrust cases, said that it’s not unusual for chief executives to be called to testify, though plaintiffs must prove that the executive is the only one with knowledge of the issues in the case.

“Usually CEOs don’t have a lot of firsthand knowledge of the things that are in litigation and so if you’re representing the corporation, you’re arguing that this is just to harass the company and the CEO,” he said. “The magistrate judge very specifically found that Steve Jobs had specific knowledge and limited the subject of the deposition to that narrow scope where he was the best, if not the only, person to be able to testify to it.”

Apple spokeswoman Kristin Huguet declined to comment on ongoing litigation.

Apple is also involved in a legal tussle over the name of the Amazon’s newly launched Appstore for Android.

Apple won approval to trademark the name “App Store,” but Microsoft has challenged the trademark on the grounds that it is too generic. “We’ve asked Amazon not to copy the App Store name because it will confuse and mislead customers,” Huguet said.

Amazon spokeswoman Mary Osako said it is Amazon policy not to comment on pending litigation.

Apple has a good chance of defending its trademark, said Mitchell J. Weinstein, the head of the intellectual property group at Levenfeld and Pearlstein in Chicago.

“In the short period of time Apple has been using this [trademark], it’s built so much power and recognition,” he said. “Frankly, my opinion is that Amazon is just trying to ride on the coattails of what Apple has built through the App Store.”