After we broke the story last week that Apple was acquiring London-based music and image recognition service Shazam, Apple confirmed the news today. It is purchasing the startup — one of earliest players in the world of mobile music — as part of its bigger ambitions in the music business.

Here is the statement that Apple provided us.

“We are thrilled that Shazam and its talented team will be joining Apple. Since the launch of the App Store, Shazam has consistently ranked as one of the most popular apps for iOS. Today, it’s used by hundreds of millions of people around the world, across multiple platforms. Apple Music and Shazam are a natural fit, sharing a passion for music discovery and delivering great music experiences to our users. We have exciting plans in store, and we look forward to combining with Shazam upon approval of today’s agreement.”

Apple did not disclose the price but we have several sources that have confirmed to us that the deal is in the region of $400 million.

Sources also tell us that Apple’s deal had been in the works for about five months and came after Shazam had been in talks with others, including Snapchat and Spotify.

Apple generally does not spell out the details of how it plans to use acquisitions, but there are a number of areas where Shazam’s current business overlaps with that of Apple’s, making for an interesting range of possibilities for where and how the two will work together.

Shazam’s core business is in music recognition: people use its app to capture a clip of music that is playing, and then it matches that against its large database to tell you what you are listening to, a business that has brought the company over 1 billion downloads of its app to date.

Over the years Shazam has augmented this with a number of other services: it sends users through to other sites to download and listen to the music at their leisure; it provides more information to users about the music and the artists behind it; it keeps charts of popular music based on the clips that it hears and that people want to identify. It’s also branched out into more marketing services based on visual recognition — essentially augmented reality plays where users can capture snaps of images that lead them to more content from a brand or another organization.

Through all of this, Shazam has developed some interesting partnerships, specifically with Apple and Spotify (who together get around 1 million referrals each month via Shazam), and Snapchat, which currently has an integration with Shazam where Snapchat users can “recognize music, engage with Shazam content, and send their music and artist discoveries as Snaps to their friends.” It is no surprise that these are also the three names that we heard were all approached and discussed an acquisition of the startup.

Shazam provided us with the below statement.

“We are excited to announce that Shazam has entered into an agreement to become part of Apple. Shazam is one of the highest rated apps in the world and loved by hundreds of millions of users and we can’t imagine a better home for Shazam to enable us to continue innovating and delivering magic for our users.”

Notably, Shazam had a post-money valuation in its last round of over $1 billion — a far cry from the roughly $400 million that is being paid by Apple. The reason for this, one source says, is that for all of Shazam’s popularity and move into revenue-generating areas like marketing, the company never really found a solid business model for the long-term future.

“Shazam should have moved into streaming music years ago,” the source said, “which is one reason why the Apple deal makes so much sense.” Spotify, as a point of comparison, has healthy recurring revenues from subscriptions and Apple Music has both subscriptions and downloads — not to mention the wider use of Apple Music and the ecosystem pull it gives Apple for its wider hardware business. That hints at some interesting integrations coming up.

Some backstory about how the deal got done between the two:

Apple and Shazam have had a friendly relationship for years, but the catalyst was that pending bid from Snap. As Recode first reported, the Snapchat parent had entertained buying the company.

It turns out that the conversations with Snap began about six months ago, after advisor Goldman Sachs drummed up interest. Snap was open to acquisition talks because its integration with Shazam’s music recognition technology had been going well.

But Snap has had a volatile time on the stock market since it went public in March, and so Shazam was getting mixed messages about how much the social media platform would be willing to pay.

Shazam’s conversations with Apple began the following month, and they became exclusive about two months ago. From what we understand, the Spotify talks were earlier and couldn’t progress because of the price, and likely also the fact that Spotify, which is gearing up for a public listing, has a lot on its plate right now.

Eddy Cue, Apple’s senior vice president of Internet Software and Services, saw an opportunity for Shazam to help build out its music business. Since the days of the iPod, music has long been a priority for the company. Lately, it’s been focused on enhancing its Spotify competitor, Apple Music.

Cue believes that Shazam could help improve its offering and liked that the app had moved beyond music discovery, building out artist pages and other music-related content.

Shazam already integrates with Apple Music, referring many of its 100 million users to play songs on its platform. It also lets users buy the music directly via iTunes.

Neither Apple nor Shazam have returned our earlier requests for comment.