plugins
plugins copied to clipboard
[video_player_avplay] Remove duplicate code for checking player
- Extract a new Macro Definition to check if the player exists.
#define CHECK_PLAYER(statement) \
{ \
VideoPlayer *player = (statement); \
if (!player) { \
return FlutterError("Invalid argument", "Player not found"); \
} \
}
- Extract a new macro definition to check the result of player
#define CHECK_PLAYER_RESULT(statement, return_value) \
{ \
const auto result = (statement); \
if (result != PLAYER_ERROR_NONE) { \
LOG_ERROR("[MediaPlayer] Player error : %s", get_error_message(result)); \
return return_value; \
} \
}
#define CHECK_PLAYER_RESULT_NO_RETURN(statement) \
{ \
const auto result = (statement); \
if (result != PLAYER_ERROR_NONE) { \
LOG_ERROR("[MediaPlayer] Player error : %s", get_error_message(result)); \
} \
}
Hi I agree with your intention to reduce duplicate code. However, we don't generally use the macro method.(we follow Google c++ style guide.) https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros If there is no suitable way, you can rename the macro (add project name + avoid conflict) and add
#undef. But I recommend changing it to an appropriate function.
Ok, I'll find a batter solution.