这个是从SCN上看到的,自己稍加修改,编制,做的还可以,可以播放视频,音频,唯一的不足就是不能控制播放视频的显示窗口大小,希望有人能帮忙解决,感激!
视频播放类:(新建类Z_CL_MEDIA,点击基于原代码,复制下面代码进去,激活)
class Z_CL_MEDIA definition public inheriting from CL_GUI_CONTROL final create public . public section. type-pools CNTL . methods CONSTRUCTOR importing !PARENT type ref to CL_GUI_CONTAINER . methods SETDATASOURCE importing !FILENAME type STRING . methods DISPATCH redefinition . methods SET_HEIGHT redefinition . methods SET_WIDTH redefinition . methods SET_POSITION redefinition . protected section. ENDCLASS. CLASS Z_CL_MEDIA IMPLEMENTATION. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Instance Public Method Z_CL_MEDIA->CONSTRUCTOR * +-------------------------------------------------------------------------------------------------+ * | [--->] PARENT TYPE REF TO CL_GUI_CONTAINER * +--------------------------------------------------------------------------------------</SIGNATURE> METHOD constructor. CALL METHOD super->constructor EXPORTING clsid = 'MediaPlayer.MediaPlayer' parent = parent lifetime = 2 EXCEPTIONS OTHERS = 1. ENDMETHOD. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Instance Public Method Z_CL_MEDIA->DISPATCH * +-------------------------------------------------------------------------------------------------+ * | [--->] CARGO TYPE SYUCOMM * | [--->] EVENTID TYPE I * | [--->] IS_SHELLEVENT TYPE CHAR1 * | [--->] IS_SYSTEMDISPATCH TYPE CHAR1(optional) * | [EXC!] CNTL_ERROR * +--------------------------------------------------------------------------------------</SIGNATURE> METHOD dispatch. CALL METHOD cl_gui_cfw=>flush. ENDMETHOD. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Instance Public Method Z_CL_MEDIA->SETDATASOURCE * +-------------------------------------------------------------------------------------------------+ * | [--->] FILENAME TYPE STRING * +--------------------------------------------------------------------------------------</SIGNATURE> METHOD setdatasource. CALL METHOD set_property EXPORTING property = 'FileName' value = filename. * CALL METHOD set_width * EXPORTING * width = 500. * CALL METHOD set_height * EXPORTING * height = 200. CALL METHOD me->set_position EXPORTING height = 200 left = 10 top = 10 width = 500 EXCEPTIONS cntl_error = 1 cntl_system_error = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. CALL METHOD cl_gui_cfw=>flush. ENDMETHOD. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Instance Public Method Z_CL_MEDIA->SET_HEIGHT * +-------------------------------------------------------------------------------------------------+ * | [--->] HEIGHT TYPE I * | [EXC!] CNTL_ERROR * +--------------------------------------------------------------------------------------</SIGNATURE> METHOD set_height. CALL METHOD super->set_height EXPORTING height = height EXCEPTIONS cntl_error = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDMETHOD. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Instance Public Method Z_CL_MEDIA->SET_POSITION * +-------------------------------------------------------------------------------------------------+ * | [--->] HEIGHT TYPE I(optional) * | [--->] LEFT TYPE I(optional) * | [--->] TOP TYPE I(optional) * | [--->] WIDTH TYPE I(optional) * | [EXC!] CNTL_ERROR * | [EXC!] CNTL_SYSTEM_ERROR * +--------------------------------------------------------------------------------------</SIGNATURE> METHOD set_position. CALL METHOD super->set_position EXPORTING height = height left = left top = top width = width EXCEPTIONS cntl_error = 1 cntl_system_error = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. ENDMETHOD. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Instance Public Method Z_CL_MEDIA->SET_WIDTH * +-------------------------------------------------------------------------------------------------+ * | [--->] WIDTH TYPE I * | [EXC!] CNTL_ERROR * +--------------------------------------------------------------------------------------</SIGNATURE> METHOD set_width. CALL METHOD super->set_width EXPORTING width = width EXCEPTIONS cntl_error = 1 OTHERS = 2. IF sy-subrc <> 0. ENDIF. ENDMETHOD. ENDCLASS.
程序ZMEDIA_PLAY
TOP:
TYPES:BEGIN OF ty_list, sel(1), name(50), string TYPE string, END OF ty_list. DATA:gv_con TYPE REF TO cl_gui_custom_container. DATA:gl_meida TYPE REF TO z_cl_media, cl_control TYPE REF TO i_oi_container_control, cl_error TYPE REF TO i_oi_error, g_has_activex TYPE c, cl_errors TYPE REF TO i_oi_error OCCURS 0 WITH HEADER LINE. DATA:gt_list TYPE TABLE OF ty_list. DATA:gw_list LIKE LINE OF gt_list. *&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9876' ITSELF CONTROLS: tc_9876 TYPE TABLEVIEW USING SCREEN 9876. *&SPWIZARD: LINES OF TABLECONTROL 'TC_9876' DATA: g_tc_9876_lines LIKE sy-loopc. DATA: ok_code LIKE sy-ucomm.
PBO:
*----------------------------------------------------------------------* ***INCLUDE ZMEIDA_PBO. *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Module STATUS_9876 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_9876 OUTPUT. SET PF-STATUS 'MEDIA'. " SET TITLEBAR 'xxx'. ENDMODULE. *&---------------------------------------------------------------------* *& Module MOD_INI_CON OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE mod_ini_con OUTPUT. DATA:gv_width TYPE i. DATA:gv_height TYPE i. IF gv_con IS INITIAL. CREATE OBJECT gv_con EXPORTING * parent = container_name = 'GV_CON' * style = * lifetime = lifetime_default * repid = * dynnr = * no_autodef_progid_dynnr = EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. IF sy-subrc <> 0. ENDIF. ENDIF. IF gl_meida IS INITIAL. CREATE OBJECT gl_meida EXPORTING parent = gv_con. ENDIF. IF gt_list IS INITIAL. gw_list-string = 'C:\Wildlife.wmv'. gw_list-name = 'Wildlife.wmv'. APPEND gw_list TO gt_list. gw_list-string = 'C:\123.mp4'. gw_list-name = '123.mp4'. APPEND gw_list TO gt_list. gw_list-string = 'C:\正业之歌.mp3'. gw_list-name = '正业之歌.mp3'. APPEND gw_list TO gt_list. ENDIF. CALL METHOD cl_gui_cfw=>flush. ENDMODULE. *&SPWIZARD: OUTPUT MODULE FOR TC 'TC_9876'. DO NOT CHANGE THIS LINE! *&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR MODULE tc_9876_change_tc_attr OUTPUT. DESCRIBE TABLE gt_list LINES tc_9876-lines. ENDMODULE. *&SPWIZARD: OUTPUT MODULE FOR TC 'TC_9876'. DO NOT CHANGE THIS LINE! *&SPWIZARD: GET LINES OF TABLECONTROL MODULE tc_9876_get_lines OUTPUT. g_tc_9876_lines = sy-loopc. ENDMODULE.
PAI:
*----------------------------------------------------------------------* ***INCLUDE ZMEIDA_PAI. *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Module USER_COMMAND_9876 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_9876 INPUT. CASE sy-ucomm. WHEN 'BACK'. LEAVE TO SCREEN 0. WHEN 'CANL' OR 'EXIT'. LEAVE PROGRAM. WHEN 'PLAY'. READ TABLE gt_list INTO gw_list WITH KEY sel = 'X'. IF sy-subrc = 0. CALL METHOD gl_meida->setdatasource EXPORTING filename = gw_list-string. ENDIF. WHEN 'ADD'. PERFORM prm_add_list. WHEN OTHERS. ENDCASE. CLEAR:sy-ucomm. ENDMODULE. *&SPWIZARD: INPUT MODUL FOR TC 'TC_9876'. DO NOT CHANGE THIS LINE! *&SPWIZARD: MARK TABLE MODULE tc_9876_mark INPUT. DATA: g_tc_9876_wa2 LIKE LINE OF gt_list. IF tc_9876-line_sel_mode = 1 AND gw_list-sel = 'X'. LOOP AT gt_list INTO g_tc_9876_wa2 WHERE sel = 'X'. g_tc_9876_wa2-sel = ''. MODIFY gt_list FROM g_tc_9876_wa2 TRANSPORTING sel. ENDLOOP. ENDIF. MODIFY gt_list FROM gw_list INDEX tc_9876-current_line TRANSPORTING sel. ENDMODULE. *&SPWIZARD: INPUT MODULE FOR TC 'TC_9876'. DO NOT CHANGE THIS LINE! *&SPWIZARD: PROCESS USER COMMAND MODULE tc_9876_user_command INPUT. ok_code = sy-ucomm. PERFORM user_ok_tc USING 'TC_9876' 'GT_LIST' 'SEL' CHANGING ok_code. sy-ucomm = ok_code. ENDMODULE.
frm:
*----------------------------------------------------------------------* * INCLUDE TABLECONTROL_FORMS * *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form USER_OK_TC * *&---------------------------------------------------------------------* FORM user_ok_tc USING p_tc_name TYPE dynfnam p_table_name p_mark_name CHANGING p_ok LIKE sy-ucomm. *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA: l_ok TYPE sy-ucomm, l_offset TYPE i. *&SPWIZARD: END OF LOCAL DATA------------------------------------------* *&SPWIZARD: Table control specific operations * *&SPWIZARD: evaluate TC name and operations * SEARCH p_ok FOR p_tc_name. IF sy-subrc <> 0. EXIT. ENDIF. l_offset = strlen( p_tc_name ) + 1. l_ok = p_ok+l_offset. *&SPWIZARD: execute general and TC specific operations * CASE l_ok. WHEN 'INSR'. "insert row PERFORM fcode_insert_row USING p_tc_name p_table_name. CLEAR p_ok. WHEN 'DELE'. "delete row PERFORM fcode_delete_row USING p_tc_name p_table_name p_mark_name. CLEAR p_ok. WHEN 'P--' OR "top of list 'P-' OR "previous page 'P+' OR "next page 'P++'. "bottom of list PERFORM compute_scrolling_in_tc USING p_tc_name l_ok. CLEAR p_ok. * WHEN 'L--'. "total left * PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME. * * WHEN 'L-'. "column left * PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME. * * WHEN 'R+'. "column right * PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME. * * WHEN 'R++'. "total right * PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME. * WHEN 'MARK'. "mark all filled lines PERFORM fcode_tc_mark_lines USING p_tc_name p_table_name p_mark_name . CLEAR p_ok. WHEN 'DMRK'. "demark all filled lines PERFORM fcode_tc_demark_lines USING p_tc_name p_table_name p_mark_name . CLEAR p_ok. * WHEN 'SASCEND' OR * 'SDESCEND'. "sort column * PERFORM FCODE_SORT_TC USING P_TC_NAME * l_ok. ENDCASE. ENDFORM. " USER_OK_TC *&---------------------------------------------------------------------* *& Form FCODE_INSERT_ROW * *&---------------------------------------------------------------------* FORM fcode_insert_row USING p_tc_name TYPE dynfnam p_table_name . *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA l_lines_name LIKE feld-name. DATA l_selline LIKE sy-stepl. DATA l_lastline TYPE i. DATA l_line TYPE i. DATA l_table_name LIKE feld-name. FIELD-SYMBOLS <tc> TYPE cxtab_control. FIELD-SYMBOLS <table> TYPE STANDARD TABLE. FIELD-SYMBOLS <lines> TYPE i. *&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (p_tc_name) TO <tc>. *&SPWIZARD: get the table, which belongs to the tc * CONCATENATE p_table_name '[]' INTO l_table_name. "table body ASSIGN (l_table_name) TO <table>. "not headerline *&SPWIZARD: get looplines of TableControl * CONCATENATE 'G_' p_tc_name '_LINES' INTO l_lines_name. ASSIGN (l_lines_name) TO <lines>. *&SPWIZARD: get current line * GET CURSOR LINE l_selline. IF sy-subrc <> 0. " append line to table l_selline = <tc>-lines + 1. *&SPWIZARD: set top line * IF l_selline > <lines>. <tc>-top_line = l_selline - <lines> + 1 . ELSE. <tc>-top_line = 1. ENDIF. ELSE. " insert line into table l_selline = <tc>-top_line + l_selline - 1. l_lastline = <tc>-top_line + <lines> - 1. ENDIF. *&SPWIZARD: set new cursor line * l_line = l_selline - <tc>-top_line + 1. *&SPWIZARD: insert initial line * INSERT INITIAL LINE INTO <table> INDEX l_selline. <tc>-lines = <tc>-lines + 1. *&SPWIZARD: set cursor * SET CURSOR LINE l_line. ENDFORM. " FCODE_INSERT_ROW *&---------------------------------------------------------------------* *& Form FCODE_DELETE_ROW * *&---------------------------------------------------------------------* FORM fcode_delete_row USING p_tc_name TYPE dynfnam p_table_name p_mark_name . *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA l_table_name LIKE feld-name. FIELD-SYMBOLS <tc> TYPE cxtab_control. FIELD-SYMBOLS <table> TYPE STANDARD TABLE. FIELD-SYMBOLS <wa>. FIELD-SYMBOLS <mark_field>. *&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (p_tc_name) TO <tc>. *&SPWIZARD: get the table, which belongs to the tc * CONCATENATE p_table_name '[]' INTO l_table_name. "table body ASSIGN (l_table_name) TO <table>. "not headerline *&SPWIZARD: delete marked lines * DESCRIBE TABLE <table> LINES <tc>-lines. LOOP AT <table> ASSIGNING <wa>. *&SPWIZARD: access to the component 'FLAG' of the table header * ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>. IF <mark_field> = 'X'. DELETE <table> INDEX syst-tabix. IF sy-subrc = 0. <tc>-lines = <tc>-lines - 1. ENDIF. ENDIF. ENDLOOP. ENDFORM. " FCODE_DELETE_ROW *&---------------------------------------------------------------------* *& Form COMPUTE_SCROLLING_IN_TC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_TC_NAME name of tablecontrol * -->P_OK ok code *----------------------------------------------------------------------* FORM compute_scrolling_in_tc USING p_tc_name p_ok. *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA l_tc_new_top_line TYPE i. DATA l_tc_name LIKE feld-name. DATA l_tc_lines_name LIKE feld-name. DATA l_tc_field_name LIKE feld-name. FIELD-SYMBOLS <tc> TYPE cxtab_control. FIELD-SYMBOLS <lines> TYPE i. *&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (p_tc_name) TO <tc>. *&SPWIZARD: get looplines of TableControl * CONCATENATE 'G_' p_tc_name '_LINES' INTO l_tc_lines_name. ASSIGN (l_tc_lines_name) TO <lines>. *&SPWIZARD: is no line filled? * IF <tc>-lines = 0. *&SPWIZARD: yes, ... * l_tc_new_top_line = 1. ELSE. *&SPWIZARD: no, ... * CALL FUNCTION 'SCROLLING_IN_TABLE' EXPORTING entry_act = <tc>-top_line entry_from = 1 entry_to = <tc>-lines last_page_full = 'X' loops = <lines> ok_code = p_ok overlapping = 'X' IMPORTING entry_new = l_tc_new_top_line EXCEPTIONS * NO_ENTRY_OR_PAGE_ACT = 01 * NO_ENTRY_TO = 02 * NO_OK_CODE_OR_PAGE_GO = 03 OTHERS = 0. ENDIF. *&SPWIZARD: get actual tc and column * GET CURSOR FIELD l_tc_field_name AREA l_tc_name. IF syst-subrc = 0. IF l_tc_name = p_tc_name. *&SPWIZARD: et actual column * SET CURSOR FIELD l_tc_field_name LINE 1. ENDIF. ENDIF. *&SPWIZARD: set the new top line * <tc>-top_line = l_tc_new_top_line. ENDFORM. " COMPUTE_SCROLLING_IN_TC *&---------------------------------------------------------------------* *& Form FCODE_TC_MARK_LINES *&---------------------------------------------------------------------* * marks all TableControl lines *----------------------------------------------------------------------* * -->P_TC_NAME name of tablecontrol *----------------------------------------------------------------------* FORM fcode_tc_mark_lines USING p_tc_name p_table_name p_mark_name. *&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------* DATA l_table_name LIKE feld-name. FIELD-SYMBOLS <tc> TYPE cxtab_control. FIELD-SYMBOLS <table> TYPE STANDARD TABLE. FIELD-SYMBOLS <wa>. FIELD-SYMBOLS <mark_field>. *&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (p_tc_name) TO <tc>. *&SPWIZARD: get the table, which belongs to the tc * CONCATENATE p_table_name '[]' INTO l_table_name. "table body ASSIGN (l_table_name) TO <table>. "not headerline *&SPWIZARD: mark all filled lines * LOOP AT <table> ASSIGNING <wa>. *&SPWIZARD: access to the component 'FLAG' of the table header * ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>. <mark_field> = 'X'. ENDLOOP. ENDFORM. "fcode_tc_mark_lines *&---------------------------------------------------------------------* *& Form FCODE_TC_DEMARK_LINES *&---------------------------------------------------------------------* * demarks all TableControl lines *----------------------------------------------------------------------* * -->P_TC_NAME name of tablecontrol *----------------------------------------------------------------------* FORM fcode_tc_demark_lines USING p_tc_name p_table_name p_mark_name . *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA l_table_name LIKE feld-name. FIELD-SYMBOLS <tc> TYPE cxtab_control. FIELD-SYMBOLS <table> TYPE STANDARD TABLE. FIELD-SYMBOLS <wa>. FIELD-SYMBOLS <mark_field>. *&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (p_tc_name) TO <tc>. *&SPWIZARD: get the table, which belongs to the tc * CONCATENATE p_table_name '[]' INTO l_table_name. "table body ASSIGN (l_table_name) TO <table>. "not headerline *&SPWIZARD: demark all filled lines * LOOP AT <table> ASSIGNING <wa>. *&SPWIZARD: access to the component 'FLAG' of the table header * ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>. <mark_field> = space. ENDLOOP. ENDFORM. "fcode_tc_mark_lines *&---------------------------------------------------------------------* *& Form PRM_ADD_LIST *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM prm_add_list . DATA:lt_file TYPE filetable. DATA:ls_file LIKE LINE OF lt_file. DATA:gv_return TYPE i. CALL METHOD cl_gui_frontend_services=>file_open_dialog * EXPORTING * window_title = * default_extension = * default_filename = * file_filter = * with_encoding = * initial_directory = * multiselection = CHANGING file_table = lt_file rc = gv_return * user_action = * file_encoding = EXCEPTIONS file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 not_supported_by_gui = 4 OTHERS = 5. IF sy-subrc <> 0. ENDIF. IF lt_file IS NOT INITIAL. LOOP AT lt_file INTO ls_file. gw_list-string = ls_file-filename. SPLIT ls_file-filename AT '\' INTO ls_file-filename gw_list-name. WHILE gw_list-name CS '\'. SPLIT ls_file-filename AT '\' INTO ls_file-filename gw_list-name. ENDWHILE. APPEND gw_list TO gt_list. ENDLOOP. SORT gt_list BY name. DELETE ADJACENT DUPLICATES FROM gt_list COMPARING name. ENDIF. ENDFORM.
在屏幕上分两块,左边为视频或音频播放栏,右边为文件列表,可新增本地文件,可点击文件播放
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^