{"name":"addMusicEventHandler","title":"addMusicEventHandler","type":"command","url":"https://community.bistudio.com/wiki/addMusicEventHandler","revid":370195,"updated":"2024-11-06T12:01:24Z","groups":["Event Handlers","Sounds"],"status":"ok","games":{"arma3":"0.50"},"since":"arma3 0.50","arma3_since":"0.50","locality":{"effect":"local"},"description":"Adds playMusic event handler. Returns id of the handler or -1 when failed. Like addMissionEventHandler, the music event handler is attached to the mission.\nSee Arma 3: Event Handlers - Music Event Handlers.","syntaxes":[{"syntax":"addMusicEventHandler [type, function]","params":[{"name":"type","type":"String","description":"\"MusicStart\" or \"MusicStop\"","type_expr":"String"},{"name":"function","type":"String or Code","description":"passed params array is [musicClassname, eventHandlerId] where:\n\n```sqf\nparams [\"_musicClassname\", \"_eventHandlerId\", \"_currentPosition\", \"_totalLength\"];\n```\n\n- musicClassName: String - CfgMusic class name of the music that started\n- eventHandlerId: Number - event handler id (same as returned by addMusicEventHandler usage)\n- Arma 3 v2.18 currentPosition: Number - current playback position in 0..1 range (see getMusicPlayedTime)\n- Arma 3 v2.18 totalLength: Number - track total length in seconds","type_expr":"String | Code"}],"returns":{"type":"Number","type_expr":"Number","description":"event handler id"},"form":"unary","right":{"text":"[type, function]"}}],"examples":[{"code":["private _ehID = addMusicEventHandler [\"MusicStart\", { hint str _this }];"]},{"code":["private _ehID = addMusicEventHandler [\"MusicStop\", { hint str _this }];"]}],"see_also":["removeMusicEventHandler","playMusic","removeAllMusicEventHandlers","getEventHandlerInfo"],"notes":[{"user":"Druid","date":"2013-03-04T13:30:00Z","text":"There are these two types at this time:\n\n- **MusicStart** - It is triggered when the music is started (command playMusic). In variable _this is stored class name from CfgMusic.\n- **MusicStop** - It is triggered when the music is ended (command playMusic). In variable _this is stored class name from CfgMusic."}]}