A method and system for uniform routing of multimedia resources
Patent Information
- Application Number
- CN202610870356.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-16
- Publication Date
- 2026-10-27
AI Technical Summary
[0015]根据上述描述可知,资源内容适配规则决定了当前资源内容如何在子视图上进行渲染,当采用矩阵变换模式时,能够将平移、缩放、错切等复杂变换直接应用到当前资源内容的渲染上,适用于复杂的应用场景,提高灵活性。当采用居中裁剪模式时,通过计算出最终裁剪比例对当前资源内容进行裁剪,且还会计算出水平裁剪起始偏移量与垂直裁剪起始偏移量,保证在对更新后的当前资源内容进行渲染时无拉伸变形,避免画面失真。当采用居中缩放模式时,通过计算出最终缩放比例对当前资源内容进行等比缩放,同时会计算出水平缩放起始偏移量与垂直缩放起始偏移量,使得等比缩放后的当前资源内容完全适应子视图内容,确保渲染后的当前资源内容能够被用户看见,保证多媒体资源展示的完整性。当采用填充拉伸模式时,将当前资源固定宽度与当前资源固定高度独立拉伸至更新后的子视图的视图宽度与视图高度,使得当前资源内容能够快速填满子视图,简化业务处理。
Smart Images

Figure CN122986102A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a unified routing loading method and system for multimedia resources. Background Technology
[0002] With the increasing richness of mobile internet content formats, Android applications need to display a wider variety of media resources, expanding from traditional static images to include animated images, vector animations, special effects animations, and transparent videos, among other new media formats. Different types of multimedia resources rely on dedicated rendering engines and loading interfaces for interpretation and display. Currently, most mainstream multimedia loading solutions in the industry employ a format-specific independent adaptation architecture, but this approach has the following drawbacks: (i) Dispersed calls and high coupling. Different media formats are supported by different rendering engines. Business code needs to import and manually call their respective APIs. When the format of a resource needs to be changed, the calling code must be modified synchronously, resulting in high maintenance costs. (ii) The format modules are tightly coupled and cannot be integrated as needed. Existing solutions typically statically import all format modules into the core code, which means that even if some formats are not used, their compilation artifacts will still be packaged into the application, causing the installation package size to increase and affecting the application installation and running performance.
[0003] Therefore, there is an urgent need for a technical solution that can uniformly handle multiple media formats and enable on-demand loading of format modules. Summary of the Invention
[0004] The technical problem to be solved by the present invention is: the present invention provides a unified routing loading method and system for multimedia resources, which can uniformly process multiple media formats and realize on-demand loading of format modules, thereby improving the loading and rendering efficiency of multimedia resources.
[0005] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows: In a first aspect, the present invention provides a unified routing loading method for multimedia resources, comprising: The unified display component receives a resource loading request from the caller. The resource loading request carries the unified resource identifier of the multimedia resource and the adaptation rules of the loading configuration object. The unified resource identifier is parsed to obtain the format type of the multimedia resource. The unified display component has a subview pre-built inside to carry the rendered content. The loading strategy is executed according to the format type, and the historical resource content existing in the subview is cleared before the loading strategy is executed. When the format type belongs to the first type, the corresponding interface of Glide is called to execute the loading and generate the corresponding Drawable carrier object. When the format type belongs to the second type, the loading utility class corresponding to the format type is dynamically created through the reflection mechanism to execute the loading and generate the corresponding Drawable carrier object. The current resource content, fixed width, and fixed height of the Drawable carrier object are obtained. Based on the adaptation rules, the fixed width and fixed height of the current resource are dynamically calculated to obtain layout parameters. The layout parameters are then synchronously updated to the subview to obtain the updated subview. The current resource content is then rendered onto the updated subview to complete the unified loading and display of multimedia resources.
[0006] The beneficial effects of this invention are as follows: A unified display component enables unified access to multimedia resources. The caller only needs to pass in a resource loading request carrying the unified resource identifier of the multimedia resources and the adaptation rules of the loading configuration object to achieve complete unified loading and display of multimedia resources. There is no need to concern oneself with the rendering engine corresponding to a specific format type, nor is any modification to the business code required, thus reducing business coupling and maintenance costs. A differentiated loading strategy is executed based on the format type. For format types belonging to the second category, a loading utility class corresponding to the format type is dynamically created through reflection to perform loading, rather than statically importing all format types in the core code. This ensures that unused format types are not packaged during compilation and packaging, avoiding excessive size of the generated Drawable carrier object and enabling on-demand loading of format modules. Before executing the loading strategy, historical resource content in subviews is automatically cleared, ensuring that each loading starts with a clean view state. This prevents visual flickering and content confusion caused by temporary residue of previously loaded content, improving loading and rendering efficiency. During rendering, dynamic rendering can be achieved according to the adaptation rules of the loading configuration object, flexibly adapting to diverse rendering needs and optimizing the user experience for the caller.
[0007] Optionally, the first type of format includes static image format and dynamic image format, and the second type of format includes vector animation format, special effects animation format and transparent video format.
[0008] Optionally, the step of dynamically creating a loading utility class corresponding to the format type through reflection to perform loading and generate the corresponding Drawable carrier object includes: The target class name is generated according to the format type and preset naming rules. The loading utility class corresponding to the target class name is loaded through the class query method in the reflection mechanism. If the loading is successful, the loading utility class is instantiated by calling the parameterless constructor to obtain an instance object. The loading is performed through the instance object to generate the corresponding Drawable carrier object, and the instance object is stored in the global cache. If loading fails, the loading utility class of the target class name is set to null, and a loading failure callback is triggered to the caller to achieve a security degradation.
[0009] As described above, the target class name is generated using preset naming rules, and the corresponding loading utility class is dynamically instantiated at runtime using reflection. This decouples the core code from the compile-time compilation of various format adaptations, preventing the generated Drawable carrier object from becoming excessively large. A global caching mechanism facilitates subsequent reuse of instance objects, avoiding performance overhead caused by frequent instance creation via reflection. Upon loading failure, the loading utility class for the target class name is automatically set to null, triggering a loading failure callback without causing crashes or exceptions, achieving seamless safety degradation and improving stability.
[0010] Optionally, the step of loading through the instance object to generate the corresponding Drawable carrier object includes: Determine whether the path type of the Uniform Resource Identifier is a local resource path. If it is, the instance object calls the synchronous loading strategy to perform dedicated resource loading according to the format type and generates the corresponding Drawable carrier object. If not, the instance object calls the asynchronous loading strategy to perform dedicated resource loading according to the format type and generates the corresponding Drawable carrier object. Determine whether the Drawable carrier object has been loaded successfully. If not, convert the format type to the first type using a custom decoder, call the asynchronous loading strategy to roll back and call the corresponding Glide interface to perform loading, and generate the corresponding Drawable carrier object.
[0011] As described above, a differentiated loading strategy is adopted based on the path type of the Uniform Resource Identifier (URI). A synchronous loading strategy is used for local resource paths to ensure immediacy, while an asynchronous loading strategy is used for non-local resource paths to avoid blocking the main program and preventing page lag. This differentiated loading strategy balances local rendering speed and non-local loading smoothness. A fallback mechanism is also set up for loading failures, calling the asynchronous loading strategy to revert to the corresponding Glide interface for loading, improving fault tolerance and enhancing the success rate of multimedia resource loading and scene compatibility.
[0012] Optionally, the adaptation rules include subview adaptation rules and resource content adaptation rules. The step of dynamically calculating the fixed width and fixed height of the current resource based on the adaptation rules to obtain layout parameters, synchronously updating the layout parameters to the subview to obtain the updated subview, and rendering the current resource content onto the updated subview to complete the unified loading and display of multimedia resources includes: When the adaptation rule is a subview adaptation rule, the fixed width and fixed height of the current resource are dynamically calculated based on the subview adaptation rule. When the subview adaptation rule is a fixed width adaptive height mode, the view width of the subview is obtained, and the view width, the fixed width of the current resource, and the fixed height of the current resource are input into the adaptive height formula for dynamic calculation to obtain the adaptation height corresponding to the subview. The adaptation height and the view width are used as the layout parameters of the subview, and the layout parameters are updated synchronously to obtain the updated subview. The current resource content is rendered onto the updated subview to complete the unified loading and display of multimedia resources. When the subview adaptation rule is a fixed height adaptive width mode, the view height of the subview is obtained, and the view height, the current resource fixed width, and the current resource fixed height are input into the adaptive width formula for dynamic calculation to obtain the adaptation width corresponding to the subview. The adaptation width and the view height are used as the layout parameters of the subview, and the layout parameters are synchronously updated to the subview to obtain the updated subview. The current resource content is rendered onto the updated subview to complete the unified loading and display of multimedia resources. When the subview adaptation rule is the original resource size mode, the screen density conversion coefficient of the current device is obtained, the fixed width and fixed height of the current resource are multiplied by the screen density conversion coefficient respectively to obtain the final width and final height, the final width and final height are used as layout parameters, and the layout parameters are synchronously updated to the subview to obtain the updated subview, and the current resource content is rendered on the updated subview to complete the unified loading and display of multimedia resources; When the adaptation rule is a resource content adaptation rule, the view height and view width of the subview are directly used as layout parameters, the original subview is used as the updated subview, and the current resource content is rendered onto the updated subview according to the resource content adaptation rule, thus completing the unified loading and display of multimedia resources.
[0013] As described above, the adaptation rules are divided into subview adaptation rules and resource content adaptation rules. Subview adaptation rules directly affect the layout parameters of the subview. Through fixed-width adaptive-height mode, fixed-height adaptive-width mode, and resource original size mode, reasonable layout parameters can be dynamically calculated and the subview updated based on the current resource's fixed width, current resource's fixed height, the subview's view height, and the subview's view width. Business users do not need to write screen adaptation code or perform manual calculations to achieve size matching between the current resource content and the subview, reducing development complexity and enabling adaptation to diverse scenarios. Furthermore, when using the resource original size mode, calculations are performed using the current device's screen conversion factor to ensure that the current resource content is presented at the expected physical size on screens of different densities, avoiding blurring and distortion caused by improper density conversion.
[0014] Optionally, rendering the current resource content onto the updated subview according to the resource content adaptation rules to complete the unified loading and display of multimedia resources includes: When the resource content adaptation rule is matrix transformation mode, the transformation matrix provided by the caller is obtained, and the current resource content is rendered onto the updated subview based on the transformation matrix to complete the unified loading and display of multimedia resources. The transformation matrix includes X-axis scaling component, Y-axis scaling component, X-axis translation component, Y-axis translation component, X-axis shear component, Y-axis shear component, X-axis rotation component, Y-axis rotation component, and perspective component. When the resource content adaptation rule is center-cropping mode, the layout parameters of the updated subview are input into the cropping ratio formula along with the fixed width and fixed height of the current resource to calculate the final cropping ratio. The fixed width and fixed height of the current resource are then cropped according to the final cropping ratio to obtain the cropped current resource width and height. The current resource content is then updated according to the cropped current resource width and height to obtain the updated current resource content. If the cropped current resource width is greater than the view width of the updated subview, a horizontal cropping start offset is calculated based on the view width and the cropped current resource width. If the cropped current resource height is greater than the view height of the updated subview, a vertical cropping start offset is calculated based on the view height and the cropped current resource height. The updated current resource content is then rendered onto the updated subview based on the horizontal and vertical cropping start offsets, completing the unified loading and display of multimedia resources. When the resource content adaptation rule is center scaling mode, the layout parameters of the updated subview are input into the scaling ratio formula along with the fixed width and fixed height of the current resource to calculate the final scaling ratio. The fixed width and fixed height of the current resource are then scaled according to the final scaling ratio to obtain the scaled current resource width and scaled current resource height. The scaled current resource width and scaled current resource height are used as the proportional scaling ratio, and the current resource content is scaled proportionally according to the proportional scaling ratio to obtain the proportionally scaled current resource content. If the scaled current resource width is greater than the view width of the updated subview, a horizontal scaling start offset is calculated based on the view width and the clipped current resource width. If the scaled current resource height is greater than the view height of the updated subview, a vertical scaling start offset is calculated based on the view height and the clipped current resource height. The proportionally scaled current resource content is rendered onto the updated subview based on the horizontal scaling start offset and the vertical scaling start offset, completing the unified loading and display of multimedia resources. When the resource content adaptation rule is the fill-stretch mode, the current resource is stretched to the view width of the updated subview with a fixed width, and the current resource is stretched to the view height of the updated subview with a fixed height, so that the current resource content is rendered on the updated subview in a full manner, thus completing the unified loading and display of multimedia resources.
[0015] As described above, the resource content adaptation rules determine how the current resource content is rendered on the subview. When using matrix transformation mode, complex transformations such as translation, scaling, and shearing can be directly applied to the rendering of the current resource content, making it suitable for complex application scenarios and improving flexibility. When using center-cropping mode, the current resource content is cropped by calculating the final cropping ratio, and the horizontal and vertical cropping start offsets are also calculated to ensure no stretching or distortion when rendering the updated current resource content, avoiding image distortion. When using center-scaling mode, the current resource content is scaled proportionally by calculating the final scaling ratio, and the horizontal and vertical scaling start offsets are also calculated, ensuring that the proportionally scaled current resource content fully adapts to the subview content, ensuring that the rendered current resource content is visible to the user and guaranteeing the integrity of the multimedia resource display. When using fill-stretch mode, the fixed width and height of the current resource are independently stretched to the view width and height of the updated subview, allowing the current resource content to quickly fill the subview and simplifying business processing.
[0016] Optionally, rendering the current resource content onto the updated subview based on the transformation matrix to complete the unified loading and display of multimedia resources includes: Determine whether the format type is a special effects animation. If so, input the fixed width of the current resource and the view width of the updated subview into the compensation formula for calculation to obtain the compensation coefficient. The transformation matrix is corrected based on the compensation coefficient to obtain the corrected transformation matrix. The current resource content is then rendered onto the updated subview based on the corrected transformation matrix, thus completing the unified loading and display of multimedia resources.
[0017] As described above, considering the built-in pre-scaling interference problem in special effects animations, the transformation matrix is corrected by dynamically calculating the compensation coefficient between the fixed width of the current resource and the fixed width of the updated subview. This offsets the impact of the built-in pre-scaling, improves the display effect of multimedia resources, and eliminates the need to manually adjust the transformation matrix, thus reducing development complexity.
[0018] Optionally, rendering the current resource content onto the updated subview includes: Determine whether there is an asynchronous callback in the loading process of the current resource content. If so, obtain the path identifier carried in the asynchronous callback and compare the path identifier with the unified resource identifier. If the path identifier matches the unified resource identifier, render the current resource content onto the updated subview. If the path identifier does not match the unified resource identifier, discard the callback result corresponding to the path identifier that does not match the unified resource identifier, stop rendering, and clear the resource loading request.
[0019] As described above, before rendering the current resource content to the updated subview, the path identifier carried in the asynchronous callback is checked to ensure it matches the unified resource identifier. Rendering is only allowed if they match; otherwise, rendering is stopped and the resource loading request is cleared. In RecyclerView scenarios involving high-speed view reuse, rapid refresh, and continuous resource switching, this approach can logically eliminate issues such as resource overwriting, screen distortion, content flickering, and view rendering misalignment caused by delayed callbacks from old network asynchronous requests.
[0020] In a second aspect, the present invention provides a unified routing loading system for multimedia resources, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the unified routing loading method for multimedia resources described in the first aspect.
[0021] The technical effects of the unified routing loading system for multimedia resources provided in the second aspect are the same as those of the unified routing loading method for multimedia resources provided in the first aspect. Attached Figure Description
[0022] Figure 1 A flowchart illustrating a unified routing loading method for multimedia resources provided in this embodiment; Figure 2 This is a schematic diagram of the overall process of a unified routing loading method for multimedia resources provided in this embodiment; Figure 3 This is a schematic diagram of the structure of a unified routing and loading system for multimedia resources provided in this embodiment.
[0023] [Explanation of Labels in the Attached Image] 1. A unified routing and loading system for multimedia resources; 2. Processor; 3. Memory. Detailed Implementation
[0024] To better understand the above technical solutions, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that the present invention can be understood more clearly and thoroughly, and that the scope of the present invention can be fully conveyed to those skilled in the art.
[0025] Example 1 Please refer to Figures 1 to 2 This invention provides a unified routing loading method for multimedia resources, comprising the following steps: S1. The unified display component receives a resource loading request from the caller. The resource loading request carries the unified resource identifier of the multimedia resource and the adaptation rules of the loading configuration object. The unified resource identifier is parsed to obtain the format type of the multimedia resource. The unified display component has a subview pre-built inside to carry the rendering content. In this embodiment, as Figure 2As shown, a unified display component receives resource loading requests from the caller. This component pre-builds subviews to hold the rendered content, as well as placeholder and static image views. The visibility of these views can be switched. During the loading phase, the placeholder view is displayed while the other views are hidden. After successful loading, the component switches to the subview holding the rendered content and hides the other views. Using BBImageLayout as the unified display component, the caller can pass the resource loading request by calling the BBImageLayout.show(url, config) method. The specific unified display component can be adjusted according to the actual situation. The resource loading request carries the unified resource identifier (URI) of the multimedia resource and the adaptation rules of the loading configuration object. The URI is parsed, and the file extension is obtained from the substring after the last "." character, thus determining the format type of the multimedia resource. Specific format types include: static image format, with corresponding file extensions of .png or .jpg; animated image format, with corresponding file extensions of .gif or .webp; vector animation format, with corresponding file extensions of .svga; special effects animation format, with corresponding file extensions of .pag; and transparent video format, with corresponding file extensions of .mp4.
[0026] S2. Execute a loading strategy according to the format type, and clear the historical resource content existing in the subview before executing the loading strategy. When the format type belongs to the first type of format, call the corresponding interface of Glide to execute loading and generate the corresponding Drawable carrier object. When the format type belongs to the second type of format, dynamically create a loading utility class corresponding to the format type through reflection mechanism to execute loading and generate the corresponding Drawable carrier object. In this embodiment, as Figure 2 As shown, a differentiated loading strategy is executed based on the format type. When the format type belongs to the first category, the corresponding Glide interface is called to perform loading and generate the corresponding Drawable carrier object. The first category includes static image formats and dynamic image formats. When the format type belongs to the second category, a loading utility class corresponding to the format type is dynamically created through reflection to perform loading and generate the corresponding Drawable carrier object. The second category includes vector animation formats, special effects animation formats, and transparent video formats. Furthermore, before executing the loading strategy, historical resource content and unfinished loading tasks in the subviews are cleared.
[0027] At this point, step S2, which involves dynamically creating a loading utility class corresponding to the format type using reflection to perform loading and generate the corresponding Drawable carrier object, includes: S21. Generate a target class name according to the format type and preset naming rules, load the loading utility class corresponding to the target class name through the class query method in the reflection mechanism, if the loading is successful, call the parameterless constructor to instantiate the loading utility class, obtain an instance object, perform loading through the instance object, generate the corresponding Drawable carrier object, and store the instance object in the global cache. In this embodiment, as Figure 2 As shown, the target class name is generated according to the format type and preset naming rules. For example, the preset naming rules are: The class name is obtained by concatenating "package_name.autolayout.imagelayout.{type}.{Type}ImageProvider"; When the format type is .pag, a special effects animation format, the generated target class name is: according to the preset naming rules. com.sinyee.babybus.autolayout.imagelayout.pag.PagImageProvider; After generating the target class name, the loading utility class corresponding to the target class name is loaded through the class lookup method in the reflection mechanism. The class lookup method can be represented as Class.forName(). If the loading is successful, the parameterless constructor is called to instantiate the loading utility class and obtain an instance object. The loading is performed through the instance object to generate the corresponding Drawable carrier object, that is, the drawable carrier, which is used to hold the current resource content such as images, animations, and graphics. The instance object is stored in the global cache for easy reuse of the same format type in the future.
[0028] At this point, step S21, which involves loading the instance object to generate the corresponding Drawable carrier object, includes: S211. Determine whether the path type of the Uniform Resource Identifier is a local resource path. If yes, the instance object calls the synchronous loading strategy to perform exclusive resource loading according to the format type and generates the corresponding Drawable carrier object. If no, the instance object calls the asynchronous loading strategy to perform exclusive resource loading according to the format type and generates the corresponding Drawable carrier object. S212. Determine whether the Drawable carrier object has been successfully loaded. If not, convert the format type to the first type format using a custom decoder, call the asynchronous loading strategy to roll back and call the corresponding Glide interface to perform loading, and generate the corresponding Drawable carrier object.
[0029] In this embodiment, as Figure 2As shown, when loading via an instance object, a two-phase loading method is used. Phase 1: First, it checks if the path type of the Uniform Resource Identifier (URI) is a local resource path. If so, a synchronous loading strategy is invoked to load the dedicated resource according to the format type; that is, it waits for loading to complete before proceeding to the next step. Otherwise, if it is not a local resource path (i.e., a network resource path, remote resource path, etc.), an asynchronous loading strategy is invoked to load the dedicated resource according to the format type; that is, it loads silently in the background without blocking the page, thereby generating the corresponding Drawable carrier object. If the Drawable carrier object fails to load, it enters the second phase. Phase 2: A custom decoder converts the format type to the first type of format, and the asynchronous loading strategy is invoked to fall back and call the corresponding Glide interface to perform loading; that is, Glide's global fallback loading mechanism is set up to generate the corresponding Drawable carrier object.
[0030] S22. If loading fails, the loading utility class of the target class name is set to null, and a loading failure callback is triggered to the caller to achieve security degradation.
[0031] In this embodiment, as Figure 2 As shown, if the loading utility class corresponding to the target class name fails to load through the class lookup method in the reflection mechanism, the reflection mechanism will catch the exception. The system will not crash or throw an exception. Instead, it will set the loading utility class of the target class name to null and trigger a loading failure callback to the caller. The upper-level business processing interface will then display the result, such as an error message when the placeholder view is displayed, thus achieving security degradation.
[0032] S3. Obtain the current resource content, fixed width, and fixed height of the Drawable carrier object. Based on the adaptation rules, dynamically calculate the fixed width and fixed height of the current resource to obtain layout parameters. Update the layout parameters to the subview to obtain the updated subview. Render the current resource content onto the updated subview to complete the unified loading and display of multimedia resources.
[0033] At this point, the adaptation rules in step S3 include subview adaptation rules and resource content adaptation rules. The step of dynamically calculating the fixed width and fixed height of the current resource based on the adaptation rules to obtain layout parameters, and then synchronously updating the layout parameters to the subview to obtain the updated subview, and finally rendering the current resource content onto the updated subview to complete the unified loading and display of multimedia resources, includes: S31. When the adaptation rule is a subview adaptation rule, the fixed width and fixed height of the current resource are dynamically calculated based on the subview adaptation rule. When the subview adaptation rule is a fixed width adaptive height mode, the view width of the subview is obtained, and the view width, the fixed width of the current resource, and the fixed height of the current resource are input into the adaptive height formula for dynamic calculation to obtain the adaptation height corresponding to the subview. The adaptation height and the view width are used as the layout parameters of the subview, and the layout parameters are updated synchronously to obtain the updated subview. The current resource content is rendered onto the updated subview to complete the unified loading and display of multimedia resources. S32. When the subview adaptation rule is fixed height adaptive width mode, obtain the view height of the subview, input the view height, the current resource fixed width and the current resource fixed height into the adaptive width formula for dynamic calculation to obtain the adaptation width corresponding to the subview, use the adaptation width and the view height as the layout parameters of the subview, and update the layout parameters to the subview synchronously to obtain the updated subview, render the current resource content onto the updated subview to complete the unified loading and display of multimedia resources; S33. When the subview adaptation rule is the original resource size mode, obtain the screen density conversion coefficient of the current device, multiply the current fixed width and the current fixed height of the resource by the screen density conversion coefficient respectively to obtain the final width and the final height, use the final width and the final height as layout parameters, and update the layout parameters to the subview synchronously to obtain the updated subview, render the current resource content onto the updated subview, and complete the unified loading and display of multimedia resources; S34. When the adaptation rule is a resource content adaptation rule, the view height and view width of the subview are directly used as layout parameters, the original subview is used as the updated subview, and the current resource content is rendered onto the updated subview according to the resource content adaptation rule to complete the unified loading and display of multimedia resources.
[0034] In this embodiment, the adaptation rules are divided into two categories: subview adaptation rules and resource content adaptation rules. Subview adaptation rules directly affect the layout parameters of the subview, i.e., the layout size, determining the size of the subview. Resource content adaptation rules, on the other hand, determine how the current resource content is drawn within the subview. Subview adaptation rules include: fixed width adaptive height mode, fixed height adaptive width mode, and resource original size mode. Resource content adaptation rules include: matrix transformation mode, center-cropping mode, center-scaling mode, and fill-stretch mode.
[0035] When the subview adaptation rule is "fixed width, adaptive height mode," the subview's view width, the current resource's fixed width, and the current resource's fixed height are input into the adaptive height formula for dynamic calculation, resulting in the adaptive height corresponding to the subview. This adaptive height, along with the view width, is used as the subview's layout parameters, and these parameters are synchronously updated to the subview, resulting in the updated subview. The current resource content is then rendered onto the updated subview, completing the unified loading and display of multimedia resources. The adaptive height formula is: Adaptive height = View width × (Current resource fixed height / Current resource fixed width); When the subview adaptation rule is "fixed height, adaptive width mode," the subview's view height, the current resource's fixed width, and the current resource's fixed height are input into the adaptive width formula for dynamic calculation to obtain the corresponding adaptive width of the subview. This adaptive width and view height are then used as layout parameters for the subview, and these parameters are synchronously updated to the subview, resulting in the updated subview. The current resource content is then rendered onto the updated subview, completing the unified loading and display of multimedia resources. The adaptive width formula is: Adaptive width = View height × (Current resource fixed width / Current resource fixed height); When the subview adaptation rule is: original resource size mode, obtain the screen density conversion factor of the current device. The current device refers to the business party that receives the resource loading request from the caller, i.e., the Android system. Multiply the fixed width and fixed height of the current resource by the screen density conversion factor to obtain the final width and final height. Use the final width and final height as layout parameters and update the layout parameters to the subview synchronously to obtain the updated subview. Render the current resource content onto the updated subview to complete the unified loading and display of multimedia resources.
[0036] When the adaptation rule is a resource content adaptation rule, since it does not affect the layout parameters of the subview, the view height and view width of the subview are directly used as layout parameters. The current resource content is rendered onto the updated subview according to the resource content adaptation rule, thus completing the unified loading and display of multimedia resources.
[0037] At this point, step S34, which involves rendering the current resource content onto the updated subview according to the resource content adaptation rules to complete the unified loading and display of multimedia resources, includes: S341. When the resource content adaptation rule is matrix transformation mode, obtain the transformation matrix provided by the caller, and render the current resource content onto the updated subview based on the transformation matrix to complete the unified loading and display of multimedia resources. The transformation matrix includes X-axis scaling component, Y-axis scaling component, X-axis translation component, Y-axis translation component, X-axis shear component, Y-axis shear component, X-axis rotation component, Y-axis rotation component, and perspective component. At this point, step S341, which involves rendering the current resource content onto the updated subview based on the transformation matrix to complete the unified loading and display of multimedia resources, includes: S3411. Determine whether the format type is a special effects animation. If so, input the fixed width of the current resource and the view width of the updated subview into the compensation formula for calculation to obtain the compensation coefficient. S3412. Based on the compensation coefficient, the transformation matrix is corrected to obtain the corrected transformation matrix. Based on the corrected transformation matrix, the current resource content is rendered onto the updated subview to complete the unified loading and display of multimedia resources.
[0038] In this embodiment, when the resource content adaptation rule is matrix transformation mode, the transformation matrix provided by the caller is directly obtained. This transformation matrix is a 3×3 matrix with nine components: X-axis scaling component, Y-axis scaling component, X-axis translation component, Y-axis translation component, X-axis shear component, Y-axis shear component, X-axis rotation component, Y-axis rotation component, and perspective component. The X-axis rotation component is calculated based on the X-axis scaling component and the X-axis shear component, and the Y-axis rotation component is calculated based on the Y-axis scaling component and the Y-axis shear component. Based on the transformation matrix, the current resource content is rendered onto the updated subview. Considering the built-in pre-scaling interference issue for special effects animations, if the format type is a special effects animation, the transformation matrix is corrected. The fixed width of the current resource and the view width of the updated subview are input into the compensation formula for calculation to obtain the compensation coefficient. The compensation formula is as follows: Compensation coefficient = (Current resource fixed width / Updated subview view width) × Image decoding compensation coefficient; The image decoding compensation coefficient is obtained by pre-decoding a fixed-size test image and comparing the decoding result with the original size.
[0039] The transformation matrix is corrected based on compensation coefficients. Specifically, the X-axis scaling component and Y-axis scaling component in the transformation matrix are multiplied by the compensation coefficients respectively to obtain the corrected transformation matrix, thus offsetting the system's built-in pre-scaling interference. Based on the corrected transformation matrix, the current resource content is rendered onto the updated subview, completing the unified loading and display of multimedia resources.
[0040] S342. When the resource content adaptation rule is center-cropping mode, the layout parameters of the updated subview are input into the cropping ratio formula along with the fixed width and fixed height of the current resource to calculate the final cropping ratio. The fixed width and fixed height of the current resource are cropped according to the final cropping ratio to obtain the cropped current resource width and height. The current resource content is updated according to the cropped current resource width and height to obtain the updated current resource content. If the cropped current resource width is greater than the view width of the updated subview, the horizontal cropping start offset is calculated based on the view width and the cropped current resource width. If the cropped current resource height is greater than the view height of the updated subview, the vertical cropping start offset is calculated based on the view height and the cropped current resource height. The updated current resource content is rendered onto the updated subview based on the horizontal cropping start offset and the vertical cropping start offset to complete the unified loading and display of multimedia resources. S343. When the resource content adaptation rule is center scaling mode, the layout parameters of the updated subview are input into the scaling ratio formula along with the fixed width and fixed height of the current resource to calculate the final scaling ratio. The fixed width and fixed height of the current resource are scaled according to the final scaling ratio to obtain the scaled current resource width and scaled current resource height. The scaled current resource width and scaled current resource height are used as the proportional scaling ratio, and the current resource content is scaled proportionally according to the proportional scaling ratio to obtain the proportionally scaled current resource content. If the scaled current resource width is greater than the view width of the updated subview, the horizontal scaling start offset is calculated based on the view width and the clipped current resource width. If the scaled current resource height is greater than the view height of the updated subview, the vertical scaling start offset is calculated based on the view height and the clipped current resource height. The proportionally scaled current resource content is rendered onto the updated subview based on the horizontal scaling start offset and the vertical scaling start offset, completing the unified loading and display of multimedia resources. S344. When the resource content adaptation rule is the fill-stretch mode, the current resource is stretched to the view width of the updated subview with a fixed width, and the current resource is stretched to the view height of the updated subview with a fixed height, so that the current resource content is rendered on the updated subview in a full manner, thus completing the unified loading and display of multimedia resources.
[0041] In this embodiment, when the resource content adaptation rule is: center-cropping mode, the updated subview layout parameters, namely: view width and view height, are input into the cropping ratio formula along with the current resource fixed width and current resource fixed height to calculate the final cropping ratio. The cropping ratio formula is: Final cropping ratio = max(view width / current resource fixed width, view height / current resource fixed height); The current resource's fixed width and height are cropped according to the final clipping ratio to obtain the cropped current resource width and height. The current resource content is then updated based on the cropped current resource width and height to obtain the updated current resource content. If the cropped current resource width is greater than the updated subview's view width, the horizontal clipping starting offset is calculated based on the view width and the cropped current resource width, specifically: Horizontal cropping starting offset = (video width - current resource width after cropping) / 2; Similarly, if the current height of the clipped resource is greater than the view height of the updated subview, then the vertical clipping starting offset is calculated based on the view height and the current height of the clipped resource, specifically: Vertical cropping starting offset = (video height - current resource height after cropping) / 2; The updated current resource content is rendered onto the updated subview based on the horizontal and vertical clipping start offsets. That is, when rendering the updated current resource content onto the updated subview, the rendering is performed based on the position after the horizontal and vertical clipping start offsets, and the part that exceeds the subview is clipped, thus completing the unified loading and display of multimedia resources.
[0042] When the resource content adaptation rule is: center scaling mode, the updated subview layout parameters, i.e., view width and view height, are input into the scaling ratio formula along with the current resource's fixed width and current resource fixed height to calculate the final scaling ratio. The scaling ratio formula is: Final scaling ratio = min(view width / current fixed width of resource, view height / current fixed height of resource); The current resource's fixed width and height are scaled according to the final scaling ratio to obtain the scaled current resource width and height. The scaled current resource width and height are then used as a proportional scaling ratio to scale the current resource content proportionally, resulting in proportionally scaled current resource content. This proportionally scaled current resource content is then rendered onto the updated subview, and the portion of the updated subview's view width and height that exceeds the proportionally scaled current resource content is displayed as the background color, thus completing the unified loading and display of multimedia resources.
[0043] If the current resource width after scaling is greater than the view width of the updated subview, then the horizontal clipping starting offset is calculated based on the view width and the current resource width after scaling, specifically: Horizontal scaling starting offset = (video width - current resource width after scaling) / 2; Similarly, if the scaled current resource height is greater than the updated subview's view height, then the vertical clipping starting offset is calculated based on the view height and the scaled current resource height, specifically: Vertical scaling start offset = (video height - current resource height after scaling) / 2; The current resource content, after being scaled proportionally, is rendered onto the updated subview based on the horizontal and vertical scaling start offsets. In other words, when rendering the current resource content after being scaled proportionally onto the updated subview, the rendering is performed based on the position after the horizontal and vertical scaling start offsets, and the short side of the subview is set to the background color or left blank, thus completing the unified loading and display of multimedia resources.
[0044] When the resource content adaptation rule is the fill-stretch mode, the current resource is stretched to the view width of the updated subview with a fixed width, and the current resource is stretched to the view height of the updated subview with a fixed height, so that the current resource content is rendered on the updated subview in a full manner, thus completing the unified loading and display of multimedia resources.
[0045] At this point, step S3, which involves rendering the current resource content onto the updated subview, includes: S35. Determine whether there is an asynchronous callback in the loading process of the current resource content. If there is, obtain the path identifier carried in the asynchronous callback, compare the path identifier with the unified resource identifier. If the path identifier is consistent with the unified resource identifier, render the current resource content onto the updated subview. If the path identifier is inconsistent with the unified resource identifier, discard the callback result corresponding to the path identifier that is inconsistent with the unified resource identifier, stop rendering, and clear the resource loading request.
[0046] In this embodiment, as Figure 2 As shown, when rendering the current resource content onto the updated subview, it is determined whether there is an asynchronous callback in the loading process of the current resource content. If there is, the path identifier carried in the asynchronous callback is obtained. If the path identifier is consistent with the unified resource identifier, rendering continues. If they are inconsistent, rendering stops and the resource loading request is cleared.
[0047] Example 2 Please refer to Figure 3 The present invention provides a unified routing and loading system 1 for multimedia resources, including a memory 3, a processor 2, and a computer program stored on the memory 3 and executable on the processor 2. When the processor 2 executes the computer program, it implements the steps in Embodiment 1.
[0048] Since the systems / devices described in the above embodiments of the present invention are systems / devices used to implement the methods of the above embodiments of the present invention, those skilled in the art can understand the specific structure and modifications of the systems / devices based on the methods described in the above embodiments of the present invention, and therefore will not be repeated here. All systems / devices used in the methods of the above embodiments of the present invention fall within the scope of protection of the present invention.
[0049] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0050] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions.
[0051] It should be noted that any reference numerals placed between parentheses in the claims should not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention can be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In claims that enumerate several means, several of these means may be embodied by the same hardware. The use of the terms first, second, third, etc., is merely for convenience of expression and does not indicate any order. These terms can be understood as part of the component names.
[0052] Furthermore, it should be noted that in the description of this specification, the terms "one embodiment," "some embodiments," "embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0053] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the claims should be interpreted to include both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0054] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, then this invention should also include these modifications and variations.
Claims
1. A unified routing loading method for multimedia resources, characterized in that, include: The unified display component receives a resource loading request from the caller. The resource loading request carries the unified resource identifier of the multimedia resource and the adaptation rules of the loading configuration object. The unified resource identifier is parsed to obtain the format type of the multimedia resource. The unified display component has a subview pre-built inside to carry the rendered content. The loading strategy is executed according to the format type, and the historical resource content existing in the subview is cleared before the loading strategy is executed. When the format type belongs to the first type, the corresponding interface of Glide is called to execute the loading and generate the corresponding Drawable carrier object. When the format type belongs to the second type, the loading utility class corresponding to the format type is dynamically created through the reflection mechanism to execute the loading and generate the corresponding Drawable carrier object. The current resource content, fixed width, and fixed height of the Drawable carrier object are obtained. Based on the adaptation rules, the fixed width and fixed height of the current resource are dynamically calculated to obtain layout parameters. The layout parameters are then synchronously updated to the subview to obtain the updated subview. The current resource content is then rendered onto the updated subview to complete the unified loading and display of multimedia resources.
2. The unified routing loading method for multimedia resources as described in claim 1, characterized in that, The first type of format includes static image format and dynamic image format, while the second type of format includes vector animation format, special effects animation format, and transparent video format.
3. The unified routing loading method for multimedia resources as described in claim 1, characterized in that, The step of dynamically creating a loading utility class corresponding to the format type through reflection to perform loading and generate the corresponding Drawable carrier object includes: The target class name is generated according to the format type and preset naming rules. The loading utility class corresponding to the target class name is loaded through the class query method in the reflection mechanism. If the loading is successful, the loading utility class is instantiated by calling the parameterless constructor to obtain an instance object. The loading is performed through the instance object to generate the corresponding Drawable carrier object, and the instance object is stored in the global cache. If loading fails, the loading utility class of the target class name is set to null, and a loading failure callback is triggered to the caller to achieve a security degradation.
4. The unified routing loading method for multimedia resources as described in claim 3, characterized in that, The process of loading through the instance object to generate the corresponding Drawable carrier object includes: Determine whether the path type of the Uniform Resource Identifier is a local resource path. If yes, the instance object calls the synchronous loading strategy to perform dedicated resource loading according to the format type and generates the corresponding Drawable carrier object. If no, the instance object calls the asynchronous loading strategy to perform dedicated resource loading according to the format type and generates the corresponding Drawable carrier object. Determine whether the Drawable carrier object has been loaded successfully. If not, convert the format type to the first type using a custom decoder, call the asynchronous loading strategy to roll back and call the corresponding Glide interface to execute loading, and generate the corresponding Drawable carrier object.
5. The unified routing loading method for multimedia resources as described in claim 1, characterized in that, The adaptation rules include subview adaptation rules and resource content adaptation rules. The process involves dynamically calculating the fixed width and fixed height of the current resource based on these rules to obtain layout parameters, synchronously updating these layout parameters to the subview to obtain an updated subview, and then rendering the current resource content onto the updated subview to complete the unified loading and display of multimedia resources. When the adaptation rule is a subview adaptation rule, the fixed width and fixed height of the current resource are dynamically calculated based on the subview adaptation rule. When the subview adaptation rule is a fixed width adaptive height mode, the view width of the subview is obtained, and the view width, the fixed width of the current resource, and the fixed height of the current resource are input into the adaptive height formula for dynamic calculation to obtain the adaptation height corresponding to the subview. The adaptation height and the view width are used as the layout parameters of the subview, and the layout parameters are updated synchronously to obtain the updated subview. The current resource content is rendered onto the updated subview to complete the unified loading and display of multimedia resources. When the subview adaptation rule is a fixed height adaptive width mode, the view height of the subview is obtained, and the view height, the current resource fixed width, and the current resource fixed height are input into the adaptive width formula for dynamic calculation to obtain the adaptation width corresponding to the subview. The adaptation width and the view height are used as the layout parameters of the subview, and the layout parameters are synchronously updated to the subview to obtain the updated subview. The current resource content is rendered onto the updated subview to complete the unified loading and display of multimedia resources. When the subview adaptation rule is the original resource size mode, the screen density conversion coefficient of the current device is obtained, the fixed width and fixed height of the current resource are multiplied by the screen density conversion coefficient respectively to obtain the final width and final height, the final width and final height are used as layout parameters, and the layout parameters are synchronously updated to the subview to obtain the updated subview, and the current resource content is rendered on the updated subview to complete the unified loading and display of multimedia resources; When the adaptation rule is a resource content adaptation rule, the view height and view width of the subview are directly used as layout parameters, the original subview is used as the updated subview, and the current resource content is rendered onto the updated subview according to the resource content adaptation rule, thus completing the unified loading and display of multimedia resources.
6. The unified routing loading method for multimedia resources as described in claim 5, characterized in that, The step of rendering the current resource content onto the updated subview according to the resource content adaptation rules to complete the unified loading and display of multimedia resources includes: When the resource content adaptation rule is matrix transformation mode, the transformation matrix provided by the caller is obtained, and the current resource content is rendered onto the updated subview based on the transformation matrix to complete the unified loading and display of multimedia resources. The transformation matrix includes X-axis scaling component, Y-axis scaling component, X-axis translation component, Y-axis translation component, X-axis shear component, Y-axis shear component, X-axis rotation component, Y-axis rotation component, and perspective component. When the resource content adaptation rule is center-cropping mode, the layout parameters of the updated subview are input into the cropping ratio formula along with the fixed width and fixed height of the current resource to calculate the final cropping ratio. The fixed width and fixed height of the current resource are then cropped according to the final cropping ratio to obtain the cropped current resource width and height. The current resource content is then updated according to the cropped current resource width and height to obtain the updated current resource content. If the cropped current resource width is greater than the view width of the updated subview, a horizontal cropping start offset is calculated based on the view width and the cropped current resource width. If the cropped current resource height is greater than the view height of the updated subview, a vertical cropping start offset is calculated based on the view height and the cropped current resource height. The updated current resource content is then rendered onto the updated subview based on the horizontal and vertical cropping start offsets, completing the unified loading and display of multimedia resources. When the resource content adaptation rule is center scaling mode, the layout parameters of the updated subview are input into the scaling ratio formula along with the fixed width and fixed height of the current resource to calculate the final scaling ratio. The fixed width and fixed height of the current resource are then scaled according to the final scaling ratio to obtain the scaled current resource width and scaled current resource height. The scaled current resource width and scaled current resource height are used as the proportional scaling ratio, and the current resource content is scaled proportionally according to the proportional scaling ratio to obtain the proportionally scaled current resource content. If the scaled current resource width is greater than the view width of the updated subview, a horizontal scaling start offset is calculated based on the view width and the clipped current resource width. If the scaled current resource height is greater than the view height of the updated subview, a vertical scaling start offset is calculated based on the view height and the clipped current resource height. The proportionally scaled current resource content is rendered onto the updated subview based on the horizontal scaling start offset and the vertical scaling start offset, completing the unified loading and display of multimedia resources. When the resource content adaptation rule is the fill-stretch mode, the current resource is stretched to the view width of the updated subview with a fixed width, and the current resource is stretched to the view height of the updated subview with a fixed height, so that the current resource content is rendered on the updated subview in a full manner, thus completing the unified loading and display of multimedia resources.
7. The unified routing loading method for multimedia resources as described in claim 6, characterized in that, The step of rendering the current resource content onto the updated subview based on the transformation matrix to complete the unified loading and display of multimedia resources includes: Determine whether the format type is a special effects animation. If so, input the fixed width of the current resource and the view width of the updated subview into the compensation formula for calculation to obtain the compensation coefficient. The transformation matrix is corrected based on the compensation coefficient to obtain the corrected transformation matrix. The current resource content is then rendered onto the updated subview based on the corrected transformation matrix, thus completing the unified loading and display of multimedia resources.
8. The unified routing loading method for multimedia resources as described in claim 1, characterized in that, The step of rendering the current resource content onto the updated subview includes: Determine whether there is an asynchronous callback in the loading process of the current resource content. If so, obtain the path identifier carried in the asynchronous callback and compare the path identifier with the unified resource identifier. If the path identifier matches the unified resource identifier, render the current resource content onto the updated subview. If the path identifier does not match the unified resource identifier, discard the callback result corresponding to the path identifier that does not match the unified resource identifier, stop rendering, and clear the resource loading request.
9. A unified routing and loading system for multimedia resources, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 8.