• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Why do we use MediaPlayer for long clips if it's resource intensive?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note: Cross - posted from here(https://stackoverflow.com/questions/67342407/why-do-we-use-mediaplayer-for-long-clips-if-its-resource-intensive)--couldn't get any help there.

I was reading this post: AudioTrack, SoundPool or MediaPlayer Which Should I use?(https://stackoverflow.com/questions/13527134/audiotrack-soundpool-or-mediaplayer-which-should-i-use)

but got confused on the post by @Kishore P

MediaPlayer - Streams and decodes in real-time for local or remote files. Good for long clips and applications such as background music. More CPU and resource-intensive. Relatively long initialization time. MediaPlayer is a state machine!‚Äč

"More CPU and resource intensive."

Why would we use MediaPlayer for long audio tracks if it's resource intensive? Wouldn't that just waste a ton of memory over time?

Thanks!

 
Marshal
Posts: 3501
495
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe McMillan wrote:... Why would we use MediaPlayer for long audio tracks if it's resource intensive? Wouldn't that just waste a ton of memory over time?


I don't think MediaPlayer memory utilization increases over time, but it sounds like each instance does consume a significant number of media-related resources (which would include memory) so you should probably not keep the instance hanging around longer than needed.

The use cases for SoundPool and MediaPlayer are different.

SoundPool is intended to be used for relatively short clips which can be played without any startup delay.  This is accomplished by loading and decoding the sound resources in to memory up-front when the sound pool is created.  The length of the audio tracks in limited, and depending on the quality of the audio track, it could be capped at 10 seconds or so.  SoundPool allows multiple audio streams to be played at the same time.  A classic use case for SoundPool would be sound effects for a game (gun fire, explosions,  etc.).

MediaPlayer is intended to be used for playing longer (even unbounded network-streamed) audio tracks.  The sound resources are loaded in chunks and the decoding is done on-the-fly.  MediaPlayer only supports playing a single audio stream, so if you wanted to play multiple streams concurrently, you would need to have multiple instances of MediaPlayer.  An example use case for MediaPlayer would be a music player or podcast app.

WHat kind of application are you building?

 
Joe McMillan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thank you! I think that since Media player decodes media in real-time(to play long clips), it uses a lot of processing-power while doing so. So it's kind of like a cause an effect relationship.
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
ScroogeXHTML - a fast and small RTF to HTML5 and XHTML converter library
https://coderanch.com/t/742149/ScroogeXHTML-RTF-HTML-XHTML-converter
reply
    Bookmark Topic Watch Topic
  • New Topic