Audio streaming in mobile app

TRUETECH is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Audio streaming in mobile app
Medium
~2-3 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1054
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Implementing Audio Streaming in Mobile Applications

Radio, podcasts, music streaming — audio in background with buffering. Main complexity not in playback but in stability: user goes to another app, returns — player should be alive, not recreated, synchronized with what's playing.

Architecture: Player in Service

Android. MediaBrowserServiceCompat (deprecated) or media3 MediaSessionService — player lives in separate service, Activity only displays state. MediaController binds UI to service via Binder/IPC. Activity destruction — player continues.

// In MediaSessionService
val player = ExoPlayer.Builder(this).build()
val mediaSession = MediaSession.Builder(this, player).build()

override fun onGetSession(controllerInfo: MediaSession.ControllerInfo) = mediaSession

iOS. AVAudioSession.sharedInstance().setCategory(.playback) + UIBackgroundModes: audio in Info.plist. Player created in AppDelegate or separate singleton, survives ViewController recreation.

Buffering and Chunk Caching

ExoPlayer buffers forward automatically. Control via DefaultLoadControl:

val loadControl = DefaultLoadControl.Builder()
    .setBufferDurationsMs(
        15_000,  // minBufferMs
        50_000,  // maxBufferMs
        2_500,   // bufferForPlaybackMs
        5_000    // bufferForPlaybackAfterRebufferMs
    )
    .build()

minBufferMs = 15000 — player starts playback after 2.5 s buffer accumulation, holds in memory up to 50 s. On network loss — continues from buffer 50 s, then pause with loading indicator.

For disk caching (so not re-downloading on track return):

val cache = SimpleCache(cacheDir, LeastRecentlyUsedCacheEvictor(100 * 1024 * 1024))
val cacheDataSourceFactory = CacheDataSource.Factory()
    .setCache(cache)
    .setUpstreamDataSourceFactory(DefaultHttpDataSource.Factory())

iOS. AVURLAsset doesn't cache to disk natively. For caching — AVAssetResourceLoader with custom AVAssetResourceLoadingDelegate, write data to file on load. Or URLCache for HTTP segments with HLS.

Streaming Formats

Protocol Latency Use
HTTP progressive none podcasts, single file
HLS 3–30 s music streaming
Icecast/Shoutcast (MP3/AAC stream) < 1 s internet radio
OPUS over WebRTC < 0.2 s voice chats

Icecast streams (Content-Type: audio/mpeg with infinite body) — ExoPlayer handles as ProgressiveMediaSource. On iOS — AVPlayer handles natively via http:// stream URL.

IceCast Metadata

Radio stations transmit metadata (track title) directly in stream via ICY headers. ExoPlayer IcyDecoder reads automatically, get via Player.Listener.onMediaMetadataChanged. iOS not supported natively — need custom AVAssetResourceLoadingDelegate with ICY parsing.

Network Loss Handling

Streaming — unstable environment. On connection loss, player should auto-reconnect, not just stop.

ExoPlayer: LoadControl.getBackBufferDurationUs() keeps already-played data in memory. On reconnect — buffer not lost, playback continues from where it stopped. For radio stream (live), reconnect means getting actual fragment, not what was before break.

On iOS: AVPlayer.automaticallyWaitsToMinimizeStalling = true — player decides when to buffer. On HLS stream break, subscribe to AVPlayerItem.status KVO, on .failed with NSURLErrorNetworkConnectionLostreplaceCurrentItem(with:) with new AVPlayerItem from same URL after 3–5 seconds.

Timeline

Basic audio streaming with background playback and media controls — 2 days. Disk chunk caching, Icecast metadata handling and offline mode — 3–4 days.