Reputation: 33
i want play video in media element from shearing file in networking . how can do it ?
for example my local IP is 192.168.1.51 and shared folder name is 'SharedFileVideo' . i can access this file from windows explorer with \192.168.1.51\SharedFileVideo\video.mp4 but when i use \192.168.1.51\SharedFileVideo or file://192.168.1.51/SharedFileVideo/video.mp4 in Uri for source of element media doesn't play my video .
how can bind video from file shared in networking for medial element in uwp .
many thanks
Upvotes: 2
Views: 1772
Reputation: 200
Have you tried setting your source to:
\\192.168.1.51\SharedFileVideo\video.mp4
back slashes (\) not forward slashes (/) and make sure to start with a double back slash
i do this with my raspberry pi and it gets them fine
\\RASPBERRYPI\Films\OS1\Films\video.mp4
dont forget to do this in xaml youll need this:
<MediaElement Source="\\192.168.1.51\SharedFileVideo\video.mp4"/>
or for binding:
<MediaElement Source="{Binding Path=URI}"/>
and in code:
URI = @"\\192.168.1.51\SharedFileVideo\video.mp4";
as i said this works fine for me, i dont need synchronous programming and my machines and routers seem good enough not to cause lag or buffering issues
one other thing to remember if binding the source to a string then sometimes the media element needs telling to play. if so dont forget to tell it your manually loading video with the loaded behaviour tag.
so xaml:
<MediaElement Name="VideoPlayer" Source="{Binding Path=URI}" LoadedBehaviour="Manual"/>
and in code add:
URI = @"\\192.168.1.51\SharedFileVideo\video.mp4";
VideoPlayer.Play();
Upvotes: 2
Reputation: 15758
To play a video file in shared folder on network, we can get the StorageFile first and then use the SetSource method to set the source to the file. To access files in the shared folder, we need declare some capabilities in the app manifest.
Universal Naming Convention (UNC) is the naming system commonly used in Microsoft Windows for accessing shared network folders. For more info, please see File access permissions.
So we can set Package.appxmanifest like following:
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="UWPApp.App">
<uap:VisualElements DisplayName="UWPApp" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="UWPApp" BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="myvideotest">
<uap:DisplayName>MyVideoTest</uap:DisplayName>
<uap:SupportedFileTypes>
<uap:FileType>.mp4</uap:FileType>
</uap:SupportedFileTypes>
</uap:FileTypeAssociation>
</uap:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="privateNetworkClientServer" />
<Capability Name="internetClientServer" />
<uap:Capability Name="enterpriseAuthentication" />
</Capabilities>
And then in code-behind, retrieve the shared folder first.
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(@"\\192.168.1.51\SharedFileVideo");
After this, we can retrieve the video file and set it as MediaElement
's source like:
StorageFile file = await folder.GetFileAsync("video.mp4");
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
MediaElement.SetSource(stream, file.ContentType);
Upvotes: 3