Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

Problem at LayoutRoot when download and load a .XAP file

$
0
0

Hello friends,

I didnt found a solition or explication about my problem. I'm using MEF to load the .XAP file on demand. 
At my LayoutRoot (xaml) I have a ItemsControl that I load and add my xap files there.
When I loaded my application, I play music using "MediaElement", until here no problem.
But when I click in a button to load a xap inside my ItemsControl my music stops and doesn't return sound.

Whats I have to do for my song doesn't stop? Below I will put my code to you see whats I'm doing wrong.

MediaElement tocarAlarmeMediaElement;

//Mehod that I call to start the music
void Method ()
{
     if (tocarAlarmeMediaElement == null)
                {
                    tocarAlarmeMediaElement = new MediaElement();
                    LayoutRoot.Children.Add(tocarAlarmeMediaElement);
                }
                if (tocarAlarmeMediaElement != null && tocarAlarmeMediaElement.CurrentState == MediaElementState.Playing || tocarAlarmeMediaElement.CurrentState == MediaElementState.Opening)
                {
                    tocarAlarmeMediaElement.Stop();
                }

     servicoWCF.DownloadArquivoAsync(SongPath);
}

//Completed of my WCF Service that return my music
void servicoWCF_DownloadArquivoCompleted(object sender, DownloadArquivoCompletedEventArgs e)
        {
            ArquivoObject vArquivoObject;
            Stream vArquivoStream = null;

            if (e.ncErro == null || e.ncErro == "")
            {
                if (e.Result != null)
                {
                    try
                    {
                        vArquivoObject = e.Result;
                        vArquivoStream = new MemoryStream(vArquivoObject.ArquivoStream);

                        vArquivoStream.Seek(0, SeekOrigin.Begin);

                        tocarAlarmeMediaElement.SetSource(vArquivoStream);
                        tocarAlarmeMediaElement.Volume = 50;
                        tocarAlarmeMediaElement.AutoPlay = true;
                        tocarAlarmeMediaElement.MediaEnded += new RoutedEventHandler(tocarAlarmeMediaElement_MediaEnded);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error");
                    }
                }
            }
            else
            {
                MessageBox.Show("Error");
            }
        }

void tocarAlarmeMediaElement_MediaEnded(object sender, RoutedEventArgs e)
        {
            MediaElement midiaAtual = (MediaElement)sender;
            midiaAtual.Position = System.TimeSpan.FromSeconds(0);
            midiaAtual.Play();
        }

//Class ArquivoObject that I call above
public class ArquivoObject : INotifyPropertyChanged
    {
        public ArquivoObject();

        [DataMember]
        public string ArquivoName { get; set; }
        [DataMember]
        public byte[] ArquivoStream { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName);
    }

Thank advance.


Atenciosamente, Seratti. Se esta resposta lhe ajudar "marque-a".


Viewing all articles
Browse latest Browse all 1083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>