none
[UWP]How to combine audio and video tracks for playback RRS feed

  • Question

  • Hello, guys!

    I develop YouTube UWP client and I need to combine video and audio tracks (muxed files are only with 480p and lower). I've written this code:

    MediaComposition muxedStream = new MediaComposition();
    
    BackgroundAudioTrack audioTrack = await BackgroundAudioTrack.CreateFromFileAsync(await StorageFile.GetFileFromPathAsync(audioInfo.Url));
    MediaClip videoTrack = await MediaClip.CreateFromFileAsync(await StorageFile.GetFileFromApplicationUriAsync(videoInfo.Url.ToUri()));
    
    muxedStream.BackgroundAudioTracks.Add(audioTrack);
    muxedStream.Clips.Add(videoTrack);
    
    videoSource.SetMediaStreamSource(muxedStream.GenerateMediaStreamSource());

    But I can't get StorageFile's because of PathTooLongException. According to Microsoft documentation (https://docs.microsoft.com/ru-ru/dotnet/api/system.io.pathtoolongexception?view=netframework-4.7.2) it may be caused by framework incompability but I don't know how to change the version (there is a guide for C++ project but it's not suitable for me) Rising minimum target version to April 2018 Update didn't help. Any ideas?

    P.S. Url sample: https://r9---sn-n8v7znsz.googlevideo.com/videoplayback?mime=video%2Fmp4&expire=1546167117&lmt=1543098677581810&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278%2C298%2C299%2C302%2C303&sparams=aitags,clen,dur,ei,expire,gir,id,ip,ipbits,ipbypass,itag,keepalive,lmt,mime,mip,mm,mn,ms,mv,nh,pl,requiressl,source&key=cms1&pl=24&ipbits=0&txp=5532432&keepalive=yes&itag=137&requiressl=yes&ei=7U4oXNOULs-fyAWHl74I&ip=95.47.116.128&c=WEB&gir=yes&dur=274.999&id=o-ACk7-_Fgu_caJbjuRbtlayK-dgmNtLEqypLyLfwWbA2j&signature=8173BAF30157D47064F9BE1DB85CB5A910AA5008.28DA3ACEEE47AD89D56E1F162602C99D73751E02&source=youtube&clen=102247371&fvip=15&video_id=xO_XyOsHK6A&title=WOLFENSTEIN+2+SONG+%28COLOSSAL+CARNAGE%29+LYRIC+VIDEO+-+DAGames&rm=sn-uixgxjvh-ig3e7e,sn-3c2ed7y&fexp=23763603&req_id=69d1c8f74394a3ee&redirect_counter=2&cms_redirect=yes&ipbypass=yes&mip=5.187.79.66&mm=29&mn=sn-n8v7znsz&ms=rdu&mt=1546157635&mv=m&nh=IgpwcjA0LnN2bzA2KgkxMjcuMC4wLjE&ir=1&rr=12 (976 characters)







    Sunday, December 30, 2018 8:40 AM

Answers

  • Actually. I've found another solution.

    Unfortunately, StorageFile cannot be gotten from the web. But I can use two different players linked with one timeline controller. Here's more detailed solution: https://stackoverflow.com/questions/51276649/how-to-play-video-and-audio-from-separate-urls-in-uwp-app

    • Marked as answer by XFox111 Tuesday, January 1, 2019 7:04 PM
    Tuesday, January 1, 2019 7:04 PM

All replies

  • Hi XFox111,

    Thank you for posting here.

    Since your question is more related to UWP, I will move it to UWP forum for suitable support.

    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/home?forum=wpdevelop

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 31, 2018 6:44 AM
  • Hi XFox111,

    First, I wanted to let you know that you could use this method to access your app's storage files using either "ms-appx://" or "ms-appdata://". For example,

    await StorageFile.GetFileFromApplicationUriAsync(new Uri(“ms-appx:///Assets/1.jpg”));

    But, you provided me the Url sample like “https://...”. I did not think it will work.

    If it’s an online video file, you first need to download and save it in your application data folder. For example, ApplicationData.LocalFolder

    If it’s a small file, you could use HttpClient to download it, if it's a big file, you need to use BackgroundDownloader Class. Then, whatever method you use, you can rename them when you save them.

    After that, you could use 'StorageFile.GetFileFromApplicationUriAsync()' method to get the storage file from your local folder.

    Best Regards,

    Xavier Xie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 1, 2019 2:54 AM
    Moderator
  • Actually. I've found another solution.

    Unfortunately, StorageFile cannot be gotten from the web. But I can use two different players linked with one timeline controller. Here's more detailed solution: https://stackoverflow.com/questions/51276649/how-to-play-video-and-audio-from-separate-urls-in-uwp-app

    • Marked as answer by XFox111 Tuesday, January 1, 2019 7:04 PM
    Tuesday, January 1, 2019 7:04 PM