开发者

How to go about playing audio files from a map-based iPhone app?

开发者 https://www.devze.com 2023-03-24 00:18 出处:网络
I\'m currently building a cultural heri开发者_运维技巧tage audio tour for iPhone and would like to be able to position markers on a map so that when a user is in a particular location they can click o

I'm currently building a cultural heri开发者_运维技巧tage audio tour for iPhone and would like to be able to position markers on a map so that when a user is in a particular location they can click on a hotspot and listen to audio playback relating to where they are. The audio files will be part of the app download so will not be streamed.

I am a complete beginner with iOS and have a long way to go on this project but thought best to ask some people in the know for some pointers before going in completely the wrong direction. What would be the best way to achieve audio playback from the mapView?


Providing audio playback and using the map view together should not be a problem. Though your app won't be doing audio playback "from the mapView". It will be using both an MKMapView control and issuing audio api calls as the user interacts with the map.

You can add the hotspots as map annotations using the MKPointAnnotation class or your own custom class that implements the MKAnnotation protocol.

Your app can detect when an annotation is tapped in the map view delegate method didSelectAnnotationView (see MKMapViewDelegate) or, probably better, add a disclosure button on the annotation's callout view and detect the tap of that button using the calloutAccessoryControlTapped delegate method.

So for example: app adds pins (or custom images) for each hotspot, user taps on pin, callout bubble pops up with hotspot name and a disclosure button (blue circle with arrow), user taps on button, map calls delegate method.

In those map view delegate methods, you can tell what annotation was selected using view.annotation and then based on the annotation's title or some custom property, play the matching audio.

For simple audio playback, you can use the AVAudioPlayer class.

0

精彩评论

暂无评论...
验证码 换一张
取 消