Current location - Music Encyclopedia - NetEase Cloud Music - API interface of cmp player
API interface of cmp player
Introduction of cm P4 API interface

The API is an application program interface, and the API of CMP4 is used to provide calling plug-ins or page scripts, so as to control CMP4.

Through API, you can read or set related properties of CMP4, call some methods, bind some events for monitoring, and so on.

Among them, CMP4 supports API:

(1), plugins and backgrounds in global configuration, custom spectrum mixer _src, and logo, video_image, lrc_image.

(2) Five window backgrounds src in the skin.

(3) Video background bg_video and lyrics background bg_lrc of the list item.

(4) JavaScript page scripts (partially supported) must allow script communication (allowScriptAccess=always).

Among them, the script of Flash must be ActionScript 3.0, so the API interface is discussed in the following two situations: through the communication of API interface of AS3, we can directly obtain CMP data and control it in plug-ins or skins,

The following are all supported properties, methods and events.

Attribute attribute:

Cmp: object; Return cmp object

config:Object; Obtain the global configuration of cmp, including all readable and writable global configurations, and other read-only properties of the configuration, such as the current playback state state, which can be queried through the for in statement.

Project: object; Get the current playitem, including the properties of all list items, and the read-only properties of other playitems. What can I query with the for in statement?

list _ XML:XML; Get a reference to the list xml

skin _ XML:XML list; Gets a reference to the current skin configuration.

Tools: objects; Return to cmp toolbox, mainly including: base64, effects, graphics, netclient, output, states, strings, types, zoom, zip.

win _ list:Object;

Get references to five windows with the following five attributes: Options/List/Media/Console /lrc.

Of course, you can also access the objects at the next level. If you want to access the play button bt_play, you can:

var Bt _ play = API . win _ list . console . Bt _ play;

The structure and name are the same as skin configuration skin.xml in the skin package.

Method:

addevent listener():void;

Add an event listener, such as listening to the skin loading completion event:

api.addEventListener(api.key,' skin_loaded ',skinHandler);

Particularly different, the first parameter here needs to be passed in api.key, which is a unique key value used to destroy all registered events with third-party flash removed.

add proxy():void;

Add a proxy function for the protocol, such as src=proxy: function name and function parameters, such as:

Api.addProxy (youku, yk _ callback);

In this way, you can use the custom yk_callback (function parameter) method to parse the protocol: src=proxy:youku, function parameter.

Cookie (): String read (cookie (name)) and write (cookie(name, data)) are stored locally, similar to browser cookies, but there is no time expiration limit.

removeEventListener():void; Remove an event listener, such as api.removeeventlistener ('skin _ loaded', skinhandler);

send event():void;

Send an event, such as: api.sendevent (view _ play);

If there is a parameter data to pass, it is: api.sendEvent(view_play, data);

sendState():void;

Send a new playback status, such as changing the playback status to positive connection:

Api.sendState (connecting);

toString():String; Print all the properties, methods and event types of the api for easy access to all supported APIs.

Event Type Events: In alphabetical order

Dispatched when the api sends an api sharing event.

Called when the api_removeapi plug-in is removed.

Dispatched when the full-screen state of control_fullscreen changes.

Dispatched when control_link opens a linked page.

Dispatched when control_load music starts loading.

Control_max maximizes scheduling when changes occur. Will the data of the event be passed as lrc_max or video_max?

Dispatched when the mute state of control_mute changes.

Dispatched when control_next plays the next song.

Dispatched when control_pause is paused.

Control the playback plan during playback.

Dispatched when the control_playmode playback mode changes.

Dispatched when control_prev plays the previous one.

Dispatched when the progress of control_progress changes.

Dispatched when control_stop stops.

Dispatched when the volume of control_volume changes.

Dispatched when the control_win window opens and closes.

Dispatched when the state of the button corresponding to the control_winbt window changes.

Item _ Deleted

Dispatched when a list item is deleted.

Event will return the deleted item object.

Dispatched when the list_change list has been changed, indicating that the new list has been refreshed and can be used for operations such as playing.

List _ Load

Dispatched when the list starts loading.

The data of the event can be passed to the newly specified configuration list for loading.

List _ Loaded

Dispatched when the list content is loaded, multiple lists will be dispatched, and the loaded list data will be parsed every time, then appended to the main list, and then the list will be refreshed.

The data of the event can be parsed by the newly specified xml list content characters. This function is convenient for external calling and direct input of list contents.

Lrc _ complete

Dispatched when the lyrics are successfully loaded.

Event data returns the currently loaded lyric type: lrc or kmc.

Lrc _ error

Dispatched when lyrics are loaded or parsed incorrectly.

Event data will return an error message.

lrc_load

Dispatched when the lyrics of the current music start to load.

Event data can be passed in to specify the lyric address of the current music, supporting lrc and kmc addresses.

lrc_loaded

Dispatched when lyrics are loaded.

Event data can be passed into the specified lyric content, supporting lrc and kmc format content.

Lrc_max switches the lyric maximization state.

Scheduling when lrc_resize lyrics change in size, including scaling lyrics.

lrc_rowchange

Dispatched when the content of the current lyric line changes. Only lrc and kmc formats are supported.

The event data will return the lyrics of the current line.

With this event, you can easily call js api to print the lyrics of the current position in the title bar or status bar of the browser.

Mixer _ Color

Dispatched when the mixer color changes.

Event data can pass in new color values.

Mixer _ displacement

Scheduling when switching the replacement effect state of the mixer.

Event data can be passed in as true or false.

Mixer _ filter

Dispatched when the filter effect state of the mixer switches.

Event data can be passed in as true or false.

Mixer _ Next

Dispatched when the next mixer effect is used.

Event data can be passed into the id of the next spectral effect.

Mixer _ Previous

Dispatched when the last mixer effect is used.

Event data can be passed into the id of the next spectral effect.

Model _ change

Scheduling when a module changes.

Event data can be passed to the new module type to be used.

Model _ Error

Dispatched when there is an error in the preceding paragraph.

Event data will return an error message.

Model _ Load

Dispatched when the module starts loading.

Event data can be passed to the url of the media to be played.

Dispatched when the current item is downloaded.

Dispatch Model_loading when downloading the current project.

Model _ element

Dispatched when the meta information is obtained in the preceding paragraph.

The event data will return a metadata object.

Model_start is scheduled when the current project starts playing for the first time. Usually, the lyrics will be loaded or the frequency spectrum will be displayed at this time.

Model state

Dispatched when the status of the preceding paragraph changes.

The event data will be returned to the current state, and all supported status codes are as follows:

Undefined is undefined.

connect

buffer area

Play is play.

Pause has been paused.

It stops when it stops.

Finished playing. Finished.

Reconnecting will retry the connection.

When the status changes, the description corresponding to the current status will be displayed in the status bar of the skin, and the language of skin configuration can be customized.

Dispatch Model_time when the play time of the current project changes.

Plug-in _ Load

Dispatched when the plug-in and background start loading.

Event data can be loaded by passing in a newly specified configuration plug-in (background is not supported).

Dispatched when all plug-ins specified by the plugins_loadedplugins parameter have been loaded (at this point, the file specified by the list list will be loaded for the first time).

Plug-ins _ Delete plug-ins and dispatch them when deleting them in the background.

Dispatched when the resize player stage changes size.

Skin _ change

Dispatched when the appearance of the appearance id changes.

Event data can be directly passed into the new skin id.

Dispatched when skin_complete skin display is completed.

Skin load

Dispatched when the appearance starts loading.

You can load event data by passing in newly specified configuration skin parameters.

Dispatched when the skin_loaded skin finishes loading.

Video _ Black and White

Whether the black-and-white effect filter is enabled for the video.

Event data can be passed in as true or false.

Video _ Effect

Dispatched when the ColorMatrixFilter of the video changes.

Event data can be passed into array values separated by English commas to create a new colormatrix filter.

Video _ Highlight

Whether the highlight filter is enabled for the video.

Event data can be passed in as true or false.

Video_max scheduling in video maximization switching.

Dispatched when the video size changes.

Video _ Rotation

Arrange videos while rotating.

Event data can be passed into the rotation angle value, such as 90 degrees.

Video _ Zoom Mode

Scheduling when the video zoom mode changes.

Event data can be passed in with an id supporting zoom mode, which supports 0, 1, 2, 3.

Video smoothing

Dispatched when smoothing effect is enabled for video.

Event data can be passed in as true or false.

Dispatched when view_console changes the state of the control window.

Schedule View_forward when you click the fast forward button.

Dispatched when view_fullscreen changes the full-screen state.

View _ Project

Dispatched when changes are made to the playitem.

View _ link

Dispatched when the link button is clicked.

You can open the event data by passing in the newly specified link.

Dispatched when view_list changes the list window.

Dispatched when view_lrc changes the lyrics window.

Dispatched when view_mute clicks the mute button.

Schedule View_next when you click the Next button.

Dispatched when view_option changes the settings window.

View _ Play

Dispatched when the Play or Pause button is clicked.

The data of the event can indicate which one to play through the list id position.

Schedule View_prev when you click the Back button.

Check the progress

Dispatched when the playback progress bar is dragged.

Event data can be passed in at a specified progress percentage.

Dispatched when view_random clicks the shuffle mode button.

Dispatched when view_repeat clicks the repeat mode button.

When you click the rewind button, View_rewind is scheduled.

View single-player games when you click the single-player mode button.

Dispatch View_stop when the stop button is clicked.

Schedule the time when view_video changes the state of the video window.

View _ Volume

Dispatched when the volume bar is dragged.

Event data can be passed into the specified volume value and translation value, separated by English commas, for example: 1, 0.

Examples of specific API interface applications can be found in the example of installation package: plugins/ApiExample. As or directly to the official plug-in library.

Attach all source files: you need to get the object in flash where CMP is located, that is, cmpo in the example, to call the following functions. See the usage example for the acquisition method.

CMP _ API(); Read-only, return all API information supported by cmp, including API var str = cmpo.cmp _ API () supported by CMP;

config(); 1, read all current global configurations of CMP, and return an Object object, which contains all readable and writable global configuration attribute settings and other read-only attributes var config = cmpo.config ();

2. By reading a configured attribute value, you can query which attributes are specifically supported by the for in statement.

var name = cmpo . config(name);

var name = cmpo.config()。 Name;

3. To modify the value of an attribute, you need to pass in the attribute name and value.

Note: Modifying an attribute only writes the value into the configuration, and the new value will not be applied until the next related refresh (such as sending an event).

cmpo.config(skin_id, 1);

item(); 1, returns the Object object of the current playitem. If the playback is not started, null is returned, which contains all the attributes of the current item: var item = cmpo.item ();

2. Returns an attribute value of the currently played item, which is specially supported and can be queried by the for in statement.

var src = cmpo . item(src);

var src = cmpo.item()。 src

3. Modify the value of an attribute (generally not used) cmpo.item(src, test.mp3);

list _ XML(); 1, read the contents of CMP current list and return an xml string var XML = cmpo.list _ XML ();

2. To modify the list content, you need to pass in a string in xml list format.

Var xml ='< list & gt & ltmlabel = testsrc = test.mp3/></list & gt' ;

cmpo . list _ XML(XML);

If you need to overwrite the original music, you can set a second parameter to indicate whether to append to the original list. By default, it means appending, and passing in false means not appending. The list will be reconstructed and written into the new list content cmpo.list_xml(xml, false);

list();

1, returns all information of CMP list number, including unopened list.

Will return an array, and each item in the array is a music item Object of type Object.

var arr = cmpo . list();

Read var num = cmpo.list () for the number of first-level lists. Length;

Returns the second item, the array starts from 0, and the index of the second item is1varm2 = cmpo.list () [1];

If this music item is a directory, it will have a children attribute, which means that the sub-list below it is also an array.

And so on, so that we can loop through the whole list one by one.

Of course, a music item also has a parent attribute, which represents its parent directory object.

var m2 _ arr = m2.children

2. Returns the specified item object.

This parameter can be an object with a unique key value, or it can pass in a character key value directly.

Key values can be read from the list item object in 1 above.

var item = cmpo . list(m2);

var ITEM = cmpo . list(ITEM _ 1);

3. Read an attribute of this item, var src = cmpo.list (item _ 1, src);

If the passed-in parameter is a method name supported by the item, one of the methods of the item is executed.

Current support: play this project, open this directory, close this directory, toggle the switch, and delete this project.

Cmpo.list(ITEM_ 1, play);

skin _ XML(); Read-only, returns the xml character form of the current skin summary content: varxml = cmpo.skin _ XML ();

Skin (); 1, reading an attribute value of the skin element, 1 parameter indicates the location of the skin element, and the second parameter is the attribute name of the element.

Var width = cmpo.skin (console, width);

Var xywh = cmpo.skin (console. bt_play,xywh);

2. Modify an attribute of the component, and if the modification is successful, return truempo.skin (console.bt _ play, xywh, 0,0,100,20);

send event();

Send events to CMP

The 1 th parameter is the event type. For all supported types, see the list of all event types in AS3.

The second parameter is the data to be passed in (optional).

cmpo . send event(view _ play);

cmpo.sendEvent(view_play,2);

addevent listener();

Add a js listening method.

Parameter 1 is the event type, as above.

The second parameter is the callback function name in string format.

cmpo . addevent listener(item _ deleted,del);

Function del (data) {}

removeEventListener(); Remove the registered js listening method cmpo. removeeventlistener(item _ deleted,del);

cookie(); The general storage interface of CMP can store and read the stored data on the local computer. Flash needs to enable local storage (the default capacity is 10K), and these data are permanently stored across browsers.

Cmpo.cookie (name, cmp4);

var name = cmpo . cookie(name);