PB à toute heure et à tout moment. (à parcourir avec modération)

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 24-09-2020 08:57:01

John77  
Membre Geek
Lieu: Paris
Date d'inscription: 26-10-2012
Messages: 42
Pépites: 186
Banque: 0

Utiliser Windows Media Player dans une fenêtre PB

Bonjour

Je ne pensais pas qu'on me demanderait ça un jour mais dans le cadre de ma mission pour une régie publicitaire, il me faut intégrer Windows Media Player dans une fenêtre PB pour que des utilisateurs puissent contrôler les spots de pub depuis leur appli métier avant de les transférer sur le système de diffusion.

Intégrer WMP via un contrôle OLE ne pose pas de problème, ni jouer un son. Par contre, cliquer directement sur le contrôle a des résultats assez aléatoire.
J'ai trouvé un petit tuto pour faire une fenêtre basique à l'adresse: ici
Je me suis un peu amusé avec, je mets le code plus bas si ça intéresse quelqu'un de l'importer (il y aura un ch'tit problème de compil pour le menu m_environment).

Cela devrait combler le besoin mais je me demandais si quelqu'un avait quelque-chose de plus sexy qu'un truc qui ressemble vaguement à la première version de WinAmp.
Je suis actuellement en SAP PB 12.6

Code: pb

$PBExportHeader$w_music_player.srw
forward
global type w_music_player from window
end type
type cb_stop from commandbutton within w_music_player
end type
type cb_next from commandbutton within w_music_player
end type
type cb_playpause from commandbutton within w_music_player
end type
type cb_prev from commandbutton within w_music_player
end type
type lb_playlist from listbox within w_music_player
end type
type ole_mp from olecontrol within w_music_player
end type
end forward

global type w_music_player from window
integer width = 2843
integer height = 2136
boolean titlebar = true
string title = "Phileas Music Player V1"
string menuname = "m_environment"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
event ue_prev ( )
event ue_playpause ( )
event ue_next ( )
event ue_stop ( )
cb_stop cb_stop
cb_next cb_next
cb_playpause cb_playpause
cb_prev cb_prev
lb_playlist lb_playlist
ole_mp ole_mp
end type
global w_music_player w_music_player

type prototypes
Function boolean GetUserName( ref string buffer, ref ulong buflen ) Library "advapi32.dll" Alias For "GetUserNameW"

end prototypes

type variables
String is_filepath

end variables

event ue_prev();String ls_song_name
Integer li_1, li_2

li_1 = lb_playlist.SelectedIndex()

If li_1 > 1 Then
  li_2 = Integer(li_1) - 1
  lb_playlist.SelectItem(li_2)
  ls_song_name=lb_playlist.SelectedItem()
Else
  lb_playlist.selectitem( li_1)
  ls_song_name=lb_playlist.SelectedItem()
End If

ole_mp.object.URL = is_filepath + ls_song_name

ole_mp.Object.Controls.Play()
Timer(1)

Return

end event

event ue_playpause();Integer i
Long ll_state
String ls_song_name

ll_state = ole_mp.Object.PlayState

Choose Case ll_state
  Case 0, 1
    //ole_mp est initial state ou stopped
    i = lb_playlist.SelectedIndex()
    If i > 0 Then
      ls_song_name = lb_playlist.SelectedItem()
    end if
    
    ole_mp.object.URL = is_filepath + ls_song_name
    
    ole_mp.Object.Controls.Play()
    cb_playpause.text="||"
    Timer(1)
    
    //Pour passer automatiquement à la chanson suivante
    ole_mp.Object.Settings.AutoStart = True
    
  Case 2
    //ole_mp est paused
    ole_mp.Object.Controls.Play()
    cb_playpause.text="||"
    
    Timer(1)
    
  Case 3
    //ole_mp est playing
    ole_mp.Object.Controls.Pause()
    cb_playpause.text=">"
    
    Timer(0)
    
  Case Else
  

End Choose

Return

end event

event ue_next();String ls_song_name
Integer li_1, li_2

li_1 = lb_playlist.SelectedIndex()

If li_1 >= 1 Then
  li_2 = Integer(li_1) + 1
  lb_playlist.SelectItem(li_2)
  ls_song_name = lb_playlist.SelectedItem( )
Else
  lb_playlist.SelectItem(li_1)
  ls_song_name = lb_playlist.SelectedItem()
end if

ole_mp.object.URL = is_filepath + ls_song_name

ole_mp.Object.Controls.Play()
Timer(1)

end event

event ue_stop();ole_mp.Object.Controls.Stop()
cb_playpause.text=">"
Timer(0)

end event

on w_music_player.create
if this.MenuName = "m_environment" then this.MenuID = create m_environment
this.cb_stop=create cb_stop
this.cb_next=create cb_next
this.cb_playpause=create cb_playpause
this.cb_prev=create cb_prev
this.lb_playlist=create lb_playlist
this.ole_mp=create ole_mp
this.Control[]={this.cb_stop,&
this.cb_next,&
this.cb_playpause,&
this.cb_prev,&
this.lb_playlist,&
this.ole_mp}
end on

on w_music_player.destroy
if IsValid(MenuID) then destroy(MenuID)
destroy(this.cb_stop)
destroy(this.cb_next)
destroy(this.cb_playpause)
destroy(this.cb_prev)
destroy(this.lb_playlist)
destroy(this.ole_mp)
end on

event open;String ls_file_pattern
ULong lul_buffer=100
String ls_winusr, ls_file

ls_winusr = Space(100)

If Not GetUserName(ls_winusr, lul_buffer) Then
  Post Close(This)
End If

is_filepath = "C:\Users\"+ls_winusr+"\Music\"

ole_mp.Object.Settings.AutoStart = False

ls_file_pattern = "*.mp3"
ls_file_pattern = is_filepath + ls_file_pattern
lb_playlist.Reset()

If lb_playlist.DirList(ls_file_pattern, 0) Then
  lb_playlist.SelectItem(1)
Else
  Messagebox ("Not able to read the files : ", ls_file_pattern)
End If

ls_file = lb_playlist.SelectedItem()

//J'ai bien testé le FileExists(is_filepath + ls_file) mais il renvoit True même si ls_file = ""
If Lower(RightA(ls_file, 4)) <> ".mp3" Then
  MessageBox("Aucun fichier trouvé", "Veuillez déposer vos fichiers mp3 à l'emplacement: ~""+ is_filepath + "~"")
  Post Close(This)
End If


end event

event timer;Long ll_state

ll_state = ole_mp.Object.PlayState

//La playlist est terminée
If ll_state = 1 Then
  //Pour arrêter le Timer et changer le libellé de cb_playpause
  This.TriggerEvent("ue_stop")
End If

end event

type cb_stop from commandbutton within w_music_player
integer x = 1893
integer y = 1680
integer width = 402
integer height = 112
integer taborder = 60
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "&#8419;"
end type

event clicked;Parent.TriggerEvent("ue_stop")

end event

type cb_next from commandbutton within w_music_player
integer x = 1413
integer y = 1680
integer width = 402
integer height = 112
integer taborder = 50
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = ">>"
end type

event clicked;Parent.triggerEvent("ue_next")

end event

type cb_playpause from commandbutton within w_music_player
integer x = 933
integer y = 1680
integer width = 402
integer height = 112
integer taborder = 40
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = ">"
end type

event clicked;Parent.TriggerEvent("ue_playpause")

end event

type cb_prev from commandbutton within w_music_player
integer x = 453
integer y = 1680
integer width = 402
integer height = 112
integer taborder = 30
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "<<"
end type

event clicked;Parent.TriggerEvent("ue_prev")

end event

type lb_playlist from listbox within w_music_player
integer x = 306
integer y = 112
integer width = 2185
integer height = 1468
integer taborder = 20
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
boolean hscrollbar = true
boolean vscrollbar = true
borderstyle borderstyle = stylelowered!
end type

type ole_mp from olecontrol within w_music_player
event openstatechange ( long newstate )
event playstatechange ( long newstate )
event audiolanguagechange ( long langid )
event statuschange ( )
event scriptcommand ( string sctype,  string param )
event newstream ( )
event ocx_disconnect ( long result )
event buffering ( boolean start )
event ocx_error ( )
event warning ( long warningtype,  long param,  string description )
event endofstream ( long result )
event positionchange ( double oldposition,  double newposition )
event markerhit ( long markernum )
event durationunitchange ( long newdurationunit )
event cdrommediachange ( long cdromnum )
event playlistchange ( oleobject playlist,  integer change )
event currentplaylistchange ( integer change )
event currentplaylistitemavailable ( string bstritemname )
event mediachange ( oleobject item )
event currentmediaitemavailable ( string bstritemname )
event currentitemchange ( oleobject pdispmedia )
event mediacollectionchange ( )
event mediacollectionattributestringadded ( string bstrattribname,  string bstrattribval )
event mediacollectionattributestringremoved ( string bstrattribname,  string bstrattribval )
event mediacollectionattributestringchanged ( string bstrattribname,  string bstroldattribval,  string bstrnewattribval )
event playlistcollectionchange ( )
event playlistcollectionplaylistadded ( string bstrplaylistname )
event playlistcollectionplaylistremoved ( string bstrplaylistname )
event playlistcollectionplaylistsetasdeleted ( string bstrplaylistname,  boolean varfisdeleted )
event modechange ( string modename,  boolean newvalue )
event mediaerror ( oleobject pmediaobject )
event openplaylistswitch ( oleobject pitem )
event domainchange ( string strdomain )
event switchedtoplayerapplication ( )
event switchedtocontrol ( )
event playerdockedstatechange ( )
event playerreconnect ( )
event click ( integer nbutton,  integer nshiftstate,  long fx,  long fy )
event doubleclick ( integer nbutton,  integer nshiftstate,  long fx,  long fy )
event keydown ( integer nkeycode,  integer nshiftstate )
event keypress ( integer nkeyascii )
event keyup ( integer nkeycode,  integer nshiftstate )
event mousedown ( integer nbutton,  integer nshiftstate,  long fx,  long fy )
event mousemove ( integer nbutton,  integer nshiftstate,  long fx,  long fy )
event mouseup ( integer nbutton,  integer nshiftstate,  long fx,  long fy )
event deviceconnect ( oleobject pdevice )
event devicedisconnect ( oleobject pdevice )
event devicestatuschange ( oleobject pdevice,  integer newstatus )
event devicesyncstatechange ( oleobject pdevice,  integer newstate )
event devicesyncerror ( oleobject pdevice,  oleobject pmedia )
event cdromripstatechange ( oleobject pcdromrip,  integer wmprs )
event cdromripmediaerror ( oleobject pcdromrip,  oleobject pmedia )
event cdromburnstatechange ( oleobject pcdromburn,  integer wmpbs )
event cdromburnmediaerror ( oleobject pcdromburn,  oleobject pmedia )
event libraryconnect ( oleobject plibrary )
event librarydisconnect ( oleobject plibrary )
event folderscanstatechange ( integer wmpfss )
event stringcollectionchange ( oleobject pdispstringcollection,  integer change,  long lcollectionindex )
event mediacollectionmediaadded ( oleobject pdispmedia )
event mediacollectionmediaremoved ( oleobject pdispmedia )
boolean visible = false
integer x = 59
integer y = 24
integer width = 219
integer height = 164
integer taborder = 10
borderstyle borderstyle = stylelowered!
boolean focusrectangle = false
string binarykey = "w_music_player.win"
omactivation activation = activateondoubleclick!
omdisplaytype displaytype = displayascontent!
omcontentsallowed contentsallowed = containsany!
end type


Start of PowerBuilder Binary Data Section : Do NOT Edit
0Aw_music_player.bin 
2900000a00e011cfd0e11ab1a1000000000000000000000000000000000003003e0009fffe000000060000000000000000000000010000000100000000000010000000000200000001fffffffe0000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffffffefffffffefffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff006f00520074006f004500200074006e00790072000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050016ffffffffffffffff000000016bf52a5211d3394ac00053b1a6fa794f000000000000000000000000092c3a8001d6931800000003000000c000000000006f00430074006e006e00650073007400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001020012ffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000a2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002fffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
2Fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000003000000000800050000000000003ff0000000000003000500000000000000000000000200080000000000010003000b00000003ffff00000000ffff000b000200080000000000320003000b0000000800000000000a00750066006c006c000b0000000b0000000b0000000bffff000bffff0008000000000002000800000000000200080000000000020008000000000002000b00001952000018ce000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1Aw_music_player.bin 
End of PowerBuilder Binary Data Section : No Source Expected After This Point

Dernière modification par John77 (25-09-2020 08:58:43)

Hors ligne

 

Pied de page des forums

Propulsé par FluxBB 1.2.22