Visual studio feeds

All Visual Studio blogs in one place

Subscribe

Enter your email address:

Delivered by FeedBurner

Increase your website traffic with Attracta.com

Google+

Contact

Email:
Subject:
Message:
Anti-spam: How many eyes has a typical person?

Follow us on FB

Search

Silverlight for Windows Phone Programming Tip #7

AddThis Social Bookmark Button
I recently worked on a phone project that required me to tombstone a MediaElement control. Basically, I needed to save the current playback position when the app was deactivated, and restore it when (and if) the app was reactivated. So I whipped up something like this:   protected override void OnNavigatedFrom(NavigationEventArgs e) {     this.State["Pos"] = Player.Position; }   protected override void OnNavigatedTo(NavigationEventArgs e) {     if (this.State.ContainsKey("Pos"))     {         Player.Position = (TimeSpan)this.State["Pos"];         Player.Play();     } }   Unfortunately, it didn’t work.
Each time the app was reactivated, playback started from the beginning. Investigation revealed that Position was being persisted in page state just fine. The problem was that the MediaElement seemed to be ignoring the Position I assigned to it in OnNavigatedTo. That’s when it hit me. You can’t set a MediaElement’s position property when the MediaElement isn’t playing. And you’re not sure it’s playing until it fires a MediaOpened event. So one small change to the code solved the problem:   protected override void OnNavigatedFrom(NavigationEventArgs e) {     this.State["Pos"] = Player.Position; }  ...(Read whole news on source site)

Home : Blog List : Jeff Prosise's Blog : Silverlight for Windows Phone Programming Tip #7