Click here to Skip to main content
15,886,422 members
Home / Discussions / Mobile
   

Mobile

 
QuestionCopying and Playing of an mp3 from a URL in Windows Phone 8 Pin
Vimalsoft(Pty) Ltd8-Nov-13 23:10
professionalVimalsoft(Pty) Ltd8-Nov-13 23:10 
Good Day All

I am trying to stream an mp3 from a URL , So i first wanted to download the file first into the Isolated Storate or Local Storage and start to play the file. Below is the code i use to copy the File locally

C#
public static void  CopyToIsolatedStorage(string _fileName)
        {
            List<string> MyList = new List<string>();
            MyList.Add(_fileName);

            foreach (var item in MyList)
            {
                using (IsolatedStorageFile localFile = IsolatedStorageFile.GetUserStoreForApplication())
                {

                    Uri uri = new Uri(_fileName, UriKind.Absolute);
                    HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
                    request.BeginGetResponse((ar) =>
                    {
                        var response = request.EndGetResponse(ar);
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            using (var stream = response.GetResponseStream())
                            {
                                var name = GetFileNameinURL(item);
                                if (localFile.FileExists(name))
                                {
                                    localFile.DeleteFile(name);
                                }
                                using (IsolatedStorageFileStream fs = localFile.CreateFile(name))
                                {
                                    stream.CopyTo(fs);

                                }
                            }
                        });
                    }, null);
                }
            }

        }


and i try to play it like this


C#
private void btnPlay_Click(object sender, RoutedEventArgs e)
{       Button button = sender as Button;

        //Copy file to Temp isolated Storate as Files can only play if they are in the Isolated Storage
GenericFunctions.CopyToIsolatedStorage(button.Tag.ToString());  //eg. url http://media.lakewood.org.edgesuite.net/JOM/podcast/mp3_audio/596_Podcast.mp3
        //<MediaElement Name="media"   />
        media.Source = new Uri(GenericFunctions.GetFileNameinURL(button.Tag.ToString()));
        media.Play();
        media.Volume = 1;
}


Thanks
Vuyiswa Maseko,

Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.

C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa[at]dotnetfunda.com
http://www.Dotnetfunda.com

SuggestionRe: Copying and Playing of an mp3 from a URL in Windows Phone 8 Pin
Richard MacCutchan8-Nov-13 23:41
mveRichard MacCutchan8-Nov-13 23:41 
GeneralRe: Copying and Playing of an mp3 from a URL in Windows Phone 8 Pin
Vimalsoft(Pty) Ltd8-Nov-13 23:45
professionalVimalsoft(Pty) Ltd8-Nov-13 23:45 
QuestionHow to Download the a Video,Audio, PDF, etc into a Local Storage Pin
Vimalsoft(Pty) Ltd8-Nov-13 20:55
professionalVimalsoft(Pty) Ltd8-Nov-13 20:55 
QuestionXML contents to Model in C# Windows Phone Pin
Vimalsoft(Pty) Ltd8-Nov-13 6:49
professionalVimalsoft(Pty) Ltd8-Nov-13 6:49 
AnswerRe: XML contents to Model in C# Windows Phone Pin
Vimalsoft(Pty) Ltd8-Nov-13 7:23
professionalVimalsoft(Pty) Ltd8-Nov-13 7:23 
QuestionAjax Navigation in Windows Phone 8 Pin
santhosh_init6-Nov-13 21:10
santhosh_init6-Nov-13 21:10 
AnswerRe: Ajax Navigation in Windows Phone 8 Pin
Hadrich Mohamed31-Dec-13 9:15
professionalHadrich Mohamed31-Dec-13 9:15 
Questioneclipse Pin
Member 103849266-Nov-13 12:38
Member 103849266-Nov-13 12:38 
AnswerRe: eclipse Pin
Richard MacCutchan6-Nov-13 23:02
mveRichard MacCutchan6-Nov-13 23:02 
QuestionLooking for cross platform development/framework feedback Pin
Joe Woodbury30-Oct-13 5:53
professionalJoe Woodbury30-Oct-13 5:53 
AnswerRe: Looking for cross platform development/framework feedback Pin
Jeremy Hutchinson30-Oct-13 7:05
professionalJeremy Hutchinson30-Oct-13 7:05 
AnswerRe: Looking for cross platform development/framework feedback Pin
A_WoodApple30-Oct-13 8:39
A_WoodApple30-Oct-13 8:39 
GeneralRe: Looking for cross platform development/framework feedback Pin
Joe Woodbury1-Nov-13 6:50
professionalJoe Woodbury1-Nov-13 6:50 
GeneralRe: Looking for cross platform development/framework feedback Pin
Member 1047558618-Dec-13 14:02
Member 1047558618-Dec-13 14:02 
AnswerRe: Looking for cross platform development/framework feedback Pin
dexterama30-Oct-13 8:41
professionaldexterama30-Oct-13 8:41 
GeneralRe: Looking for cross platform development/framework feedback Pin
Joe Woodbury1-Nov-13 6:32
professionalJoe Woodbury1-Nov-13 6:32 
AnswerRe: Looking for cross platform development/framework feedback Pin
Kent Sharkey30-Oct-13 11:01
staffKent Sharkey30-Oct-13 11:01 
GeneralRe: Looking for cross platform development/framework feedback Pin
Joe Woodbury1-Nov-13 6:54
professionalJoe Woodbury1-Nov-13 6:54 
GeneralRe: Looking for cross platform development/framework feedback Pin
Kent Sharkey1-Nov-13 7:28
staffKent Sharkey1-Nov-13 7:28 
AnswerRe: Looking for cross platform development/framework feedback Pin
docdal2-Jan-17 23:09
docdal2-Jan-17 23:09 
QuestionGPS Coordinate system Pin
i gr825-Oct-13 3:46
i gr825-Oct-13 3:46 
AnswerRe: GPS Coordinate system Pin
Member 1036859130-Oct-13 6:53
Member 1036859130-Oct-13 6:53 
AnswerRe: GPS Coordinate system Pin
Black68cougar4-Nov-13 6:28
Black68cougar4-Nov-13 6:28 
QuestionBitmapFactory.decodeStream problem for Android 4.1.2 or grater Pin
arifkomurculer23-Oct-13 1:42
arifkomurculer23-Oct-13 1:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.