Abstract:
A media file playing method and device. The method comprises: submitting information about a media file to a first window; judging whether the first window is a browser top window; if so, creating a sub-window in the browser top window, setting the sub-window as the first window, loading player logic in the browser top window, and playing the media file by using the player logic in the browser top window; otherwise, transmitting, by the first window, the information about the media file to the browser top window to which the first window belongs, and playing the media file by using the player logic in the browser top window. By means of the present invention, it can be achieved that a webpage player window can play a new media file without refreshing when playing requests of other webpage browser windows are received.

Description:
CROSS REFERENCE TO RELATED APPLICATION 
       [0001]    The present application claims priority to Chinese Patent Application No. 201310608510.2, titled “METHOD AND DEVICE FOR PLAYING MULTIMEDIA FILE IN WEBPAGE” and filed on Nov. 26, 2013 with the State Intellectual Property Office of People&#39;s Republic of China, which is incorporated herein by reference in its entirety. 
       TECHNICAL FIELD 
       [0002]    The present disclosure relates to the technical field of web player, and in particular to a method and a device for playing a media file. 
       BACKGROUND 
       [0003]    A web player is a player achieved by using a web technology (such as html, javascript, flash, css) and a play plug-in (such as a wmp music play plug-in, a flash music play plug-in, a QQ music play plug-in and a html5 audio play plug-in) of a browser in a window of a web browser. 
         [0004]    In general, each time when a song is to be played by using the web player, the web player is opened by a browser window with a same name, so that the web player can be always opened in the same browser window of the browser, which ensures that there is only one web player playing the song. 
         [0005]    In the conventional technology, it can be achieved that only one web browser is opened to play a song, but each time when a new song is to be played by using the opened web player, the web player window is reloaded, which cause refreshing a page of the web player window and reinitializing the page of the web player window, thereby causing a long time delay. 
       SUMMARY 
       [0006]    A method for playing a media file is provided according to the present disclosure, so that a web player window can play a new media file without refreshing a page, when receiving a playing request from another web browser window. 
         [0007]    A device for playing a media file is further provided according to the present disclosure, so that a web player window may play a new media file without refreshing a page, when receiving a playing request from another web browser window. 
         [0008]    The method for playing a media file includes: 
         [0009]    submitting media file information to a first window; and 
         [0010]    determining whether the first window is a top-level window of a browser; creating a sub-window in the top-level window of the browser, setting the sub-window as the first window, loading a player logic in the top-level window of the browser, and playing the media file by using the player logic in the top-level window of the browser, in case that the first window is determined as the top-level window; and transferring the media file information to the top-level window of the browser to which the first window belongs, and playing the media file by using the player logic in the top-level window of the browser, in case that the first window is not determined as the top-level window. 
         [0011]    In the above method, the process of submitting the media file information to the first window includes: 
         [0012]    determining whether there is the first window; submitting directly the media file information to the first window, in case that there is the first window; and creating a first window and submitting the media file information to the first window, in case that there is no first window; where the first window is a browser window whose name is a preset name. 
         [0013]    The process of creating a sub-window in the top-level window of the browser, and setting the sub-window as the first window of the browser includes: 
         [0014]    modifying a name of the top-level window of the browser as a name different from the preset name, creating a hidden sub-window in the top-level window of the browser, and naming the hidden sub-window as the preset name. 
         [0015]    In the method, the media file may be an audio file or a video file, etc. 
         [0016]    A device for playing a media file includes: 
         [0017]    a data transferring module, configured to submit a media file to a first window; and 
         [0018]    a playing module, configured to determine whether the first window is a top-level window of a browser; create a sub-window in the top-level window of the browser, setting the sub-window as the first window, loading a player logic in the top-level window of the browser, and playing the media file by using the player logic in the top-level window of the browser, in case that the first window is determined as the top-level window; and transferring the media file information to the top-level window of the browser to which the first window belongs, and playing the media file by using the player logic in the top-level window of the browser, in case that the first window is not determined as the top-level window. 
         [0019]    In the device, the process of submitting the media file information to the first window by the data transferring module includes: 
         [0020]    determining whether there is the first window; submitting directly the media file information to the first window, in case that there is the first window; and creating a first window and submitting the media file information to the first window, in case that there is no first window; where the first window is a browser window whose name is a preset name. 
         [0021]    In the device, the process of creating a sub-window in the top-level window of the browser, and setting the sub-window as the first window of the browser includes: 
         [0022]    modifying a name of the top-level window of the browser as a name different from the preset name, creating a hidden sub-window in the top-level window of the browser, and naming the hidden sub-window as the preset name. 
         [0023]    A media and a browser for achieving the method are further provided according to embodiments of the present disclosure. 
         [0024]    The media file may be an audio file or a video file, etc. 
         [0025]    With the method and the device for playing a media file, a window is created by a player page as a data transferring page such as a hidden iframe window; a media file is submitted to the data transferring page; and a dynamic scripting language of a top-level player page is directly invoked by a scripting language of the data transferring page to achieve playing the media file without refreshing a page for user perception. The method is achieved without resubmitting the media file to the player and refreshing the whole player, thereby avoiding refreshing the whole player when a new media file is loaded and played, and reducing the time delay. Since the data transferring page is a hidden iframe, when a playing page with a playlist submits data to the data transferring page, the data transferring page refreshes, but a user can not perceive that the data transferring page is refreshed. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0026]      FIG. 1  is a flow chart of a method for playing a media file according to a first embodiment of the disclosure; 
           [0027]      FIG. 2  is a flow chart of a method for playing a media file according to another embodiment of the disclosure; 
           [0028]      FIG. 3  is a schematic structural diagram of a device for playing a media file according to the disclosure; and 
           [0029]      FIG. 4  is a schematic diagram of a hardware structure of a device for playing a media file according to an embodiment of the disclosure. 
       
    
    
     DETAILED DESCRIPTION OF THE EMBODIMENTS 
       [0030]    A method for playing a media file is provided according to the disclosure.  FIG. 1  shows a flow chart of the method. The method includes steps S 101  to S 104 . 
         [0031]    In step S 101 , media file information is submitted to a first window. 
         [0032]    The media file information may be information such as a storage location of a media file. 
         [0033]    In step S 102 , whether the first window is a top-level window of a browser is determined. Step  103  is proceeded, if he first window is the top-level window of the browser; and step S 104  is proceeded, if the first window is not the top-level window of the browser. 
         [0034]    In step S 103 , a sub-window is created in the top-level window of the browser and is set as the first window of the browser, a player logic is loaded in the top-level window of the browser, and a media file is played by using the player logic in the top-level window of the browser. 
         [0035]    The player logic refers to an interface of the player and a control method thereof. 
         [0036]    In step S 104 , the media file information is transferred from the first window to the top-level window to which the first window belongs, and the media file is played by using the player logic in the top-level window of the browser. 
         [0037]    The special implementation of S 101  may include: 
         [0038]    determining whether there is the first window; submitting directly the media file information to the first window, if there is the first window; and creating a first window, and submitting the media file information to the first window, if there is no first window; wherein the first window is a browser window with a preset name. 
         [0039]    In the step S 103 , the process of creating the sub-window in the top-level window of the browser, and setting the sub-window as the first window of the browser may include: 
         [0040]    modifying a name of the top-level window of the browser as a name different from the preset name, creating a hidden sub-window in the top-level window of the browser, and naming the hidden sub-window as the preset name. 
         [0041]    In the disclosure, a window is a frame realized in a computer system. The window may be visible or invisible to a user. The window may be an interface which exists independently, or an interface whose existence is not independent and has to depend on another window. 
         [0042]    In the disclosure, the window may be associated with an application. For example, the browser window refers to a window associated with a browser application. For another example, the browser window may be a browser page, or a browser instance. 
         [0043]    In the disclosure, the top-level window refers to an outermost window container which may exist independently. The top-level window may contain one or more derived sub-windows; and the sub-window is created in the top-level window or in a lower-level sub-window of the top-level window. For example, an iframe created in a top-level window is a sub-window of the top-level window. It may be understood for a person of skill in the art that the sub-window may have one or more derived sub-windows. 
         [0044]    Windows with nested relationship may be created in an application window. An outer window is called as a parent window; and an inner window is called as a sub-window. A sub-window has to depend on a corresponding parent window and cannot exist independently. 
         [0045]    In the disclosure, the top-level window of the browser to which a sub-window belongs refers to an outmost window container opened by a current browser. The sub-window is created in the top-level window or in a sub-window of the top-level window, and the existence of the sub-window depends on the top-level window. 
         [0046]    In the disclosure, the hidden sub-window refers to a sub-window invisible to the user created in a window. 
         [0047]    In the method, the media file may be an audio file or a video file, etc. 
         [0048]    Hereinafter specific embodiments are described in detail in conjunction with the drawings. 
       First Embodiment 
       [0049]    In the embodiment, a media file is a song. 
         [0050]    In the embodiment, a way, in which a window object of a web browser is named and a window of a web browser named as a preset name is used as a data transferring page to transfer song data, is mainly used. In the embodiment, the preset name of the data transferring page is playWindow 1 . 
         [0051]    There are two kinds of windows of a web browser according to a hierarchical relationship. The first kind is a top-level window which is an outmost window opened by the browser; and the second kind is an iframe created in the top-level window of the browser. The page in a top-level window and the page in a sub-window may access each other and transfer data between each other through a dynamic scripting language such as javascript, in a case that the loaded pages belong to a same domain name. 
         [0052]      FIG. 2  shows a flow chart of a method according to the embodiment. The method includes step S 201  to S 208 . 
         [0053]    In step S 201 , a user clicks on a song to play the song in a browser window A with a song list including one or more songs. 
         [0054]    In step S 202 , a dynamic scripting language of the window A such as javascript invokes an interface window.open (‘ ’, ‘playWindow 1 ’) of the browser with respect to opening a window, to open a data transferring page named as playWindow 1 . 
         [0055]    In step S 203 , the browser determines whether there is the data transferring page playWindow 1 , namely a browser window named as playWindow 1 . Step  204  is proceeded, in case that there is no data transferring page playWindow 1 ; and step  205  is proceeded, in case that there is the data transferring page playWindow  1 . 
         [0056]    In step S 204 , the browser creates the data transferring page named as playWindow 1 , and step S 205  is proceeded. 
         [0057]    In step S 205 , the dynamic scripting language of the window A such as javascript submits the song data to the data transferring page named as playWindow 1  by using a POST mode. The reason for using the POST mode to submit the song data to the data transferring page is that a length of URL in the GET mode is limited in the browser and little information can be transfer in the GET mode while a length of the submitted data is not limited in the POST mode. 
         [0058]    In step S 206 , the dynamic scripting language in the controlling module of the data transferring page named as playWindow  1  determines whether the data transferring page playWindow 1  is the top-level window of the browser. If the data transferring page playWindow 1  is the top-level window of the browser, it is indicated that the data transferring page is opened for the first time, a logic of a web player is not loaded, and the browser window needs to be redirected to a final page of the web player, and step s 207  is proceeded; and if the data transferring page playWindow 1  is not the top-level window of the browser, it is indicated that logic of the web player is loaded and the data transferring page playWindow 1  is a hidden iframe sub-window in the top-level window of the browser, and step s 208  is proceeded. 
         [0059]    In step S 207 , the logic of the web player is loaded in the top-level window of the browser, and the name of the top-level window of the browser is changed from the name playWindow  1  originally belonging to the data transferring page to another name such as playWindow 2 . The hidden iframe sub-window is created in the top-level window of the browser named playWindow 2 , the hidden IFRAME sub-window is named as playWindow 1 , and the hidden IFRAME sub-window is a new data transferring page. The logic of the web player is loaded in the top-level window of the browser named playWindow 2 , data information of the song to be played is directly transferred to the logic of the web player, and the song corresponding to the song data is played by the logic of the web player. The method is ended. 
         [0060]    In step S 208 , the data transferring page playWindow 1  invokes, by using the dynamic scripting language such as javascript, an interface of the player logic of the parent window of the data transferring page playWindow 1 , and transfers the song data to the top-level window such as playWindow 2  to which the data transferring page belongs. The song corresponding to the song data is played by using the player logic in playWindow 2 . The scripting language such as javascript in the data transferring page playWindow 1  directly invokes a playing interface of the player logic of the parent window playWindow 2  to play the song, thereby achieving the playing without refreshing the page of the web player for the user perception. 
         [0061]    With the method, when receiving a playing request from other web browser, an independent and unique web player window may play a new song without reloading a web player page. 
         [0062]    A device for playing a media file is further provided according to the disclosure.  FIG. 3  shows a schematic structural diagram of the device. The device includes: 
         [0063]    a data transferring module  301 , configured to submit a media file to a first window; and 
         [0064]    a playing module  302 , configured to determine whether the first window is a top-level window of a browser; create a sub-window in the top-level window of the browser, setting the sub-window as the first window, loading a player logic in the top-level window of the browser, and playing the media file by using the player logic in the top-level window of the browser, in case that the first window is determined as the top-level window; and transferring the media file information to the top-level window of the browser to which the first window belongs, and playing the media file by using the player logic in the top-level window of the browser, in case that the first window is not determined as the top-level window. 
         [0065]    In the above device, the process of submitting the media file information to the first window by the data transferring module  301  may include: 
         [0066]    determining whether there is the first window; submitting directly the media file information to the first window, in case that there is the first window; and creating a first window; and submitting the media file information to the first window, in case that there is no first window, where the first window is a browser window whose name is a preset name. 
         [0067]    The process of creating a sub-window in the top-level window of the browser, and setting the sub-window as the first window of the browser by the playing module  302  may include: 
         [0068]    modifying a name of the top-level window of the browser as a name different from the preset name, creating a hidden sub-window in the top-level window of the browser, and naming the hidden sub-window as the preset name. 
         [0069]    In the above device, the media file may be an audio file or a video file, etc. 
         [0070]      FIG. 4  is a schematic diagram of a hardware structure of a device for playing a media file according to an embodiment of the disclosure. The media playing device may be a terminal device such as a mobile phone, a tablet computer, a personal digital assistant (PDA), a point of sales (POS) and an auto pc, etc, which is not limited in the disclosure. 
         [0071]    The media playing device  1000  may include a communication unit  1110 , one or more memorizers  1120  of a computer readable storage media, an inputting unit  1130 , a displaying unit  1140 , a sensor  1150 , an audio circuit  1160 , a wireless fidelity (WiFi) module  1170 , one or more processors  1180  as a processing core and a power source  1190 , etc. It should be understood for those skilled in the art that the media playing device is not limited by the structure of the media playing device showed in  FIG. 4 , and the media playing device may include more or less units than the structure shown in  FIG. 4 , or include a combination of the units, or include different arrangements of the units. 
         [0072]    The inputting unit  1130  is configured to receive input number information or character information, and to generate a key signal input associated with a user setting and a function control of the media playing device  1000 . 
         [0073]    The displaying unit  1140  is configured to display information input by a user or information provided to the user. The displaying unit  1140  may include a display panel, which is configured by using a liquid crystal display (LCD), or an organic light-emitting diode (OLED), etc. Specially, in a case that the media file is a video file, the displaying unit  1140  may display an image of the video file. 
         [0074]    The audio circuit  1160  may provide an audio interface. The audio circuit  1160  may transmit an electric signal converted from received audio data to a loudspeaker, and the loudspeaker converts the electric signal into a voice signal for outputting. Specially, the audio circuit  1160  may output audio data associated with the media file. 
         [0075]    The media playing device  1000  further includes a memorizer and one or more programs stored in the memorizer, and instructions included in the one or more programs when executed by one or more processors, configure the media play device to: 
         [0076]    submit media file information to a first window; and 
         [0077]    determine whether the first window is a top-level window of a browser; create a sub-window in the top-level window of the browser, set the sub-window as the first window, load a player logic in the top-level window of the browser, and play the media file by using the player logic in the top-level window of the browser, in case that the first window is determined as the top-level window; and transfer the media file information to the top-level window of the browser to which the first window belongs, and play the media file by using the player logic in the top-level window of the browser, in case that the first window is not determined as the top-level window. 
         [0078]    The number in the embodiments according to the disclosure is only used for description, and does not indicate advantages or disadvantages of the embodiments. 
         [0079]    In view of above, a method and a device for playing a media file are provided according to the disclosure. By creating the hidden iframe window in the player page as the first window, the media file is submitted to the first window, and the dynamic scripting language of the top-level player page is invoked directly by the scripting language of the first window to play the media file, thereby achieving the playing of the media file without refreshing a page for user perception. 
         [0080]    According to another embodiment of the disclosure, by executing a computer program including a program code which can play a media file when executed in a general computing device like a computer including processing units such as a central processing unit (CPU) a random access memory (RAM) and a read only memory (ROM), and a storage unit, a device and a browser for playing a media file are configured, and the media playing method according to embodiments of the disclosure are achieved. 
         [0081]    The foregoing embodiments are only preferred embodiments of the disclosure and are not meant to limit the disclosure. All modifications, equivalent variations and improvements made without departing from the spirit and principle of the disclosure shall fall in the scope of the technical solutions of the disclosure.