简体   繁体   English

如何在网络中的共享文件夹中播放媒体元素中的视频

[英]how play video in media element from shared folder in networking

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' . 例如我的本地IP是192.168.1.51,共享文件夹名称是'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 . 我可以使用\\ 192.168.1.51 \\ SharedFileVideo \\ video.mp4从Windows资源管理器访问此文件,但是当我在Uri中使用\\ 192.168.1.51 \\ SharedFileVideo或file://192.168.1.51/SharedFileVideo/video.mp4作为元素媒体源时不播放我的视频。

how can bind video from file shared in networking for medial element in uwp . 如何从网络共享的文件中为uwp中的media元素绑定视频。

many thanks 非常感谢

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. 要在网络上的共享文件夹中播放视频文件,我们可以先获取StorageFile ,然后使用SetSource方法将源设置为文件。 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. 通用命名约定(UNC)是Microsoft Windows中常用于访问共享网络文件夹的命名系统。 For more info, please see File access permissions . 有关更多信息,请参见文件访问权限

So we can set Package.appxmanifest like following: 所以我们可以像下面这样设置Package.appxmanifest

<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: 之后,我们可以检索视频文件并将其设置为MediaElement的源,例如:

StorageFile file = await folder.GetFileAsync("video.mp4");
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
MediaElement.SetSource(stream, file.ContentType);

Have you tried setting your source to: 您是否尝试将源设置为:

\\\\192.168.1.51\\SharedFileVideo\\video.mp4 \\\\ 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 \\\\树莓派\\薄膜\\ OS1 \\薄膜\\ video.mp4

dont forget to do this in xaml youll need this: 不要忘记在xaml中执行此操作,您将需要以下内容:

<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: 所以xaml:

<MediaElement Name="VideoPlayer" Source="{Binding Path=URI}" LoadedBehaviour="Manual"/>

and in code add: 并在代码中添加:

URI = @"\\192.168.1.51\SharedFileVideo\video.mp4";
VideoPlayer.Play();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM