Results:
1. Play video needs to be manually placed in the MediaPlayerControl1 control, set Mediaplayercontrol1.mediaplayer: = MediaPlayer1;
2. Playing sound file is normal, but the player sees that the first side of the normal second side of the error (which God knows, please m i oh, thank you first).
3. You need to enter MP3 and MP4 files when packing, the path is "assets\internal\".
Instance code:
1 UnitUnit1;2 3 Interface4 5 uses6 system.sysutils, System.types, System.uitypes, system.classes, System.variants,7 FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs,8 FMX. Controls.presentation, Fmx.stdctrls, FMX. Media, FMX. Layouts;9 Ten type OneTForm1 =class(Tform) A Mediaplayer1:tmediaplayer; - Label1:tlabel; - Timer1:ttimer; the layout2:tlayout; - layout3:tlayout; - Button1:tbutton; - Button2:tbutton; + Button3:tbutton; - Trackbar1:ttrackbar; + Trackbar2:ttrackbar; A Label2:tlabel; at Label3:tlabel; - layout4:tlayout; - Mediaplayercontrol1:tmediaplayercontrol; - layout1:tlayout; - procedureButton1Click (sender:tobject); - procedureButton2click (sender:tobject); in procedureTrackbar1change (sender:tobject); - procedureTimer1timer (sender:tobject); to procedureButton3click (sender:tobject); + procedureTrackbar2change (sender:tobject); - procedureformcreate (sender:tobject); the Private * {Private Declarations} $ PublicPanax Notoginseng {Public Declarations} - End; the + var A Form1:tform1; the + Implementation - uses $System.ioutils;//need to introduce $ {$R *.FMX} - {$R *. NMXHDPIPH.FMX ANDROID} - the //Execute pause button - procedureTform1.button1click (sender:tobject);Wuyi begin the Mediaplayer1.stop; -Timer1.enabled: =false; WuButton2.enabled: =true; -Button1.enabled: =false; About End; $ - //Execute play button - procedureTform1.button2click (sender:tobject); - begin AMediaplayer1.filename: = Tpath.getdocumentspath +'/abc.mp3';//specify the file to open of course, it is also possible to specify other directories in the SD card as files. +Mediaplayer1.currenttime: = Trunc ((trackbar1.value * mediaplayer1.duration)/ -);//Play progress adjustment to progress bar indicates location theMediaplayer1.volume: = Trackbar2.value;//volume also adjusts to the volume indication value -Mediaplayer1.play;//Play $Timer1.enabled: =true; theButton2.enabled: =false; theButton1.enabled: =true; the End; the - procedureTform1.button3click (sender:tobject); in begin theMediaplayer1.filename: = Includetrailingpathdelimiter (Tpath.getdocumentspath) +'Abc.mp4';//Specify the video file to play the Mediaplayer1.play; AboutTimer1.enabled: =true; the End; the the //set where the video is displayed + proceduretform1.formcreate (sender:tobject); - begin theMediaplayercontrol1.mediaplayer: =MediaPlayer1;Bayi End; the the procedureTform1.timer1timer (sender:tobject); - var - handler:tnotifyevent; the begin theHandler: =Trackbar1.onchange; theTrackbar1.onchange: =Nil;//temporarily cancel its OnChange event theTrackbar1.value: = Int ((mediaplayer1.currenttime/mediaplayer1.duration) * -); - //instructions for updating the progress bar theLabel2.Text: = IntToStr (Trunc (Mediaplayer1.currenttime/60000)) +':'+ theIntToStr (Trunc (Mediaplayer1.currenttime/ +- theTrunc (Mediaplayer1.currenttime/60000) * -));94 //display the remaining playback time of the sound file, in minutes: seconds theLabel3.text: = IntToStr (Trunc (Mediaplayer1.duration/60000)) +':'+ theIntToStr (Trunc (Mediaplayer1.duration/ +-Trunc (Mediaplayer1.duration/ the 60000) * -));//Displays the total playback time of the sound file, in minutes: seconds98Trackbar1.onchange: = handler;//restore its OnChange event About //processing after play is complete - ifMediaplayer1.currenttime >= Mediaplayer1.duration- + Then//If you're done playing101 begin102 Mediaplayer1.stop;103trackbar1.value:=0;104Button2.enabled: =true; theButton1.enabled: =false;106Timer1.enabled: =false;107 End;108 End;109 the //Change Playback Progress while sliding the progress bar111 procedureTform1.trackbar1change (sender:tobject); the begin113Mediaplayer1.currenttime: = Trunc ((trackbar1.value * mediaplayer1.duration)/ -); the End; the the //change the playback volume when sliding the volume adjustment bar117 procedureTform1.trackbar2change (sender:tobject);118 begin119Mediaplayer1.volume: =Trackbar2.value; - End;121 122 End.
Android instance-mediaplayer play music and video (xe8+ Xiaomi 2)