DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Fixing a Streaming Issue in ShoutStreamSource on Windows Phone

Fixing a Streaming Issue in ShoutStreamSource on Windows Phone

Denzel D. user avatar by
Denzel D.
·
Apr. 01, 12 · Mobile Zone · Interview
Like (0)
Save
Tweet
6.54K Views

Join the DZone community and get the full member experience.

Join For Free

Music streaming is a practice that is used by many Windows Phone applications, incuding but not limited to MetroRadio and Spotify. This weekend I got the chance to experiment with this too, and I had a Shoutcast stream to work with. Although I could still work with the default implementation through MediaElement, which supports streaming to a limited extent, or AudioPlayerAgent, I wanted to research the internals of the process.

Tim Heuer posted two articles on this topic that interested me:

  • MediaStreamSource sample for Silverlight
  • Storing and playing media on Windows Phone 7
There is a very basic project that implements the MediaStreamSource for a Shoutcast stream, available here.

Right down my alley, so I downloaded the source and tried to re-write some parts of it to fit my needs. It seemed to work fine, however whenever I started the streaming, the audio was extremely choppy. First, I thought there was a problem with the stream itself, but after a quick check in the browser, it seemed like the stream was doing just fine.

It turns out that there is a bad segment in the code. Take a look (RadioStream -> GetAsyncData):

byte read;
while(ContinueStreaming)
{
      read = (byte)r.ReadByte();
      _radioStream.WriteByte(read);
}

There is no streaming buffer, as such, so the data is handled as it comes in - byte by byte. This is not something that should be done. Instead, I rewrote it like this:

byte[] buffer = new byte[128*1024];
while (ContinueStreaming)
{
	int read = stream.Read(buffer, 0, buffer.Length);
	mediaStream.Write(buffer, 0, read);
}

There is a 128K buffer that is being written to a media stream, that is later handled by the application. The size can be ultimately adjusted, but with the current value I found it to be optimal.

Also, if you are working with Shoutcast and don't want to write the media parser on your own like I did, you might want to check Shoutcast MediaStreamSource - a much more mature project with many performance and parsing optimizations.

Windows Phone

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Deployment of Low-Latency Solutions in the Cloud
  • Open Source Security Risks
  • Top Soft Skills to Identify a Great Software Engineer
  • Choosing Between GraphQL Vs REST

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo