WP8.1 in the development of the media (image) file generation operations, how to set properties (content/Embed resources, etc.);

Source: Internet
Author: User

(reprint) WindowsPhone question Note--Correct Select Build Action to resolve media resource unreadable problem

Links: http://www.cnblogs.com/qinxg/archive/2012/07/17/2594503.html

In the development process encountered the picture loader and the video player does not read the media resources properly.

The picture path is correct in the code, and the picture does not read normally. While the video section takes the same code, it can be read normally.

Read the image code as follows:

Read the video code as follows:

(reprint) WindowsPhone question Note--Correct Select Build Action to resolve media resource unreadable problem

2 of them have similar addresses:/assets/xxxx/xxx.xxx

Read the picture error message as follows:

After comparing the video file with the picture file when the problem is found.

The original image and video generation action (Build action) settings are different.

The video is: Content (contents) of the Picture: Rescoure

After reviewing MSDN, it was found that the two build operations had a significant difference in the final acquisition of resources and had a significant impact on performance.

Start by introducing the build action

Action

Description

None

Resources are neither integrated into the assembly nor packaged in a XAP package. However, we can set the Copytooutputdirectory option to automatically copy it to the directory where the XAP package resides. In this case, the relative URI that accesses the image needs to start with "/".

Scenario: In most cases, we want to put the Video/audio file outside of the XAP, because this file is generally larger, will affect the loading of Silverlight applications, and the general video audio files are compressed format, Placing them in the XAP does not reduce their file size. Similar to Image video This resource file generation operation is the same as none when they are not added to the project, and can be referenced with an absolute URI.

Compile

Not suitable for resource files. class file to use "Compile" to generate operations, refers to the project. cs or. vb files.

Content

Resources will be packaged in the XAP package. In this case, the relative URI that accesses the image needs to start with "/". In this way, if the image file is not found in the XAP, Silverlight automatically finds the desired picture file from the folder where the current Xap app resides, and if it does not, then triggers the imagefailed event. This approach is more appropriate when multiple assemblies reference the same file.

Embedded Resource

This way the files are embedded in the assembly, Silverlight cannot use the URI reference in XAML and C #, and Microsoft does not recommend embedding resources in the assembly in this way in Silverlight. If there is such a demand can be used Reflection.Assembly.GetExecutingAssembly (). The GetManifestResourceStream (string path)-related method gets a stream reference to the file.

ApplicationDefinition

The entry XAML file for the Silverlight program (the default is App.xaml) should be set to this "app definition". Other documents are not suitable for this.

Page

Not suitable for resource files. All the user controls, pages and subforms (Usercontrol/page/childwindow) of the XAML file should take the build action. If you change to another way, it will cause the code file behind the background to not be linked to this XAML file. Errors in XAML when you use the "page" Build Action cause the project to not build correctly.

Codeanalysisdictionary

Code analysis used, can be ignored in Silverlight

Resource

The resource is packaged inside the assembly. When this build is selected, the resource file is embedded in the application's assembly, which means that the generated xap is not visible to the file. can be accessed relative to the current XAML file, <image source= "Sl.png"/> or <image source= "./sl.png"/> in subfolders, you can use <image Source= "./images/sl.png"/> access to. The most insured way is to use the unique assembly resource URI access, in the format <image source= "/{assemblyshortname};component/sl.png"/> This way you can also refer to pictures in other assemblies in the XAP. This method of generating system resources can be directly used with Application.getresourcestream (URI). Stream is in the code to get it.

SplashScreen

"SplashScreen" is this option that is used by the WPF splash screen. Silverlight Boot loading screen is implemented in other ways, so do not use this method in Silverlight.

Entitydeploy

This is the way entityframework is built, and it's useless in Silverlight.

The concern is that for media resources, Content is typically used in two different ways than Resource.

Take Content , The resource is packaged in the XAP package. In this case, the relative URI that accesses the image needs to start with "/". In this way, if the image file is not found in the XAP, Silverlight automatically finds the desired picture file from the folder where the current Xap app resides, and if it does not, then triggers the imagefailed event. This approach is more appropriate when multiple assemblies reference the same file.

How to get the media resource: directly take/folder/file to get to the resource file.

Adopt Resource , The resource is packaged inside the assembly. When this build is selected, the resource file is embedded in the application's assembly, which means that the generated xap is not visible to the file. can be accessed relative to the current XAML file, <image source= "Sl.png"/> or <image source= "./sl.png"/> in subfolders, you can use <image Source= "./images/sl.png"/> access to. The most insured way is to use the unique assembly resource URI access, in the format <image source= "/{assemblyshortname};component/sl.png"/> This way you can also refer to pictures in other assemblies in the XAP. This method of generating system resources can be directly used with Application.getresourcestream (URI). Stream is in the code to get it.

Get the Media resource way:/{assemblyshortname};component/sl.png way to get, where Assemblyshortname is the assembly name.

In this issue, Resource is used for the image file, and the video file uses content. So there was a problem.

As explained in MSDN, for performance reasons, the media resource needs to be set to content, as described below:

Optimize media processing on Windows Phone to use file and network streams, rather than using in-memory streams. This means that any media files included in the application, such as sound effects, should have their build Action set to content instead of Resources ". When a media file is compiled as content, it is used as a loose file with an application file (. XAP), rather than stored in an application file. When a media file is compiled as a resource, it is typically accessed by retrieving the file stream, which may degrade performance. In addition, when you play a media file that is compiled into content, it plays directly. When a media file is compiled as a resource, the content needs to be copied to a file on the Windows Phone before playback, which degrades performance.

Reference address: http://msdn.microsoft.com/zh-cn/library/ff967560 (v=vs.92). aspx

Http://www.cnblogs.com/listenfly/archive/2011/11/03/2235059.html

WP8.1 in the development of the media (image) file generation operations, how to set properties (content/Embed resources, etc.);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.