LocalMusic.ets 402 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889
  1. import TitleBar from './TitleBar'
  2. import { curves, display, PiPWindow, promptAction, router, SymbolGlyphModifier, window } from '@kit.ArkUI';
  3. import { VideoItem } from '../viewmodel/VideoItem';
  4. import {
  5. AppUtil,
  6. ArrayUtil,
  7. Base64Util,
  8. DateUtil,
  9. DeviceUtil,
  10. DisplayUtil,
  11. FileUtil,
  12. ImageUtil,
  13. LogUtil,
  14. MD5,
  15. PreferencesUtil,
  16. RandomUtil,
  17. StrUtil,
  18. ToastUtil
  19. } from '@pura/harmony-utils';
  20. import { unifiedDataChannel, uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
  21. import { CommonConstants } from '../common/constants/CommonConstants';
  22. import Logger from '../common/util/Logger';
  23. import { photoAccessHelper } from '@kit.MediaLibraryKit';
  24. import { BusinessError, emitter } from '@kit.BasicServicesKit';
  25. import { BubbleBean } from '../viewmodel/BubbleBean';
  26. import { PopupPosition, XPopup } from '@chinalike/popup';
  27. import { common, ConfigurationConstant } from '@kit.AbilityKit';
  28. import { AnimationHelper, DialogAction, DialogHelper } from '@pura/harmony-dialog';
  29. import { fileIo, fileUri, picker } from '@kit.CoreFileKit';
  30. import { MessageEvents, util, worker, ErrorEvent } from '@kit.ArkTS';
  31. import { Verify } from './Verify';
  32. import { RotatingCover } from './RotatingCover';
  33. import { PlayConstants } from '../common/constants/PlayConstants';
  34. import { effectKit } from '@kit.ArkGraphics2D';
  35. import { ColorConversion } from '../common/util/ColorConversion';
  36. import { LyricController, LyricParser, LyricView2 } from '@seagazer/cclyric';
  37. import { AvSessionController } from '../controller/AvSessionController';
  38. import { repairAudioMetadata, getApiLyric,changeMusicCover} from '../common/util/MusicTagUtils';
  39. import { FFMpegTags,Utility } from '../common/util/Utility';
  40. import {
  41. // DeviceChangeReason,
  42. IjkMediaPlayer,
  43. InterruptEvent,
  44. InterruptHintType,
  45. LogUtils,
  46. OnBufferingUpdateListener,
  47. OnCompletionListener,
  48. OnErrorListener,
  49. OnInfoListener,
  50. OnPreparedListener,
  51. OnSeekCompleteListener,
  52. OnTimedTextListener,
  53. OnVideoSizeChangedListener
  54. } from '@ohos/ijkplayer';
  55. import { PlayStatus } from '../common/PlayStatus';
  56. import fs from '@ohos.file.fs';
  57. import { image } from '@kit.ImageKit';
  58. import { AVCastPicker, AVCastPickerState, AVCastPickerStyle, avSession } from '@kit.AVSessionKit';
  59. import { UniversalDetector } from '@ohos/juniversalchardet';
  60. import { SettingPage } from '../pages/SettingPage';
  61. import { secondToTime } from '../common/util/CommUtils';
  62. import { CommonConstants2 } from '../common/util/CommonConstants2';
  63. import { hilog } from '@kit.PerformanceAnalysisKit';
  64. import { LazyDataSource } from '../common/util/LazyDataSource';
  65. import MediaTable from '../common/util/MediaTable';
  66. import NetAxiosUtil from '../common/util/NetAxiosUtil';
  67. import ImageUtils from '../common/util/ImageUtils';
  68. import { ringtone } from '@kit.RingtoneKit';
  69. import { BreakpointType, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
  70. import { resourceManager } from '@kit.LocalizationKit';
  71. import { deviceInfo } from '@kit.BasicServicesKit';
  72. import { HSBColorPicker, HSBColorPickerLayout } from '@keke/color-picker'
  73. import app from '@system.app';
  74. import { TextNodeController } from './PipLyricTextBuilder';
  75. import { IndexerView } from './IndexerView';
  76. import { KeyCode } from '@kit.InputKit';
  77. import { KnockController } from '../controller/KnockController';
  78. // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
  79. const TAG = 'LocalMusic';
  80. const DEFAULT_INDEX =
  81. ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  82. 'X', 'Y', 'Z']
  83. //排序类型
  84. function getTypeOrder(type: number) {
  85. switch (type) {
  86. case CommonConstants.TYPE_IS_DIR:
  87. return 1; // First
  88. case CommonConstants.TYPE_IS_CSJAD:
  89. return 2; // Middle
  90. case CommonConstants.TYPE_LOCAL:
  91. return 3; // Last
  92. default:
  93. return 4; // Unknown types, if any, go last
  94. }
  95. }
  96. const workerInstance = new worker.ThreadWorker("entry/ets/workers/Worker.ets");
  97. // 定义接口
  98. interface HiCarAspectRatio {
  99. ratio: number;
  100. name: string;
  101. }
  102. interface GeneratedObjectLiteralInterface_1 {
  103. assetId: string;
  104. title: string;
  105. artist: string;
  106. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  107. mediaUri: string;
  108. // 该字段大写,音频'AUDIO',视频'VIDEO'
  109. mediaType: string;
  110. mediaSize: number;
  111. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  112. startPosition: number;
  113. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  114. duration: number;
  115. albumCoverUri: string;
  116. albumTitle: string;
  117. appName: string;
  118. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  119. drmScheme: string;
  120. }
  121. const ITEM_HEIGHT_SMALL: number = 48; // 列表项小高度
  122. const ITEM_HEIGHT: number = 58; // 列表项中高度
  123. const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
  124. //功能强大的音乐播放器
  125. @Preview
  126. @Component
  127. export struct LocalMusic {
  128. @State opacityValueImage: number = 1;
  129. @State tipPopup:boolean = false
  130. @Consume mType: number;
  131. @StorageProp('themeColor') themeColor: string =
  132. PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  133. themeMode: number = 0;
  134. @State titleName: string = '首页'
  135. @State textStr: string = ''
  136. // static readonly STR_MUSIC_VIDEO: string = 'Audios';
  137. // private download_path: string = '';
  138. @Consume rootPath: string //音频根目录
  139. @Consume currentPath: string
  140. static readonly STR_LOCK_VIDEO: string = '.私密音频';
  141. static readonly STR_FAC_VIDEO: string = '.我的收藏';
  142. @State lockPath: string = ''
  143. @State favPath: string = ''
  144. static readonly STR_HISTORY_MUSIC: string = '.最近播放';
  145. @State historyPath: string = ''
  146. @State historyList: Array<VideoItem> = []
  147. @Consume isHistory: boolean
  148. static readonly HISTORY_MUSIC: string = 'music_historyList';
  149. private table: MediaTable = new MediaTable(getContext(this))
  150. @State isZero: boolean = false
  151. @State fileList: Array<string> = []
  152. @State dirList: Array<VideoItem> = []
  153. @Consume videoLocalList: Array<VideoItem>
  154. @State dataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.videoLocalList)
  155. @State mediaKuList: Array<VideoItem> = []; //媒体库文件
  156. @State artistList: Array<VideoItem> = []; //艺术家文件
  157. @State artistMap: Map<string, VideoItem[]> = new Map(); //艺术家Map
  158. @State albumList: Array<VideoItem> = []; //专辑文件
  159. @State albumMap: Map<string, VideoItem[]> = new Map(); //专辑Map
  160. private mScrollMap: Map<string, number> = new Map(); // 艺术家、专辑名->滚动index
  161. @State imageOpacities: number[] = [];
  162. @Consume isCanBack: boolean
  163. @Consume @Watch('onModeChange') modeType: number; // 0首页,1媒体库,2艺术家,3专辑
  164. @State showSingleLyric: boolean = false
  165. @State sortType: number = 4 //默认排序方式
  166. @State isShowSimi: boolean = false //是否显示私密音频
  167. @State isShowFAV: boolean = true //是否显示我的收藏
  168. @State isShowTitleBar: boolean = true //是否显示分类导航条
  169. @State isShowAllBar: boolean = true //是否显示播放全部条
  170. @State isShowHistory: boolean = true //是否显示最近播放
  171. @State isCustomizeBg: boolean = false //自定义背景界面
  172. @State isGridMusic: boolean = false //是否网格布局
  173. @State isCircleBtn: boolean = false //是否圆形播放按钮
  174. @State twoFingerType: number = 3 //双支放大缩小的类型
  175. @State isScrollHide: boolean = false //是否滚动隐藏
  176. @State isSameTimePlay: boolean = false //是否和其他app同时播放
  177. @State isStartAutoPlay: boolean = false //启动后自动播放
  178. @State isShowPlayPageBack: boolean = false //是否显示播放页返回键
  179. @State isShowHeader: boolean = true
  180. @State isPlayListBgGrass: boolean = true //是否播放列表玻璃透明效果
  181. @State isShowSingleLineLyric: boolean = false //是否显示播放页返回键
  182. @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
  183. @State isCoverTopBig: boolean = false //顶部大封面部分手机显示会和播放控制页重叠
  184. @State isSwipe: boolean = false //listItem的左滑开关
  185. @State openSkipSongAnimate: boolean = true//切歌动画效果
  186. @State customizeBgPath: string | undefined = '';
  187. @State isDarkMode: boolean = false
  188. @State lyricTextWeight: number = 400
  189. @State lyricTextWeightPip: number = 400
  190. @State currentSwiperIndex: number = 0
  191. @State blurValue: number = 0 //背景模糊
  192. @State bgBrightness: number = 0 //背景亮度
  193. private listScroller: ListScroller = new ListScroller()
  194. private playListScroller: Scroller = new Scroller()
  195. @StorageProp('isLandscape') isLandscape: boolean = false;
  196. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  197. @StorageProp('windowWidth') windowWidth: number = 0;
  198. @StorageProp('windowHeight') windowHeight: number = 0;
  199. @StorageProp('isHiCarStatus') isHiCarStatus: boolean = false;
  200. @StorageProp('curDisplayIsHiCar') curDisplayIsHiCar: boolean = false;
  201. private UNKONWN:string = '';
  202. private listArea: Area = {
  203. width: 0,
  204. height: 0,
  205. position: {},
  206. globalPosition: {}
  207. }
  208. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  209. ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET;
  210. onColorModeChange() {
  211. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  212. if (this.isCustomizeBg) {
  213. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  214. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  215. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  216. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  217. } else {
  218. if (!this.isDarkMode) {
  219. this.titleBarModel.setTitleBarBackground(this.themeColor)
  220. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  221. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  222. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  223. } else {
  224. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  225. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  226. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  227. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  228. }
  229. }
  230. }
  231. onModeChange() {
  232. this.isFavMusic = false
  233. if (this.modeType === 2 || this.modeType === 3) {
  234. this.titleBarModel.setRightIcon(null)
  235. } else {
  236. this.titleBarModel.setRightIcon(($r('app.media.add')))
  237. }
  238. LogUtil.info('onecold onModeChange = ' + this.modeType)
  239. switch (this.modeType) {
  240. case 0:
  241. this.getSortedFiles(this.currentPath)
  242. break
  243. case 1:
  244. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  245. this.updateListData(this.mediaKuList)
  246. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  247. break
  248. case 2:
  249. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  250. this.updateListData(this.artistList)
  251. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  252. break
  253. case 3:
  254. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  255. this.updateListData(this.albumList)
  256. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  257. break
  258. }
  259. }
  260. @StorageLink('currentSong') currentSong: VideoItem | undefined = undefined;
  261. // @StorageLink('isPlay') isPlay: boolean = false;
  262. @StorageLink('isShowPlay') isShowPlay: boolean = false;
  263. @StorageLink('songList') songList: Array<VideoItem> = [];
  264. @State translateY: number = 0;
  265. @State isShowSheet: boolean = false;
  266. @State isShowSheetView: boolean = false;
  267. @State isShowTimeCloseView: boolean = false;
  268. private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Vertical });
  269. @StorageLink('currIndex') curIndex: number = 0;
  270. @Consume isShowDrawer: boolean;
  271. @Consume offsetX: number;
  272. @State isFac: boolean = false;
  273. @State favList: Array<VideoItem> = []
  274. @Consume isFavMusic: boolean
  275. @State isClickedPLayAll: boolean = false;
  276. private scrollerForlist: ListScroller = new ListScroller();
  277. private knockController: KnockController | undefined = undefined;
  278. imagesF: ImageFrameInfo[] = [
  279. { src: $r("app.media.app_loading0") },
  280. { src: $r("app.media.app_loading1") },
  281. { src: $r("app.media.app_loading2") },
  282. { src: $r("app.media.app_loading3") },
  283. ]
  284. @State animationState: AnimationStatus = AnimationStatus.Initial
  285. // 缓存机制
  286. private cache: Map<string, Array<VideoItem>> = new Map();
  287. private stringCache: Map<string, string> = new Map(); // 新增字符串缓存
  288. // 持久化缓存
  289. private async saveCacheToStorage() {
  290. const cacheArray = Array.from(this.cache.entries());
  291. const stringCacheArray = Array.from(this.stringCache.entries());
  292. await PreferencesUtil.putSync('music_cache', JSON.stringify(cacheArray));
  293. await PreferencesUtil.putSync('music_string_cache', JSON.stringify(stringCacheArray));
  294. }
  295. // 载入缓存
  296. private async loadCacheFromStorage() {
  297. const cacheString = await PreferencesUtil.getStringSync('music_cache', '');
  298. const stringCacheString = await PreferencesUtil.getStringSync('music_string_cache', ''); // 载入字符串缓存
  299. if (cacheString) {
  300. const cacheArray: [string, Array<VideoItem>][] = JSON.parse(cacheString);
  301. this.cache = new Map(cacheArray);
  302. }
  303. if (stringCacheString) {
  304. const stringCacheArray: [string, string][] = JSON.parse(stringCacheString);
  305. this.stringCache = new Map(stringCacheArray);
  306. }
  307. }
  308. // 查找缓存
  309. private findCache(key: string): Array<VideoItem> | undefined {
  310. return this.cache.get(key);
  311. }
  312. // 查找字符串缓存
  313. private findStringCache(key: string): string | undefined {
  314. return this.stringCache.get(key);
  315. }
  316. // 添加缓存
  317. private addCache(key: string, value: Array<VideoItem>) {
  318. this.cache.set(key, value);
  319. }
  320. // 添加字符串缓存
  321. private addStringCache(key: string, value: string) {
  322. this.stringCache.set(key, value);
  323. }
  324. // 删除缓存
  325. private deleteCache(key: string) {
  326. this.cache.delete(key);
  327. this.saveCacheToStorage()
  328. }
  329. // 删除字符串缓存
  330. private deleteStringCache(key: string) {
  331. this.stringCache.delete(key);
  332. }
  333. // 多选机制
  334. @State selectedFiles: Array<VideoItem> = [];
  335. @State isMultiSelect: boolean = false;
  336. @State isAllSelected: boolean = false;
  337. @State appName: string = ''
  338. @State isHasDir: boolean = false
  339. @State packName: string = ''
  340. context = this.getUIContext().getHostContext() as common.UIAbilityContext
  341. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  342. .setTitleTextStyle(FontStyle.Normal)
  343. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  344. .setLeftIcon($r('app.media.menu'))
  345. .setLeftIconWidth(26)
  346. .setLeftIconHeight(26)
  347. .setTitleName('首页')
  348. .setTitleFontSize(18)
  349. .setTitleFontColor(Color.White)
  350. .setTitleBarBackground(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  351. .setTitleBarBottomLineColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  352. .setLeftTitleStateNormalStyleColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  353. .setRightIcon($r('app.media.add'))
  354. .setOnRightClickListener(() => {
  355. this.showSheelDialog()
  356. })
  357. // .setOnTitleClickListener(() => {
  358. // this.showPupDialog()
  359. // })
  360. .setOnLeftClickListener(() => {
  361. this.doSwipBack()
  362. })
  363. doSwipBack() {
  364. if (this.modeType !== 0 && this.isCanBack) {
  365. this.onModeChange()
  366. this.isCanBack = false
  367. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  368. // 返回专辑列表时恢复滚动偏移量,支持列表和网格
  369. setTimeout(() => {
  370. if (this.modeType == 2) {
  371. if (this.isGridMusic) {
  372. let lastOffset = this.mScrollMap.get('lastGridArtistScrollOffset') ?? 0
  373. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  374. } else {
  375. let lastOffset = this.mScrollMap.get('lastListArtistScrollOffset') ?? 0
  376. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  377. }
  378. } else if (this.modeType == 3) {
  379. if (this.isGridMusic) {
  380. let lastOffset = this.mScrollMap.get('lastGridAlBumScrollOffset') ?? 0
  381. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  382. } else {
  383. let lastOffset = this.mScrollMap.get('lastListAlBumScrollOffset') ?? 0
  384. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  385. }
  386. }
  387. }, 200)
  388. return
  389. }
  390. if (this.isHistory || this.isFavMusic) {
  391. this.isHistory = false
  392. this.getSortedFiles(this.currentPath)
  393. return
  394. }
  395. if (this.currentPath === this.rootPath || this.modeType !== 0) {
  396. animateTo({ duration: 555 }, () => {
  397. // 动画闭包内控制Image组件的出现和消失
  398. this.isShowDrawer = !this.isShowDrawer
  399. this.offsetX = 0
  400. })
  401. return
  402. }
  403. //返回上一级歌单的滚动位置
  404. setTimeout(() => {
  405. if (this.modeType == 0) {
  406. if (this.isGridMusic) {
  407. let lastOffset = this.mScrollMap.get('lastGridDirScrollOffset') ?? 0
  408. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  409. } else {
  410. let lastOffset = this.mScrollMap.get('lastListDirScrollOffset') ?? 0
  411. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  412. }
  413. }
  414. }, 300)
  415. this.currentPath = Utility.getParentDirectory(this.currentPath)
  416. Logger.info('this.currentPath2 = ' + this.currentPath)
  417. this.getSortedFiles(this.currentPath)
  418. }
  419. // 组件生命周期
  420. aboutToAppear() {
  421. if(PreferencesUtil.getBooleanSync('isFirstTiped',true)){
  422. this.tipPopup = !this.tipPopup
  423. PreferencesUtil.putSync('isFirstTiped',false)
  424. }
  425. this.initSetting()
  426. this.UNKONWN = Utility.resourceToString(this.context, $r('app.string.unknown'));
  427. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  428. Utility.getAppName(getContext(this)).then((appName: string) => {
  429. this.appName = appName
  430. })
  431. this.packName = AppUtil.getBundleName()
  432. this.loadCacheFromStorage(); // 加载缓存
  433. this.mkDownLoadDir()
  434. let eventMusic: emitter.InnerEvent = { eventId: 2 }
  435. // 监听广播事件(打开其他应用处理)
  436. emitter.on(eventMusic, (eventData: emitter.EventData) => {
  437. this.saveVideoDatas([eventData.data?.message], true)
  438. });
  439. //侧滑广播接收时间
  440. let eventUpdateSwipeBack: emitter.InnerEvent = { eventId: 888 }
  441. // 监听广播事件(打开其他应用处理)
  442. emitter.on(eventUpdateSwipeBack, (eventData: emitter.EventData) => {
  443. animateTo({ duration: 555 }, () => {
  444. this.doSwipBack()
  445. })
  446. });
  447. //ScanFilePage广播接收时间
  448. let eventScanUpdate: emitter.InnerEvent = { eventId: 101 }
  449. // 监听ScanFilePage广播事件(更新数据库)
  450. emitter.on(eventScanUpdate, (eventData: emitter.EventData) => {
  451. this.doUpdateData()
  452. });
  453. let eventSetting: emitter.InnerEvent = { eventId: 333 }
  454. // 监听广播事件(通用设置配置更新)
  455. emitter.on(eventSetting, (eventData: emitter.EventData) => {
  456. this.doChangeSetting()
  457. });
  458. let event: Callback<InterruptEvent> = (event) => {
  459. LogUtils.getInstance().LOGI(`onecold 与其他应用音频冲突 被截断点event: ${JSON.stringify(event)}`);
  460. this.savePlaybackPosition()
  461. if (event.hintType === InterruptHintType.INTERRUPT_HINT_PAUSE) {
  462. this.pause();
  463. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_RESUME) {
  464. this.startPlayOrResumePlay();
  465. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_STOP) {
  466. this.stop();
  467. }
  468. }
  469. this.mIjkMediaPlayer.on('audioInterrupt', event);
  470. // 音频设备断连回调处理
  471. // let deviceChangeEvent: Callback<InterruptEvent> = (event) => {
  472. // LogUtils.getInstance().LOGI(`Heanup deviceChange event: ${JSON.stringify(event)}`);
  473. // if (event.reason === DeviceChangeReason.REASON_OLD_DEVICE_UNAVAILABLE) { // 音频设备断开连接
  474. // this.pause();
  475. // }
  476. // }
  477. // this.mIjkMediaPlayer.on('deviceChange', deviceChangeEvent);
  478. this.makeWorker()
  479. //折叠屏的屏幕显示模式变化
  480. display.on('foldDisplayModeChange', (data) => {
  481. this.doChangeBarHeight()
  482. });
  483. display.on('foldStatusChange', (data) => {
  484. Logger.info('onecold foldStatusChange ')
  485. });
  486. this.isCoverRectangle = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_RECTANGLE, true)
  487. // 读取 themeMode 并同步 currentColorMode
  488. this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
  489. this.applyThemeMode(this.themeMode)
  490. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  491. AppStorage.setOrCreate('themeColor', themeColor);
  492. this.themeColor = themeColor;
  493. this.doChangeSetting()
  494. this.windowClass.on('windowSizeChange', (size) => {
  495. LogUtil.info('onecold windowSizeChange')
  496. this.doChangeBarHeight()
  497. let viewWidth = px2vp(size.width);
  498. let viewHeight = px2vp(size.height);
  499. if(this.isPhoneLan()){
  500. this.is_auto_hide_progress = false
  501. if(this.isHiCar()){
  502. return
  503. }
  504. setTimeout(() => {
  505. this.is_auto_hide_progress = true
  506. }, 6000)
  507. }else{
  508. this.startAutoHide()
  509. }
  510. });
  511. this.eventHub.on('onStateChange', (fg: boolean) => {
  512. if (fg && this.curState === 'STARTED') {
  513. this.stopPip();
  514. }
  515. });
  516. }
  517. startAutoHide() {
  518. if(this.isHiCar()){
  519. return
  520. }
  521. if(PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_HIDE_PROGRESS,false)){
  522. console.info('onecold startAutoHide')
  523. this.is_auto_hide_progress = false
  524. setTimeout(() => {
  525. this.is_auto_hide_progress = true
  526. }, 6000)
  527. }
  528. }
  529. applyThemeMode(mode: number) {
  530. let colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET
  531. if (mode === 1) {
  532. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
  533. } else if (mode === 2) {
  534. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  535. }
  536. AppStorage.setOrCreate('currentColorMode', colorMode)
  537. AppStorage.setOrCreate('isDarkMode', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK)
  538. PreferencesUtil.putSync(SettingPage.THEME_MODE, mode)
  539. AppStorage.setOrCreate('themeMode', mode)
  540. this.isDarkMode = colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  541. // 只有强制浅色/深色时才主动设置
  542. const context = getContext(this) as common.UIAbilityContext
  543. context.getApplicationContext().setColorMode(colorMode)
  544. }
  545. initSetting() {
  546. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  547. this.isCustomizeBg = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
  548. this.customizeBgPath = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
  549. this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, true)
  550. this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
  551. this.isSameTimePlay = PreferencesUtil.getBooleanSync(SettingPage.IS_SAMETIME_PLAY, false)
  552. this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
  553. this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
  554. this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
  555. this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
  556. this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
  557. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
  558. this.isShowAllBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_ALLBAR, true)
  559. this.twoFingerType = PreferencesUtil.getNumberSync(SettingPage.TWO_FINGER_TYPE, 3)
  560. this.isCoverTop = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP, false)
  561. this.isCircleBtn = PreferencesUtil.getBooleanSync(SettingPage.IS_CIRCLE_BTN, true)
  562. this.isShowPlayPageBack = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_PLAYPAGE_BACK, true)
  563. this.isCoverTopBig = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP_BIG, false)
  564. this.isShowSingleLineLyric = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SLLYRIC, false)
  565. this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
  566. this.isPlayListBgGrass = PreferencesUtil.getBooleanSync(SettingPage.IS_PLAYLIST_BG_GRASS, true)
  567. this.isShowHeader = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HEADER, true)
  568. this.volume = PreferencesUtil.getNumberSync('DefalutVolume', this.volume)
  569. this.isSwipe = PreferencesUtil.getBooleanSync(SettingPage.IS_SWIPE, false)
  570. this.openSkipSongAnimate = PreferencesUtil.getBooleanSync(SettingPage.OPEN_SKIPSONG_ANIMATE, true)
  571. //如果是hicar连接状态,这些都是false
  572. if(this.isHiCar()){
  573. this.isShowTitleBar = false//不显示导航栏
  574. if(!(this.windowWidth>1800&&this.windowHeight>=1200))//小屏幕不可以Grid
  575. {
  576. this.isShowHeader = false//二级菜单不显示头部
  577. this.isGridMusic= false//用list不用网格
  578. this.isCoverTopBig = false
  579. }
  580. this.isShowPlayPageBack = true //播放页返回键要显示,方便驾驶员操作
  581. }
  582. if (this.isSavePlayMode) {
  583. this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
  584. }
  585. if (this.isCustomizeBg) {
  586. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  587. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  588. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  589. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  590. } else {
  591. if (!this.isDarkMode) {
  592. this.titleBarModel.setTitleBarBackground(this.themeColor)
  593. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  594. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  595. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  596. } else {
  597. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  598. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  599. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  600. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  601. }
  602. }
  603. }
  604. doChangeSetting() {
  605. this.initSetting()
  606. this.deleteCache(this.currentPath)
  607. if (this.modeType === 0) {
  608. this.getSortedFiles(this.currentPath)
  609. }
  610. }
  611. doChangeBarHeight() {
  612. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  613. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  614. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  615. this.setBarHeightNormal()
  616. }
  617. }
  618. onPageShow() {
  619. this.knockController?.immersiveListening();
  620. app.setImageCacheCount(100);
  621. // 设置解码前图片数据内存缓存上限为100MB (100MB=100*1024*1024B=104857600B)
  622. app.setImageRawDataCacheSize(104857600);
  623. Logger.info('onecold onPageShow currentBreakpoint= ' + this.currentBreakpoint)
  624. }
  625. //开启线程查看各个数据库
  626. makeWorker() {
  627. setTimeout(() => {
  628. if (PreferencesUtil.getBooleanSync('isFirstApp', true)) {
  629. ToastUtil.showToast('请到文件扫描页面导入音乐!')
  630. //发送worker通知扫描文件入库,用户反馈4000多首用这个方法扫描会闪退。
  631. // workerInstance.postMessage({
  632. // code: 1,
  633. // data1: this.context,
  634. // data2: this.rootPath,
  635. // data3: this.lockPath,
  636. // data4: PreferencesUtil.getStringSync('COVER_API', ''),
  637. // });
  638. PreferencesUtil.putSync('isFirstApp', false)
  639. } else {
  640. workerInstance.postMessage({ code: 2, data: this.context });
  641. workerInstance.postMessage({ code: 3, data: this.context });
  642. workerInstance.postMessage({ code: 4, data: this.context });
  643. this.getHistoryList(false)
  644. }
  645. }, 1000)
  646. workerInstance.onmessage = (e: MessageEvents): void => {
  647. switch (e.data.code) {
  648. case 101: //第一次扫描文件夹入库
  649. ToastUtil.showToast('刷新同步数据库成功!')
  650. Logger.info('onecold 扫描数据库结束 this.mediaKuList length= ' + this.mediaKuList.length)
  651. this.doUpdateData()
  652. break;
  653. case 102: //查询媒体库列表
  654. this.mediaKuList = e.data.data
  655. Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
  656. Utility.doSortListAscending(this.mediaKuList)
  657. AppStorage.setOrCreate('mediaKuList', this.mediaKuList);
  658. if (this.modeType === 1) {
  659. this.updateListData(this.mediaKuList)
  660. }
  661. break;
  662. case 103: //收到查询艺术家列表
  663. this.artistMap = e.data.data1;
  664. this.artistList = e.data.data2;
  665. break;
  666. case 104: //收到查询专辑列表
  667. this.albumMap = e.data.data1;
  668. this.albumList = e.data.data2
  669. //查询完毕在启动是否自动播放
  670. if (this.isStartAutoPlay) {
  671. this.startPlayOrResumePlay()
  672. }
  673. break;
  674. }
  675. };
  676. // 在调用terminate后,执行onexit
  677. workerInstance.onexit = (code) => {
  678. console.log("main thread terminate");
  679. }
  680. //若Worker处于已销毁或正在销毁等非运行状态时,调用其功能接口,会抛出相应的错误。
  681. // 使用Worker模块时,需要在主线程中注册onerror接口,否则当worker线程出现异常时会发生jscrash问题。
  682. workerInstance.onerror = (err: ErrorEvent) => {
  683. console.log("onerror" + err.message);
  684. }
  685. // let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  686. //碰一碰分享的监听
  687. this.knockController = KnockController.getInstance(this.context);
  688. this.knockController?.immersiveListening();
  689. }
  690. onPageHide(): void {
  691. this.knockController?.immersiveDisableListening();
  692. }
  693. @State isFirstStartPlay: boolean = false
  694. //获取download_path
  695. async mkDownLoadDir() {
  696. const documentViewPicker = new picker.DocumentViewPicker()
  697. let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
  698. this.rootPath = new fileUri.FileUri(documentSaveResult[0]).path
  699. // this.rootPath = this.download_path
  700. this.lockPath = this.rootPath + '/' + LocalMusic.STR_LOCK_VIDEO
  701. this.favPath = this.rootPath + '/' + LocalMusic.STR_FAC_VIDEO
  702. this.historyPath = this.rootPath + '/' + LocalMusic.STR_HISTORY_MUSIC
  703. Logger.info('onecold rootPath = ' + this.rootPath)
  704. Logger.info('onecold lockPath = ' + this.lockPath)
  705. if (!FileUtil.accessSync(this.lockPath)) {
  706. FileUtil.mkdirSync(this.lockPath)
  707. }
  708. if (!FileUtil.accessSync(this.favPath)) {
  709. FileUtil.mkdirSync(this.favPath)
  710. }
  711. if (!FileUtil.accessSync(this.historyPath)) {
  712. FileUtil.mkdirSync(this.historyPath)
  713. }
  714. this.getSortedFiles(this.rootPath).then(() => {
  715. this.isFavMusic = false
  716. //穿山甲
  717. // this.loadBannerAd(CSJUtil.getBannerID())
  718. this.songList = PreferencesUtil.getSync('LastMusicList', []) as Array<VideoItem>
  719. this.currentSong = PreferencesUtil.getSync('LastMusicInfo', undefined) as VideoItem
  720. if (ArrayUtil.isEmpty(this.songList)) {
  721. this.songList = this.getCurFileList()
  722. } else {
  723. this.curIndex = Utility.getIndexFromList(this.songList, this.currentSong.filePath)
  724. }
  725. if (ArrayUtil.isNotEmpty(this.songList)) {
  726. this.isFirstStartPlay = true
  727. this.sonDataSource.pushArrayData(this.songList)
  728. if (this.currentSong === undefined) {
  729. this.isFirstStartPlay = false
  730. this.currentSong = this.songList[0]
  731. }
  732. this.videoUrl = this.currentSong.filePath
  733. this.name = this.currentSong.name
  734. this.cover = this.currentSong.pixelMapPath
  735. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  736. } else {
  737. this.name = '空空如也'
  738. }
  739. })
  740. this.getFavList(false)
  741. }
  742. getFavList(isFavRefresh: boolean) {
  743. this.table.queryByisFav(1, async (result: VideoItem[]) => {
  744. this.favList = result
  745. if (isFavRefresh || this.isFavMusic) { //如果是我的收藏,更新我的收藏数据
  746. this.videoLocalList = this.favList
  747. this.updateListData(this.videoLocalList)
  748. }
  749. })
  750. }
  751. getHistoryList(isRefresh: boolean) {
  752. this.table.queryRecentPlayedRecords(50, async (result: VideoItem[]) => {
  753. this.historyList = result
  754. // for (let i = 0; i < this.historyList.length; i++) {
  755. //
  756. // console.info(`onecold gengxin 1: ${this.historyList[i].name}`);
  757. // console.info(`onecold gengxin 1: ${this.historyList[i].lastPlayedStr}`);
  758. // }
  759. if (isRefresh) {
  760. this.videoLocalList = this.historyList
  761. this.updateListData(this.videoLocalList, true)
  762. }
  763. })
  764. }
  765. // 组件消失生命周期
  766. aboutToDisappear() {
  767. console.info('LifeCycleComponent aboutToDisappear');
  768. this.knockController?.immersiveDisableListening();
  769. this.curIndex = 0
  770. emitter.off(2);
  771. emitter.off(101);
  772. emitter.off(888);
  773. emitter.off(333);
  774. this.mDestroyPage = true;
  775. this.mIjkMediaPlayer.setScreenOnWhilePlaying(false);
  776. if (this.CONTROL_PlayStatus != PlayStatus.INIT) {
  777. this.stop();
  778. }
  779. this.mIjkMediaPlayer.off('audioInterrupt');
  780. if (workerInstance) {
  781. workerInstance.terminate();
  782. }
  783. this.stopPip();
  784. this.destroyPipController()
  785. }
  786. async getSortedFiles(curPath: string, isWorkerPost?: boolean, destPath?: string, isOpen?: boolean) {
  787. this.isFavMusic = false
  788. if (isWorkerPost) {
  789. workerInstance.postMessage({ code: 2, data: this.context }); //刷新媒体库列表
  790. }
  791. if (this.modeType !== 0) {
  792. return
  793. }
  794. this.isCanBack = false
  795. this.currentPath = curPath
  796. this.titleBarModel.setTitleName(getFileDirName(this.currentPath, this.rootPath))
  797. if (curPath === this.rootPath) {
  798. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  799. } else {
  800. this.currentTitleName = getFileDirName(this.currentPath, this.rootPath)
  801. if (this.rootPath === Utility.getParentDirectory(curPath)) {
  802. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  803. }
  804. }
  805. // Get the current file list and calculate its hash
  806. this.fileList = FileUtil.listFileSync(curPath);
  807. const currentHash = simpleHash(this.fileList);
  808. // Check cache
  809. const cachedValue = this.findCache(curPath);
  810. Logger.info('onecold cachedValue = ' + cachedValue)
  811. const cachedHash = this.findStringCache(curPath + '_hash');
  812. const cachedDirList = this.findCache(curPath + "_dirList");
  813. if (cachedValue !== undefined) {
  814. // this.videoLocalList = cachedValue;
  815. Logger.info('onecold 有缓存 cachedValue = ' + cachedValue)
  816. if (this.currentPath != this.rootPath) { //第一个封面赋值给currentTitleCover
  817. this.currentTitleCover = Utility.getFirstCoverFromList(cachedValue)
  818. }
  819. this.updateListData(cachedValue)
  820. }
  821. if (cachedDirList !== undefined) {
  822. this.dirList = cachedDirList
  823. }
  824. //通过当前hash值和缓存hash判断list有没有变化
  825. if (cachedValue && cachedHash === currentHash) {
  826. return;
  827. }
  828. this.fileList = FileUtil.listFileSync(curPath)
  829. let directories: Array<VideoItem> = [];
  830. let files: Array<VideoItem> = [];
  831. for (let i = 0; i < this.fileList.length; i++) {
  832. console.info(`The name of file: ${this.fileList[i]}`);
  833. let path = curPath + '/' + this.fileList[i]
  834. if (FileUtil.isDirectory(path)) {
  835. let item: VideoItem =
  836. new VideoItem(this.fileList[i].toString(), this.fileList[i].toString(), path, CommonConstants.TYPE_IS_DIR, 0,
  837. '')
  838. if (this.isShowDir(item.name)) {
  839. directories.push(item);
  840. }
  841. // directories.sort((a, b) => a.cTime.localeCompare(b.cTime));
  842. // Utility.doSortListAscending(directories)
  843. } else {
  844. if (this.currentPath === this.lockPath&&Utility.isMeidaByExtension(path)) {
  845. let item: VideoItem =
  846. await Utility.uriGetMusicAssetsFromFile(this.context, path, CommonConstants.TYPE_LOCAL, false);
  847. if (!path.endsWith('.lrc') && Utility.isMeidaByExtension(path) && !path.endsWith('.srt')) {
  848. files.push(item);
  849. // files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  850. // this.doSortListAscending(files)
  851. }
  852. }
  853. }
  854. }
  855. this.table.queryByParentPath(curPath, async (result: VideoItem[]) => {
  856. if (this.currentPath !== this.lockPath) {
  857. files = result;
  858. }
  859. files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  860. Utility.doSortListAscending(files)
  861. if (this.currentPath === this.rootPath) {
  862. this.dirList = directories
  863. this.addCache(curPath + "_dirList", this.dirList);
  864. }
  865. //插入广告先注释掉
  866. // if (this.isShowAd && ArrayUtil.isNotEmpty(directories)) {
  867. // let adItem: VideoItem = new VideoItem('', '', '', CommonConstants.TYPE_IS_CSJAD, 0, '')
  868. // directories.push(adItem)
  869. // }
  870. // 合并文件夹和文件,文件夹在前,文件在后,广告在中间
  871. this.videoLocalList = directories.concat(files);
  872. this.updateListData(this.videoLocalList)
  873. if (ArrayUtil.isNotEmpty(files)) {
  874. if (this.currentPath != this.rootPath) {
  875. if (files) {
  876. this.currentTitleCover = Utility.getFirstCoverFromList(files)
  877. }
  878. }
  879. // 缓存结果
  880. this.addCache(curPath, this.videoLocalList);
  881. await this.saveCacheToStorage(); // 保存缓存至本地存储
  882. this.addStringCache(curPath + '_hash', currentHash);
  883. }
  884. console.info(`onecold gengxin 1: ${this.videoLocalList.length}`);
  885. // for (let i = 0; i < this.videoLocalList.length; i++) {
  886. //
  887. // console.info(`onecold gengxin 1: ${this.videoLocalList[i].pixelMapPath}`);
  888. //
  889. // }
  890. // this.setButtonStatus()
  891. if (isOpen) {
  892. if (destPath === undefined) {
  893. // 处理 destPath 为 undefined 的情况
  894. return
  895. }
  896. if (destPath.endsWith('.lrc')) {
  897. ToastUtil.showToast('导入歌词成功!请注意歌词文件和歌曲要同个歌单路径。')
  898. if (StrUtil.isNotEmpty(this.videoUrl)) {
  899. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  900. this.initLyric(lyricPath);
  901. }
  902. return
  903. }
  904. let item2 = new VideoItem(Utility.getMediaNameByUri(destPath), destPath, destPath, 0, 0, '')
  905. this.doPlay(item2)
  906. this.isShowPlay = true
  907. }
  908. });
  909. }
  910. //扫描文件夹入库
  911. async scanDirectory(curPath: string): Promise<VideoItem[]> {
  912. const files = FileUtil.listFileSync(curPath);
  913. let mediaItems: VideoItem[] = [];
  914. Logger.info('onecold scanDirectory start ')
  915. for (const file of files) {
  916. const fPath = `${curPath}/${file}`;
  917. if (fPath === this.lockPath) {
  918. Logger.info(`Skipping locked path: ${fPath}`);
  919. continue;
  920. }
  921. if (FileUtil.isDirectory(fPath)) {
  922. // Recursively scan subdirectories
  923. const subDirItems = await this.scanDirectory(fPath);
  924. mediaItems = mediaItems.concat(subDirItems);
  925. } else {
  926. Logger.info('onecold scanDirectory filePath = ' + fPath)
  927. // Process media files
  928. if (!fPath.endsWith('.lrc') && Utility.isMeidaByExtension(fPath) && !fPath.endsWith('.srt')) {
  929. let mediaItem: VideoItem =
  930. await Utility.uriGetMusicAssetsFromFile(this.context, fPath, CommonConstants.TYPE_LOCAL, true);
  931. mediaItems.push(mediaItem);
  932. this.table.insert(mediaItem, (id: number) => {
  933. });
  934. }
  935. }
  936. }
  937. return mediaItems;
  938. }
  939. updateListData(mList: Array<VideoItem>, noSort?: boolean) {
  940. animateTo({ duration: 888 }, () => {
  941. this.opacityItem = 0;
  942. });
  943. setTimeout(() => {
  944. this.videoLocalList = mList;
  945. if (!noSort) {
  946. if (this.modeType === 0 || this.modeType === 1) {
  947. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  948. this.doSortType(this.sortType)
  949. }
  950. }
  951. this.dataSource.pushArrayData(this.videoLocalList)
  952. animateTo({ duration: 888 }, () => {
  953. this.opacityItem = 1;
  954. });
  955. this.setButtonStatus()
  956. }, 200);
  957. }
  958. //排序模式和多选模式
  959. showPupDialog() {
  960. if (this.modeType === 2 || this.modeType === 3) {
  961. this.titleBarModel.setRightIcon(null)
  962. } else {
  963. this.titleBarModel.setRightIcon(($r('app.media.add')))
  964. }
  965. let dataBean = new BubbleBean()
  966. dataBean.data = ["首页", "媒体库", "艺术家", "专辑", "同步数据"]
  967. dataBean.color = this.themeColor
  968. dataBean.modeType = this.modeType
  969. dataBean.imageRes =
  970. [$r('app.media.home_press'), $r('app.media.kp_music'), $r('app.media.music_menu'), $r('app.media.llq'),
  971. $r('app.media.refresh')]
  972. let pup: XPopup;
  973. if (this.isDarkMode) {
  974. pup = XPopup.Builder()
  975. .setPopupPosition(PopupPosition.BOTTOM)
  976. .atView('pup_positon_music')
  977. .setBackgroundColor(Color.Black)
  978. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  979. .show()
  980. } else {
  981. pup = XPopup.Builder()
  982. .setPopupPosition(PopupPosition.BOTTOM)
  983. .atView('pup_positon_music')
  984. .setBackgroundColor(Color.White)
  985. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  986. .show()
  987. }
  988. dataBean.onItemClick = (i) => {
  989. XPopup.dismissTop()
  990. switch (i) {
  991. case 0: //首页
  992. this.modeType = 0
  993. this.getSortedFiles(this.currentPath)
  994. break
  995. case 1:
  996. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  997. this.modeType = 1
  998. this.updateListData(this.mediaKuList)
  999. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  1000. break
  1001. case 2:
  1002. this.modeType = 2
  1003. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1004. this.updateListData(this.artistList)
  1005. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  1006. break
  1007. case 3:
  1008. this.modeType = 3
  1009. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1010. this.updateListData(this.albumList)
  1011. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  1012. break
  1013. case 4: //同步数据
  1014. this.asyncCurrentPathData()
  1015. break
  1016. }
  1017. }
  1018. }
  1019. getCurFileList(): Array<VideoItem> {
  1020. let files: Array<VideoItem> = [];
  1021. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1022. for (let i = 0; i < this.videoLocalList.length; i++) {
  1023. if (this.videoLocalList[i].type === CommonConstants.TYPE_LOCAL) {
  1024. files.push(this.videoLocalList[i]);
  1025. }
  1026. }
  1027. }
  1028. return files
  1029. }
  1030. setButtonStatus() {
  1031. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1032. this.isZero = false
  1033. } else {
  1034. this.isZero = true
  1035. }
  1036. if (this.currentPath !== this.rootPath &&
  1037. ArrayUtil.isNotEmpty(Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR))) {
  1038. this.isHasDir = true //不为空,说明有子文件夹
  1039. } else {
  1040. this.isHasDir = false
  1041. }
  1042. }
  1043. showRankDialog() {
  1044. if (this.modeType === 2 || this.modeType === 3) {
  1045. //动作面板
  1046. DialogHelper.showBottomSheetDialog({
  1047. title: "请选择排序模式",
  1048. maskColor: Color.Transparent,
  1049. // sheets: ["按名称升序", "按名称降序"],
  1050. sheets: [
  1051. { value: '按名称升序', fontColor: $r('app.color.text_color') },
  1052. { value: '按名称降序', fontColor: $r('app.color.text_color') },
  1053. ],
  1054. backgroundColor: $r('app.color.bg_card'),
  1055. height: '30%',
  1056. transition: AnimationHelper.transitionInDown(555),
  1057. onAction: (index) => {
  1058. switch (index) {
  1059. case 0:
  1060. Utility.doSortListAscending(this.videoLocalList)
  1061. break;
  1062. case 1:
  1063. Utility.doSortListDescending(this.videoLocalList)
  1064. break;
  1065. }
  1066. this.updateListData(this.videoLocalList)
  1067. }
  1068. })
  1069. return
  1070. }
  1071. //动作面板
  1072. DialogHelper.showBottomSheetDialog({
  1073. title: "请选择排序模式",
  1074. maskColor: Color.Transparent,
  1075. height: '75%',
  1076. // sheets: ["按艺术家升序", "按艺术家降序", "按专辑升序", "按专辑降序", "按名称升序", "按名称降序", "按添加时间升序","按添加时间降序"],
  1077. sheets: [
  1078. { value: "按艺术家升序", fontColor: $r('app.color.text_color') },
  1079. { value: "按艺术家降序", fontColor: $r('app.color.text_color') },
  1080. { value: "按专辑升序", fontColor: $r('app.color.text_color') },
  1081. { value: "按专辑降序", fontColor: $r('app.color.text_color') },
  1082. { value: "按名称升序", fontColor: $r('app.color.text_color') },
  1083. { value: "按名称降序", fontColor: $r('app.color.text_color') },
  1084. { value: "按添加时间升序", fontColor: $r('app.color.text_color') },
  1085. { value: "按添加时间降序", fontColor: $r('app.color.text_color') },
  1086. ],
  1087. backgroundColor: $r('app.color.bg_card'),
  1088. transition: AnimationHelper.transitionInDown(555),
  1089. onAction: (index) => {
  1090. this.doSortType(index)
  1091. PreferencesUtil.put(SettingPage.SORT_TYPE, index)
  1092. this.updateListData(this.videoLocalList, true)
  1093. }
  1094. })
  1095. }
  1096. doSortType(index: number) {
  1097. switch (index) {
  1098. case 0:
  1099. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1100. // 类型排序优先级
  1101. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1102. if (typeOrder !== 0) {
  1103. return typeOrder;
  1104. }
  1105. // 处理艺术家可能为undefined的字符串比较
  1106. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1107. const artistB = b.artist?.trim() || '';
  1108. return artistA.localeCompare(artistB);
  1109. });
  1110. break;
  1111. case 1:
  1112. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1113. // 类型排序优先级
  1114. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1115. if (typeOrder !== 0) {
  1116. return typeOrder;
  1117. }
  1118. // 处理艺术家可能为undefined的字符串比较
  1119. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1120. const artistB = b.artist?.trim() || '';
  1121. return artistB.localeCompare(artistA);
  1122. });
  1123. break;
  1124. case 2:
  1125. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1126. // 类型排序优先级
  1127. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1128. if (typeOrder !== 0) {
  1129. return typeOrder;
  1130. }
  1131. // 处理专辑可能为undefined的字符串比较
  1132. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1133. const albumB = b.album?.trim() || '';
  1134. return albumA.localeCompare(albumB);
  1135. });
  1136. break;
  1137. case 3:
  1138. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1139. // 类型排序优先级
  1140. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1141. if (typeOrder !== 0) {
  1142. return typeOrder;
  1143. }
  1144. // 处理专辑可能为undefined的字符串比较
  1145. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1146. const albumB = b.album?.trim() || '';
  1147. return albumB.localeCompare(albumA);
  1148. });
  1149. break;
  1150. case 4:
  1151. Utility.doSortListAscending(this.videoLocalList)
  1152. break;
  1153. case 5:
  1154. Utility.doSortListDescending(this.videoLocalList)
  1155. break;
  1156. case 6:
  1157. this.videoLocalList.sort((a, b) => {
  1158. // First, sort by type
  1159. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1160. if (typeOrder !== 0) {
  1161. return typeOrder;
  1162. }
  1163. // If types are the same, sort by cTime in ascending order
  1164. return a.cTime.localeCompare(b.cTime);
  1165. });
  1166. break;
  1167. case 7:
  1168. this.videoLocalList.sort((a, b) => {
  1169. // First, sort by type
  1170. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1171. if (typeOrder !== 0) {
  1172. return typeOrder;
  1173. }
  1174. // If types are the same, sort by cTime in descending order
  1175. return b.cTime.localeCompare(a.cTime);
  1176. });
  1177. break;
  1178. }
  1179. }
  1180. showSheelDialog() {
  1181. // if(PreferencesUtil.getBooleanSync('isFirstMusic',true)) {
  1182. // this.showTips()
  1183. // return
  1184. // }
  1185. this.showAddDialog()
  1186. }
  1187. showAddDialog() {
  1188. if (this.modeType === 2 || this.modeType === 3) {
  1189. return
  1190. }
  1191. DialogHelper.showActionSheetDialog({
  1192. title: "请选择添加方式(建议歌词文件一起导入)",
  1193. // sheets: ["新建歌单", "手动导入", "自动导入"],
  1194. sheets: [
  1195. { value: "新建歌单", fontColor: $r('app.color.text_color') },
  1196. { value: "手动导入", fontColor: $r('app.color.text_color') },
  1197. { value: "自动导入", fontColor: $r('app.color.text_color') },
  1198. { value: "全选导入", fontColor: $r('app.color.text_color') },
  1199. ],
  1200. maskColor: Color.Transparent,
  1201. backgroundColor: $r('app.color.bg_card'),
  1202. transition: AnimationHelper.transitionInDown(555),
  1203. onAction: (index) => {
  1204. switch (index) {
  1205. case 0:
  1206. if (this.modeType === 0) {
  1207. this.showMkDialog()
  1208. } else {
  1209. ToastUtil.showToast('请切换到首页才能新建歌单!')
  1210. }
  1211. break;
  1212. case 1:
  1213. this.callFilePickerSelectFile()
  1214. break;
  1215. case 2:
  1216. this.showTips()
  1217. break;
  1218. case 3:
  1219. this.goSelectMusic()
  1220. break;
  1221. }
  1222. }
  1223. })
  1224. }
  1225. //拉起音频
  1226. goSelectMusic() {
  1227. if (DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_TABLET ||
  1228. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_PC ||
  1229. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1
  1230. ) {
  1231. ToastUtil.showToast('暂时不支持该设备')
  1232. return
  1233. }
  1234. try {
  1235. let documentSelectOptions = new picker.DocumentSelectOptions();
  1236. documentSelectOptions.authMode = true
  1237. documentSelectOptions.multiAuthMode = true
  1238. documentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO;
  1239. let documentPicker = new picker.DocumentViewPicker(this.context);
  1240. documentPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => {
  1241. if (documentSelectResult !== null && documentSelectResult !== undefined) {
  1242. this.saveVideoDatas(documentSelectResult)
  1243. }
  1244. console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' +
  1245. JSON.stringify(documentSelectResult));
  1246. }).catch((err: BusinessError) => {
  1247. console.error(`DocumentViewPicker.select failed with err, code is: ${err.code}, message is: ${err.message}`);
  1248. });
  1249. } catch (error) {
  1250. let err: BusinessError = error as BusinessError;
  1251. console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1252. }
  1253. }
  1254. async showTips() {
  1255. DialogHelper.showTipsDialog({
  1256. title: '使用提示:自动导入教程',
  1257. content: '用系统自带的文件管理器将:\n\n1、音频文件放入' + '\n\n我的设备/Download/'
  1258. + this.appName + '\n\n2、无需繁琐的勾选和分类步骤。\n\n3、每个子文件夹将被组成一个分组。' +
  1259. '\n\n4、歌词文件的文件名必须和目标歌曲文件名相同(不包含后缀名)。\n\n5、歌词文件和目标歌曲文件必须同个目录。' +
  1260. '\n\n6、电脑上Download的目录是\nDownload/' + this.packName + '。\n\n7、放好文件后如果没显示点击刷新按钮。\n',
  1261. onAction: (action) => {
  1262. if (action == DialogAction.TWO) {
  1263. PreferencesUtil.putSync('isFirstMusic', false)
  1264. router.pushUrl({
  1265. url: 'pages/ScanFilePage'
  1266. });
  1267. }
  1268. }
  1269. })
  1270. }
  1271. showMkDialog() {
  1272. DialogHelper.showTextInputDialog({
  1273. title: '新建歌单',
  1274. maskColor: Color.Transparent,
  1275. text: '',
  1276. transition: AnimationHelper.transitionInDown(666),
  1277. onChange: (text) => {
  1278. console.error("onChange: " + text);
  1279. },
  1280. onAction: (action, dialogId, content) => {
  1281. // ToastUtil.showToast('content = ' +content)
  1282. if (action == DialogAction.TWO) {
  1283. const newName = content
  1284. const newPath = this.currentPath + '/' + newName
  1285. FileUtil.mkdir(newPath, true).then(() => {
  1286. this.cache.delete(this.currentPath); // 删除目标路径缓存
  1287. this.getSortedFiles(this.currentPath)
  1288. }).catch((error: BusinessError) => {
  1289. console.error(error.message);
  1290. });
  1291. }
  1292. }
  1293. })
  1294. }
  1295. @State progress: number = 0;
  1296. async saveVideoDatas(uris: string[], isOpen?: boolean) {
  1297. if (ArrayUtil.isEmpty(uris)) {
  1298. return;
  1299. }
  1300. let newUris: string[] = [];
  1301. this.progress = 0
  1302. DialogHelper.showLoadingProgress({
  1303. progress: this.progress,
  1304. backCancel: false,
  1305. autoCancel: false,
  1306. loadColor: this.themeColor,
  1307. fontColor: this.themeColor
  1308. });
  1309. // 计算所有文件的总大小
  1310. let totalSize = 0;
  1311. for (let uri of uris) {
  1312. const sourceFile = await fileIo.open(uri, fileIo.OpenMode.READ_ONLY);
  1313. totalSize += (await fileIo.stat(sourceFile.fd)).size;
  1314. await fileIo.close(sourceFile.fd);
  1315. }
  1316. let totalRead = 0;
  1317. let destPath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[0]);
  1318. Logger.info(TAG, 'destPath uri: ' + destPath);
  1319. for (let i = 0; i < uris.length; i++) {
  1320. let filePath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[i]);
  1321. Logger.info(TAG, 'filePath uri: ' + filePath);
  1322. newUris.push(filePath);
  1323. try {
  1324. const sourceFile = await fileIo.open(uris[i], fileIo.OpenMode.READ_ONLY);
  1325. const destFile = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  1326. const buffSize = 1024 * 1024; // 1MB 缓冲区大小
  1327. const buffer = new ArrayBuffer(buffSize);
  1328. let len = await fileIo.read(sourceFile.fd, buffer);
  1329. while (len > 0) {
  1330. await fileIo.write(destFile.fd, buffer.slice(0, len));
  1331. totalRead += len;
  1332. // 计算总进度
  1333. this.progress = Math.floor((totalRead / totalSize) * 100);
  1334. DialogHelper.updateLoading('正在导入', this.progress);
  1335. len = await fileIo.read(sourceFile.fd, buffer);
  1336. }
  1337. await fileIo.close(sourceFile.fd);
  1338. await fileIo.close(destFile.fd);
  1339. if (this.currentPath !== this.lockPath) { //判断不是私密音乐,才入库
  1340. if (!filePath.endsWith('.lrc') && Utility.isMeidaByExtension(filePath) && !filePath.endsWith('.srt')) {
  1341. let mediaItem: VideoItem =
  1342. await Utility.uriGetMusicAssetsFromFile(this.context, filePath, CommonConstants.TYPE_LOCAL, true);
  1343. this.table.insert(mediaItem, (id: number) => {
  1344. // 删除目标路径缓存
  1345. this.cache.delete(this.currentPath);
  1346. this.getSortedFiles(this.currentPath, true, destPath, isOpen)
  1347. });
  1348. }
  1349. }
  1350. } catch (error) {
  1351. Logger.error(TAG, 'saveVideoDatas failed with err: ' + JSON.stringify(error));
  1352. }
  1353. }
  1354. DialogHelper.closeLoading()
  1355. this.isZero = false
  1356. // setTimeout(() => {
  1357. // // 删除目标路径缓存
  1358. // this.cache.delete(this.currentPath);
  1359. // this.getSortedFiles(this.currentPath,true,destPath,isOpen)
  1360. // }, 500);
  1361. Logger.info(TAG, 'scan select video result:' + newUris)
  1362. }
  1363. //拉起音频
  1364. // goSelectMusic(){
  1365. //
  1366. // try {
  1367. // let audioSelectOptions = new picker.AudioSelectOptions();
  1368. // let audioPicker = new picker.AudioViewPicker(this.context);
  1369. // audioPicker.select(audioSelectOptions).then((audioSelectResult: Array<string>) => {
  1370. // if (audioSelectResult !== null && audioSelectResult !== undefined) {
  1371. // this.saveVideoDatas(audioSelectResult)
  1372. // }
  1373. // console.info('AudioViewPicker.select successfully, audioSelectResult uri: ' + JSON.stringify(audioSelectResult));
  1374. // }).catch((err: BusinessError) => {
  1375. //
  1376. // console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
  1377. // });
  1378. // } catch (error) {
  1379. // let err: BusinessError = error as BusinessError;
  1380. // console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1381. // }
  1382. //
  1383. //
  1384. //
  1385. // }
  1386. async goSelectImage(item: VideoItem): Promise<string | undefined> {
  1387. if (!item) {
  1388. return undefined;
  1389. }
  1390. try {
  1391. let selectUris: Array<string> = [];
  1392. let photoPicker = new photoAccessHelper.PhotoViewPicker();
  1393. let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  1394. photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
  1395. photoSelectOptions.maxSelectNumber = 1;
  1396. const photoSelectResult = await photoPicker.select(photoSelectOptions);
  1397. selectUris = photoSelectResult.photoUris;
  1398. console.info('photoViewPicker.select to file succeed and uris are:' + selectUris);
  1399. let file = fs.openSync(selectUris[0], fs.OpenMode.READ_ONLY);
  1400. console.info('file fd: ' + file.fd);
  1401. let name = await MD5.digestSync(this.videoUrl)+'.jpg'
  1402. let imagePath = this.context.filesDir + FileUtil.separator + name
  1403. imagePath = fileUri.getUriFromPath(imagePath)
  1404. let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  1405. fileIo.copyFileSync(file.fd, file2.fd)
  1406. fileIo.closeSync(file);
  1407. fileIo.closeSync(file2);
  1408. if (item.filePath == this.currentSong?.filePath) {
  1409. this.cover = imagePath
  1410. }
  1411. if (item) {
  1412. item.pixelMapPath = imagePath
  1413. }
  1414. this.table.updatePixelMapPath(item.filePath, imagePath, (success: boolean, error?: string) => {
  1415. if (success) {
  1416. this.doUpdateData()
  1417. console.log("onecold 更新音乐封面成功,数据库已同步");
  1418. } else {
  1419. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  1420. }
  1421. });
  1422. LogUtil.debug("onecold this.cover =" + this.cover)
  1423. return FileUtil.getFilePath(imagePath); // Return the image path here
  1424. } catch (err) {
  1425. console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
  1426. return undefined;
  1427. }
  1428. }
  1429. // 拉起picker选择文件管理器
  1430. async callFilePickerSelectFile(): Promise<void> {
  1431. try {
  1432. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  1433. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE) {
  1434. DocumentSelectOptions.fileSuffixFilters = CommonConstants.MEDIA_FORMAT
  1435. } else {
  1436. DocumentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO
  1437. }
  1438. let documentPicker = new picker.DocumentViewPicker();
  1439. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  1440. Logger.info(TAG,
  1441. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  1442. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  1443. this.saveVideoDatas(DocumentSelectResult)
  1444. }
  1445. }).catch((err: BusinessError) => {
  1446. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  1447. });
  1448. } catch (err) {
  1449. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  1450. }
  1451. }
  1452. showWarnIsDeleteFile(item: VideoItem, index: string, filePath: string) {
  1453. //操作确认类弹出框
  1454. DialogHelper.showAlertDialog({
  1455. maskColor: Color.Transparent,
  1456. content: "确定要删除这个文件吗?",
  1457. backgroundColor: Color.Grey,
  1458. transition: AnimationHelper.transitionInUp(555),
  1459. onAction: (action) => {
  1460. if (action == DialogAction.ONE) {
  1461. // ToastUtil.showToast(`您点击了取消按钮`);
  1462. } else if (action == DialogAction.TWO) {
  1463. // ToastUtil.showToast(`您点击了确认按钮`);
  1464. this.doDelete(item, index + '', filePath)
  1465. }
  1466. }
  1467. })
  1468. }
  1469. //删除单个索引index的视频
  1470. doDelete(item: VideoItem, index: string, filePath: string) {
  1471. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1472. Logger.info(TAG, 'delete filePath = ' + filePath);
  1473. if (item.type === CommonConstants.TYPE_IS_DIR) {
  1474. //旧文件删除
  1475. this.table.deleteDataForParentPath(item.filePath, () => {
  1476. FileUtil.rmdir(filePath).then(() => {
  1477. this.videoLocalList.splice(Number(index), 1)
  1478. this.deleteCache(this.currentPath)
  1479. this.getSortedFiles(this.currentPath, true)
  1480. }).catch((error: BusinessError) => {
  1481. console.error(error.message);
  1482. });
  1483. });
  1484. } else {
  1485. this.table.deleteData(item, () => {
  1486. FileUtil.unlink(filePath)
  1487. .catch((error: BusinessError) => {
  1488. console.error(error.message);
  1489. // 可以根据 error.code 判断是否为"文件不存在",如需特殊处理
  1490. })
  1491. .finally(() => {
  1492. this.videoLocalList.splice(Number(index), 1)
  1493. this.deleteCache(this.currentPath)
  1494. this.getSortedFiles(this.currentPath, true)
  1495. });
  1496. });
  1497. }
  1498. }
  1499. }
  1500. //重命名的对话框
  1501. showReNameDialog(item: VideoItem, index: string, filePath: string) {
  1502. DialogHelper.showTextInputDialog({
  1503. title: '重命名',
  1504. text: item.type === CommonConstants.TYPE_IS_DIR ? item.name : item.fileName,
  1505. maskColor: Color.Transparent,
  1506. backgroundColor: Color.Grey,
  1507. transition: AnimationHelper.transitionInDown(666),
  1508. onChange: (text) => {
  1509. console.error("onChange: " + text);
  1510. },
  1511. onAction: (action, dialogId, content) => {
  1512. // ToastUtil.showToast('content = ' +content)
  1513. if (action == DialogAction.TWO) {
  1514. const newName = content
  1515. const newPath = this.currentPath + '/' + newName
  1516. console.log("onecold item = " + item.type);
  1517. this.doReName(index, newName, filePath, newPath, item)
  1518. }
  1519. }
  1520. })
  1521. }
  1522. //剪切 移动到另个文件夹的对话框
  1523. showCutDialog(isCurrent: boolean, item: VideoItem, index: number, id: string) {
  1524. Logger.info('onecold showCutDialog')
  1525. let mList: Array<string> = []
  1526. let rPath = this.rootPath
  1527. if (isCurrent) {
  1528. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1529. rPath = this.currentPath
  1530. } else {
  1531. mList = Utility.getNameList(this.dirList);
  1532. rPath = this.rootPath
  1533. }
  1534. let dataBean = new BubbleBean()
  1535. dataBean.data = mList
  1536. dataBean.color = this.themeColor
  1537. dataBean.onItemClick = (i) => {
  1538. const newPath = rPath + '/' + mList[i] + '/' + item.fileName
  1539. Logger.info('newPath = ' + newPath)
  1540. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  1541. ToastUtil.showToast('移动成功')
  1542. this.table.deleteData(item, () => {
  1543. });
  1544. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  1545. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  1546. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  1547. CommonConstants.TYPE_LOCAL, true);
  1548. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  1549. this.table.insert(newItem, (id: number) => {
  1550. //加入数据库
  1551. });
  1552. }
  1553. this.cache.delete(this.currentPath); // 删除原路径缓存
  1554. this.cache.delete(rPath + '/' + mList[i]); // 删除目标路径缓存
  1555. this.getSortedFiles(this.currentPath, true)
  1556. }).catch((error: BusinessError) => {
  1557. console.error(error.message);
  1558. });
  1559. XPopup.dismissTop()
  1560. }
  1561. let popupPosition: PopupPosition = PopupPosition.BOTTOM
  1562. if (ArrayUtil.isNotEmpty(this.videoLocalList) && this.videoLocalList.length > 7) {
  1563. popupPosition = PopupPosition.TOP
  1564. }
  1565. if (index <= 3) {
  1566. popupPosition = PopupPosition.BOTTOM
  1567. }
  1568. let pup: XPopup
  1569. if (this.isDarkMode) {
  1570. pup = XPopup.Builder()
  1571. .setPopupPosition(popupPosition)
  1572. .atView(id)// .setHeight(this.isCoverOpacity()?100:420)
  1573. .setBackgroundColor(Color.Black)
  1574. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1575. .show()
  1576. } else {
  1577. pup = XPopup.Builder()
  1578. .setPopupPosition(popupPosition)
  1579. .atView(id)// .setHeight(this.isCoverOpacity()?280:420)
  1580. .setBackgroundColor(Color.White)
  1581. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1582. .show()
  1583. }
  1584. }
  1585. //复制 到另个文件夹的对话框
  1586. showCopyDialog(isCurrent: boolean, item: VideoItem, index: number, id: string) {
  1587. Logger.info('onecoldv showCopyDialog')
  1588. let mList: Array<string> = []
  1589. let rPath = this.rootPath
  1590. if (isCurrent) {
  1591. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1592. rPath = this.currentPath
  1593. } else {
  1594. mList = Utility.getNameList(this.dirList);
  1595. rPath = this.rootPath
  1596. }
  1597. let dataBean = new BubbleBean()
  1598. dataBean.data = mList
  1599. dataBean.isCopy = true
  1600. dataBean.color = this.themeColor
  1601. dataBean.onItemClick = (i) => {
  1602. const newPath = rPath + '/' + mList[i] + '/' + item.fileName
  1603. Logger.info('newPath = ' + newPath)
  1604. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  1605. ToastUtil.showToast('复制成功')
  1606. this.cache.delete(rPath + '/' + mList[i]); // 删除目标路径缓存
  1607. this.getSortedFiles(this.currentPath)
  1608. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  1609. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  1610. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  1611. CommonConstants.TYPE_LOCAL, true);
  1612. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  1613. this.table.insert(newItem, (id: number) => {
  1614. //加入数据库
  1615. });
  1616. }
  1617. }).catch((error: BusinessError) => {
  1618. console.error(error.message);
  1619. });
  1620. XPopup.dismissTop()
  1621. }
  1622. let popupPosition: PopupPosition = PopupPosition.BOTTOM
  1623. if (ArrayUtil.isNotEmpty(this.videoLocalList) && this.videoLocalList.length > 7) {
  1624. popupPosition = PopupPosition.TOP
  1625. }
  1626. if (index <= 3) {
  1627. popupPosition = PopupPosition.BOTTOM
  1628. }
  1629. let pup: XPopup
  1630. if (this.isDarkMode) {
  1631. pup = XPopup.Builder()
  1632. .setPopupPosition(popupPosition)
  1633. .atView(id)
  1634. .setMaxHeight('60%')
  1635. .setBackgroundColor(Color.Black)
  1636. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1637. .show();
  1638. } else {
  1639. pup = XPopup.Builder()
  1640. .setPopupPosition(popupPosition)
  1641. .atView(id)
  1642. .setMaxHeight('60%')
  1643. .setBackgroundColor(Color.White)
  1644. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1645. .show();
  1646. }
  1647. }
  1648. //重命名索引index的视频
  1649. doReName(index: string, newName: string, oldPath: string, newPath: string, info: VideoItem) {
  1650. FileUtil.rename(oldPath, newPath).then(async () => {
  1651. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1652. if (info.type === CommonConstants.TYPE_IS_DIR) {
  1653. //如果是文件夹先删除源数据,再添加新数据
  1654. this.table.deleteDataForParentPath(oldPath, (success: boolean, error?: string) => {
  1655. if (success) {
  1656. console.log(" onecold deleteDataForParentPath 文件夹重命名成功,数据库已同步");
  1657. } else {
  1658. console.error(" onecold deleteDataForParentPath 文件夹重命名数据库失败原因: " + error);
  1659. }
  1660. });
  1661. this.scanDirectory(newPath)
  1662. } else if (info.type === CommonConstants.TYPE_LOCAL) {
  1663. this.table.updateRename(newName, oldPath, newPath, (success: boolean, error?: string) => {
  1664. if (success) {
  1665. console.log(" onecold 重命名成功,数据库已同步");
  1666. } else {
  1667. console.error(" onecold 重命名数据库失败原因: " + error);
  1668. }
  1669. });
  1670. }
  1671. let mediaItem: VideoItem =
  1672. await Utility.uriGetMusicAssetsFromFile(this.context, newPath, CommonConstants.TYPE_LOCAL, true);
  1673. this.videoLocalList[index] = mediaItem;
  1674. }
  1675. this.cache.delete(this.currentPath)
  1676. this.getSortedFiles(this.currentPath, true)
  1677. }).catch((error: BusinessError) => {
  1678. console.error(error.message);
  1679. });
  1680. }
  1681. build() {
  1682. Scroll() {
  1683. Column() {
  1684. if (!this.isShowCoverHeader()) {
  1685. Column() {
  1686. Line().width('100%').height('100%')
  1687. }
  1688. .height(this.topRectHeight)
  1689. .backgroundColor(this.isCustomizeBg ? Color.Transparent :
  1690. (this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor))
  1691. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  1692. TitleBar({ model: $titleBarModel })
  1693. .id('pup_positon_music')
  1694. }
  1695. Stack() {
  1696. Column() {
  1697. XComponent({
  1698. id: 'xcomponentId',
  1699. type: 'surface',
  1700. libraryname: 'ijkplayer_napi',
  1701. controller: this.xcomponentController
  1702. })
  1703. .onLoad((event?: object) => {
  1704. if (!!event) {
  1705. this.initDelayPlay(event);
  1706. }
  1707. })
  1708. .onKeyEvent((event?: KeyEvent) => {
  1709. // If the button type is pressed, the subsequent code will not be executed; the specific button logic will be executed upon release.
  1710. if (!event || event.type !== KeyType.Down) {
  1711. return;
  1712. }
  1713. //空格键 Space key controls pause/play
  1714. if (event.keyCode === KeyCode.KEYCODE_SPACE) {
  1715. this.playOrPause()
  1716. }
  1717. // Right-click to fast forward
  1718. if (event.keyCode === KeyCode.KEYCODE_DPAD_RIGHT) {
  1719. this.sessionFastForwardCallback(15);
  1720. }
  1721. // Left-click to rewind
  1722. if (event.keyCode === KeyCode.KEYCODE_DPAD_LEFT) {
  1723. this.sessionRewindCallback(15);
  1724. }
  1725. })
  1726. .onDestroy(() => {
  1727. })
  1728. .width('100%')// .width(this.videoWidth)
  1729. .aspectRatio(this.videoAspectRatio)
  1730. }
  1731. .aspectRatio(this.videoAspectRatio)
  1732. .justifyContent(FlexAlign.Center)
  1733. .backgroundColor(Color.Transparent)
  1734. .visibility(Visibility.Hidden)
  1735. .height(CommonConstants.FULL_PERCENT)
  1736. .width(CommonConstants.FULL_PERCENT)
  1737. Stack() {
  1738. Row() {
  1739. Blank()
  1740. .layoutWeight(1)
  1741. IndexerView(
  1742. {
  1743. indexArray: DEFAULT_INDEX,
  1744. selectedIndex: this.selectedIndex,
  1745. textSize: 12,
  1746. selectedColor: "#ff419ee5",
  1747. normalColor: "#ffa0a0a0",
  1748. floatSelectedTextColor: "#ffffff",
  1749. floatSelectedViewColor: "#ff419ee5",
  1750. onIndexChanged: (index) => {
  1751. this.listScroller.scrollToIndex(index)
  1752. }
  1753. })
  1754. .width(24)
  1755. .height("50%")
  1756. }.visibility(Visibility.None)
  1757. Column() {
  1758. if (!this.isShowCoverHeader()) {
  1759. this.tabTitle()
  1760. }
  1761. if (this.isGridMusic) {
  1762. this.getGridView()
  1763. } else {
  1764. this.getListView()
  1765. }
  1766. if (this.modeType == 0) {
  1767. Column() {
  1768. Button('同步数据', { type: ButtonType.Capsule, stateEffect: true })
  1769. .width(130)
  1770. .height(50)
  1771. .margin({ top: 100, bottom: 40 })
  1772. .backgroundColor(this.themeColor)
  1773. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  1774. .onClick(() => {
  1775. this.asyncCurrentPathData()
  1776. })
  1777. }
  1778. .height(100)
  1779. .position({ top: 260 })
  1780. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  1781. .animation({ duration: 500 }),
  1782. TransitionEffect.scale({ x: 0, y: 0 })))
  1783. .justifyContent(FlexAlign.Center)
  1784. .opacity(this.isZero ? 1 : 0)
  1785. .visibility(this.isZero && !this.isFavMusic && !this.isHistory
  1786. && this.modeType === 0 ? Visibility.Visible : Visibility.None)
  1787. .animation({
  1788. duration: 500,
  1789. curve: 'ease-in-out' // 可选动画曲线
  1790. })
  1791. .width('100%')
  1792. }
  1793. }
  1794. .layoutWeight(1)
  1795. .height('100%')
  1796. }
  1797. .layoutWeight(1)
  1798. .height('100%')
  1799. Row() {
  1800. Button(this.isAllSelected ? '全不选' : '全选', { type: ButtonType.Circle, stateEffect: true })
  1801. .width('35%')
  1802. .height(60)
  1803. .margin({ top: 10, bottom: 10, right: 6 })
  1804. .backgroundColor(this.themeColor)
  1805. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1806. .onClick(() => {
  1807. if (this.isAllSelected) {
  1808. // 全不选
  1809. this.selectedFiles = [];
  1810. } else {
  1811. // 全选
  1812. this.selectedFiles = [...this.getCurFileList()];
  1813. }
  1814. this.isAllSelected = !this.isAllSelected;
  1815. })
  1816. Button('剪切', { type: ButtonType.Circle, stateEffect: true })
  1817. .width('35%')
  1818. .height(60)
  1819. .id('music_cut')
  1820. .margin({ top: 10, bottom: 10, right: 6 })
  1821. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1822. .backgroundColor(this.themeColor)
  1823. .onClick(() => {
  1824. this.showCutDialogForMultipleFiles(false, 'music_cut')
  1825. })
  1826. Button('移动', { type: ButtonType.Circle, stateEffect: true })
  1827. .width('35%')
  1828. .height(60)
  1829. .id('music_cut_current')
  1830. .visibility(this.isHasDir ? Visibility.Visible : Visibility.None)
  1831. .margin({ top: 10, bottom: 10, right: 6 })
  1832. .backgroundColor(this.themeColor)
  1833. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1834. .onClick(() => {
  1835. this.showCutDialogForMultipleFiles(true, 'music_cut_current')
  1836. })
  1837. Button('复制', { type: ButtonType.Circle, stateEffect: true })
  1838. .width('35%')
  1839. .height(60)
  1840. .id('music_copy_current')// .visibility(this.isHasDir?Visibility.None:Visibility.None)
  1841. .margin({ top: 10, bottom: 10, right: 6 })
  1842. .backgroundColor(this.themeColor)
  1843. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1844. .onClick(() => {
  1845. this.showCopyDialogForMultipleFiles(false, 'music_copy_current')
  1846. })
  1847. Button('删除', { type: ButtonType.Circle, stateEffect: true })
  1848. .width('35%')
  1849. .height(60)
  1850. .margin({ top: 10, bottom: 10, right: 6 })
  1851. .visibility(this.isFavMusic ? Visibility.None : Visibility.Visible)
  1852. .backgroundColor(this.themeColor)
  1853. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1854. .onClick(() => {
  1855. this.showWarnIsDelete()
  1856. })
  1857. Button('取消', { type: ButtonType.Circle, stateEffect: true })
  1858. .width('35%')
  1859. .height(60)
  1860. .margin({ top: 10, bottom: 10, right: 6 })
  1861. .backgroundColor(this.themeColor)
  1862. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1863. .onClick(() => {
  1864. this.selectedFiles = [];
  1865. this.isAllSelected = false
  1866. this.isMultiSelect = false
  1867. })
  1868. }
  1869. .width('100%')
  1870. .justifyContent(FlexAlign.Center)
  1871. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  1872. .opacity(this.isMultiSelect ? 1 : 0)
  1873. .animation({
  1874. duration: 666,
  1875. curve: 'ease-in-out' // 可选动画曲线
  1876. })
  1877. .position(this.isShowCoverHeader() ? { bottom: 78 }
  1878. : { bottom: this.isPhoneLan() ? 130 : 168 }) // 将 Row 固定在底部
  1879. }
  1880. .width('100%')
  1881. .height('100%')
  1882. .alignContent(Alignment.Top)
  1883. Column() {
  1884. this.PlayController()
  1885. }
  1886. .hitTestBehavior(HitTestMode.Transparent)
  1887. .position({ bottom: 0 }) // 将 Row 固定在底部
  1888. .opacity(this.barBottomOpacity)
  1889. }
  1890. .width('100%')
  1891. .height('100%')
  1892. .backgroundImage(this.isCustomizeBg ? this.customizeBgPath : $r('app.color.bottom_control_background'))
  1893. .backgroundImageSize(this.isCoverOpacity() ? { width: '100%' } : { height: '100%' })
  1894. .backgroundImagePosition(Alignment.Center)
  1895. .backdropBlur(this.blurValue)
  1896. .backgroundBrightness({ rate: this.isCustomizeBg ? 0.1 : 0, lightUpDegree: this.bgBrightness })
  1897. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
  1898. }
  1899. }
  1900. asyncCurrentPathData() {
  1901. if (this.modeType == 0) {
  1902. workerInstance.postMessage({
  1903. code: 1,
  1904. data1: this.context,
  1905. data2: this.currentPath,
  1906. data3: this.lockPath,
  1907. data4: PreferencesUtil.getStringSync('COVER_API', ''),
  1908. });
  1909. }
  1910. }
  1911. // 处理文件选择的函数
  1912. handleFileSelection(item: VideoItem, checked: boolean) {
  1913. if (checked) {
  1914. if (!this.selectedFiles.some(x => x.filePath == item.filePath)) {
  1915. this.selectedFiles.push(item);
  1916. }
  1917. } else {
  1918. const index = this.selectedFiles.findIndex(x => x.filePath == item.filePath);
  1919. if (index > -1) {
  1920. this.selectedFiles.splice(index, 1);
  1921. }
  1922. }
  1923. }
  1924. showWarnIsDelete() {
  1925. //操作确认类弹出框
  1926. DialogHelper.showAlertDialog({
  1927. content: "确定要删除这些文件吗?",
  1928. transition: AnimationHelper.transitionInUp(666),
  1929. maskColor: Color.Transparent,
  1930. backgroundColor: Color.Grey,
  1931. onAction: (action) => {
  1932. if (action == DialogAction.ONE) {
  1933. // ToastUtil.showToast(`您点击了取消按钮`);
  1934. } else if (action == DialogAction.TWO) {
  1935. // ToastUtil.showToast(`您点击了确认按钮`);
  1936. this.deleteMultipleFiles()
  1937. }
  1938. }
  1939. })
  1940. }
  1941. //多选删除文件
  1942. deleteMultipleFiles() {
  1943. if (ArrayUtil.isNotEmpty(this.selectedFiles)) {
  1944. this.selectedFiles.forEach((item) => {
  1945. Logger.info(TAG, 'delete filePath = ' + item.filePath);
  1946. if (item.type === CommonConstants.TYPE_IS_DIR) {
  1947. this.table.deleteDataForParentPath(item.filePath, () => {
  1948. FileUtil.rmdir(item.filePath).then(() => {
  1949. this.videoLocalList = this.videoLocalList.filter(v => v !== item);
  1950. this.selectedFiles = [];
  1951. this.isMultiSelect = false
  1952. this.isAllSelected = false
  1953. this.cache.delete(this.currentPath);
  1954. this.getSortedFiles(this.currentPath, true);
  1955. }).catch((error: Error) => {
  1956. console.error(error.message);
  1957. });
  1958. });
  1959. } else {
  1960. this.table.deleteData(item, () => {
  1961. FileUtil.unlink(item.filePath).catch((error: Error) => {
  1962. console.error(error.message);
  1963. }).finally(() => {
  1964. this.videoLocalList = this.videoLocalList.filter(v => v !== item);
  1965. this.selectedFiles = [];
  1966. this.isMultiSelect = false
  1967. this.isAllSelected = false
  1968. this.cache.delete(this.currentPath);
  1969. this.getSortedFiles(this.currentPath, true);
  1970. });
  1971. });
  1972. }
  1973. });
  1974. }
  1975. }
  1976. //多选移动文件
  1977. showCutDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  1978. Logger.info('onecold showCutDialogForMultipleFiles')
  1979. let mList: Array<string> = []
  1980. let rPath = this.rootPath
  1981. if (isCurrent) {
  1982. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1983. rPath = this.currentPath
  1984. } else {
  1985. mList = Utility.getNameList(this.dirList);
  1986. rPath = this.rootPath
  1987. }
  1988. let dataBean = new BubbleBean();
  1989. dataBean.data = mList;
  1990. dataBean.color = this.themeColor
  1991. dataBean.onItemClick = (i) => {
  1992. const newDirPath = rPath + '/' + mList[i];
  1993. // Logger.info('newDirPath = ' + newDirPath)
  1994. this.selectedFiles.forEach((item) => {
  1995. const newPath = newDirPath + '/' + item.fileName;
  1996. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  1997. ToastUtil.showToast('移动成功');
  1998. this.table.deleteData(item, () => {
  1999. this.cache.delete(this.currentPath); // 删除原路径缓存
  2000. this.cache.delete(newDirPath); // 删除目标路径缓存
  2001. this.getSortedFiles(this.currentPath, true);
  2002. });
  2003. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2004. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2005. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2006. CommonConstants.TYPE_LOCAL, true);
  2007. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2008. this.table.insert(newItem, (id: number) => {
  2009. //加入数据库
  2010. });
  2011. }
  2012. }).catch((error: Error) => {
  2013. console.error(error.message);
  2014. });
  2015. });
  2016. this.isMultiSelect = false
  2017. this.selectedFiles = [];
  2018. this.isAllSelected = false
  2019. XPopup.dismissTop();
  2020. };
  2021. let pup: XPopup
  2022. if (this.isDarkMode) {
  2023. pup = XPopup.Builder()
  2024. .setPopupPosition(PopupPosition.TOP)
  2025. .atView(viewId)
  2026. .setBackgroundColor(Color.Black)
  2027. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2028. .show();
  2029. } else {
  2030. pup = XPopup.Builder()
  2031. .setPopupPosition(PopupPosition.TOP)
  2032. .atView(viewId)
  2033. .setBackgroundColor(Color.White)
  2034. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2035. .show();
  2036. }
  2037. }
  2038. doFav(item: VideoItem) {
  2039. LogUtil.info('onecold doFav isFav=' + item.isFav)
  2040. let isFav = 0
  2041. if (Utility.getIsFav(this.favList, item)) {
  2042. isFav = 0
  2043. } else {
  2044. isFav = 1
  2045. }
  2046. this.table.updateIsFavByFilePath(item.filePath, isFav, async (result: boolean) => {
  2047. if (result) {
  2048. if (isFav === 1) {
  2049. ToastUtil.showToast('收藏成功');
  2050. } else {
  2051. ToastUtil.showToast('取消收藏成功');
  2052. }
  2053. this.deleteCache(this.currentPath)
  2054. this.getFavList(false)
  2055. if (this.modeType === 0 && !this.isFavMusic) {
  2056. LogUtil.info('onecold doFav currentPath =' + this.currentPath)
  2057. this.getSortedFiles(this.currentPath)
  2058. }
  2059. workerInstance.postMessage({ code: 2, data: this.context });
  2060. workerInstance.postMessage({ code: 3, data: this.context });
  2061. workerInstance.postMessage({ code: 4, data: this.context });
  2062. }
  2063. })
  2064. }
  2065. //多选复制文件
  2066. showCopyDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  2067. console.log('onecold showCopyDialogForMultipleFiles');
  2068. let mList: Array<string> = []
  2069. let rPath = this.rootPath
  2070. if (isCurrent) {
  2071. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  2072. rPath = this.currentPath
  2073. } else {
  2074. mList = Utility.getNameList(this.dirList);
  2075. rPath = this.rootPath
  2076. }
  2077. let dataBean = new BubbleBean();
  2078. dataBean.data = mList;
  2079. dataBean.isCopy = true
  2080. dataBean.color = this.themeColor
  2081. dataBean.onItemClick = (i) => {
  2082. const newDirPath = rPath + '/' + mList[i];
  2083. // Logger.info('newDirPath = ' + newDirPath)
  2084. this.selectedFiles.forEach((item) => {
  2085. const newPath = newDirPath + '/' + item.fileName;
  2086. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  2087. ToastUtil.showToast('复制成功');
  2088. this.cache.delete(newDirPath); // 删除目标路径缓存
  2089. this.getSortedFiles(this.currentPath);
  2090. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2091. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2092. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2093. CommonConstants.TYPE_LOCAL, true);
  2094. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2095. this.table.insert(newItem, (id: number) => {
  2096. //加入数据库
  2097. });
  2098. }
  2099. }).catch((error: Error) => {
  2100. console.error(error.message);
  2101. });
  2102. });
  2103. this.isMultiSelect = false
  2104. this.selectedFiles = [];
  2105. this.isAllSelected = false
  2106. XPopup.dismissTop();
  2107. };
  2108. let pup: XPopup
  2109. if (this.isDarkMode) {
  2110. pup = XPopup.Builder()
  2111. .setPopupPosition(PopupPosition.TOP)
  2112. .atView(viewId)
  2113. .setBackgroundColor(Color.Black)
  2114. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2115. .show();
  2116. } else {
  2117. pup = XPopup.Builder()
  2118. .setPopupPosition(PopupPosition.TOP)
  2119. .atView(viewId)
  2120. .setBackgroundColor(Color.White)
  2121. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2122. .show();
  2123. }
  2124. }
  2125. @Builder
  2126. private DirItem(item: VideoItem, index?: number) {
  2127. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2128. Row() {
  2129. Image(this.modeType !== 0 && StrUtil.isNotEmpty(item.pixelMapPath) ? item.pixelMapPath :
  2130. $r('app.media.music_group'))
  2131. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2132. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2133. .fillColor(this.themeColor)// .fontSize(33)
  2134. .alt($r('app.media.music_group'))
  2135. .borderRadius('100%')
  2136. .clip(true)
  2137. .margin({ left: 20, top: 8, bottom: 8 })
  2138. Column() {
  2139. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  2140. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2141. .maxLines(1)// .width('88%')
  2142. .animation({
  2143. duration: 555,
  2144. curve: 'ease-in-out',
  2145. })
  2146. .transition({
  2147. type: TransitionType.Insert,
  2148. opacity: 0,
  2149. translate: { x: 160 }
  2150. })
  2151. .margin({ left: 10, right: 20 })
  2152. .fontColor($r('app.color.text_color'))
  2153. Row() {
  2154. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  2155. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2156. .padding({ top: 8 })
  2157. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2158. .fontColor($r('app.color.text_color'))
  2159. .margin({ left: 10 })
  2160. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  2161. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2162. .padding({ top: 8 })
  2163. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2164. .fontColor($r('app.color.text_color'))
  2165. .margin({ left: 10 })
  2166. Blank()
  2167. }
  2168. }
  2169. .height('100%')
  2170. .layoutWeight(1)
  2171. .justifyContent(FlexAlign.Center)
  2172. .alignItems(HorizontalAlign.Start)
  2173. Blank()
  2174. Image($r('app.media.arrow_right'))
  2175. .height(25)
  2176. .margin({ right: 10 })
  2177. .alignSelf(ItemAlign.Center)
  2178. .id(item.filePath)
  2179. }
  2180. }
  2181. .backgroundColor(Color.Transparent)
  2182. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2183. .width('100%')
  2184. .visibility(this.isShowDir(item.name) ? Visibility.Visible : Visibility.None)
  2185. .opacity(this.opacityItem) // 绑定透明度
  2186. }
  2187. isShowDir(dirName: string) {
  2188. this.isShowSimi = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, false)
  2189. this.isShowFAV = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_FAV, true)
  2190. this.isShowHistory = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HISTORY, true)
  2191. if (dirName === undefined) {
  2192. return true
  2193. }
  2194. if (dirName === LocalMusic.STR_LOCK_VIDEO) {
  2195. return this.isShowSimi
  2196. }
  2197. if (dirName === LocalMusic.STR_FAC_VIDEO) {
  2198. return this.isShowFAV
  2199. }
  2200. if (dirName === LocalMusic.STR_HISTORY_MUSIC) {
  2201. return this.isShowHistory
  2202. }
  2203. return true
  2204. }
  2205. @State opacityItem: number = 1; // 控制透明度的状态变量
  2206. @Builder
  2207. private MusicItem(item: VideoItem, index?: number) {
  2208. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2209. Row() {
  2210. Stack() {
  2211. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  2212. .fillColor(this.themeColor)
  2213. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2214. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2215. .alt($r('app.media.music_red'))
  2216. .borderRadius('100%')
  2217. .clip(true)
  2218. .draggable(false)
  2219. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  2220. .autoResize(true) // 重采样,可减少内存占用
  2221. .opacity(this.opacityItem)// 绑定透明度
  2222. .margin({ left: 20 })
  2223. .gesture(LongPressGesture()
  2224. .onAction(async () => {
  2225. //如果是专辑和艺术家的首页,不能长按
  2226. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2227. return
  2228. //如果是我的收藏 最近播放等也不能长按
  2229. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2230. item.name === LocalMusic.STR_HISTORY_MUSIC
  2231. )
  2232. return
  2233. this.longItemFilePath = item.filePath
  2234. this.tempLyricContent = await this.getLyricContent(item)
  2235. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2236. })
  2237. .onActionEnd((event: GestureEvent) => {
  2238. }))
  2239. }
  2240. Column() {
  2241. Column() {
  2242. Text(item.name)
  2243. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2244. .maxLines(1)
  2245. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  2246. .animation({
  2247. duration: 555,
  2248. curve: 'Linear',
  2249. })
  2250. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2251. $r('app.color.text_color'))
  2252. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2253. .bindPopup(this.longItemFilePath === item.filePath, {
  2254. builder: this.MenuBuilder(item,index,item.filePath),
  2255. placement: Placement.Top,
  2256. // autoCancel: true,
  2257. mask: {color:'#33000000'},
  2258. // popupColor: Color.Yellow,
  2259. enableArrow: false,//是否显示箭头
  2260. showInSubWindow: false,
  2261. onStateChange: (e) => {
  2262. if (!e.isVisible) {
  2263. this.longItemFilePath = ''
  2264. this.tempLyricContent = ''
  2265. }
  2266. }
  2267. })
  2268. .gesture(LongPressGesture()
  2269. .onAction(async () => {
  2270. //如果是专辑和艺术家的首页,不能长按
  2271. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2272. return
  2273. //如果是我的收藏 最近播放等也不能长按
  2274. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2275. item.name === LocalMusic.STR_HISTORY_MUSIC
  2276. )
  2277. return
  2278. this.longItemFilePath = item.filePath
  2279. this.tempLyricContent = await this.getLyricContent(item)
  2280. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2281. })
  2282. .onActionEnd((event: GestureEvent) => {
  2283. })
  2284. )
  2285. Row() {
  2286. Column(){
  2287. Text(item.md5Str?.includes('Lossless')?
  2288. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  2289. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  2290. .padding({ top: 3,right:6,left:6,bottom:3 })
  2291. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2292. $r('app.color.text_color'))
  2293. .fontWeight(500)
  2294. .borderRadius(12)
  2295. .visibility(StrUtil.isEmpty(item.md5Str)?Visibility.None:Visibility.Visible)
  2296. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2297. .backgroundColor('#FFC107')
  2298. }
  2299. .padding({ top: 8 })
  2300. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  2301. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2302. .padding({ top: 8 })
  2303. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2304. $r('app.color.text_color'))
  2305. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2306. Blank()
  2307. Text(item.size)
  2308. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2309. .padding({ top: 8 })
  2310. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  2311. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2312. $r('app.color.text_color'))
  2313. .margin({ left: 10 })
  2314. }
  2315. .gesture(LongPressGesture()
  2316. .onAction(async () => {
  2317. //如果是专辑和艺术家的首页,不能长按
  2318. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2319. return
  2320. //如果是我的收藏 最近播放等也不能长按
  2321. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2322. item.name === LocalMusic.STR_HISTORY_MUSIC
  2323. )
  2324. return
  2325. this.longItemFilePath = item.filePath
  2326. this.tempLyricContent = await this.getLyricContent(item)
  2327. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2328. })
  2329. .onActionEnd((event: GestureEvent) => {
  2330. })
  2331. )
  2332. }
  2333. .height('100%')
  2334. .width('100%')
  2335. .justifyContent(FlexAlign.Center)
  2336. .alignItems(HorizontalAlign.Start)
  2337. }
  2338. .height('100%')
  2339. .margin({ left: 5 })
  2340. .layoutWeight(1)
  2341. Column() {
  2342. Checkbox({ name: 'checkbox' + index })
  2343. .select(this.selectedFiles.some(x => x.filePath === item.filePath))
  2344. .selectedColor(this.themeColor)
  2345. .shape(CheckBoxShape.CIRCLE)
  2346. .opacity(this.isMultiSelect ? 1 : 0)
  2347. .animation({
  2348. duration: 666,
  2349. curve: 'Smooth' // 可选动画曲线
  2350. })
  2351. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  2352. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  2353. .margin({ left: 20, top: 8, bottom: 8 })
  2354. .width(22)
  2355. .height(22)
  2356. ImageAnimator()
  2357. .images(this.imagesF)// 动画数组
  2358. .duration(1000)// 持续
  2359. .state(this.animationState)// 动画状态
  2360. .fillMode(FillMode.Forwards)
  2361. .width(18)
  2362. .margin({ right: 20, top: 8, bottom: 8 })
  2363. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  2364. Visibility.None)
  2365. .height(18)
  2366. .iterations(-1) // 播放次数
  2367. }
  2368. }
  2369. }
  2370. .backgroundColor(Color.Transparent)
  2371. .width('100%')
  2372. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2373. }
  2374. private readonly tabs: string[] = ['文件夹', '媒体库', '艺术家', '专辑']
  2375. @Builder
  2376. tabTitle() {
  2377. Column() {
  2378. // 使用 Stack 布局来实现绝对定位效果
  2379. Stack() {
  2380. // 背景动画容器
  2381. Row() {
  2382. ForEach(this.tabs, (i: string, index) => {
  2383. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2384. Flex()
  2385. .backgroundColor(this.isDarkMode ? $r('app.color.tab_item_bg') : this.themeColor)
  2386. .borderRadius(20)
  2387. .padding(10)
  2388. .margin(6)
  2389. .width('100%')
  2390. .height('100%')
  2391. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2392. .visibility(this.modeType === index ? Visibility.Visible : Visibility.None)
  2393. .opacity(this.modeType === index ? 1 : 0)
  2394. .animation({
  2395. duration: 666,
  2396. playMode: PlayMode.Normal,
  2397. curve: 'ease-in-out'
  2398. });
  2399. }
  2400. .layoutWeight(1)
  2401. .margin({
  2402. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5,
  2403. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5, bottom: 1
  2404. });
  2405. });
  2406. }
  2407. .width('100%')
  2408. .height(50);
  2409. // 导航栏容器
  2410. Row() {
  2411. ForEach(this.tabs, (item: string, index) => {
  2412. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2413. Text(item)
  2414. .fontSize(16)
  2415. .fontColor(this.modeType === index ? Color.White : $r('app.color.text_color'))
  2416. .padding(15)
  2417. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2418. .onClick(() => {
  2419. this.modeType = index;
  2420. this.onModeChange();
  2421. });
  2422. }
  2423. .layoutWeight(1)
  2424. .stateStyles({
  2425. pressed: { opacity: 0.6 } // 按压反馈
  2426. });
  2427. });
  2428. }
  2429. .width('100%')
  2430. .height(this.topBarHeight)
  2431. .opacity(this.barOpacity)
  2432. .backgroundColor(Color.Transparent);
  2433. }
  2434. .width('100%')
  2435. .height(this.topBarHeight)
  2436. .opacity(this.barOpacity)
  2437. Line()
  2438. .width('100%')
  2439. .height(1)
  2440. .backgroundColor($r('app.color.index_background'))
  2441. .opacity(this.barOpacity)
  2442. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  2443. }
  2444. .visibility(this.isShowTitleBar ? Visibility.Visible : Visibility.None)
  2445. }
  2446. @State currentTitleName: string = '' //点击歌单,艺术家,专辑进去后的标题
  2447. @State currentTitleCover: string | ResourceStr = '' //点击歌单,艺术家,专辑进去后的封面
  2448. isShowCoverHeader() {
  2449. if (!this.isShowHeader) {
  2450. return false
  2451. }
  2452. if (this.modeType == 0) {
  2453. if (this.isHistory || this.isFavMusic) {
  2454. return true
  2455. }
  2456. if (this.currentPath != this.rootPath) {
  2457. return true
  2458. }
  2459. }
  2460. return (this.modeType == 2 || this.modeType == 3) && this.isCanBack
  2461. }
  2462. @Builder
  2463. coverHeader() {
  2464. if (this.isShowCoverHeader()) {
  2465. Column() {
  2466. Stack() {
  2467. // 居中标题
  2468. Text('')
  2469. .fontSize(18)
  2470. .fontColor(Color.White)
  2471. .align(Alignment.Center)
  2472. // 左右按钮
  2473. Row() {
  2474. Image($r('app.media.left_back_white'))
  2475. .width(28)
  2476. .height(28)
  2477. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2478. .margin({ left: 12, right: 8 })
  2479. .onClick(() => {
  2480. animateTo({ duration: 555 }, () => {
  2481. this.doSwipBack()
  2482. })
  2483. })
  2484. Blank().flexGrow(1)
  2485. if (this.modeType == 0 && !this.isHistory && !this.isFavMusic) {
  2486. Image($r('app.media.add'))
  2487. .width(25)
  2488. .height(25)
  2489. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2490. .margin({ left: 8, right: 15 })
  2491. .onClick(() => {
  2492. this.showAddDialog()
  2493. })
  2494. }
  2495. }
  2496. .height(48)
  2497. .width('100%')
  2498. .alignItems(VerticalAlign.Center)
  2499. }
  2500. .height(48)
  2501. .width('100%')
  2502. Row() {
  2503. Column() {
  2504. Image(this.currentTitleCover)
  2505. .height(100)
  2506. .width(100)
  2507. .alt(this.imageLabel)
  2508. .borderRadius(8)
  2509. .clickEffect({ level: ClickEffectLevel.HEAVY })
  2510. }
  2511. .alignItems(HorizontalAlign.Start)
  2512. .margin({ left: 30, top: 3, bottom: 15 })
  2513. Column() {
  2514. Column() {
  2515. Text(this.currentTitleName)
  2516. .fontSize(16)
  2517. .maxLines(1)
  2518. .fontWeight(FontWeight.Bold)
  2519. .fontColor($r('app.color.text_color'))
  2520. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2521. if (this.modeType == 3 && ArrayUtil.isNotEmpty(this.videoLocalList)) {
  2522. Text(`艺术家:${this.videoLocalList[0].artist}`)
  2523. .fontSize(14)
  2524. .padding({ top: 8 })
  2525. .maxLines(1)
  2526. .fontWeight(FontWeight.Bold)
  2527. .fontColor($r('app.color.text_color'))
  2528. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2529. if(this.videoLocalList[0].genre){
  2530. Text(`风格:${this.videoLocalList[0].genre}`)
  2531. .fontSize(14)
  2532. .padding({ top: 8 })
  2533. .maxLines(1)
  2534. .visibility(StrUtil.isEmpty(this.videoLocalList[0].genre)||
  2535. this.videoLocalList[0].genre.includes(this.UNKONWN)
  2536. ?Visibility.None:Visibility.Visible)
  2537. .fontWeight(FontWeight.Bold)
  2538. .fontColor($r('app.color.text_color'))
  2539. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2540. }
  2541. if(this.videoLocalList[0].year){
  2542. Text(`发行时间:${this.videoLocalList[0].year}`)
  2543. .fontSize(14)
  2544. .padding({ top: 8 })
  2545. .maxLines(1)
  2546. .visibility(StrUtil.isEmpty(this.videoLocalList[0].year)||
  2547. this.videoLocalList[0].year.includes(this.UNKONWN)
  2548. ?Visibility.None:Visibility.Visible)
  2549. .fontWeight(FontWeight.Bold)
  2550. .fontColor($r('app.color.text_color'))
  2551. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2552. }
  2553. }
  2554. if(this.modeType != 3){
  2555. Row() {
  2556. Text(`共${this.videoLocalList.length}首歌`)
  2557. .fontSize(13)
  2558. .fontWeight(FontWeight.Bold)
  2559. .padding({ top: 8 })
  2560. .fontColor($r('app.color.text_color'))
  2561. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2562. Blank()
  2563. }
  2564. }
  2565. }
  2566. .height('100%')
  2567. .width('100%')
  2568. .justifyContent(FlexAlign.Center)
  2569. .alignItems(HorizontalAlign.Start)
  2570. }
  2571. .height('100%')
  2572. .layoutWeight(1)
  2573. .margin({ left: 20 })
  2574. }
  2575. this.listViewTitle()
  2576. }
  2577. .backgroundImage(this.getCoverTitleBg())
  2578. .height(250)
  2579. .width('100%')
  2580. .backgroundImageSize({ height: '100%', width: '100%' })
  2581. .backgroundBlurStyle(this.isCustomizeBg ? BlurStyle.NONE : BlurStyle.BACKGROUND_ULTRA_THICK)
  2582. .padding({ top: this.topRectHeight, bottom: this.bottomBarHeight + 48 })
  2583. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  2584. .justifyContent(FlexAlign.SpaceBetween)
  2585. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.7, y: 0.7 }).animation({ duration: 500 }),
  2586. TransitionEffect.scale({ x: 0, y: 0 })))
  2587. } else {
  2588. this.listViewTitle()
  2589. }
  2590. }
  2591. getCoverTitleBg(): ResourceStr | image.PixelMap {
  2592. if (this.isCustomizeBg) {
  2593. return ('rgba(255,255,255,0.2)')
  2594. }
  2595. if (this.isDarkMode) {
  2596. return $r('app.color.user_center_card_background')
  2597. }
  2598. return this.currentTitleCover
  2599. }
  2600. @Builder
  2601. listViewTitle() {
  2602. Column() {
  2603. Row({ space: 8 }) {
  2604. Row({ space: 8 }) {
  2605. Image($r("app.media.hm_playlist"))
  2606. .width(25)
  2607. .margin({ left: 8 })
  2608. .fillColor(this.themeColor)
  2609. Text(`共找到${this.artistList.length}位艺术家`)
  2610. .fontColor($r('app.color.text_color'))
  2611. .fontSize(14)
  2612. .opacity(this.opacityItem)
  2613. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2614. Text(`共找到${this.albumList.length}张专辑`)
  2615. .fontColor($r('app.color.text_color'))
  2616. .opacity(this.opacityItem)
  2617. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2618. .fontSize(14)
  2619. }
  2620. .layoutWeight(1)
  2621. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  2622. Row() {
  2623. TextInput({
  2624. placeholder: this.modeType === 2 ? '输入艺术家名称...' : '输入专辑名称...',
  2625. text: this.searchText
  2626. })
  2627. .height(35)
  2628. .onChange((value: string) => {
  2629. this.onSearchInput(value);
  2630. })
  2631. .layoutWeight(1)
  2632. Text(`取消`)
  2633. .margin({ left: 10, right: 10 })
  2634. .fontColor($r('app.color.text_color'))
  2635. .fontSize(16)
  2636. .onClick(() => {
  2637. this.isSearchMode = false
  2638. this.searchText = ''
  2639. if (this.modeType === 2) {
  2640. this.updateListData(this.artistList)
  2641. } else {
  2642. this.updateListData(this.albumList)
  2643. }
  2644. })
  2645. }
  2646. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  2647. .animation({
  2648. duration: 666,
  2649. curve: 'ease-in-out' // 可选动画曲线
  2650. })
  2651. Blank()
  2652. Image($r("app.media.search"))
  2653. .width(25)
  2654. .visibility(this.modeType === 2 || this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2655. .animation({
  2656. duration: 666,
  2657. curve: 'ease-in-out' // 可选动画曲线
  2658. })// .opacity(this.opacityItem)
  2659. .fillColor(this.themeColor)
  2660. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2661. .onClick(() => {
  2662. this.isSearchMode = true
  2663. })
  2664. Image($r("app.media.top_rank"))
  2665. .width(25)// .opacity(this.opacityItem)
  2666. .fillColor(this.themeColor)
  2667. .animation({
  2668. duration: 666,
  2669. curve: 'ease-in-out' // 可选动画曲线
  2670. })
  2671. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2672. .onClick(() => {
  2673. this.showRankDialog()
  2674. })
  2675. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  2676. .width(25)
  2677. .animation({
  2678. duration: 666,
  2679. curve: 'ease-in-out' // 可选动画曲线
  2680. })
  2681. .fillColor(this.themeColor)
  2682. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2683. .onClick(() => {
  2684. this.isGridMusic = !this.isGridMusic
  2685. })
  2686. }
  2687. .visibility(((this.modeType === 2 || this.modeType === 3) && !this.isCanBack) ? Visibility.Visible :
  2688. Visibility.None)
  2689. .width('100%')
  2690. .padding(10)
  2691. .height(50)
  2692. .border({
  2693. width: { bottom: 1 },
  2694. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2695. })
  2696. Row({ space: 8 }) {
  2697. Row({ space: 8 }) {
  2698. Image($r("app.media.hm_play"))
  2699. .width(25)
  2700. .margin({ left: 8 })
  2701. .fillColor(this.themeColor)
  2702. Text(`播放全部`)
  2703. .fontColor($r('app.color.text_color'))
  2704. .fontSize(14)
  2705. .animation({
  2706. duration: 666,
  2707. curve: 'ease-in-out' // 可选动画曲线
  2708. })
  2709. Text(`(${Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length}首)`)
  2710. .fontColor($r('app.color.text_color'))
  2711. .fontSize(14)
  2712. .opacity(this.opacityItem)
  2713. .animation({
  2714. duration: 666,
  2715. curve: 'ease-in-out' // 可选动画曲线
  2716. })
  2717. }
  2718. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2719. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  2720. .animation({
  2721. duration: 666,
  2722. curve: 'ease-in-out' // 可选动画曲线
  2723. })
  2724. // .backgroundColor(this.isClickedPLayAll ? $r('app.color.button_click') : Color.Transparent)
  2725. .onTouch((event: TouchEvent) => {
  2726. if (event.type === TouchType.Down) {
  2727. this.isClickedPLayAll = true;
  2728. } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
  2729. this.isClickedPLayAll = false;
  2730. }
  2731. })
  2732. .onClick(() => {
  2733. // ToastUtil.showToast('当前的手机的折叠状态 ='+DisplayUtil.getFoldStatus())
  2734. if (this.modeType === 0) {
  2735. if (ArrayUtil.isNotEmpty(this.getCurFileList())) {
  2736. this.doPlay(this.getCurFileList()[0])
  2737. }
  2738. } else {
  2739. if (ArrayUtil.isNotEmpty(this.mediaKuList)) {
  2740. this.doPlay(this.mediaKuList[0])
  2741. }
  2742. }
  2743. })
  2744. Row() {
  2745. TextInput({ placeholder: '输入名称...', text: this.searchText })
  2746. .height(35)
  2747. .onChange((value: string) => {
  2748. this.onSearchInput(value);
  2749. })
  2750. .layoutWeight(1)
  2751. Text(`取消`)
  2752. .margin({ left: 10, right: 10 })
  2753. .fontColor($r('app.color.text_color'))
  2754. .fontSize(16)
  2755. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2756. .onClick(() => {
  2757. this.isSearchMode = false
  2758. this.searchText = ''
  2759. this.updateListData(this.mediaKuList)
  2760. })
  2761. }
  2762. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  2763. .animation({
  2764. duration: 666,
  2765. curve: 'ease-in-out' // 可选动画曲线
  2766. })
  2767. Blank()
  2768. Image($r("app.media.search"))
  2769. .width(25)// .visibility(this.modeType===1?Visibility.Visible:Visibility.None)
  2770. .animation({
  2771. duration: 666,
  2772. curve: 'ease-in-out' // 可选动画曲线
  2773. })// .opacity(this.opacityItem)
  2774. .fillColor(this.themeColor)
  2775. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2776. .onClick(() => {
  2777. this.isSearchMode = true
  2778. })
  2779. Image($r("app.media.refresh"))
  2780. .fillColor(this.themeColor)
  2781. .width(25)
  2782. .visibility(this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
  2783. .animation({
  2784. duration: 666,
  2785. curve: 'ease-in-out' // 可选动画曲线
  2786. })
  2787. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2788. .onClick(() => {
  2789. if (this.isFavMusic) {
  2790. this.getFavList(true)
  2791. } else {
  2792. if(this.modeType == 0){
  2793. this.asyncCurrentPathData()
  2794. }else if(this.modeType ==1){
  2795. workerInstance.postMessage({ code: 2, data: this.context });
  2796. }
  2797. }
  2798. })
  2799. Image($r("app.media.top_rank"))
  2800. .width(25)
  2801. .visibility(this.isHistory || this.isSearchMode ? Visibility.None :
  2802. Visibility.Visible)// .opacity(this.opacityItem)
  2803. .animation({
  2804. duration: 666,
  2805. curve: 'ease-in-out' // 可选动画曲线
  2806. })
  2807. .fillColor(this.themeColor)
  2808. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2809. .onClick(() => {
  2810. this.showRankDialog()
  2811. })
  2812. Image(this.isMultiSelect ? $r("app.media.cancel_multi") : $r("app.media.top_flower"))
  2813. .width(24)
  2814. .visibility(this.isHistory || this.isSearchMode ? Visibility.None : Visibility.Visible)
  2815. .animation({
  2816. duration: 666,
  2817. curve: 'ease-in-out' // 可选动画曲线
  2818. })
  2819. .fillColor(this.themeColor)
  2820. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2821. .onClick(() => {
  2822. this.isMultiSelect = !this.isMultiSelect
  2823. })
  2824. SymbolGlyph($r('sys.symbol.trash'))
  2825. .fontColor([this.themeColor])
  2826. .fontSize(25)
  2827. .effectStrategy(1)
  2828. .visibility(this.isHistory ? Visibility.Visible : Visibility.None)
  2829. .animation({
  2830. duration: 666,
  2831. curve: 'ease-in-out' // 可选动画曲线
  2832. })
  2833. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2834. .onClick(() => {
  2835. this.clearVideoHistory() //清空播放记录
  2836. })
  2837. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  2838. .width(24)
  2839. .animation({
  2840. duration: 666,
  2841. curve: 'ease-in-out' // 可选动画曲线
  2842. })
  2843. .fillColor(this.themeColor)
  2844. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2845. .bindPopup($$this.tipPopup, {
  2846. builder: this.popupBuilder,
  2847. placement: Placement.Bottom,
  2848. maskColor: 0x33000000,
  2849. enableArrow: true,
  2850. onStateChange: (e) => {
  2851. if (!e.isVisible) {
  2852. this.tipPopup = false;
  2853. }
  2854. }
  2855. })
  2856. .onClick(() => {
  2857. this.isGridMusic = !this.isGridMusic
  2858. })
  2859. }
  2860. .width('100%')
  2861. .padding(10)
  2862. .height(50)
  2863. .visibility(this.modeType === 0 || this.modeType === 1 || this.isCanBack ? Visibility.Visible : Visibility.None)
  2864. .border({
  2865. width: { bottom: 1 },
  2866. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2867. })
  2868. }
  2869. .visibility(this.isShowAllBar ? Visibility.Visible : Visibility.None)
  2870. }
  2871. // 第二步:popup构造器定义弹框内容
  2872. @Builder popupBuilder() {
  2873. Column({ space: 2 }) {
  2874. Text('友情提示:双指缩放可以放大缩小列表')
  2875. .fontSize(12)
  2876. .fontWeight(FontWeight.Regular)
  2877. .fontColor($r('app.color.text_color'))
  2878. }
  2879. .justifyContent(FlexAlign.SpaceAround)
  2880. .width(220)
  2881. .height(55)
  2882. .padding(15)
  2883. }
  2884. //搜索功能的实现
  2885. @State searchText: string = ''; // 用户输入内容
  2886. @State filteredList: Array<VideoItem> = []; // 过滤后的结果
  2887. @State isSearchMode: boolean = false
  2888. // 实时搜索逻辑(带防抖)
  2889. private onSearchInput(value: string) {
  2890. this.searchText = value.trim();
  2891. let mSearchList: Array<VideoItem> = []
  2892. switch (this.modeType) {
  2893. case 0:
  2894. mSearchList = this.videoLocalList
  2895. break;
  2896. case 1:
  2897. mSearchList = this.mediaKuList
  2898. break;
  2899. case 2:
  2900. mSearchList = this.artistList
  2901. break;
  2902. case 3:
  2903. mSearchList = this.albumList
  2904. break;
  2905. }
  2906. // 新增条件判断:空输入时显示所有数据
  2907. if (this.searchText === '') {
  2908. this.filteredList = [...mSearchList]; // 创建新数组以触发状态更新
  2909. } else {
  2910. this.filteredList = mSearchList.filter((item: VideoItem) => {
  2911. return item.name.toLowerCase().includes(this.searchText.toLowerCase());
  2912. });
  2913. }
  2914. this.updateListData(this.filteredList);
  2915. // this.isSearchMode = false; // 根据业务需求决定是否启用
  2916. }
  2917. @State dragItem: number = -1
  2918. @State scaleItem: number = -1
  2919. @State neighborItem: number = -1
  2920. @State neighborScale: number = -1
  2921. @State offsetY: number = 0
  2922. private dragRefOffset: number = 0
  2923. private ITEM_INTV: number = 78
  2924. scaleSelect(item: number): number {
  2925. if (this.scaleItem === item) {
  2926. return 1.05
  2927. } else if (this.neighborItem === item) {
  2928. return this.neighborScale
  2929. } else {
  2930. return 1
  2931. }
  2932. }
  2933. itemMove(index: number, newIndex: number): void {
  2934. if (newIndex < 0 || newIndex >= this.videoLocalList.length) {
  2935. return;
  2936. }
  2937. let tmp = this.videoLocalList.splice(index, 1);
  2938. this.videoLocalList.splice(newIndex, 0, tmp[0]);
  2939. this.dataSource.pushArrayData(this.videoLocalList)
  2940. }
  2941. // Grid布局的开始
  2942. private dragRefOffSetX: number = 0;
  2943. private dragRefOffSetY: number = 0;
  2944. private FIX_VP_X: number = 180;
  2945. private FIX_VP_Y: number = 84;
  2946. isDraggable(index: number): boolean {
  2947. return index >= 0;
  2948. }
  2949. getRowEnd(item: number) {
  2950. if (item.toString() === '0') {
  2951. return 1;
  2952. } else {
  2953. return 0;
  2954. }
  2955. }
  2956. // [Start itemMove_start]
  2957. // itemMoveGrid(index: number, newIndex: number): void {
  2958. // if (!this.isDraggable(newIndex)) {
  2959. // return;
  2960. // }
  2961. // let tmp = this.videoLocalList.splice(index, 1);
  2962. // this.videoLocalList.splice(newIndex, 0, tmp[0]);
  2963. // // this.bigItemIndex = this.videoLocalList.findIndex((item) => item === 0);
  2964. // }
  2965. isInLeft(index: number) {
  2966. return index % 2 == 0;
  2967. }
  2968. down(index: number): void {
  2969. if ([this.videoLocalList.length - 1, this.videoLocalList.length - 2].includes(index)) {
  2970. return;
  2971. }
  2972. this.offsetY -= this.FIX_VP_Y;
  2973. this.dragRefOffSetY += this.FIX_VP_Y;
  2974. this.itemMove(index, index + 1);
  2975. }
  2976. up(index: number): void {
  2977. if (!this.isDraggable(index - 2)) {
  2978. return;
  2979. }
  2980. this.offsetY += this.FIX_VP_Y;
  2981. this.dragRefOffSetY -= this.FIX_VP_Y;
  2982. this.itemMove(index, index - 1);
  2983. }
  2984. left(index: number): void {
  2985. if (this.isInLeft(index)) {
  2986. return;
  2987. }
  2988. if (!this.isDraggable(index - 1)) {
  2989. return;
  2990. }
  2991. this.offsetX += this.FIX_VP_X;
  2992. this.dragRefOffSetX -= this.FIX_VP_X;
  2993. this.itemMove(index, index - 1)
  2994. }
  2995. right(index: number): void {
  2996. if (!this.isInLeft(index)) {
  2997. return;
  2998. }
  2999. if (!this.isDraggable(index + 1)) {
  3000. return;
  3001. }
  3002. this.offsetX -= this.FIX_VP_X;
  3003. this.dragRefOffSetX += this.FIX_VP_X;
  3004. this.itemMove(index, index + 1)
  3005. }
  3006. private scroller: Scroller = new Scroller();
  3007. @State startIndex: number = 0
  3008. @State endIndex: number = 0
  3009. @State scaleValue: number = 1
  3010. @State pinchValue: number = 1
  3011. layoutOptionsForHeader: GridLayoutOptions = {
  3012. regularSize: [1, 1], // 只支持[1, 1]
  3013. irregularIndexes: [0], // 索引为0的GridItem占用一行
  3014. };
  3015. @Builder
  3016. getGridView() {
  3017. Grid(this.scroller, this.layoutOptionsForHeader) {
  3018. GridItem() {
  3019. if (this.isShowCoverHeader()) {
  3020. this.coverHeader()
  3021. } else {
  3022. this.listViewTitle()
  3023. }
  3024. }
  3025. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3026. GridItem() {
  3027. Stack({ alignContent: Alignment.Center }) {
  3028. this.MusicItemGrid(item, index)
  3029. }
  3030. }
  3031. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3032. {
  3033. preview: MenuPreviewMode.IMAGE,
  3034. previewAnimationOptions: { scale: [0.8, 1.0] },
  3035. })
  3036. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3037. {
  3038. preview: MenuPreviewMode.IMAGE,
  3039. previewAnimationOptions: { scale: [0.8, 1.0] },
  3040. })
  3041. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3042. TransitionEffect.scale({ x: 0, y: 0 })))
  3043. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3044. .scale({ x: this.scaleItem === index ? 1.02 : 1, y: this.scaleItem === index ? 1.02 : 1 })
  3045. .zIndex(this.dragItem === index ? 1 : 0)
  3046. .translate(this.dragItem === index ? { x: this.offsetX, y: this.offsetY } : { x: 0, y: 0 })
  3047. .hitTestBehavior(this.isDraggable(this.videoLocalList.indexOf(item)) ? HitTestMode.Default : HitTestMode.None)
  3048. //长按拖动代码
  3049. // .gesture(
  3050. // GestureGroup(GestureMode.Sequence,
  3051. // LongPressGesture({ repeat: true })
  3052. // .onAction(() => {
  3053. // this.getUIContext().animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3054. // this.scaleItem = index;
  3055. // })
  3056. // })
  3057. // .onActionEnd(() => {
  3058. // this.getUIContext().animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3059. // this.scaleItem = -1;
  3060. // })
  3061. // }),
  3062. // PanGesture({ fingers: 1, direction: null, distance: 0 })
  3063. // .onActionStart(() => {
  3064. // this.dragItem = index;
  3065. // this.dragRefOffSetX = 0;
  3066. // this.dragRefOffSetY = 0;
  3067. // })
  3068. // .onActionUpdate((event: GestureEvent) => {
  3069. // this.offsetX = event.offsetX - this.dragRefOffSetX;
  3070. // this.offsetY = event.offsetY - this.dragRefOffSetY;
  3071. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3072. // let index = this.videoLocalList.indexOf(item);
  3073. // if (this.offsetY >= this.FIX_VP_Y / 2 && (this.offsetX <= 44 && this.offsetX >= -44)) {
  3074. // this.down(index);
  3075. // } else if (this.offsetY <= -this.FIX_VP_Y / 2 && (this.offsetX <= 44 && this.offsetX >= -44)) {
  3076. // this.up(index);
  3077. // } else if (this.offsetX >= this.FIX_VP_X / 2 && (this.offsetY <= 50 && this.offsetY >= -50)) {
  3078. // this.right(index);
  3079. // } else if (this.offsetX <= -this.FIX_VP_Y / 2 && (this.offsetY <= 50 && this.offsetY >= -50)) {
  3080. // this.left(index);
  3081. // }
  3082. // })
  3083. //
  3084. //
  3085. // // if (this.offsetY > this.FIX_VP_Y * 0.7) {
  3086. // // this.scroller.scrollToIndex(index + 10, true,ScrollAlign.CENTER);
  3087. // // }
  3088. //
  3089. //
  3090. // })
  3091. // .onActionEnd(() => {
  3092. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3093. // this.dragItem = -1;
  3094. // })
  3095. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150 }, () => {
  3096. // this.scaleItem = -1;
  3097. // })
  3098. // })
  3099. // )
  3100. // .onCancel(() => {
  3101. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3102. // this.dragItem = -1;
  3103. // })
  3104. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150 }, () => {
  3105. // this.scaleItem = -1;
  3106. // })
  3107. // })
  3108. // )
  3109. // [End gesture_start]
  3110. // [EndExclude GridItem_start]
  3111. }, (item: VideoItem) => item.filePath)
  3112. }
  3113. .width(this.isShowHeader ? '100%' : '94%')
  3114. .height('100%')
  3115. .editMode(true)
  3116. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3117. .animation({ duration: 500, curve: Curve.Ease }))
  3118. // .margin({ bottom: this.isCoverOpacity() ? 80 : 175 })
  3119. .margin({
  3120. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+30 : this.topBarHeight+90)
  3121. : (this.isShowCoverHeader() ? this.topBarHeight+45 : this.topBarHeight+128)
  3122. })
  3123. .layoutWeight(1)
  3124. .scrollBar(BarState.Off)
  3125. .supportAnimation(true)
  3126. .cachedCount(this.twoFingerType==1?5:this.twoFingerType==2?4:3)
  3127. // .columnsTemplate('1fr '.repeat(this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM ? 2 : 5))
  3128. .columnsTemplate(
  3129. this.twoFingerType == 3 ? 'repeat(auto-fit, 160)' :
  3130. this.twoFingerType == 2 ? 'repeat(auto-fit, 110)' : 'repeat(auto-fit, 80)'
  3131. )
  3132. .rowsGap(this.isShowDrawer ? 25 : (this.twoFingerType == 3 ? 10 : this.twoFingerType == 2 ? 5 : 1))
  3133. .visibility(this.isGridMusic ? Visibility.Visible : Visibility.None)
  3134. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3135. .gesture(PinchGesture({ fingers: 2 })
  3136. .onActionEnd((event: GestureEvent) => {
  3137. this.setGridTwoFingers()
  3138. })
  3139. .onActionUpdate(e => {
  3140. this.scaleValue = this.pinchValue * e.scale
  3141. })
  3142. .onActionStart(e => {
  3143. }))
  3144. .enableScrollInteraction(true)
  3145. // 滚轴滑动,记录下滑动时的起始位置和终点位置
  3146. .onScrollIndex((start: number, end: number) => {
  3147. this.startIndex = start
  3148. this.endIndex = end
  3149. })
  3150. .onScrollFrameBegin((offset: number) => {
  3151. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  3152. // if (this.isPhoneLan()) {
  3153. // this.setBarHeightHide(offset)
  3154. // } else
  3155. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3156. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3157. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3158. if (this.isScrollHide) {
  3159. this.setBarHeightHide2(offset)
  3160. } else {
  3161. this.setBarHeightNormal()
  3162. }
  3163. } else {
  3164. this.setBarHeightHide(offset)
  3165. }
  3166. return { offsetRemain: offset };
  3167. })
  3168. //允许拖拽音乐和视频到List或Grid上自动导入视频
  3169. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3170. .onDrop((event?: DragEvent) => {
  3171. try {
  3172. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3173. if (dragData !== undefined) {
  3174. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3175. if (records.length > 0) {
  3176. for (let i = 0; i < records.length; i++) {
  3177. let types = records[i].getTypes();
  3178. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3179. const fileUriUds =
  3180. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3181. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3182. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3183. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3184. this.targetFile = fileUriUds.oriUri;
  3185. this.saveVideoDatas([this.targetFile])
  3186. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3187. }
  3188. }
  3189. }
  3190. } else {
  3191. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3192. }
  3193. } else {
  3194. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3195. }
  3196. } catch (error) {
  3197. const err = error as BusinessError;
  3198. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3199. }
  3200. })
  3201. }
  3202. @State targetFile: string = '';
  3203. setGridTwoFingers() {
  3204. this.pinchValue = this.scaleValue;
  3205. Logger.info('this.pinchValue = ' + this.pinchValue);
  3206. if (this.pinchValue >= 1) {
  3207. this.twoFingerType++
  3208. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3209. if (this.twoFingerType > 3) {
  3210. this.twoFingerType = 3
  3211. }
  3212. } else {
  3213. this.twoFingerType--
  3214. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3215. if (this.twoFingerType < 1) {
  3216. this.twoFingerType = 3
  3217. this.isGridMusic = false
  3218. }
  3219. }
  3220. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3221. this.pinchValue = 1;
  3222. this.scaleValue = 1;
  3223. }
  3224. @State longItemFilePath: string = ''
  3225. @State tempLyricContent: string = ''
  3226. @Builder
  3227. private MusicItemGrid(item: VideoItem, index: number) {
  3228. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3229. Stack() {
  3230. Column() {
  3231. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3232. .height(this.getGridHeight())
  3233. .width(this.getGridWight())
  3234. .draggable(false)
  3235. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  3236. .autoResize(true) // 重采样,可减少内存占用
  3237. .alt($r('app.media.ic_avatar2'))
  3238. .clip(true)
  3239. .borderRadius({
  3240. topLeft: 12,
  3241. topRight: 12,
  3242. bottomLeft: 0,
  3243. bottomRight: 0
  3244. })
  3245. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3246. height: '99%' ,
  3247. dragBar: true,
  3248. onDisappear: () => {
  3249. this.longItemFilePath = '';
  3250. this.tempLyricContent = ''
  3251. },
  3252. showClose: true,
  3253. preferType: SheetType.CENTER ,
  3254. title: { title: '编辑标签' }
  3255. })
  3256. .draggable(false)
  3257. .opacity(this.opacityItem)// 绑定透明度
  3258. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3259. // .animation({ duration: 500, curve: Curve.Ease }))
  3260. .animation({
  3261. duration: 666,
  3262. curve: 'ease-in-out' // 可选动画曲线
  3263. })
  3264. .margin({
  3265. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3266. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3267. })
  3268. Column() {
  3269. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3270. .fontSize(this.twoFingerType == 1 ? 14 : this.twoFingerType == 2 ? 16 : 18)
  3271. .maxLines(1)
  3272. .fontWeight(FontWeight.Bold)
  3273. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3274. .animation({
  3275. duration: 555,
  3276. curve: 'Linear',
  3277. })
  3278. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3279. height: '95%',
  3280. dragBar: true,
  3281. showClose: true,
  3282. onDisappear: () => {
  3283. this.longItemFilePathDetail = '';
  3284. },
  3285. blurStyle:BlurStyle.Thin,
  3286. backgroundColor:Color.Transparent,
  3287. preferType: SheetType.CENTER ,
  3288. title: { title: '详情' }
  3289. })
  3290. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3291. $r('app.color.text_color'))
  3292. Column() {
  3293. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  3294. .fontSize(11)
  3295. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3296. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3297. .fontColor($r('app.color.text_color'))
  3298. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  3299. .fontSize(11)
  3300. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3301. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3302. .fontColor($r('app.color.text_color'))
  3303. Row(){
  3304. Column(){
  3305. Text(item.md5Str?.includes('Lossless')?
  3306. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  3307. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  3308. .padding({ top: 3,right:6,left:6,bottom:3 })
  3309. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3310. $r('app.color.text_color'))
  3311. .fontWeight(500)
  3312. .borderRadius(12)
  3313. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  3314. .backgroundColor('#FFC107')
  3315. .visibility(StrUtil.isEmpty(item.md5Str)?Visibility.None:Visibility.Visible)
  3316. }
  3317. .margin({ top: 2 ,right:6})
  3318. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  3319. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  3320. Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  3321. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 13)
  3322. .maxLines(1)
  3323. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3324. .margin({ top: 2})
  3325. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  3326. || item.type == CommonConstants.TYPE_IS_ALBUM
  3327. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3328. .fontWeight(FontWeight.Medium)
  3329. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3330. $r('app.color.text_color'))
  3331. }
  3332. }
  3333. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  3334. }
  3335. // .bindPopup(this.longItemFilePath === item.filePath, {
  3336. // builder: this.MenuBuilder(item, index, item.filePath),
  3337. // placement: Placement.Top,
  3338. // // autoCancel: true,
  3339. // mask: { color: '#33000000' },
  3340. // // popupColor: Color.Yellow,
  3341. // enableArrow: false, //是否显示箭头
  3342. // showInSubWindow: false,
  3343. // onStateChange: (e) => {
  3344. // if (!e.isVisible) {
  3345. // this.longItemFilePath = ''
  3346. // this.tempLyricContent = ''
  3347. // }
  3348. // }
  3349. // })
  3350. //
  3351. // .gesture(LongPressGesture()
  3352. // .onAction(async () => {
  3353. // //如果是专辑和艺术家的首页,不能长按
  3354. // if ((this.modeType === 2 || this.modeType == 3) && !this.isCanBack) {
  3355. // return
  3356. // }
  3357. // //如果是我的收藏 最近播放等也不能长按
  3358. // if (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3359. // item.name === LocalMusic.STR_HISTORY_MUSIC
  3360. // ) {
  3361. // return
  3362. // }
  3363. // this.longItemFilePath = item.filePath
  3364. // this.tempLyricContent = await this.getLyricContent(item)
  3365. // LogUtil.info('长按this.tempLyricContent = ' + this.tempLyricContent)
  3366. // })
  3367. // .onActionEnd((event: GestureEvent) => {
  3368. //
  3369. // })
  3370. // )
  3371. .height(this.twoFingerType == 3 ? 60 : this.twoFingerType == 2 ? 55 : 42)
  3372. .width(this.getGridWight())
  3373. .justifyContent(FlexAlign.Center)
  3374. .margin({
  3375. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3376. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3377. })
  3378. }
  3379. .width(this.getGridWight())
  3380. .borderRadius(12)
  3381. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  3382. .backgroundImageSize({ height: '100%', width: '100%' })
  3383. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  3384. .animation({ curve: Curve.Sharp, duration: 300 })
  3385. Checkbox({ name: 'checkbox' + index })
  3386. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  3387. .selectedColor(this.themeColor)
  3388. .shape(CheckBoxShape.CIRCLE)
  3389. .opacity(this.isMultiSelect ? 1 : 0)
  3390. .animation({
  3391. duration: 666,
  3392. curve: 'Smooth' // 可选动画曲线
  3393. })
  3394. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  3395. Visibility.None)
  3396. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  3397. .margin({ left: 20, top: 8, bottom: 8 })
  3398. .width(38)
  3399. .height(38)
  3400. }
  3401. }
  3402. .backgroundColor(Color.Transparent)
  3403. .width('100%')
  3404. .padding({ top: 15 })
  3405. .height(this.getGridAllHeight())
  3406. .onClick(() => {
  3407. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3408. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3409. this.handleFileSelection(item, !isChecked);
  3410. } else {
  3411. this.doPlay(item, index)
  3412. }
  3413. })
  3414. }
  3415. getGridAllHeight() {
  3416. let heightG = 222
  3417. switch (this.twoFingerType) {
  3418. case 1:
  3419. heightG = 118
  3420. break;
  3421. case 2:
  3422. heightG = 168
  3423. break;
  3424. case 3:
  3425. heightG = 222
  3426. break;
  3427. }
  3428. return heightG
  3429. }
  3430. getGridHeight() {
  3431. let heightG = 150
  3432. switch (this.twoFingerType) {
  3433. case 1:
  3434. heightG = 55
  3435. break;
  3436. case 2:
  3437. heightG = 100
  3438. break;
  3439. case 3:
  3440. heightG = 150
  3441. break;
  3442. }
  3443. return heightG
  3444. }
  3445. getGridWight() {
  3446. let wightG = 158
  3447. switch (this.twoFingerType) {
  3448. case 1:
  3449. wightG = 80
  3450. break;
  3451. case 2:
  3452. wightG = 110
  3453. break;
  3454. case 3:
  3455. wightG = 158
  3456. break;
  3457. }
  3458. return wightG
  3459. }
  3460. @State isShowDetail:boolean = false
  3461. // @State isShowDetailGrid:boolean = false
  3462. // @State isShowEditGrid:boolean = false
  3463. @State longItemFilePathDetail:string =''
  3464. @Builder
  3465. MenuBuilder(item: VideoItem, index: number, filePath: string) {
  3466. if(
  3467. ((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  3468. ||(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3469. item.name === LocalMusic.STR_HISTORY_MUSIC)
  3470. ){
  3471. //如果是专辑和艺术家的首页,不能长按
  3472. //如果是我的收藏 最近播放等也不能长按
  3473. }else{
  3474. Scroll() {
  3475. Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
  3476. Menu() {
  3477. MenuItem({
  3478. symbolStartIcon: new SymbolGlyphModifier(Utility.getIsFav(this.favList, item) ?
  3479. $r('sys.symbol.heart_fill') : $r('sys.symbol.heart')),
  3480. content: Utility.getIsFav(this.favList, item) ? '取消收藏' : '收藏'
  3481. })
  3482. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3483. .onClick(() => {
  3484. if (item) {
  3485. this.doFav(item)
  3486. }
  3487. this.longItemFilePath = ''
  3488. })
  3489. MenuItem({
  3490. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.forward_end_fill')),
  3491. content: '下一首播放'
  3492. })
  3493. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3494. .onClick(() => {
  3495. this.addToNextPlay(item);
  3496. this.longItemFilePath = ''
  3497. })
  3498. MenuItem({
  3499. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
  3500. content: '编辑标签'
  3501. })
  3502. .bindSheet($$this.isShowEdit, this.editSheet(item), {
  3503. height: '99%',
  3504. dragBar: true,
  3505. showClose: true,
  3506. preferType: SheetType.CENTER ,
  3507. title: { title: '编辑标签' }
  3508. })
  3509. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3510. .onClick(async() => {
  3511. this.setEditStrEmpty()
  3512. this.tempLyricContent = await this.getLyricContent(item);
  3513. // console.info('onecold 长按this.tempLyricContent' +this.tempLyricContent)
  3514. if(this.isGridMusic){
  3515. this.longItemFilePath = item.filePath
  3516. }else{
  3517. this.isShowEdit = !this.isShowEdit;
  3518. }
  3519. })
  3520. MenuItem({
  3521. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.checkmark_square_on_square')),
  3522. content: $r('app.string.select_all')
  3523. })
  3524. .onClick(() => {
  3525. this.isMultiSelect = !this.isMultiSelect
  3526. this.longItemFilePath = ''
  3527. })
  3528. MenuItem({
  3529. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.rename')),
  3530. content: $r('app.string.rename')
  3531. })
  3532. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3533. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3534. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3535. .onClick(() => {
  3536. this.showReNameDialog(item, index + '', filePath)
  3537. this.longItemFilePath = ''
  3538. })
  3539. MenuItem({
  3540. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
  3541. content: $r('app.string.delete')
  3542. })
  3543. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3544. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3545. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3546. .onClick(() => {
  3547. this.showWarnIsDeleteFile(item, index + '', filePath)
  3548. this.longItemFilePath = ''
  3549. })
  3550. MenuItem({
  3551. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.info_circle')),
  3552. content: $r('app.string.detail')
  3553. })
  3554. .bindSheet($$this.isShowDetail, this.detailSheet(item), {
  3555. height:'95%',
  3556. dragBar: true,
  3557. showClose: true,
  3558. blurStyle:BlurStyle.Thin,
  3559. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  3560. backgroundColor:Color.Transparent,
  3561. title: { title: '详情信息' }
  3562. })
  3563. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3564. .onClick(() => {
  3565. if(this.isGridMusic){
  3566. this.longItemFilePathDetail = item.filePath
  3567. }else{
  3568. this.isShowDetail = !this.isShowDetail
  3569. }
  3570. })
  3571. MenuItem({
  3572. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.share')),
  3573. content: $r('app.string.share')
  3574. })
  3575. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3576. .onClick(() => {
  3577. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  3578. this.longItemFilePath = ''
  3579. })
  3580. }
  3581. .font({ size: 15, weight: FontWeight.Normal })
  3582. }
  3583. .width(180)
  3584. }
  3585. .height('auto')
  3586. }
  3587. }
  3588. private listMaxScrollOffsetY: number = 0
  3589. @State selectedIndex: number = -1
  3590. setlistTwoFingers() {
  3591. this.pinchValue = this.scaleValue;
  3592. Logger.info('this.pinchValue = ' + this.pinchValue);
  3593. if (this.pinchValue >= 1) {
  3594. this.twoFingerType++
  3595. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3596. if (this.twoFingerType > 3) {
  3597. this.twoFingerType = 1
  3598. this.isGridMusic = true
  3599. }
  3600. } else {
  3601. this.twoFingerType--
  3602. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3603. if (this.twoFingerType < 1) {
  3604. this.twoFingerType = 1
  3605. }
  3606. }
  3607. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3608. this.pinchValue = 1;
  3609. this.scaleValue = 1;
  3610. }
  3611. @Builder
  3612. getListView() {
  3613. List({ scroller: this.listScroller }) {
  3614. ListItemGroup({ header: this.coverHeader() }) {
  3615. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3616. ListItem() {
  3617. Column() {
  3618. if (item.type === CommonConstants.TYPE_IS_DIR
  3619. || item.type === CommonConstants.TYPE_IS_ARTIST || item.type === CommonConstants.TYPE_IS_ALBUM) {
  3620. this.DirItem(item, index)
  3621. } else if (item.type === CommonConstants.TYPE_IS_CSJAD) { //如果是穿山甲广告
  3622. } else {
  3623. this.MusicItem(item, index)
  3624. }
  3625. }
  3626. .shadow(this.scaleItem === index ? {
  3627. radius: 70,
  3628. color: '#15000000',
  3629. offsetX: 0,
  3630. offsetY: 0
  3631. } :
  3632. {
  3633. radius: 0,
  3634. color: '#15000000',
  3635. offsetX: 0,
  3636. offsetY: 0
  3637. })
  3638. .animation({ curve: Curve.Sharp, duration: 300 })
  3639. }
  3640. // .transition(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }))
  3641. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  3642. .animation({ duration: 500 }),
  3643. TransitionEffect.scale({ x: 0, y: 0 })))
  3644. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3645. .swipeAction((
  3646. (this.isSwipe&&this.modeType == 0 || this.modeType == 1 || ((this.modeType == 3 || this.modeType == 2) && this.isCanBack))
  3647. && item.type !== CommonConstants.TYPE_IS_CSJAD &&
  3648. !this.isHistory) ? { end: this.DeleteButton(item, index, item.filePath) } : {}) //左滑
  3649. .onClick(() => {
  3650. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3651. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3652. this.handleFileSelection(item, !isChecked);
  3653. } else {
  3654. this.doPlay(item, index)
  3655. }
  3656. })
  3657. //拖动List关键代码开始
  3658. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  3659. .zIndex(this.dragItem === index ? 1 : 0)
  3660. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  3661. .gesture(
  3662. GestureGroup(GestureMode.Sequence,
  3663. LongPressGesture({ repeat: true })
  3664. .onAction((event?: GestureEvent) => {
  3665. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3666. this.scaleItem = index
  3667. })
  3668. })
  3669. .onActionEnd(() => {
  3670. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3671. this.scaleItem = -1
  3672. })
  3673. }),
  3674. PanGesture({ fingers: 1, direction: null, distance: 0 })
  3675. .onActionStart(() => {
  3676. this.dragItem = index // 记录当前拖动项索引
  3677. this.dragRefOffset = 0 // 重置偏移基准
  3678. })
  3679. .onActionUpdate((event: GestureEvent) => {
  3680. this.offsetY = event.offsetY - this.dragRefOffset;
  3681. this.neighborItem = -1;
  3682. let indexA = this.videoLocalList.indexOf(item);
  3683. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  3684. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  3685. let value: number = 0;
  3686. if (this.offsetY < 0) {
  3687. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  3688. this.neighborItem = indexA - 1;
  3689. this.neighborScale = 1 - value / 20;
  3690. } else if (this.offsetY > 0) {
  3691. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  3692. this.neighborItem = indexA + 1;
  3693. this.neighborScale = 1 - value / 20;
  3694. }
  3695. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.videoLocalList.length) {
  3696. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3697. this.offsetY -= this.ITEM_INTV;
  3698. this.dragRefOffset += this.ITEM_INTV;
  3699. this.itemMove(indexA, indexA + 1);
  3700. });
  3701. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  3702. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3703. this.offsetY += this.ITEM_INTV;
  3704. this.dragRefOffset -= this.ITEM_INTV;
  3705. this.itemMove(indexA, indexA - 1);
  3706. });
  3707. }
  3708. let curListOffset = this.listScroller.currentOffset()
  3709. // 获取手指信息
  3710. let fingerInfo = event.fingerList[0]
  3711. let clickPercentY =
  3712. (fingerInfo.globalY - Number(this.listArea.globalPosition.y)) / Number(this.listArea.height)
  3713. if (clickPercentY > 0.8 && !this.listScroller.isAtEnd()) {
  3714. let scrollVelocity = clickPercentY > 0.9 ? 4 : 2
  3715. if (this.listMaxScrollOffsetY - curListOffset.yOffset > scrollVelocity + 5) {
  3716. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset += scrollVelocity })
  3717. }
  3718. } else if (clickPercentY < 0.2 && curListOffset.yOffset >= 0) {
  3719. let scrollVelocity = clickPercentY < 0.1 ? 4 : 2
  3720. if (curListOffset.yOffset > scrollVelocity + 5) {
  3721. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset -= scrollVelocity })
  3722. }
  3723. }
  3724. })
  3725. .onActionEnd((event: GestureEvent) => {
  3726. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3727. this.dragItem = -1
  3728. this.neighborItem = -1
  3729. })
  3730. animateTo({
  3731. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  3732. }, () => {
  3733. this.scaleItem = -1
  3734. })
  3735. })
  3736. )
  3737. .onCancel(() => {
  3738. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3739. this.dragItem = -1
  3740. this.neighborItem = -1
  3741. })
  3742. animateTo({
  3743. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  3744. }, () => {
  3745. this.scaleItem = -1
  3746. })
  3747. })
  3748. ) //拖动List关键代码结束
  3749. }, (item: VideoItem) => item.filePath)
  3750. }
  3751. }
  3752. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3753. .gesture(PinchGesture({ fingers: 2 })
  3754. .onActionEnd((event: GestureEvent) => {
  3755. this.setlistTwoFingers()
  3756. })
  3757. .onActionUpdate(e => {
  3758. this.scaleValue = this.pinchValue * e.scale
  3759. })
  3760. .onActionStart(e => {
  3761. }))
  3762. // .divider({ strokeWidth: 1, color: this.isDarkMode? '#333333':'#ffe9f0f0' })
  3763. .margin({
  3764. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+25 : this.topBarHeight+80)
  3765. : (this.isShowCoverHeader() ? this.topBarHeight+35 : this.isHiCarSmall()?this.topBarHeight+90:this.topBarHeight+125)
  3766. })
  3767. .cachedCount(6)
  3768. .borderRadius(20)
  3769. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  3770. TransitionEffect.scale({ x: 0, y: 0 })))
  3771. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3772. // .animation({ duration: 500, curve: Curve.Ease }))
  3773. .layoutWeight(1)
  3774. .onScrollIndex((start) => {
  3775. this.selectedIndex = start
  3776. })
  3777. .visibility(this.isGridMusic ? Visibility.None : Visibility.Visible)
  3778. .lanes(
  3779. new BreakpointType<number>({
  3780. sm: 1,
  3781. md: 2,
  3782. lg: 2,
  3783. xl: 3,
  3784. xxl: 4
  3785. }).getValue(this.currentBreakpoint),
  3786. new BreakpointType<number>({
  3787. sm: 0,
  3788. md: 12,
  3789. lg: 12,
  3790. xl: 16,
  3791. xxl: 20
  3792. }).getValue(this.currentBreakpoint)
  3793. )
  3794. .onAreaChange((oldValue: Area, newValue: Area) => {
  3795. this.listArea = newValue
  3796. if (this.twoFingerType == 3) {
  3797. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_BIG) - 10
  3798. } else if (this.twoFingerType == 2) {
  3799. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT) - 10
  3800. } else if (this.twoFingerType == 1) {
  3801. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_SMALL) - 10
  3802. }
  3803. })
  3804. .onScrollFrameBegin((offset: number) => {
  3805. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  3806. // if (this.isPhoneLan()) {
  3807. // this.setBarHeightHide(offset)
  3808. // } else
  3809. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3810. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3811. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3812. if (this.isScrollHide) {
  3813. this.setBarHeightHide2(offset)
  3814. } else {
  3815. this.setBarHeightNormal()
  3816. }
  3817. } else {
  3818. this.setBarHeightHide(offset)
  3819. }
  3820. return { offsetRemain: offset };
  3821. })
  3822. //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
  3823. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3824. .onDrop((event?: DragEvent) => {
  3825. try {
  3826. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3827. if (dragData !== undefined) {
  3828. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3829. if (records.length > 0) {
  3830. for (let i = 0; i < records.length; i++) {
  3831. let types = records[i].getTypes();
  3832. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3833. const fileUriUds =
  3834. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3835. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3836. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3837. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3838. this.targetFile = fileUriUds.oriUri;
  3839. this.saveVideoDatas([this.targetFile])
  3840. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3841. }
  3842. }
  3843. }
  3844. } else {
  3845. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3846. }
  3847. } else {
  3848. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3849. }
  3850. } catch (error) {
  3851. const err = error as BusinessError;
  3852. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3853. }
  3854. })
  3855. }
  3856. setBarHeightNormal() {
  3857. this.hideDone = false;
  3858. this.getUIContext().animateTo({
  3859. duration: 300
  3860. }, () => {
  3861. this.bottomBarHeight = 55 + 0;
  3862. this.topBarHeight = 50 + 0;
  3863. this.barOpacity = 1;
  3864. this.barBottomOpacity = 1
  3865. this.currentYOffset = 0;
  3866. this.isHiding = false;
  3867. });
  3868. }
  3869. setBarHeightHide(offset: number) {
  3870. if (offset > 0 && !this.hideDone) {
  3871. this.currentYOffset += offset;
  3872. if (this.currentYOffset <= 100) {
  3873. this.bottomBarHeight = this.bottomBarHeight * (1 - this.currentYOffset / 100);
  3874. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  3875. this.barOpacity = 1 - this.currentYOffset / 100;
  3876. this.barBottomOpacity = 1 - this.currentYOffset / 100;
  3877. } else {
  3878. this.topBarHeight = 0;
  3879. this.bottomBarHeight = 0;
  3880. this.barBottomOpacity = 0
  3881. this.barOpacity = 0;
  3882. this.hideDone = true;
  3883. }
  3884. this.isHiding = true;
  3885. }
  3886. if (offset < 0 && this.isHiding) {
  3887. this.hideDone = false;
  3888. this.getUIContext().animateTo({
  3889. duration: 300
  3890. }, () => {
  3891. this.bottomBarHeight = 55 + 0;
  3892. this.topBarHeight = 50 + 0;
  3893. this.barOpacity = 1;
  3894. this.barBottomOpacity = 1
  3895. this.currentYOffset = 0;
  3896. this.isHiding = false;
  3897. });
  3898. }
  3899. }
  3900. //这个方法没隐藏bottomBar,只隐藏topbar
  3901. setBarHeightHide2(offset: number) {
  3902. if (offset > 0 && !this.hideDone) {
  3903. this.currentYOffset += offset;
  3904. if (this.currentYOffset <= 100) {
  3905. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  3906. this.barOpacity = 1 - this.currentYOffset / 100;
  3907. } else {
  3908. this.topBarHeight = 0;
  3909. this.barOpacity = 0;
  3910. this.hideDone = true;
  3911. }
  3912. this.isHiding = true;
  3913. }
  3914. if (offset < 0 && this.isHiding) {
  3915. this.hideDone = false;
  3916. this.getUIContext().animateTo({
  3917. duration: 300
  3918. }, () => {
  3919. this.topBarHeight = 50 + 0;
  3920. this.barOpacity = 1;
  3921. this.currentYOffset = 0;
  3922. this.isHiding = false;
  3923. });
  3924. }
  3925. }
  3926. private doPlay(item: VideoItem, index?: number, isFromSonPlayList?: boolean) {
  3927. switch (item.type) {
  3928. case CommonConstants.TYPE_IS_DIR:
  3929. // 进入歌单前安全保存当前滚动偏移量,支持列表和网格
  3930. let offsetB = 0
  3931. if (this.isGridMusic) {
  3932. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  3933. let cur = this.scroller.currentOffset()
  3934. if (cur && typeof cur.yOffset === 'number') {
  3935. offsetB = cur.yOffset
  3936. }
  3937. }
  3938. this.mScrollMap.set('lastGridDirScrollOffset', offsetB)
  3939. } else {
  3940. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  3941. let cur = this.listScroller.currentOffset()
  3942. if (cur && typeof cur.yOffset === 'number') {
  3943. offsetB = cur.yOffset
  3944. }
  3945. }
  3946. this.mScrollMap.set('lastListDirScrollOffset', offsetB)
  3947. }
  3948. if (item.name === LocalMusic.STR_LOCK_VIDEO) {
  3949. this.showVerifyDialog()
  3950. this.currentTitleName = '私密音频'
  3951. this.currentTitleCover = $r('app.media.ic_avatar5')
  3952. } else if (item.name === LocalMusic.STR_HISTORY_MUSIC) {
  3953. this.titleBarModel.setTitleName('最近播放')
  3954. this.currentTitleCover = $r('app.media.ic_avatar2')
  3955. this.currentTitleName = '最近播放'
  3956. //加载动画效果
  3957. this.updateListData(this.historyList, true)
  3958. // this.videoLocalList = this.historyList
  3959. if (ArrayUtil.isEmpty(this.historyList)) {
  3960. ToastUtil.showToast('最近播放记录空空如也')
  3961. } else {
  3962. this.currentTitleCover = Utility.getFirstCoverFromList(this.historyList)
  3963. }
  3964. this.isHistory = true
  3965. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  3966. } else if (item.name === LocalMusic.STR_FAC_VIDEO) {
  3967. this.titleBarModel.setTitleName('我的收藏')
  3968. this.currentTitleName = '我的收藏'
  3969. this.currentTitleCover = $r('app.media.ic_avatar1')
  3970. //加载动画效果
  3971. this.updateListData(this.favList)
  3972. if (ArrayUtil.isEmpty(this.favList)) {
  3973. ToastUtil.showToast('无音乐收藏记录')
  3974. } else {
  3975. this.currentTitleCover = Utility.getFirstCoverFromList(this.favList)
  3976. }
  3977. this.isFavMusic = true
  3978. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  3979. } else {
  3980. this.currentTitleName = item.name
  3981. this.currentPath = item.filePath
  3982. this.currentTitleCover = $r('app.media.ic_avatar5')
  3983. this.getSortedFiles(this.currentPath)
  3984. }
  3985. //进入歌单的时候的滚动位置在顶部
  3986. if (this.isGridMusic) {
  3987. this.scroller.scrollToIndex(0)
  3988. }
  3989. setTimeout(() => {
  3990. if (this.modeType == 0) {
  3991. if (!this.isGridMusic) {
  3992. this.listScroller.scrollToIndex(0)
  3993. }
  3994. }
  3995. }, 200)
  3996. break;
  3997. case CommonConstants.TYPE_IS_ARTIST:
  3998. // 进入艺术家前安全保存当前滚动偏移量,支持列表和网格
  3999. let offsetA = 0
  4000. if (this.isGridMusic) {
  4001. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4002. let cur = this.scroller.currentOffset()
  4003. if (cur && typeof cur.yOffset === 'number') {
  4004. offsetA = cur.yOffset
  4005. }
  4006. }
  4007. this.mScrollMap.set('lastGridArtistScrollOffset', offsetA)
  4008. } else {
  4009. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4010. let cur = this.listScroller.currentOffset()
  4011. if (cur && typeof cur.yOffset === 'number') {
  4012. offsetA = cur.yOffset
  4013. }
  4014. }
  4015. this.mScrollMap.set('lastListArtistScrollOffset', offsetA)
  4016. }
  4017. let mList = this.artistMap.get(item.name)
  4018. if (mList !== undefined && ArrayUtil.isNotEmpty(mList)) {
  4019. Utility.doSortListAscending(mList)
  4020. this.isCanBack = true
  4021. this.titleBarModel.setTitleName(item.name)
  4022. this.currentTitleName = '艺术家:' + item.name
  4023. if (item.pixelMapPath) {
  4024. this.currentTitleCover = item.pixelMapPath
  4025. }
  4026. this.updateListData(mList)
  4027. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4028. }
  4029. //进入歌单的时候的滚动位置在顶部
  4030. if (this.isGridMusic) {
  4031. this.scroller.scrollToIndex(0)
  4032. }
  4033. break;
  4034. case CommonConstants.TYPE_IS_ALBUM:
  4035. // 进入专辑前安全保存当前滚动偏移量,支持列表和网格
  4036. let offset = 0
  4037. if (this.isGridMusic) {
  4038. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4039. let cur = this.scroller.currentOffset()
  4040. if (cur && typeof cur.yOffset === 'number') {
  4041. offset = cur.yOffset
  4042. }
  4043. }
  4044. this.mScrollMap.set('lastGridAlBumScrollOffset', offset)
  4045. } else {
  4046. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4047. let cur = this.listScroller.currentOffset()
  4048. if (cur && typeof cur.yOffset === 'number') {
  4049. offset = cur.yOffset
  4050. }
  4051. }
  4052. this.mScrollMap.set('lastListAlBumScrollOffset', offset)
  4053. }
  4054. let albumList = this.albumMap.get(item.name)
  4055. if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
  4056. Utility.doSortListAscending(albumList)
  4057. this.isCanBack = true
  4058. this.titleBarModel.setTitleName(item.name)
  4059. this.currentTitleName = '专辑:' + item.name
  4060. if (item.pixelMapPath) {
  4061. this.currentTitleCover = item.pixelMapPath
  4062. }
  4063. this.updateListData(albumList)
  4064. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4065. this.mScrollMap.set(item.name, this.selectedIndex)
  4066. }
  4067. //进入歌单的时候的滚动位置在顶部
  4068. if (this.isGridMusic) {
  4069. this.scroller.scrollToIndex(0)
  4070. }
  4071. break;
  4072. case CommonConstants.TYPE_IS_CSJAD:
  4073. return
  4074. break;
  4075. case CommonConstants.TYPE_LOCAL:
  4076. if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
  4077. this.stop();
  4078. }
  4079. if (isFromSonPlayList) { //点击来自右下角的播放列表
  4080. this.currentSong = item
  4081. if (index !== undefined) {
  4082. this.curIndex = index
  4083. }
  4084. } else {
  4085. let globalVideoList = Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL) as VideoItem[];
  4086. this.curIndex = Utility.getCurIndexFromGlobalList(globalVideoList, item.filePath)
  4087. this.songList = globalVideoList
  4088. this.sonDataSource.pushArrayData(this.songList)
  4089. this.currentSong = globalVideoList[this.curIndex]
  4090. }
  4091. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  4092. this.videoUrl = this.currentSong.filePath
  4093. this.name = this.currentSong.name
  4094. this.cover = this.currentSong.pixelMapPath
  4095. this.artist = this.currentSong.artist
  4096. LogUtil.info('this.currentSong.duration =' + this.currentSong.duration)
  4097. LogUtil.info('this.currentSong.sampleRate =' + this.currentSong.sampleRate)
  4098. LogUtil.info('this.currentSongmimeType =' + this.currentSong.mimeType)
  4099. this.startPlayOrResumePlay()
  4100. break;
  4101. }
  4102. }
  4103. @Builder
  4104. PlayController() {
  4105. Column() {
  4106. Line().width('100%').height(1).backgroundColor($r('app.color.index_background'))
  4107. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4108. Row() {
  4109. Row() {
  4110. RotatingCover({ songLabel: this.currentSong?.pixelMapPath })
  4111. Column() {
  4112. Text(this.currentSong?.name)
  4113. .fontSize(16)
  4114. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4115. .maxLines(1)
  4116. .fontColor($r('app.color.text_color'))
  4117. .fontWeight(500)
  4118. Row() {
  4119. Text(this.currentSong?.artist)
  4120. .margin({ top: 2 })
  4121. .fontSize(13)
  4122. .maxLines(1)
  4123. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4124. .fontColor($r('app.color.text_color'))
  4125. }
  4126. }
  4127. .alignItems(HorizontalAlign.Start)
  4128. .margin({ right: 22 })
  4129. }
  4130. .padding({ right: 18 })
  4131. .layoutWeight(1)
  4132. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4133. .onClick(() => {
  4134. if (ArrayUtil.isNotEmpty(this.songList)) {
  4135. this.isShowPlay = true;
  4136. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  4137. this.initLyric(lyricPath);
  4138. this.startAutoHide()
  4139. } else {
  4140. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4141. }
  4142. })
  4143. Row() {
  4144. Image($r('app.media.hm_previous'))
  4145. .height(28)
  4146. .width(28)
  4147. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4148. .margin({ left: 8, right: 16 })
  4149. .fillColor(this.themeColor)
  4150. .displayPriority(2)
  4151. .onClick(() => {
  4152. if (ArrayUtil.isNotEmpty(this.songList)) {
  4153. this.playPrevious()
  4154. } else {
  4155. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4156. }
  4157. })
  4158. //播放进度条
  4159. Stack() {
  4160. Progress({
  4161. value: Math.floor(this.progressValue),
  4162. type: ProgressType.Ring,
  4163. })
  4164. .color(this.themeColor)// 进度条前景色为灰色
  4165. .backgroundColor($r('app.color.index_background'))
  4166. .height(40)
  4167. .aspectRatio(CommonConstants.ASPECT_RATIO)
  4168. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
  4169. .height(38)
  4170. .width(38)
  4171. .displayPriority(3)
  4172. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4173. .fillColor(this.themeColor)
  4174. .onClick(() => {
  4175. if (ArrayUtil.isNotEmpty(this.songList)) {
  4176. this.playOrPause()
  4177. } else {
  4178. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4179. }
  4180. })
  4181. }
  4182. Image($r('app.media.hm_next'))
  4183. .height(28)
  4184. .width(28)
  4185. .margin({
  4186. right: 16,
  4187. left: 16
  4188. })
  4189. .fillColor(this.themeColor)
  4190. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4191. .displayPriority(2)
  4192. .onClick(() => {
  4193. if (ArrayUtil.isNotEmpty(this.songList)) {
  4194. this.playNext()
  4195. } else {
  4196. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4197. }
  4198. })
  4199. Image($r('app.media.hm_playlist'))
  4200. .height(28)
  4201. .width(28)
  4202. .displayPriority(1)
  4203. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4204. .fillColor(this.themeColor)
  4205. .bindSheet($$this.isShowSheet, this.PlayListSheet(), {
  4206. height: '95%',
  4207. dragBar: true,
  4208. showClose: true,
  4209. blurStyle: BlurStyle.Thin,
  4210. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  4211. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  4212. title: {
  4213. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  4214. + `(${this.songList.length}首)`
  4215. }
  4216. })
  4217. .onClick(() => {
  4218. if (ArrayUtil.isNotEmpty(this.songList)) {
  4219. this.isShowSheet = !this.isShowSheet;
  4220. this.isFrontWhite = false
  4221. LogUtil.info('onecold scrollToIndex = ' + this.curIndex)
  4222. setTimeout(() => {
  4223. this.playListScroller.scrollToIndex(this.curIndex, true, ScrollAlign.CENTER)
  4224. }, 123)
  4225. } else {
  4226. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4227. }
  4228. })
  4229. }
  4230. }
  4231. .width('100%')
  4232. .height(this.bottomBarHeight)
  4233. .justifyContent(FlexAlign.Center)
  4234. .hitTestBehavior(HitTestMode.Transparent)
  4235. .backgroundColor(this.isCustomizeBg ? Color.Transparent : $r('app.color.bottom_control_background'))
  4236. .bindContentCover($$this.isShowPlay, this.MusicPlayBuilder(), {
  4237. // modalTransition: ModalTransition.DEFAULT,
  4238. transition: AnimationHelper.transitionInDown(666),
  4239. backgroundColor: 'rgba(0, 0, 0, 0.9)',
  4240. })
  4241. .padding({
  4242. left: 16,
  4243. right: 16
  4244. })
  4245. Line()
  4246. .width('100%')
  4247. .height(25)
  4248. .backgroundColor($r('app.color.bottom_control_background'))// .visibility(this.isPhoneLan()?Visibility.None:this.isCustomizeBg?Visibility.Hidden:Visibility.Visible)
  4249. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4250. }
  4251. .clickEffect({ level: ClickEffectLevel.HEAVY })
  4252. }
  4253. @State isFrontWhite: boolean = false
  4254. //播放列表布局
  4255. @Builder
  4256. PlayListSheet() {
  4257. Column() {
  4258. this.PlayList()
  4259. }
  4260. .width('100%')
  4261. .height('100%')
  4262. }
  4263. @State titleStr: string = ''
  4264. @State ablumStr: string = ''
  4265. @State artistStr: string = ''
  4266. @State lyricConStr: string = ''
  4267. @State currentEditItem: string = ''
  4268. @State yearStr: string = ''
  4269. @State trackStr: string = ''
  4270. @State genreStr: string = ''
  4271. @State imagePathStr: string = ''
  4272. @State albumArtistStr: string = ''
  4273. @State composerStr: string = ''
  4274. @State lyricistStr: string = ''
  4275. @State commentStr: string = ''
  4276. @State discStr: string = ''
  4277. doUpdateData() {
  4278. setTimeout(() => {
  4279. if (this.modeType === 0) {
  4280. this.deleteCache(this.currentPath)
  4281. this.getSortedFiles(this.currentPath)
  4282. }
  4283. workerInstance.postMessage({ code: 2, data: this.context });
  4284. workerInstance.postMessage({ code: 3, data: this.context });
  4285. workerInstance.postMessage({ code: 4, data: this.context });
  4286. }, 999)
  4287. }
  4288. //编辑信息
  4289. async doEdit(item: VideoItem) {
  4290. if (!item) {
  4291. return
  4292. }
  4293. if (StrUtil.isEmpty(this.titleStr)) {
  4294. ToastUtil.showToast('标题不能为空')
  4295. return
  4296. }
  4297. // let doChangeLyric = false
  4298. // if(item.filePath==this.currentSong?.filePath){
  4299. // if(this.lyricConStr !== this.lyricContent){
  4300. // doChangeLyric = true
  4301. // }
  4302. // }else if(this.lyricConStr !== this.tempLyricContent){
  4303. // doChangeLyric = true
  4304. // }
  4305. //用户更改了封面,那就内嵌下封面
  4306. if(StrUtil.isNotEmpty(this.imagePathStr)){
  4307. const resultCover:boolean = await changeMusicCover(this.context,
  4308. item.filePath,this.imagePathStr,true);
  4309. this.imagePathStr = ''
  4310. if(resultCover){
  4311. ToastUtil.showToast('内嵌封面成功')
  4312. }
  4313. }
  4314. const metadata:FFMpegTags = {
  4315. title: this.titleStr,
  4316. artist: this.artistStr,
  4317. album: this.ablumStr,
  4318. // LYRICS:this.lyricConStr,
  4319. // USLT:this.lyricConStr,
  4320. TYER:this.yearStr,
  4321. genre:this.genreStr,
  4322. track:this.trackStr,
  4323. albumartist:this.albumArtistStr,
  4324. TPE2:this.albumArtistStr,//ID3v2 中通常没有专门的 "专辑艺术家" 字段,但有些软件会使用 TPE2 来表示专辑艺
  4325. COMPOSER:this.composerStr,
  4326. lyricist:this.lyricistStr,
  4327. TEXT:this.lyricistStr,//ID3v2 使用 TEXT 字段来表示作词者
  4328. comment:this.commentStr,
  4329. // comm:this.commentStr,//ID3v2:使用 COMM(Comment)字段。
  4330. disc:this.discStr,
  4331. };
  4332. //内嵌下标签的值,设置overwrite为true会直接修改原文件
  4333. const result:boolean = await repairAudioMetadata(
  4334. item.filePath,
  4335. this.lyricConStr,
  4336. metadata,
  4337. true
  4338. );
  4339. if (result) {
  4340. this.table.updateMediaInfo(item.filePath, this.titleStr, this.artistStr, this.ablumStr,this.lyricConStr,
  4341. this.yearStr,this.genreStr,this.trackStr,this.albumArtistStr,this.composerStr, this.lyricistStr,this.commentStr,this.discStr,
  4342. (success: boolean, error?: string) => {
  4343. // this.isShowEdit = false
  4344. if(this.isGridMusic){
  4345. this.longItemFilePath =''
  4346. }else{
  4347. this.isShowEdit = false
  4348. }
  4349. if (success) {
  4350. console.log(" onecold 编辑信息成功,数据库已同步");
  4351. ToastUtil.showToast('内嵌音乐标签成功')
  4352. this.isShowMoreView = false
  4353. this.name = this.titleStr
  4354. if (item.filePath == this.currentSong?.filePath) {
  4355. this.currentSong.name = this.titleStr
  4356. this.artist = this.artistStr
  4357. this.currentSong.artist = this.artistStr
  4358. this.currentSong.album = this.ablumStr
  4359. this.currentSong.year = this.yearStr
  4360. this.currentSong.genre = this.genreStr
  4361. this.currentSong.track = this.trackStr
  4362. this.currentSong.ALBUMARTIST = this.albumArtistStr
  4363. this.currentSong.COMPOSER = this.composerStr
  4364. this.currentSong.LYRICIST = this.lyricistStr
  4365. this.currentSong.COMMENT = this.commentStr
  4366. }
  4367. this.doUpdateData()
  4368. } else {
  4369. // ToastUtil.showToast('保存失败' + error?.toString())
  4370. console.error(" onecold 编辑信息数据库失败原因: " + error);
  4371. }
  4372. });
  4373. console.log(' onecold 元数据标签更新成功,');
  4374. } else {
  4375. ToastUtil.showToast('内嵌音乐标签失败')
  4376. console.log('onecold 内嵌音乐标签失败');
  4377. }
  4378. }
  4379. updateLyricToDB() {
  4380. }
  4381. @Builder
  4382. editSheet(item: VideoItem) {
  4383. Scroll() {
  4384. Column() {
  4385. this.editDetail(item)
  4386. }
  4387. }
  4388. .width('100%')
  4389. .height('100%')
  4390. }
  4391. @Builder
  4392. editDetail(item: VideoItem) {
  4393. Column() {
  4394. if (item) {
  4395. Row() {
  4396. Stack() {
  4397. Image(StrUtil.isNotEmpty(this.imagePathStr)?this.imagePathStr:
  4398. StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') :
  4399. item.pixelMapPath)
  4400. .fillColor(this.themeColor)
  4401. .height(55)
  4402. .width(55)
  4403. .borderRadius('100%')
  4404. .clip(true)
  4405. .opacity(this.opacityItem)// 绑定透明度
  4406. .margin({ left: 25 })
  4407. }
  4408. .onClick(async () => {
  4409. const imagePath:string | undefined = await this.goSelectImage(item);
  4410. if (imagePath) {
  4411. //用户更改过图片
  4412. this.imagePathStr = imagePath
  4413. }
  4414. })
  4415. .width('18%')
  4416. Row() {
  4417. Column() {
  4418. Text(item.name)
  4419. .fontSize(14)
  4420. .maxLines(1)
  4421. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4422. .animation({
  4423. duration: 555,
  4424. curve: 'Linear',
  4425. })
  4426. .fontColor(this.themeColor)
  4427. .margin({ left: 18 })
  4428. Row() {
  4429. Text(item.artist)
  4430. .fontSize(11)
  4431. .maxLines(1)
  4432. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4433. .padding({ top: 8 })
  4434. .fontColor(this.themeColor)
  4435. .margin({ left: 18 })
  4436. }
  4437. }
  4438. .height('100%')
  4439. .width(100)
  4440. .visibility(this.isDarkMode ? Visibility.None : Visibility.Visible)
  4441. .justifyContent(FlexAlign.Center)
  4442. .alignItems(HorizontalAlign.Start)
  4443. Button('获取封面')
  4444. .fontColor(Color.White)
  4445. .fontSize(12)
  4446. .height(38)
  4447. .width(88)
  4448. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4449. .backgroundColor(this.themeColor)
  4450. .stateEffect(true)
  4451. .margin({ right: 5, left: 12 })
  4452. .onClick(async () => {
  4453. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  4454. this.isShowMoreView = false;
  4455. this.showTipsDialog();
  4456. return; // Return empty string when no API is configured
  4457. }
  4458. const imagePath:string | undefined = await this.doSearchCover(item);
  4459. console.info('onecold imagePath = '+imagePath)
  4460. if (imagePath) {
  4461. //用户更改过图片
  4462. this.imagePathStr = imagePath
  4463. }else{
  4464. ToastUtil.showToast('获取封面失败,请重试')
  4465. }
  4466. })
  4467. Button('获取歌词')
  4468. .fontColor(Color.White)
  4469. .fontSize(12)
  4470. .height(38)
  4471. .width(88)
  4472. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4473. .backgroundColor(this.themeColor)
  4474. .stateEffect(true)
  4475. .margin({ right: 12, left: 5 })
  4476. .onClick(async () => {
  4477. //判断有没有设置api
  4478. let apiUrl = PreferencesUtil.getStringSync('LRC_API', '')
  4479. if (StrUtil.isEmpty(apiUrl)) {
  4480. this.isLyricSetting = false
  4481. this.showTipsDialog()
  4482. return
  4483. }
  4484. let artist = item.artist
  4485. let title = item.name
  4486. if(!artist)
  4487. artist = ''
  4488. if(!title)
  4489. title = ''
  4490. let res: string | undefined = await getApiLyric(apiUrl,title, artist, false);
  4491. if (res && StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  4492. this.lyricConStr = res;
  4493. }else{
  4494. ToastUtil.showToast('获取歌词失败,请重试')
  4495. }
  4496. // let res : string | undefined = await getApiLyric(title, artist, false);
  4497. })
  4498. }
  4499. .height('100%')
  4500. .justifyContent(FlexAlign.Start)
  4501. .layoutWeight(1)
  4502. }
  4503. .width('100%')
  4504. .height(58)
  4505. Row() {
  4506. Text('标题:')
  4507. .fontSize(14)
  4508. .fontColor($r('app.color.text_color'))
  4509. .margin({ left: 22 })
  4510. TextInput({ text: item.name })
  4511. .height(40)
  4512. .maxLines(1)
  4513. .fontSize(14)
  4514. .layoutWeight(1)
  4515. .fontColor($r('app.color.text_color'))
  4516. .margin({ right: 20, left: 10 })
  4517. .onChange((val: string) => {
  4518. this.titleStr = val
  4519. })
  4520. }
  4521. .width('100%')
  4522. .margin({ top: 10, bottom: 10 })
  4523. .justifyContent(FlexAlign.Start)
  4524. Row() {
  4525. Text('艺术家:')
  4526. .fontSize(14)
  4527. .fontColor($r('app.color.text_color'))
  4528. .margin({ left: 22 })
  4529. TextInput({ text: item.artist })
  4530. .height(40)
  4531. .maxLines(1)
  4532. .fontSize(14)
  4533. .layoutWeight(1)
  4534. .fontColor($r('app.color.text_color'))
  4535. .margin({ right: 20, left: 10 })
  4536. .onChange((val: string) => {
  4537. this.artistStr = val
  4538. })
  4539. }
  4540. .width('100%')
  4541. .margin({ top: 10, bottom: 10 })
  4542. .justifyContent(FlexAlign.Start)
  4543. Row() {
  4544. Text('专辑名:')
  4545. .fontSize(14)
  4546. .fontColor($r('app.color.text_color'))
  4547. .margin({ left: 22 })
  4548. TextInput({ text: item.album })
  4549. .height(40)
  4550. .maxLines(1)
  4551. .fontSize(14)
  4552. .layoutWeight(1)
  4553. .fontColor($r('app.color.text_color'))
  4554. .margin({ right: 20, left: 10 })
  4555. .onChange((val: string) => {
  4556. this.ablumStr = val
  4557. })
  4558. }
  4559. .width('100%')
  4560. .margin({ top: 10, bottom: 10 })
  4561. .justifyContent(FlexAlign.Start)
  4562. Row() {
  4563. Text('年份:')
  4564. .fontSize(14)
  4565. .fontColor($r('app.color.text_color'))
  4566. .margin({ left: 22 })
  4567. TextInput({ text: item.year })
  4568. .height(40)
  4569. .maxLines(1)
  4570. .fontSize(14)
  4571. .type(InputType.Number)
  4572. .layoutWeight(1)
  4573. .fontColor($r('app.color.text_color'))
  4574. .margin({ right: 20, left: 10 })
  4575. .onChange((val: string) => {
  4576. this.yearStr = val
  4577. })
  4578. }
  4579. .width('100%')
  4580. .margin({ top: 10, bottom: 10 })
  4581. .justifyContent(FlexAlign.Start)
  4582. Row() {
  4583. Text('音轨号:')
  4584. .fontSize(14)
  4585. .fontColor($r('app.color.text_color'))
  4586. .margin({ left: 22 })
  4587. TextInput({ text:item.track=='未知'?'': item.track })
  4588. .height(40)
  4589. .maxLines(1)
  4590. .fontSize(14)
  4591. .type(InputType.Number)
  4592. .layoutWeight(1)
  4593. .fontColor($r('app.color.text_color'))
  4594. .margin({ right: 20, left: 10 })
  4595. .onChange((val: string) => {
  4596. this.trackStr = val
  4597. })
  4598. }
  4599. .width('100%')
  4600. .margin({ top: 10, bottom: 10 })
  4601. .justifyContent(FlexAlign.Start)
  4602. Row() {
  4603. Text('碟号:')
  4604. .fontSize(14)
  4605. .fontColor($r('app.color.text_color'))
  4606. .margin({ left: 22 })
  4607. TextInput({ text:item.disc })
  4608. .height(40)
  4609. .maxLines(1)
  4610. .fontSize(14)
  4611. .type(InputType.Number)
  4612. .layoutWeight(1)
  4613. .fontColor($r('app.color.text_color'))
  4614. .margin({ right: 20, left: 10 })
  4615. .onChange((val: string) => {
  4616. this.discStr = val
  4617. })
  4618. }
  4619. .width('100%')
  4620. .margin({ top: 10, bottom: 10 })
  4621. .justifyContent(FlexAlign.Start)
  4622. Row() {
  4623. Text('风格:')
  4624. .fontSize(14)
  4625. .fontColor($r('app.color.text_color'))
  4626. .margin({ left: 22 })
  4627. TextInput({ text: item.genre })
  4628. .height(40)
  4629. .maxLines(1)
  4630. .fontSize(14)
  4631. .layoutWeight(1)
  4632. .fontColor($r('app.color.text_color'))
  4633. .margin({ right: 20, left: 10 })
  4634. .onChange((val: string) => {
  4635. this.genreStr = val
  4636. })
  4637. }
  4638. .width('100%')
  4639. .margin({ top: 10, bottom: 10 })
  4640. .justifyContent(FlexAlign.Start)
  4641. Row() {
  4642. Text('专辑艺术家:')
  4643. .fontSize(14)
  4644. .fontColor($r('app.color.text_color'))
  4645. .margin({ left: 22 })
  4646. TextInput({ text: item.ALBUMARTIST })
  4647. .height(40)
  4648. .maxLines(1)
  4649. .fontSize(14)
  4650. .layoutWeight(1)
  4651. .fontColor($r('app.color.text_color'))
  4652. .margin({ right: 20, left: 10 })
  4653. .onChange((val: string) => {
  4654. this.albumArtistStr = val
  4655. })
  4656. }
  4657. .width('100%')
  4658. .margin({ top: 10, bottom: 10 })
  4659. .justifyContent(FlexAlign.Start)
  4660. Row() {
  4661. Text('作曲:')
  4662. .fontSize(14)
  4663. .fontColor($r('app.color.text_color'))
  4664. .margin({ left: 22 })
  4665. TextInput({ text: item.COMPOSER })
  4666. .height(40)
  4667. .maxLines(1)
  4668. .fontSize(14)
  4669. .layoutWeight(1)
  4670. .fontColor($r('app.color.text_color'))
  4671. .margin({ right: 20, left: 10 })
  4672. .onChange((val: string) => {
  4673. this.composerStr = val
  4674. })
  4675. }
  4676. .width('100%')
  4677. .margin({ top: 10, bottom: 10 })
  4678. .justifyContent(FlexAlign.Start)
  4679. Row() {
  4680. Text('作词:')
  4681. .fontSize(14)
  4682. .fontColor($r('app.color.text_color'))
  4683. .margin({ left: 22 })
  4684. TextInput({ text: item.LYRICIST })
  4685. .height(40)
  4686. .maxLines(1)
  4687. .fontSize(14)
  4688. .layoutWeight(1)
  4689. .fontColor($r('app.color.text_color'))
  4690. .margin({ right: 20, left: 10 })
  4691. .onChange((val: string) => {
  4692. this.lyricistStr = val
  4693. })
  4694. }
  4695. .width('100%')
  4696. .margin({ top: 10, bottom: 10 })
  4697. .justifyContent(FlexAlign.Start)
  4698. Row() {
  4699. Text('注释:')
  4700. .fontSize(14)
  4701. .fontColor($r('app.color.text_color'))
  4702. .margin({ left: 22 })
  4703. TextInput({ text: item.COMMENT })
  4704. .height(40)
  4705. .maxLines(1)
  4706. .fontSize(14)
  4707. .layoutWeight(1)
  4708. .fontColor($r('app.color.text_color'))
  4709. .margin({ right: 20, left: 10 })
  4710. .onChange((val: string) => {
  4711. this.commentStr = val
  4712. })
  4713. }
  4714. .width('100%')
  4715. .margin({ top: 10, bottom: 10 })
  4716. .justifyContent(FlexAlign.Start)
  4717. Row() {
  4718. Column(){
  4719. Text('歌词:')
  4720. .fontSize(14)
  4721. .fontColor($r('app.color.text_color'))
  4722. .margin({ left: 22 })
  4723. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  4724. SymbolGlyph($r('sys.symbol.trash_fill'))
  4725. .fontSize(25)
  4726. .alignSelf(ItemAlign.Center)
  4727. .margin({ left: 22,top:15})
  4728. }
  4729. .backgroundColor(Color.Transparent)
  4730. .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
  4731. Visibility.None:Visibility.Visible)
  4732. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4733. .onClick(()=>{
  4734. this.lyricConStr = ''
  4735. this.lyricContent = ''
  4736. this.tempLyricContent = ''
  4737. })
  4738. }
  4739. TextArea({ text: StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr:
  4740. this.tempLyricContent })
  4741. .type(TextAreaType.NORMAL)
  4742. .height('auto')
  4743. .fontSize(14)
  4744. .layoutWeight(1)
  4745. .fontColor($r('app.color.text_color'))
  4746. .margin({ right: 20, left: 10 })
  4747. .onChange((val: string) => {
  4748. this.lyricConStr = val
  4749. })
  4750. }
  4751. .width('100%')
  4752. .margin({ top: 10, bottom: 10 })
  4753. .justifyContent(FlexAlign.Start)
  4754. Row() {
  4755. Button('保存')
  4756. .fontColor(Color.White)
  4757. .layoutWeight(1)
  4758. .height(50)
  4759. .width(100)
  4760. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4761. .backgroundColor(this.themeColor)
  4762. .stateEffect(true)
  4763. .margin({ right: 20, bottom: 20 })
  4764. .onClick(async () => {
  4765. this.doEdit(item)
  4766. })
  4767. Button('取消')
  4768. .fontColor(Color.White)
  4769. .layoutWeight(1)
  4770. .height(50)
  4771. .width(100)
  4772. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4773. .backgroundColor(this.themeColor)
  4774. .stateEffect(true)
  4775. .margin({ left: 20, bottom: 20 })
  4776. .onClick(async () => {
  4777. if(this.isGridMusic){
  4778. this.longItemFilePath =''
  4779. }else{
  4780. this.isShowEdit = false
  4781. }
  4782. this.setEditStrEmpty()
  4783. if(this.isShowPlay){
  4784. this.isShowEdit = false
  4785. }
  4786. })
  4787. }
  4788. .margin({
  4789. left: 38,
  4790. right: 38,
  4791. top: 10,
  4792. bottom: 10
  4793. })
  4794. .width(250)
  4795. .height(60)
  4796. }
  4797. }
  4798. .margin({ bottom: 20 })
  4799. }
  4800. setEditStrEmpty(){
  4801. this.imagePathStr = ''
  4802. this.lyricConStr = ''
  4803. this.artistStr = ''
  4804. this.titleStr = ''
  4805. this.ablumStr = ''
  4806. this.genreStr = ''
  4807. this.yearStr = ''
  4808. this.trackStr = ''
  4809. this.albumArtistStr = ''
  4810. this.composerStr = ''
  4811. this.lyricistStr = ''
  4812. this.commentStr = ''
  4813. this.discStr = ''
  4814. }
  4815. @Builder
  4816. detailSheet(item:VideoItem) {
  4817. Scroll() {
  4818. Column() {
  4819. this.songDetail(item)
  4820. }
  4821. }
  4822. .width('100%')
  4823. .height('100%')
  4824. }
  4825. @Builder
  4826. songDetail(currentItem:VideoItem) {
  4827. Column() {
  4828. if (currentItem) {
  4829. Row() {
  4830. Stack() {
  4831. Image(StrUtil.isEmpty(currentItem.pixelMapPath) ? $r('app.media.music_red') :
  4832. currentItem.pixelMapPath)
  4833. .fillColor(this.themeColor)
  4834. .height(80)
  4835. .width(80)
  4836. .borderRadius(10)
  4837. .opacity(this.opacityItem)// 绑定透明度
  4838. .margin({ left: 22 })
  4839. }
  4840. Column() {
  4841. Column() {
  4842. Text(currentItem.name)
  4843. .fontSize(16)
  4844. .maxLines(1)
  4845. .animation({
  4846. duration: 555,
  4847. curve: 'Linear',
  4848. })
  4849. .fontColor($r('app.color.text_color'))
  4850. .margin({ left: 15 })
  4851. }
  4852. .height('100%')
  4853. .width('100%')
  4854. .justifyContent(FlexAlign.Center)
  4855. .alignItems(HorizontalAlign.Start)
  4856. }
  4857. .height('100%')
  4858. }
  4859. .width('100%')
  4860. .height(90)
  4861. .justifyContent(FlexAlign.SpaceBetween)
  4862. Row() {
  4863. Text('艺术家:')
  4864. .fontSize(14)
  4865. .fontColor($r('app.color.text_color'))
  4866. .margin({ left: 22 })
  4867. Text(currentItem?.artist ? currentItem.artist : '未知歌手')
  4868. .fontSize(14)
  4869. .fontColor($r('app.color.text_color'))
  4870. .margin({ left: 10 })
  4871. .layoutWeight(1)
  4872. }
  4873. .width('100%')
  4874. .margin({ top: 10, bottom: 10 })
  4875. .justifyContent(FlexAlign.Start)
  4876. Row() {
  4877. Text('专辑名:')
  4878. .fontSize(14)
  4879. .fontColor($r('app.color.text_color'))
  4880. .margin({ left: 22 })
  4881. Text(currentItem?.album ?currentItem.album : '未知专辑')
  4882. .fontSize(14)
  4883. .margin({ left: 10 })
  4884. .fontColor($r('app.color.text_color'))
  4885. .layoutWeight(1)
  4886. }
  4887. .width('100%')
  4888. .margin({ top: 10, bottom: 10 })
  4889. .justifyContent(FlexAlign.Start)
  4890. Row() {
  4891. Text('时长:')
  4892. .fontSize(14)
  4893. .fontColor($r('app.color.text_color'))
  4894. .margin({ left: 22 })
  4895. Text(StrUtil.isEmpty(currentItem.duration)?
  4896. (this.isShowDetailMore?this.totalTime:'未知'):currentItem.duration)
  4897. .fontSize(14)
  4898. .margin({ left: 10 })
  4899. .fontColor($r('app.color.text_color'))
  4900. .layoutWeight(1)
  4901. }
  4902. .width('100%')
  4903. .margin({ top: 10, bottom: 10 })
  4904. .justifyContent(FlexAlign.Start)
  4905. Row() {
  4906. Text('采样率:')
  4907. .fontSize(14)
  4908. .fontColor($r('app.color.text_color'))
  4909. .margin({ left: 22 })
  4910. Text(Utility.convertToKHz(currentItem.sampleRate))
  4911. .fontSize(14)
  4912. .margin({ left: 10 })
  4913. .fontColor($r('app.color.text_color'))
  4914. .layoutWeight(1)
  4915. }
  4916. .width('100%')
  4917. .margin({ top: 10, bottom: 10 })
  4918. .justifyContent(FlexAlign.Start)
  4919. Row() {
  4920. Text('比特率:')
  4921. .fontSize(14)
  4922. .fontColor($r('app.color.text_color'))
  4923. .margin({ left: 22 })
  4924. Text(currentItem.bit_rate)
  4925. .fontSize(14)
  4926. .margin({ left: 10 })
  4927. .fontColor($r('app.color.text_color'))
  4928. .layoutWeight(1)
  4929. }
  4930. .width('100%')
  4931. .margin({ top: 10, bottom: 10 })
  4932. .justifyContent(FlexAlign.Start)
  4933. Row() {
  4934. Text('位深:')
  4935. .fontSize(14)
  4936. .fontColor($r('app.color.text_color'))
  4937. .margin({ left: 22 })
  4938. Text(`${currentItem.bits_per_raw_sample} bits`)
  4939. .fontSize(14)
  4940. .margin({ left: 10 })
  4941. .fontColor($r('app.color.text_color'))
  4942. .layoutWeight(1)
  4943. }
  4944. .width('100%')
  4945. .margin({ top: 10, bottom: 10 })
  4946. .justifyContent(FlexAlign.Start)
  4947. Row() {
  4948. Text('声道:')
  4949. .fontSize(14)
  4950. .fontColor($r('app.color.text_color'))
  4951. .margin({ left: 22 })
  4952. Text(`${currentItem.channels}`)
  4953. .fontSize(14)
  4954. .margin({ left: 10 })
  4955. .fontColor($r('app.color.text_color'))
  4956. .layoutWeight(1)
  4957. }
  4958. .width('100%')
  4959. .margin({ top: 10, bottom: 10 })
  4960. .justifyContent(FlexAlign.Start)
  4961. Row() {
  4962. Text('声道布局:')
  4963. .fontSize(14)
  4964. .fontColor($r('app.color.text_color'))
  4965. .margin({ left: 22 })
  4966. Text(`${currentItem.channel_layout}`)
  4967. .fontSize(14)
  4968. .margin({ left: 10 })
  4969. .fontColor($r('app.color.text_color'))
  4970. .layoutWeight(1)
  4971. }
  4972. .width('100%')
  4973. .margin({ top: 10, bottom: 10 })
  4974. .justifyContent(FlexAlign.Start)
  4975. Row() {
  4976. Text('起始播放点:')
  4977. .fontSize(14)
  4978. .fontColor($r('app.color.text_color'))
  4979. .margin({ left: 22 })
  4980. Text(`${currentItem.start_time}`)
  4981. .fontSize(14)
  4982. .margin({ left: 10 })
  4983. .fontColor($r('app.color.text_color'))
  4984. .layoutWeight(1)
  4985. }
  4986. .width('100%')
  4987. .margin({ top: 10, bottom: 10 })
  4988. .justifyContent(FlexAlign.Start)
  4989. Row() {
  4990. Text('风格:')
  4991. .fontSize(14)
  4992. .fontColor($r('app.color.text_color'))
  4993. .margin({ left: 22 })
  4994. Text(currentItem.genre)
  4995. .fontSize(14)
  4996. .margin({ left: 10 })
  4997. .fontColor($r('app.color.text_color'))
  4998. .layoutWeight(1)
  4999. }
  5000. .width('100%')
  5001. .margin({ top: 10, bottom: 10 })
  5002. .justifyContent(FlexAlign.Start)
  5003. Row() {
  5004. Text('发行时间:')
  5005. .fontSize(14)
  5006. .fontColor($r('app.color.text_color'))
  5007. .margin({ left: 22 })
  5008. Text(currentItem.year)
  5009. .fontSize(14)
  5010. .margin({ left: 10 })
  5011. .fontColor($r('app.color.text_color'))
  5012. .layoutWeight(1)
  5013. }
  5014. .width('100%')
  5015. .margin({ top: 10, bottom: 10 })
  5016. .justifyContent(FlexAlign.Start)
  5017. Row() {
  5018. Text('质量评分:')
  5019. .fontSize(14)
  5020. .fontColor($r('app.color.text_color'))
  5021. .margin({ left: 22 })
  5022. Text(currentItem.probe_score+"")
  5023. .fontSize(14)
  5024. .margin({ left: 10 })
  5025. .fontColor($r('app.color.text_color'))
  5026. .layoutWeight(1)
  5027. }
  5028. .width('100%')
  5029. .margin({ top: 10, bottom: 10 })
  5030. .justifyContent(FlexAlign.Start)
  5031. Row() {
  5032. Text('音轨号:')
  5033. .fontSize(14)
  5034. .fontColor($r('app.color.text_color'))
  5035. .margin({ left: 22 })
  5036. Text(currentItem.track)
  5037. .fontSize(14)
  5038. .margin({ left: 10 })
  5039. .fontColor($r('app.color.text_color'))
  5040. .layoutWeight(1)
  5041. }
  5042. .width('100%')
  5043. .margin({ top: 10, bottom: 10 })
  5044. .justifyContent(FlexAlign.Start)
  5045. Row() {
  5046. Text('碟号:')
  5047. .fontSize(14)
  5048. .fontColor($r('app.color.text_color'))
  5049. .margin({ left: 22 })
  5050. Text(currentItem.disc)
  5051. .fontSize(14)
  5052. .margin({ left: 10 })
  5053. .fontColor($r('app.color.text_color'))
  5054. .layoutWeight(1)
  5055. }
  5056. .width('100%')
  5057. .margin({ top: 10, bottom: 10 })
  5058. .justifyContent(FlexAlign.Start)
  5059. Row() {
  5060. Text('专辑艺术家:')
  5061. .fontSize(14)
  5062. .fontColor($r('app.color.text_color'))
  5063. .margin({ left: 22 })
  5064. Text(currentItem.ALBUMARTIST)
  5065. .fontSize(14)
  5066. .margin({ left: 10 })
  5067. .fontColor($r('app.color.text_color'))
  5068. .layoutWeight(1)
  5069. }
  5070. .width('100%')
  5071. .margin({ top: 10, bottom: 10 })
  5072. .justifyContent(FlexAlign.Start)
  5073. Row() {
  5074. Text('作曲家:')
  5075. .fontSize(14)
  5076. .fontColor($r('app.color.text_color'))
  5077. .margin({ left: 22 })
  5078. Text(currentItem.COMPOSER)
  5079. .fontSize(14)
  5080. .margin({ left: 10 })
  5081. .fontColor($r('app.color.text_color'))
  5082. .layoutWeight(1)
  5083. }
  5084. .width('100%')
  5085. .margin({ top: 10, bottom: 10 })
  5086. .justifyContent(FlexAlign.Start)
  5087. Row() {
  5088. Text('作词家:')
  5089. .fontSize(14)
  5090. .fontColor($r('app.color.text_color'))
  5091. .margin({ left: 22 })
  5092. Text(currentItem.LYRICIST)
  5093. .fontSize(14)
  5094. .margin({ left: 10 })
  5095. .fontColor($r('app.color.text_color'))
  5096. .layoutWeight(1)
  5097. }
  5098. .width('100%')
  5099. .margin({ top: 10, bottom: 10 })
  5100. .justifyContent(FlexAlign.Start)
  5101. Row() {
  5102. Text('注释:')
  5103. .fontSize(14)
  5104. .fontColor($r('app.color.text_color'))
  5105. .margin({ left: 22 })
  5106. Text(currentItem.COMMENT)
  5107. .fontSize(14)
  5108. .margin({ left: 10 })
  5109. .fontColor($r('app.color.text_color'))
  5110. .layoutWeight(1)
  5111. }
  5112. .width('100%')
  5113. .margin({ top: 10, bottom: 10 })
  5114. .justifyContent(FlexAlign.Start)
  5115. Row() {
  5116. Text('格式:')
  5117. .fontSize(14)
  5118. .fontColor($r('app.color.text_color'))
  5119. .margin({ left: 22 })
  5120. Text(Utility.formatMimeType(currentItem.mimeType))
  5121. .fontSize(14)
  5122. .margin({ left: 10 })
  5123. .fontColor($r('app.color.text_color'))
  5124. .layoutWeight(1)
  5125. }
  5126. .width('100%')
  5127. .margin({ top: 10, bottom: 10 })
  5128. .justifyContent(FlexAlign.Start)
  5129. Row() {
  5130. Text('播放次数:')
  5131. .fontSize(14)
  5132. .fontColor($r('app.color.text_color'))
  5133. .margin({ left: 22 })
  5134. Text(currentItem.playCount?.toString())
  5135. .fontSize(14)
  5136. .margin({ left: 10 })
  5137. .fontColor($r('app.color.text_color'))
  5138. .layoutWeight(1)
  5139. }
  5140. .width('100%')
  5141. .margin({ top: 10, bottom: 10 })
  5142. .justifyContent(FlexAlign.Start)
  5143. Row() {
  5144. Text('流数量:')
  5145. .fontSize(14)
  5146. .fontColor($r('app.color.text_color'))
  5147. .margin({ left: 22 })
  5148. Text(currentItem.nb_streams?.toString())
  5149. .fontSize(14)
  5150. .margin({ left: 10 })
  5151. .fontColor($r('app.color.text_color'))
  5152. .layoutWeight(1)
  5153. }
  5154. .width('100%')
  5155. .margin({ top: 10, bottom: 10 })
  5156. .justifyContent(FlexAlign.Start)
  5157. Row() {
  5158. Text('文件大小:')
  5159. .fontSize(14)
  5160. .fontColor($r('app.color.text_color'))
  5161. .margin({ left: 22 })
  5162. Text(currentItem.size)
  5163. .fontSize(14)
  5164. .margin({ left: 10 })
  5165. .fontColor($r('app.color.text_color'))
  5166. .layoutWeight(1)
  5167. }
  5168. .width('100%')
  5169. .margin({ top: 10, bottom: 10 })
  5170. .justifyContent(FlexAlign.Start)
  5171. Row() {
  5172. Text('文件名:')
  5173. .fontSize(14)
  5174. .fontColor($r('app.color.text_color'))
  5175. .margin({ left: 22 })
  5176. Text(currentItem.fileName)
  5177. .fontSize(14)
  5178. .margin({ left: 10 })
  5179. .fontColor($r('app.color.text_color'))
  5180. .layoutWeight(1)
  5181. }
  5182. .width('100%')
  5183. .margin({ top: 10, bottom: 10 })
  5184. .justifyContent(FlexAlign.Start)
  5185. Row() {
  5186. Text('修改时间:')
  5187. .fontSize(14)
  5188. .fontColor($r('app.color.text_color'))
  5189. .margin({ left: 22 })
  5190. Text(currentItem.cTime)
  5191. .fontSize(14)
  5192. .margin({ left: 10 })
  5193. .fontColor($r('app.color.text_color'))
  5194. .layoutWeight(1)
  5195. }
  5196. .width('100%')
  5197. .margin({ top: 10, bottom: 10 })
  5198. .justifyContent(FlexAlign.Start)
  5199. Row() {
  5200. Text('存放目录:')
  5201. .fontSize(14)
  5202. .fontColor($r('app.color.text_color'))
  5203. .margin({ left: 22 })
  5204. Text(currentItem.filePath)
  5205. .fontSize(12)
  5206. .margin({ left: 10 })
  5207. .fontColor($r('app.color.text_color'))
  5208. .layoutWeight(1)
  5209. }
  5210. .margin({ top: 10, bottom: 10 })
  5211. .width('100%')
  5212. .justifyContent(FlexAlign.Start)
  5213. }
  5214. }
  5215. .margin({ bottom: 20 })
  5216. }
  5217. //定时关闭布局
  5218. @Builder
  5219. TimeCloseSheet() {
  5220. Scroll() {
  5221. Column() {
  5222. this.TimeClose()
  5223. }
  5224. }
  5225. .width('100%')
  5226. .height('100%')
  5227. }
  5228. //倒计时关闭音乐,退出App功能实现。
  5229. @State selectedMinutes: number = 0 // 0表示未开启
  5230. @State remainingSeconds: number = 0
  5231. // 预设时间选项
  5232. private presetTimes: number[] = [0, 5, 15, 30, 45, 60, -1]
  5233. private formatTime(seconds: number): string {
  5234. const mins = Math.floor(seconds / 60)
  5235. const secs = seconds % 60
  5236. return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
  5237. }
  5238. // 开始倒计时
  5239. private handleTimeSelect(minutes: number) {
  5240. if (minutes === this.selectedMinutes) {
  5241. this.stopCountdown();
  5242. this.selectedMinutes = 0;
  5243. return;
  5244. }
  5245. this.selectedMinutes = minutes;
  5246. this.remainingSeconds = minutes * 60;
  5247. this.startCountdown(); // 新增调用
  5248. }
  5249. @Builder
  5250. TimeClose() {
  5251. Column() {
  5252. // 倒计时显示区域
  5253. Text(this.selectedMinutes > 0 ?
  5254. `剩余时间:${this.formatTime(this.remainingSeconds)}` :
  5255. "定时关闭未开启")
  5256. .fontSize(17)
  5257. .fontColor($r('app.color.text_color'))
  5258. .margin({ top: 2, bottom: 8 });
  5259. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  5260. ForEach(this.presetTimes, (minutes: number, index: number) => {
  5261. // 单行时间选项容器
  5262. Row() {
  5263. // 文字描述区域
  5264. Text(this.getDisplayText(minutes))
  5265. .fontSize(15)
  5266. .fontColor(minutes === this.selectedMinutes ? this.themeColor :
  5267. $r('app.color.text_color'))// 选中态颜色变化
  5268. .textAlign(TextAlign.Start)
  5269. .layoutWeight(1); // 占据剩余空间
  5270. // 复选框样式的选择器
  5271. Row() {
  5272. if (minutes === this.selectedMinutes) {
  5273. // 选中状态 - 带勾号的圆形复选框
  5274. Row() {
  5275. // 使用系统内置的勾号图标
  5276. Image($r('sys.media.ohos_ic_public_ok'))
  5277. .width(14)
  5278. .height(14)
  5279. .fillColor(Color.White)
  5280. }
  5281. .width(24)
  5282. .height(24)
  5283. .borderRadius(12)
  5284. .backgroundColor(this.themeColor)
  5285. .justifyContent(FlexAlign.Center)
  5286. .alignItems(VerticalAlign.Center)
  5287. } else {
  5288. // 未选中状态的圆形边框
  5289. Row()
  5290. .width(24)
  5291. .height(24)
  5292. .borderRadius(12)
  5293. .border({
  5294. width: 2,
  5295. color: $r('app.color.text_color'),
  5296. style: BorderStyle.Solid
  5297. })
  5298. .backgroundColor(Color.Transparent)
  5299. }
  5300. }
  5301. .width(24)
  5302. .height(24)
  5303. .margin({ left: 20 })
  5304. .justifyContent(FlexAlign.Center)
  5305. .alignItems(VerticalAlign.Center)
  5306. }
  5307. .width('100%')
  5308. .padding({
  5309. top: 18,
  5310. bottom: 18,
  5311. left: 18,
  5312. right: 18
  5313. })
  5314. .backgroundColor(minutes === this.selectedMinutes ? $r('app.color.timeColor_bg') :
  5315. $r('app.color.bottom_control_background')) // 选中背景高亮
  5316. .borderRadius(12)
  5317. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  5318. .margin({ bottom: 18 })
  5319. .onClick(() => this.handleSelect(minutes)); // 点击整行触发选择
  5320. });
  5321. }
  5322. .width('100%')
  5323. .padding(16)
  5324. }
  5325. }
  5326. // 获取显示文本
  5327. private getDisplayText(minutes: number): string {
  5328. if (minutes === -1) {
  5329. return Utility.resourceToString(getContext(this), $r('app.string.customize'));
  5330. }
  5331. return minutes === 0 ? Utility.resourceToString(getContext(this), $r('app.string.close')) :
  5332. `${minutes}` + Utility.resourceToString(getContext(this), $r('app.string.minute_after'));
  5333. }
  5334. // 处理选择事件
  5335. private handleSelect(minutes: number): void {
  5336. if (minutes === -1) { // 自定义
  5337. // 弹出自定义时间对话框
  5338. DialogHelper.showTextInputDialog({
  5339. title: '自定义时间',
  5340. maskColor: Color.Transparent,
  5341. inputType: InputType.Number,
  5342. text: '',
  5343. onChange: (text) => {
  5344. console.error("onChange: " + text);
  5345. },
  5346. onAction: (action, dialogId, content) => {
  5347. if (action == DialogAction.TWO) {
  5348. const customMinutes = Number(content);
  5349. if (customMinutes > 0) {
  5350. this.handleTimeSelect(customMinutes); // 设置自定义时间
  5351. ToastUtil.showToast("设置成功," + customMinutes + "分钟后定时关闭");
  5352. }
  5353. }
  5354. }
  5355. });
  5356. } else {
  5357. this.handleTimeSelect(minutes); // 统一调用选择处理方法
  5358. }
  5359. }
  5360. // 添加定时器引用
  5361. private timerId: number = -1;
  5362. // 启动/重置倒计时
  5363. private startCountdown() {
  5364. // 清除旧定时器
  5365. if (this.timerId !== -1) {
  5366. clearInterval(this.timerId);
  5367. }
  5368. // 创建新定时器
  5369. if (this.selectedMinutes > 0) {
  5370. this.timerId = setInterval(() => {
  5371. if (this.remainingSeconds === 15) {
  5372. this.showConfirmationDialog();
  5373. }
  5374. if (this.remainingSeconds > 0) {
  5375. this.remainingSeconds -= 1;
  5376. } else {
  5377. this.stopCountdown();
  5378. this.handleTimeout();
  5379. }
  5380. }, 1000);
  5381. }
  5382. }
  5383. // 15倒计时后再次提示显示确认是否关闭App对话框
  5384. private showConfirmationDialog() {
  5385. DialogHelper.showAlertDialog({
  5386. backgroundColor: $r('app.color.btn_green'),
  5387. title: '确认关闭',
  5388. maskColor: Color.Transparent,
  5389. content: "马上到达定时关闭时间,您是否确定要退出应用?",
  5390. borderStyle: BorderStyle.Dashed,
  5391. primaryButton: '暂不关闭',
  5392. secondaryButton: '确定',
  5393. onAction: (action) => {
  5394. if (action == DialogAction.ONE) { //暂不关闭,取消定时
  5395. this.stopCountdown();
  5396. this.selectedMinutes = 0
  5397. } else if (action == DialogAction.TWO) {
  5398. }
  5399. }
  5400. })
  5401. }
  5402. // 停止倒计时
  5403. private stopCountdown() {
  5404. if (this.timerId !== -1) {
  5405. clearInterval(this.timerId);
  5406. this.timerId = -1;
  5407. }
  5408. }
  5409. // 超时处理
  5410. private handleTimeout() {
  5411. // 执行播放器关闭逻辑
  5412. this.selectedMinutes = 0;
  5413. ToastUtil.showToast(" 定时关闭已完成");
  5414. this.stop(); // 假设存在的播放器实例
  5415. //退出APP
  5416. const mContext = getContext(this) as common.UIAbilityContext
  5417. mContext.terminateSelf();
  5418. AvSessionController.getInstance(true).unregisterSessionListener()
  5419. }
  5420. //倒计时关闭音乐,退出App功能实现结束。
  5421. //播放列表的拖动List 重新排序
  5422. @State sonDataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.songList)
  5423. //左滑操作 移动文件 重命名 删除等操作
  5424. @Builder
  5425. sonButton(item: VideoItem, index: number, filePath: string) {
  5426. Row() {
  5427. //加入下一首播放
  5428. Button() {
  5429. Image($r('app.media.next_to_play'))
  5430. .fillColor(Color.White)
  5431. .width(20)
  5432. }
  5433. .width(40)
  5434. .height(40)
  5435. .type(ButtonType.Circle)
  5436. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5437. .backgroundColor(this.themeColor)
  5438. .margin(5)
  5439. .onClick(() => {
  5440. this.addToNextPlay(item);
  5441. })
  5442. Button() {
  5443. Image($r('app.media.close'))
  5444. .fillColor(Color.White)
  5445. .width(20)
  5446. }
  5447. .width(40)
  5448. .height(40)
  5449. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5450. .type(ButtonType.Circle)
  5451. .backgroundColor(this.themeColor)
  5452. .margin(5)
  5453. .onClick(() => {
  5454. this.songList.splice(Number(index), 1)
  5455. this.sonDataSource.pushArrayData(this.songList)
  5456. })
  5457. Button() {
  5458. Image($r('app.media.share2'))
  5459. .fillColor(Color.White)
  5460. .width(20)
  5461. }
  5462. .width(40)
  5463. .height(40)
  5464. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5465. .type(ButtonType.Circle)
  5466. .backgroundColor(this.themeColor)
  5467. .margin(5)
  5468. .onClick(() => {
  5469. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  5470. })
  5471. }
  5472. }
  5473. itemMoveSon(index: number, newIndex: number): void {
  5474. if (newIndex < 0 || newIndex >= this.songList.length) {
  5475. return;
  5476. }
  5477. let tmp = this.songList.splice(index, 1);
  5478. this.songList.splice(newIndex, 0, tmp[0]);
  5479. this.sonDataSource.pushArrayData(this.songList)
  5480. this.curIndex = Utility.getIndexFromList(this.songList, this.videoUrl)
  5481. }
  5482. @Builder
  5483. PlayList() {
  5484. List({ scroller: this.playListScroller }) {
  5485. LazyForEach(this.sonDataSource, (item: VideoItem, index: number) => {
  5486. ListItem() {
  5487. this.MusicItemSon(item, index)
  5488. }
  5489. .swipeAction({ end: this.sonButton(item, index, item.filePath) }) //左滑
  5490. .animation({
  5491. duration: 666,
  5492. curve: 'ease-in-out' // 可选动画曲线
  5493. })
  5494. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 600 }),
  5495. TransitionEffect.scale({ x: 0, y: 0 })))
  5496. .clickEffect({ level: ClickEffectLevel.MIDDLE })
  5497. //拖动List关键代码开始
  5498. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  5499. .zIndex(this.dragItem === index ? 1 : 0)
  5500. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  5501. .gesture(
  5502. GestureGroup(GestureMode.Sequence,
  5503. LongPressGesture({ repeat: true })
  5504. .onAction((event?: GestureEvent) => {
  5505. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5506. this.scaleItem = index
  5507. })
  5508. })
  5509. .onActionEnd(() => {
  5510. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5511. this.scaleItem = -1
  5512. })
  5513. }),
  5514. PanGesture({ fingers: 1, direction: null, distance: 0 })
  5515. .onActionStart(() => {
  5516. this.dragItem = index // 记录当前拖动项索引
  5517. this.dragRefOffset = 0 // 重置偏移基准
  5518. })
  5519. .onActionUpdate((event: GestureEvent) => {
  5520. this.offsetY = event.offsetY - this.dragRefOffset;
  5521. this.neighborItem = -1;
  5522. let indexA = this.songList.indexOf(item);
  5523. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  5524. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  5525. let value: number = 0;
  5526. if (this.offsetY < 0) {
  5527. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  5528. this.neighborItem = indexA - 1;
  5529. this.neighborScale = 1 - value / 20;
  5530. } else if (this.offsetY > 0) {
  5531. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  5532. this.neighborItem = indexA + 1;
  5533. this.neighborScale = 1 - value / 20;
  5534. }
  5535. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.songList.length) {
  5536. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5537. this.offsetY -= this.ITEM_INTV;
  5538. this.dragRefOffset += this.ITEM_INTV;
  5539. this.itemMoveSon(indexA, indexA + 1);
  5540. });
  5541. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  5542. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5543. this.offsetY += this.ITEM_INTV;
  5544. this.dragRefOffset -= this.ITEM_INTV;
  5545. this.itemMoveSon(indexA, indexA - 1);
  5546. });
  5547. }
  5548. })
  5549. .onActionEnd((event: GestureEvent) => {
  5550. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5551. this.dragItem = -1
  5552. this.neighborItem = -1
  5553. })
  5554. animateTo({
  5555. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  5556. }, () => {
  5557. this.scaleItem = -1
  5558. })
  5559. })
  5560. )
  5561. .onCancel(() => {
  5562. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5563. this.dragItem = -1
  5564. this.neighborItem = -1
  5565. })
  5566. animateTo({
  5567. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  5568. }, () => {
  5569. this.scaleItem = -1
  5570. })
  5571. })
  5572. ) //拖动List关键代码结束
  5573. .onClick(() => {
  5574. this.doPlay(item, index, true)
  5575. })
  5576. }, (item: VideoItem) => item.filePath)
  5577. }
  5578. .width('100%')
  5579. .height('100%')
  5580. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  5581. // .animation({ duration: 500, curve: Curve.Ease }))
  5582. .cachedCount(10)
  5583. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  5584. .gesture(PinchGesture({ fingers: 2 })
  5585. .onActionEnd((event: GestureEvent) => {
  5586. this.setlistTwoFingers()
  5587. })
  5588. .onActionUpdate(e => {
  5589. this.scaleValue = this.pinchValue * e.scale
  5590. })
  5591. .onActionStart(e => {
  5592. }))
  5593. .padding({
  5594. bottom: 0
  5595. })
  5596. }
  5597. @Builder
  5598. private MusicItemSon(item: VideoItem, index?: number) {
  5599. Button({ type: ButtonType.Normal, stateEffect: true }) {
  5600. Row() {
  5601. Stack() {
  5602. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  5603. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  5604. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  5605. .alt($r('app.media.music_red'))
  5606. .fillColor(this.themeColor)
  5607. .borderRadius('100%')
  5608. .clip(true)
  5609. .margin({ left: 20 })
  5610. }
  5611. .width('15%')
  5612. Column() {
  5613. Column() {
  5614. Text(item.name)
  5615. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  5616. .fontColor(this.curIndex === index ? this.themeColor :
  5617. this.isFrontWhite ? Color.White : $r('app.color.text_color'))
  5618. .maxLines(1)
  5619. .margin({ left: this.twoFingerType == 3 ? 18 : 10 })
  5620. Row() {
  5621. Column(){
  5622. Text(item.md5Str?.includes('Lossless')?
  5623. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  5624. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  5625. .padding({ top: 3,right:6,left:6,bottom:3 })
  5626. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  5627. $r('app.color.text_color'))
  5628. .fontWeight(500)
  5629. .borderRadius(12)
  5630. .margin({ left: this.twoFingerType == 3 ? 12 : 10 })
  5631. .backgroundColor('#FFC107')
  5632. }
  5633. .padding({ top: 8 })
  5634. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  5635. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  5636. .padding({ top: 8 })
  5637. .fontColor(this.curIndex === index ? this.themeColor :
  5638. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  5639. .margin({ left: this.twoFingerType == 3 ? 5 : 3 })
  5640. Blank()
  5641. Text(item.size)
  5642. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  5643. .padding({ top: 8 })
  5644. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  5645. .fontColor(this.curIndex === index ? $r('app.color.title_bar_bg_text') :
  5646. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  5647. .margin({ left: 10 })
  5648. }
  5649. }
  5650. .height('100%')
  5651. .width('100%')
  5652. .justifyContent(FlexAlign.Center)
  5653. .alignItems(HorizontalAlign.Start)
  5654. }
  5655. .height('100%')
  5656. .width('65%')
  5657. Column() {
  5658. ImageAnimator()
  5659. .images(this.imagesF)// 动画数组
  5660. .duration(1000)// 持续
  5661. .state(this.animationState)// 动画状态
  5662. .fillMode(FillMode.Forwards)
  5663. .width(18)
  5664. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  5665. Visibility.None)
  5666. .height(18)
  5667. .iterations(-1) // 播放次数
  5668. }
  5669. .width('20%')
  5670. }
  5671. }
  5672. .backgroundColor(Color.Transparent)
  5673. .width('100%')
  5674. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  5675. .shadow(this.scaleItem === index ? {
  5676. radius: 70,
  5677. color: '#15000000',
  5678. offsetX: 0,
  5679. offsetY: 0
  5680. } :
  5681. {
  5682. radius: 0,
  5683. color: '#15000000',
  5684. offsetX: 0,
  5685. offsetY: 0
  5686. })
  5687. .animation({ curve: Curve.Sharp, duration: 300 })
  5688. }
  5689. @Builder
  5690. MusicPlayBuilder() {
  5691. Column() {
  5692. this.IjkMusicPlayerView()
  5693. }
  5694. .height('100%')
  5695. .width('100%')
  5696. .onDisAppear(() => {
  5697. this.translateY = 0;
  5698. })
  5699. .translate({ y: this.translateY })
  5700. .gesture(
  5701. PanGesture(this.panOption)
  5702. .onActionUpdate((event?: GestureEvent) => {
  5703. if (event) {
  5704. // 只允许向下滑动,向上滑动时限制为0
  5705. this.translateY = Math.max(0, event.offsetY);
  5706. }
  5707. })
  5708. .onActionEnd((event?: GestureEvent) => {
  5709. // 使用更低的阈值和滑动速度判断
  5710. const minDistance = 100; // 最小滑动距离 100vp
  5711. const minVelocity = 500; // 最小滑动速度
  5712. // 获取滑动速度(如果可用)
  5713. const velocity = event?.velocityY || 0;
  5714. // 判断是否应该关闭:距离足够 或者 速度足够快
  5715. const shouldClose = this.translateY > minDistance || velocity > minVelocity;
  5716. if (shouldClose) {
  5717. // 添加关闭动画
  5718. this.getUIContext().animateTo({
  5719. duration: 300,
  5720. curve: Curve.Smooth
  5721. }, () => {
  5722. this.isShowPlay = false;
  5723. this.translateY = 0;
  5724. })
  5725. } else {
  5726. // 回弹动画
  5727. this.getUIContext().animateTo({
  5728. duration: 300,
  5729. curve: Curve.Smooth
  5730. }, () => {
  5731. this.translateY = 0;
  5732. })
  5733. }
  5734. })
  5735. )
  5736. }
  5737. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD; //一多界面适配
  5738. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  5739. HeightBreakpoint.HEIGHT_LG;
  5740. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  5741. @State topBarHeight: number = 50
  5742. @State barOpacity: number = 1
  5743. @State barBottomOpacity: number = 1
  5744. private hideDone: boolean = false;
  5745. @State currentYOffset: number = 0;
  5746. @State bottomBarHeight: number = 60;
  5747. private isHiding: boolean = false;
  5748. //是否是Pura X外屏,或者小屏幕
  5749. isPuraWP() {
  5750. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  5751. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  5752. }
  5753. //是否是Pura X外屏,或者小屏幕,手机横屏
  5754. /**
  5755. * 是否是Pura X外屏,或者小屏幕,手机横屏
  5756. * @returns
  5757. */
  5758. isCoverOpacity() {
  5759. if (this.isPuraWP()) {
  5760. return true
  5761. }
  5762. if (this.isPhoneLan()) {
  5763. return true
  5764. }
  5765. if (deviceInfo.marketName.includes('Pura X')
  5766. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  5767. return true
  5768. }
  5769. return false
  5770. }
  5771. //是不是手机横屏
  5772. isPhoneLan() {
  5773. // LogUtil.info('twocold this.currentHeightBreakpoint = '+this.currentHeightBreakpoint)
  5774. // LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
  5775. LogUtil.info('hicar isPhoneLan width= ' + this.windowWidth);
  5776. LogUtil.info('hicar isPhoneLan height= ' + this.windowHeight);
  5777. LogUtil.info(`twocold hicarWindow size: ${this.windowWidth}x${this.windowHeight}, this.isHiCarStatus: ${this.isHiCarStatus}`);
  5778. LogUtil.info(`twocold hicar Window size: ${this.windowWidth}x${this.windowHeight}, isHiCarSmall: ${this.isHiCarSmall()}`);
  5779. if (this.isHiCarKuanBianPing()) {
  5780. return true
  5781. }
  5782. if (this.isHiCar()) {
  5783. return false
  5784. }
  5785. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  5786. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_SM
  5787. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_MD&&this.isLandscape) { //如果是手机横屏,返回true
  5788. return true
  5789. }
  5790. return false
  5791. }
  5792. //是不是1920x720的hicar的屏幕分辨率
  5793. isHiCarKuanBianPing(){
  5794. if(!this.isHiCar()){
  5795. return false
  5796. }
  5797. const hiCarAspectRatios: HiCarAspectRatio[] = [
  5798. { ratio: 1920 / 720, name: "1920x720" },
  5799. ];
  5800. const currentRatio: number = this.windowWidth / this.windowHeight;
  5801. const RATIO_TOLERANCE: number = 0.18; // 宽高比容差
  5802. LogUtil.info('twocold isHiCarKuanBianPing currentRatio = ' + currentRatio)
  5803. for (const hiCarRatio of hiCarAspectRatios) {
  5804. LogUtil.info('twocold isHiCarKuanBianPing hiCarRatio= ' + hiCarRatio.ratio)
  5805. LogUtil.info('twocold isHiCarKuanBianPing Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  5806. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  5807. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  5808. return true;
  5809. }
  5810. }
  5811. return false;
  5812. }
  5813. //是不是hicar的屏幕分辨率
  5814. isHiCarSmall() {
  5815. if(!this.isHiCar()){
  5816. return false
  5817. }
  5818. if(this.windowWidth>1800&&this.windowHeight>=1200)//大屏幕可以Grid
  5819. return false
  5820. const hiCarAspectRatios: HiCarAspectRatio[] = [
  5821. { ratio: 800 / 480, name: "800x480" },
  5822. { ratio: 1280 / 720, name: "1280x720" },
  5823. ];
  5824. const currentRatio: number = this.windowWidth / this.windowHeight;
  5825. const RATIO_TOLERANCE: number = 0.18; // 宽高比容差
  5826. LogUtil.info('twocold isHiCarSmall currentRatio = ' + currentRatio)
  5827. for (const hiCarRatio of hiCarAspectRatios) {
  5828. LogUtil.info('twocold isHiCarSmall hiCarRatio= ' + hiCarRatio.ratio)
  5829. LogUtil.info('twocold isHiCarSmall Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  5830. LogUtil.info('twocold isHiCarSmall isHiCarStatus= ' + this.isHiCarStatus);
  5831. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  5832. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  5833. return true;
  5834. }
  5835. }
  5836. return false;
  5837. }
  5838. isHiCar() {
  5839. return this.isHiCarStatus&&this.curDisplayIsHiCar;
  5840. }
  5841. //是不是正常的手机竖屏
  5842. isPhonePortrait() {
  5843. // LogUtil.info('twocold this.currentHeightBreakpoint = ' + this.currentHeightBreakpoint)
  5844. // LogUtil.info('twocold this.currentWidthBreakpoint = ' + this.currentWidthBreakpoint)
  5845. // LogUtil.info('Heanup 当前设备类型:' + DeviceUtil.getDeviceType())
  5846. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  5847. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG
  5848. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_SM) { //如果是手机横屏,返回false
  5849. return true
  5850. }
  5851. return false
  5852. }
  5853. @State showSpeedDialog: boolean = false
  5854. @State longPressSpeed: number = 3 //长按默认倍数
  5855. @Builder
  5856. SpeedDialog() {
  5857. Stack() {
  5858. Column() {
  5859. Text('已切换至' + this.longPressSpeed + '倍速播放')
  5860. .fontColor(Color.White)
  5861. .visibility(Visibility.Hidden)
  5862. }
  5863. .backgroundColor(Color.Black)
  5864. .borderRadius(20)
  5865. .padding({
  5866. top: 10,
  5867. right: 20,
  5868. left: 15,
  5869. bottom: 20
  5870. })
  5871. .opacity(0.6)
  5872. Text('已切换至' + this.longPressSpeed + '倍速播放')
  5873. .fontColor(Color.White)
  5874. }
  5875. .transition(TransitionEffect.OPACITY.animation({ duration: 500, curve: Curve.Ease }))
  5876. .zIndex(5)
  5877. .margin({ top: 80 })
  5878. }
  5879. @Builder
  5880. IjkMusicPlayerView() {
  5881. Column() {
  5882. Column() {
  5883. Column() {
  5884. //播放标题
  5885. Column() {
  5886. this.PlayTitle()
  5887. }
  5888. .position({ x: 0, y: this.isCoverOpacity() ? 15 : 40 })
  5889. .width('100%')
  5890. .margin({ top: 0 })
  5891. .height(PlayConstants.HEIGHT)
  5892. .visibility(DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1 ?
  5893. Visibility.Visible : this.isShowPlayPageBack ? Visibility.Visible : Visibility.None)
  5894. if (this.showSpeedDialog) {
  5895. this.SpeedDialog()
  5896. }
  5897. Stack() {
  5898. //手势拖动快进
  5899. Column()
  5900. .width(CommonConstants.FULL_PERCENT)
  5901. .height('100%')
  5902. .gesture(
  5903. GestureGroup(GestureMode.Parallel,
  5904. // 长按屏幕倍数播放
  5905. LongPressGesture({ repeat: true })
  5906. .onAction(() => {
  5907. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  5908. this.showSpeedDialog = true;
  5909. this.mIjkMediaPlayer.setSpeed(this.longPressSpeed + 'f');
  5910. }
  5911. })
  5912. .onActionEnd(() => {
  5913. this.showSpeedDialog = false;
  5914. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  5915. }),
  5916. //双击屏幕暂停或者播放
  5917. TapGesture({ count: 2 })
  5918. .onAction((event: GestureEvent) => {
  5919. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  5920. ToastUtil.showToast('已暂停')
  5921. }
  5922. this.playOrPause()
  5923. })
  5924. )
  5925. )
  5926. }
  5927. .height('65%')
  5928. Swiper() {
  5929. this.CoverInfo()
  5930. this.PlayerLyrics()
  5931. }
  5932. .onChange((index: number) => {
  5933. this.currentSwiperIndex = index
  5934. })
  5935. .indicator(false)
  5936. // .indicator(this.currentBreakpoint === BreakpointTypeEnum.SM ?
  5937. // new DotIndicator()
  5938. // .top(this.isCoverOpacity()?0:10)
  5939. //
  5940. // .selectedColor($r('app.color.select_swiper'))
  5941. // .color($r('app.color.slider_track')):false
  5942. // )
  5943. .displayCount(new BreakpointType({
  5944. sm: 1,
  5945. md: 2,
  5946. lg: 2,
  5947. xl: 2,
  5948. xxl: 2
  5949. }).getValue(this.currentBreakpoint))
  5950. .clip(false)
  5951. .loop(false)
  5952. .autoPlay(false)
  5953. // .interval(8000)
  5954. .position({ x: 0, y: this.isCoverOpacity() ? 30 : 40 })
  5955. .height('100%')
  5956. .hitTestBehavior(HitTestMode.Transparent)
  5957. Image($r('app.media.icon_replay'))
  5958. .objectFit(ImageFit.Auto)
  5959. .width('120px')
  5960. .height('120px')
  5961. .position({ x: '45.1%', y: '47.5%' })// .visibility(this.replayVisible)
  5962. .border({ width: 0 })
  5963. .visibility(Visibility.None)
  5964. .borderStyle(BorderStyle.Dashed)// .hitTestBehavior(HitTestMode.Transparent)
  5965. .onClick(() => {
  5966. this.startPlayOrResumePlay();
  5967. })
  5968. }
  5969. .width(CommonConstants.FULL_PERCENT)
  5970. .height(CommonConstants.FULL_PERCENT)
  5971. .justifyContent(FlexAlign.End)
  5972. }
  5973. .justifyContent(FlexAlign.End)
  5974. .margin({ bottom: 8 })
  5975. }
  5976. // .backgroundImage(this.imageLabelBg)
  5977. .backgroundImage(this.isPuraWP() && this.currentSwiperIndex === 0 ?
  5978. (StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover) : this.imageLabelBg)
  5979. .backgroundImageSize(this.isPuraWP() ? { width: '100%' } : { height: '150%', width: '100%' })
  5980. // .backgroundImagePosition(Alignment.Center)
  5981. .animation({
  5982. duration: 666,
  5983. curve: 'ease-in-out' // 可选动画曲线
  5984. })
  5985. .backgroundBlurStyle(this.isPuraWP() && this.currentSwiperIndex === 0 ? BlurStyle.NONE :
  5986. BlurStyle.BACKGROUND_ULTRA_THICK)
  5987. .hitTestBehavior(HitTestMode.Transparent)
  5988. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  5989. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  5990. .backgroundBrightness({ rate: this.isPuraWP() ? 0.1 : 0, lightUpDegree: -0.1 })
  5991. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
  5992. .onClick(() => {
  5993. // this.startAutoHide()
  5994. if(this.isHiCar())
  5995. return
  5996. if(this.is_auto_hide_progress){
  5997. this.is_auto_hide_progress = false
  5998. }
  5999. this.startAutoHide()
  6000. })
  6001. }
  6002. @State progressValue: number = 0;
  6003. @State currentTime: string = "00:00";
  6004. @State totalTime: string = "00:00";
  6005. @State loadingVisible: Visibility = Visibility.None;
  6006. @State replayVisible: Visibility = Visibility.None;
  6007. @State slideEnable: boolean = false;
  6008. @State aspRatio: number = 0.5;
  6009. @State mContext: object | undefined = undefined;
  6010. // private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
  6011. @State mFirst: boolean = true;
  6012. @State mDestroyPage: boolean = false;
  6013. @State playSpeed: number = 1;
  6014. @State oldSeconds: number = 0;
  6015. @State isSeekTo: boolean = false;
  6016. @State isCurrentTime: boolean = false;
  6017. @State videoWidth: string = '100%';
  6018. @State videoHeight: string = '100%';
  6019. @State initAspectRatio: number = 1;
  6020. @State videoAspectRatio: number = this.initAspectRatio;
  6021. private videoUrl: string = '';
  6022. private last: number = 0;
  6023. @State videoParentAspectRatio: number = this.initAspectRatio;
  6024. private mIjkMediaPlayer = IjkMediaPlayer.getInstance();
  6025. @State CONTROL_PlayStatus: number = PlayStatus.INIT;
  6026. @State PROGRESS_MAX_VALUE: number = 100;
  6027. @State updateProgressTimer: number = 0;
  6028. @State isHide: boolean = false; //是否因此播放器的按钮,默认是进入横屏模式隐藏,点击视频的时候显示
  6029. @State name: string = '';
  6030. // @State loop: boolean = false;
  6031. @State playType: number = 0; //0:连续播放 1:单片重复播放 2:正常播放 3:随机播放
  6032. @State multiple: string = '1.0X';
  6033. xcomponentController: XComponentController = new XComponentController()
  6034. private panOptionBright: PanGestureOptions =
  6035. new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down });
  6036. private panOptionVolume: PanGestureOptions =
  6037. new PanGestureOptions({ direction: PanDirection.Vertical | PanDirection.Up | PanDirection.Down });
  6038. private panOptionSeekTo: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Horizontal });
  6039. //手势的音量控制和亮度控制
  6040. private positionX: number = PlayConstants.POSITION_X;
  6041. private positionY: number = PlayConstants.POSITION_Y;
  6042. private windowClass: window.Window = globalThis.windowClass
  6043. @State volume: number = 0.3;
  6044. @State volumeShow: boolean = PlayConstants.VOLUME_SHOW;
  6045. @State bright: number = PlayConstants.BRIGHT;
  6046. @State brightShow: boolean = PlayConstants.BRIGHT_SHOW;
  6047. @State seekToShow: boolean = PlayConstants.BRIGHT_SHOW;
  6048. @State screenWidth: number = 0
  6049. @State screenHeight: number = 0
  6050. @State statusBarHeight: number = 0
  6051. @State isYesFull: boolean = false
  6052. private seekValue: number = 0
  6053. @State isVideoLock: boolean = false; // Whether the video playback is locked
  6054. eventHub = getContext().eventHub;
  6055. //投播组件
  6056. private avSessionController: AvSessionController = AvSessionController.getInstance(false);
  6057. private castController: avSession.AVCastController | undefined = undefined;
  6058. @State isCastPlaying: boolean = false;
  6059. @State currentTime2: number = 0;
  6060. @State currentStringTime: string = '00:00';
  6061. @State duration: number = 0;
  6062. @State isReady: boolean = false;
  6063. @State durationTime: number = 0;
  6064. @State durationStringTime: string = '00:00';
  6065. @StorageLink('isPlaying') @Watch('animationRoFun') isPlaying: boolean = false;
  6066. // @State isPlaying: boolean = false;
  6067. private castSeek: boolean = false;
  6068. private castItem: avSession.AVQueueItem | undefined = undefined;
  6069. // @State isBgPlayOpen:boolean = true //是否启用后台播放
  6070. @State imageLabel: PixelMap | Resource = CommonConstants.musicBgList[0];
  6071. @State imageLabelBg: PixelMap | Resource = CommonConstants.musicBgList[0];
  6072. @State rotateAngle2: number = 0
  6073. @StorageLink('imageColor') imageColor: string = 'rgba(0, 0, 2, 1.00)';
  6074. @State cover: string | undefined = '';
  6075. @State artist: string | undefined = ''
  6076. // 1.初始化controller
  6077. private lyricController: LyricController = new LyricController()
  6078. private lyricControllerXF: LyricController = new LyricController() //悬浮歌词控制器
  6079. private lyricControllerSingle: LyricController = new LyricController() //播放页单行歌词控制器
  6080. private parser = new LyricParser()
  6081. @State randomColor: string = 'rgb(0,0,0)'
  6082. @State randomShakenX: number = 0
  6083. @State randomShakenY: number = 0
  6084. @State lyricTextSize: number = 24
  6085. @State lyricContent: string = ''
  6086. @State isDebug: boolean = false
  6087. @State isHightLightCenter: boolean = true
  6088. /**
  6089. * 初始化歌词加载与展示逻辑
  6090. * @param lyricPath 歌词文件路径(支持普通.lrc和加密.lrcc)
  6091. * @param isOnLineAndToast 是否弹出Toast提示(可选)获取在线歌词为true
  6092. * @param isApi2 是否使用API2获取歌词(可选)
  6093. *
  6094. * 主要流程:
  6095. * 1. 设置歌词显示样式(字号、颜色、行距、对齐、动画等)。
  6096. * 2. 优先尝试本地读取歌词文件(支持加密和普通两种后缀)。
  6097. * 3. 若本地无歌词且满足条件(调试模式或会员且安装时间超过2天),则联网获取歌词。
  6098. * 4. 获取到歌词后,解析并设置到lyricController,并保存到本地。
  6099. * 5. 本地有歌词时,读取文件内容(自动检测编码,支持解密),解析后设置到lyricController。
  6100. * 6. 解析失败或读取失败时,清空歌词显示。
  6101. *
  6102. * 注意事项:
  6103. * - 仅会员且安装时间超过2天才可联网获取歌词(调试模式isDebug=true时跳过限制)。
  6104. * - 支持加密歌词文件(.lrcc),自动检测并解密。
  6105. * - 歌词内容解析后通过lyricController驱动UI渲染。
  6106. */
  6107. async initLyric(lyricPath: string, isOnLineAndToast?: boolean, isApi2?: boolean) {
  6108. if (StrUtil.isEmpty(lyricPath)) {
  6109. return
  6110. }
  6111. this.initPipLyricSetting()
  6112. this.lyricControllerSingle
  6113. .setTextSize(15)
  6114. .setCacheSize(4)
  6115. .setTextColor("#FFFFFF")
  6116. .setHighlightColor("#FFFFFF")
  6117. .setHighlightScale(1.2)
  6118. .setEmptyHint("")
  6119. .setAlignMode('center')
  6120. .setAnimationDuration(500)
  6121. .setSingleLine(true)
  6122. this.lyricContent = ''
  6123. this.lyricController
  6124. .setTextSize(this.currentLyricSize)
  6125. .setCacheSize(4)
  6126. .setTextColor("#DDDDDD")
  6127. .setHighlightColor("#FFFFFF")
  6128. .setEmptyHint("")
  6129. .setAnimationDuration(1000)
  6130. this.currentLyricAlignMode = PreferencesUtil.getNumberSync('LyricAlignMode', 1)
  6131. this.blurDegree = PreferencesUtil.getNumberSync('setBlurDegree', 3)
  6132. this.setBlurDegree(this.blurDegree, false)
  6133. this.setLyricAlignMode(this.currentLyricAlignMode, false)
  6134. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSize', 18), false)
  6135. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSize', 1.23), false)
  6136. this.lyricController.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpace', 10))
  6137. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColor', '#FFFFFF'), false)
  6138. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColor', '#FFFFFF'), false)
  6139. this.isHightLightCenter = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, true)
  6140. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  6141. this.lyricTextWeight = PreferencesUtil.getNumberSync('lyricTextWeight', 400)
  6142. this.lyricController.setTextWeight(this.lyricTextWeight)
  6143. this.showSingleLyric = false
  6144. this.timeOffset = 0
  6145. this.lyricController.setLyric(null)
  6146. this.lyricControllerSingle.setLyric(null)
  6147. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc'
  6148. console.log("onecold lyricPath =" + lyricPath)
  6149. let neiqianLrc = ''
  6150. let lyContent = this.currentSong?.lyricContent
  6151. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  6152. neiqianLrc = lyContent
  6153. }
  6154. if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast) {
  6155. console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
  6156. //赋值给this.lyricContent,播控中心才可以显示歌词
  6157. this.lyricContent = neiqianLrc
  6158. // 将文件内容按行分割成字符串数组
  6159. let lines = neiqianLrc.split('\n').map(line => line.trim());
  6160. // 3.解析歌词
  6161. let lyric = this.parser.parse(lines);
  6162. // 4.设置歌词
  6163. this.lyricController.setLyric(lyric);
  6164. this.lyricControllerXF.setLyric(lyric)
  6165. this.lyricControllerSingle.setLyric(lyric)
  6166. return
  6167. }
  6168. if (isOnLineAndToast || ((!FileUtil.accessSync(lyricPath) && !FileUtil.accessSync(jiaMilyricPath))
  6169. && !Utility.isVideoByExtension(this.videoUrl))) {
  6170. if (this.currentSong !== undefined) {
  6171. // ToastUtil.showShort('正在为你搜索在线歌词!')
  6172. //判断是不是赞助会员,是会员的话才开启歌词功能
  6173. // if (!this.isDebug) {
  6174. // if (!Utility.isNoble()) {
  6175. // LogUtil.debug("onecold 不是赞助会员")
  6176. // return
  6177. // }
  6178. // if(!Utility.isPassInstallTime(33)){
  6179. // LogUtil.debug("onecold not pass time")
  6180. // // LogUtil.debug("onecold 用户安装app没超过12天" )
  6181. // return
  6182. // }
  6183. // }
  6184. let artist = this.currentSong?.artist
  6185. if (artist === undefined) {
  6186. artist = ''
  6187. }
  6188. if (isApi2 === undefined) {
  6189. isApi2 = false
  6190. }
  6191. NetAxiosUtil.getLyric(this.name, artist, isApi2).then((res) => {
  6192. // LogUtil.debug("onecold res =" + res)
  6193. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  6194. if (StrUtil.isNotEmpty(res)) {
  6195. this.lyricContent = res
  6196. let lines = res.split('\n').map(line => line.trim());
  6197. // 3.解析歌词
  6198. let lyric = this.parser.parse(lines);
  6199. // 4.设置歌词
  6200. this.lyricController.setLyric(lyric);
  6201. this.lyricControllerXF.setLyric(lyric)
  6202. this.lyricControllerSingle.setLyric(lyric)
  6203. this.showSingleLyric = true
  6204. // 4.保存歌词文件lyric到本地
  6205. this.saveDataToFile(res, jiaMilyricPath, true)
  6206. } else {
  6207. this.lyricController.setLyric(null)
  6208. this.lyricControllerXF.setLyric(null)
  6209. this.lyricControllerSingle.setLyric(null)
  6210. if (isOnLineAndToast) {
  6211. ToastUtil.showShort('未获取到歌词!')
  6212. }
  6213. }
  6214. } else {
  6215. this.lyricController.setLyric(null)
  6216. this.lyricControllerXF.setLyric(null)
  6217. this.lyricControllerSingle.setLyric(null)
  6218. if (isOnLineAndToast) {
  6219. ToastUtil.showShort('未获取到歌词!')
  6220. }
  6221. }
  6222. })
  6223. } else {
  6224. this.lyricController.setLyric(null)
  6225. this.lyricControllerXF.setLyric(null)
  6226. this.lyricControllerSingle.setLyric(null)
  6227. if (isOnLineAndToast) {
  6228. ToastUtil.showShort('未获取到歌词!')
  6229. }
  6230. }
  6231. return
  6232. }
  6233. try {
  6234. let isJiaMi = false;
  6235. let realLyricPath = lyricPath
  6236. if (FileUtil.accessSync(jiaMilyricPath)) {
  6237. isJiaMi = true
  6238. realLyricPath = jiaMilyricPath
  6239. console.info("onecold 找到加密本地歌词 ");
  6240. } else {
  6241. isJiaMi = false
  6242. realLyricPath = lyricPath
  6243. console.info("onecold 找到本地歌词 ");
  6244. }
  6245. // 3.读取文件内容并指定编码为 UTF-8
  6246. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  6247. const stat = await fileIo.stat(file.fd);
  6248. const arrayBuffer = new ArrayBuffer(stat.size);
  6249. fs.read(file.fd, arrayBuffer)
  6250. .then((readLen: number) => {
  6251. console.info("read file data succeed");
  6252. // let buf = buffer.from(arrayBuffer, 0, readLen);
  6253. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  6254. // 检查 buf 是否为空
  6255. if (buf.length === 0) {
  6256. throw new Error("Buffer is empty after reading the file");
  6257. }
  6258. try {
  6259. // 检测文件编码
  6260. // let detectedEncoding = chardet.detect(buf);
  6261. // console.info("onecoldT Detected encoding: " + detectedEncoding);
  6262. let detectedEncoding = this.detect(arrayBuffer)
  6263. console.info("onecoldT Detected encoding: " + detectedEncoding);
  6264. // 使用检测到的编码解码,解决中文乱码问题
  6265. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  6266. console.info("onecoldT Detected textDecoder: " + textDecoder);
  6267. let fileContent = textDecoder.decode(buf);
  6268. console.info(`onecoldT The content of file1: ${fileContent}`);
  6269. //解密
  6270. if (isJiaMi) {
  6271. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent))
  6272. }
  6273. console.info(`onecold The content of file2: ${fileContent}`);
  6274. this.lyricContent = fileContent
  6275. // 将文件内容按行分割成字符串数组
  6276. let lines = fileContent.split('\n').map(line => line.trim());
  6277. console.info(`onecold The content of file: ${fileContent}`);
  6278. // 3.解析歌词
  6279. let lyric = this.parser.parse(lines);
  6280. // 4.设置歌词
  6281. this.lyricController.setLyric(lyric);
  6282. this.lyricControllerXF.setLyric(lyric)
  6283. this.lyricControllerSingle.setLyric(lyric)
  6284. this.showSingleLyric = true
  6285. console.info(`The content of file: ${fileContent}`);
  6286. } catch (chardetError) {
  6287. console.error("chardet.detect failed with error: " + chardetError.message);
  6288. this.lyricController.setLyric(null);
  6289. this.lyricControllerXF.setLyric(null)
  6290. this.lyricControllerSingle.setLyric(null)
  6291. }
  6292. })
  6293. .catch((err: BusinessError) => {
  6294. this.lyricController.setLyric(null)
  6295. this.lyricControllerXF.setLyric(null)
  6296. this.lyricControllerSingle.setLyric(null)
  6297. console.error("read file data failed with error message: " + err.message + ", error code: " + err.code);
  6298. })
  6299. .catch((err: Error) => {
  6300. this.lyricController.setLyric(null)
  6301. this.lyricControllerXF.setLyric(null)
  6302. this.lyricControllerSingle.setLyric(null)
  6303. console.error("read file 2 data failed with error message: " + err.message);
  6304. })
  6305. .finally(() => {
  6306. fs.closeSync(file);
  6307. });
  6308. } catch (error) {
  6309. this.lyricController.setLyric(null)
  6310. this.lyricControllerSingle.setLyric(null)
  6311. this.lyricControllerXF.setLyric(null)
  6312. Logger.error(TAG, 'init Lyric failed with err: ' + JSON.stringify(error));
  6313. }
  6314. }
  6315. detect(data: ArrayBuffer): string {
  6316. //创建检测对象
  6317. let detector: UniversalDetector = new UniversalDetector();
  6318. // 传入检测数据并实时判断编码格式
  6319. detector.handleData(data, 0, data.byteLength);
  6320. // 标记检测数据 读取结束
  6321. detector.dataEnd();
  6322. // 获取检测结果
  6323. let detected: string = detector.getDetectedCharset();
  6324. // 释放资源
  6325. detector.reset();
  6326. return detected;
  6327. }
  6328. //初始化悬浮歌词的自定义设置
  6329. initPipLyricSetting() {
  6330. this.lyricControllerXF
  6331. .setTextSize(this.currentLyricSize)
  6332. .setCacheSize(4)
  6333. .setTextColor("#DDDDDD")
  6334. .setHighlightColor("#FFFFFF")// .setLineSpace(18)
  6335. .setEmptyHint("")
  6336. .setAnimationDuration(1000)
  6337. this.currentLyricAlignModePip = PreferencesUtil.getNumberSync('LyricAlignModePip', 0)
  6338. this.blurDegreePip = PreferencesUtil.getNumberSync('setBlurDegreePip', 3)
  6339. this.setBlurDegree(this.blurDegreePip, true)
  6340. this.setLyricAlignMode(this.currentLyricAlignModePip, true)
  6341. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSizePip', 18), true)
  6342. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSizePip', 1.23), true)
  6343. this.lyricControllerXF.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpacePip', 10))
  6344. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColorPip', '#FFFFFF'), true)
  6345. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColorPip', '#FFFFFF'), true)
  6346. this.lyricControllerXF.setHightLightCenter(true)
  6347. this.lyricTextWeightPip = PreferencesUtil.getNumberSync('lyricTextWeightPip', 400)
  6348. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  6349. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  6350. this.pipBgIndex = PreferencesUtil.getNumberSync('pipBgIndex', 0)
  6351. if (this.pipBgIndex === 0) {
  6352. if (this.cover) {
  6353. this.pipBg = this.cover
  6354. } else {
  6355. this.pipBg = this.imageColor
  6356. }
  6357. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  6358. }
  6359. }
  6360. //根据item返回歌词内容
  6361. async getLyricContent(item: VideoItem): Promise<string> {
  6362. let neiqianLrc = ''
  6363. let lyContent = item?.lyricContent
  6364. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  6365. neiqianLrc = lyContent
  6366. return neiqianLrc
  6367. }
  6368. try {
  6369. let filePath = item.filePath;
  6370. let lyricPath = filePath.substring(0, filePath.lastIndexOf('.')) + '.lrc';
  6371. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc';
  6372. let isJiaMi = false;
  6373. let realLyricPath = lyricPath;
  6374. if (FileUtil.accessSync(jiaMilyricPath)) {
  6375. isJiaMi = true;
  6376. realLyricPath = jiaMilyricPath;
  6377. console.info("onecold 找到加密本地歌词");
  6378. } else {
  6379. console.info("onecold 找到本地歌词");
  6380. }
  6381. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  6382. const stat = await fileIo.stat(file.fd);
  6383. const arrayBuffer = new ArrayBuffer(stat.size);
  6384. const readLen = await fs.read(file.fd, arrayBuffer);
  6385. console.info("read file data succeed");
  6386. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  6387. if (buf.length === 0) {
  6388. throw new Error("Buffer is empty after reading the file");
  6389. }
  6390. // let detectedEncoding = chardet.detect(buf);
  6391. let detectedEncoding = this.detect(arrayBuffer)
  6392. console.info("Detected encoding: " + detectedEncoding);
  6393. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  6394. let fileContent = textDecoder.decode(buf);
  6395. console.info(`onecold The content of file1: ${fileContent}`);
  6396. if (isJiaMi) {
  6397. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent));
  6398. }
  6399. console.info(`onecold The content of file2: ${fileContent}`);
  6400. fs.closeSync(file);
  6401. return fileContent;
  6402. } catch (error) {
  6403. console.error('init Lyric failed with err: ' + JSON.stringify(error));
  6404. return '';
  6405. }
  6406. }
  6407. async saveDataToFile(content: string, filePath: string, isJiaMi?: boolean) {
  6408. if (StrUtil.isEmpty(filePath)) {
  6409. return
  6410. }
  6411. try {
  6412. //将content进行加密
  6413. // let jiaMilyricPath = filePath.substring(0,filePath.lastIndexOf('.'))+'.lrcc'
  6414. let lyricContent = ''
  6415. if (isJiaMi) {
  6416. lyricContent = Base64Util.encodeToStrSync(StrUtil.strToUint8Array(content))
  6417. } else {
  6418. lyricContent = content
  6419. }
  6420. const file = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  6421. // 清空文件内容
  6422. await fileIo.truncate(file.fd, 0);
  6423. await fileIo.write(file.fd, lyricContent);
  6424. await fileIo.close(file);
  6425. console.log('onecold lyric file Data saved successfully.');
  6426. } catch (error) {
  6427. console.error('onecold lyric file Failed to save data:', error);
  6428. }
  6429. }
  6430. /**
  6431. * Get largest proportion color of an image.
  6432. */
  6433. getImageColor() {
  6434. if (!this.context) {
  6435. return;
  6436. }
  6437. let bg = Utility.getMusisBg()
  6438. this.imageLabel = bg
  6439. ColorConversion.setSysBarLightBackground(true);
  6440. this.context.resourceManager.getMediaContent(bg)
  6441. .then((value: Uint8Array) => {
  6442. let buffer = value.buffer as ArrayBuffer;
  6443. image.createImageSource(buffer).createPixelMap().then((pixelMap) => {
  6444. effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
  6445. if (error) {
  6446. Logger.error('Failed to create color picker.');
  6447. } else {
  6448. let color = colorPicker.getLargestProportionColor();
  6449. let colorArr = ColorConversion.dealColor(color.red, color.green, color.blue);
  6450. this.imageColor = `rgba(${colorArr[0]}, ${colorArr[1]}, ${colorArr[2]}, 1)`;
  6451. }
  6452. })
  6453. let headFilter = effectKit.createEffect(pixelMap);
  6454. if (headFilter !== null) {
  6455. headFilter.blur(15);
  6456. headFilter.getEffectPixelMap().then((value) => {
  6457. this.imageLabelBg = value;
  6458. })
  6459. }
  6460. })
  6461. .catch((error: BusinessError) => {
  6462. Logger.error(`${error.code} + ${error.message}`)
  6463. })
  6464. })
  6465. .catch((error: BusinessError) => {
  6466. Logger.error(`${error.code} + ${error.message}`)
  6467. })
  6468. }
  6469. setImageColor(cover: string) {
  6470. if (!this.context) {
  6471. return;
  6472. }
  6473. if (cover === undefined) {
  6474. return;
  6475. }
  6476. ImageUtil.imagePathToPixelMap(cover).then((value) => {
  6477. let headFilter = effectKit.createEffect(value);
  6478. if (headFilter !== null) {
  6479. headFilter.blur(15);
  6480. headFilter.getEffectPixelMap().then((value) => {
  6481. this.imageLabelBg = value;
  6482. })
  6483. }
  6484. }).catch((error: BusinessError) => {
  6485. Logger.error(`${error.code} + ${error.message}`)
  6486. })
  6487. }
  6488. setImageColor2(cover: string) {
  6489. if (!this.context) {
  6490. return;
  6491. }
  6492. if (cover === undefined) {
  6493. return;
  6494. }
  6495. LogUtils.getInstance().LOGI("setImageColor2--> cover ==" + cover);
  6496. ImageUtils.getImageDealData(getContext(this), cover, this.videoUrl).then((data) => {
  6497. this.imageColor = data.imageColor;
  6498. if (data.blurPixelMap) {
  6499. this.imageLabelBg = data.blurPixelMap;
  6500. }
  6501. })
  6502. }
  6503. // 定义开始旋转的方法
  6504. // 定时器用于一百毫秒执行一次旋转角度
  6505. @State timer: number = 0
  6506. @State rotateAngle: number = 0
  6507. //封面旋转动画
  6508. animationRoFun() {
  6509. if (this.isPlaying && !this.isCoverRectangle) {
  6510. this.timer = setInterval(() => {
  6511. this.rotateAngle += 1
  6512. }, 100)
  6513. this.startRotation()
  6514. } else {
  6515. clearInterval(this.timer)
  6516. this.stopRotation()
  6517. }
  6518. }
  6519. // 定义开始旋转的方法
  6520. startRotation() {
  6521. if (this.isPlaying) {
  6522. animateTo({
  6523. duration: 777,
  6524. iterations: 1,
  6525. curve: Curve.Linear
  6526. }, () => {
  6527. this.rotateAngle2 = 0
  6528. })
  6529. }
  6530. }
  6531. // 回调,暂停和播放按钮回调,下一首和上一首
  6532. playChange() {
  6533. // if(this.isCoverRectangle){
  6534. // return
  6535. // }
  6536. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6537. this.setIsPlaying(true)
  6538. this.animationState = AnimationStatus.Running
  6539. } else {
  6540. this.setIsPlaying(false)
  6541. this.animationState = AnimationStatus.Paused
  6542. }
  6543. }
  6544. // 定义停止旋转的方法
  6545. stopRotation() {
  6546. if (this.isCoverRectangle) {
  6547. this.rotateAngle = 0
  6548. } else {
  6549. //唱针以左上角为点选择逆时针40度
  6550. animateTo({
  6551. duration: 1000,
  6552. curve: Curve.Linear,
  6553. iterations: 1,
  6554. }, () => {
  6555. this.rotateAngle2 = -40;
  6556. });
  6557. }
  6558. }
  6559. @Builder
  6560. private LyricsTopItem() {
  6561. Row() {
  6562. Stack() {
  6563. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  6564. .height(55)
  6565. .width(55)
  6566. .alt(this.imageLabel)
  6567. .borderRadius(8)
  6568. .clickEffect({ level: ClickEffectLevel.HEAVY })
  6569. .margin({ left: this.currentLyricAlignMode === 0 ? 28 : -15 })
  6570. }
  6571. .width('18%')
  6572. Column() {
  6573. Column() {
  6574. Text(this.name)
  6575. .fontSize(16)
  6576. .maxLines(1)
  6577. .fontWeight(FontWeight.Bolder)
  6578. .fontColor(this.currentLyricColor)
  6579. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  6580. Row() {
  6581. Text(this.currentSong?.artist !== undefined ? this.currentSong?.artist : '')
  6582. .fontSize(13)
  6583. .fontWeight(FontWeight.Bold)
  6584. .padding({ top: 8 })
  6585. .fontColor(this.currentLyricColor)
  6586. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  6587. Blank()
  6588. }
  6589. }
  6590. .height('100%')
  6591. .width('100%')
  6592. .justifyContent(FlexAlign.Center)
  6593. .alignItems(HorizontalAlign.Start)
  6594. }
  6595. .height('100%')
  6596. .width('65%')
  6597. Column() {
  6598. Image($r('app.media.lyric'))
  6599. .width(28)
  6600. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6601. .margin({ right: 30 })
  6602. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6603. .onClick(() => {
  6604. this.isLyricSetting = !this.isLyricSetting;
  6605. })
  6606. .bindSheet($$this.isLyricSetting, this.lyricSettingSheet(false), {
  6607. height: this.isCoverOpacity() ? '95%' : '88%',
  6608. dragBar: true,
  6609. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  6610. showClose: true,
  6611. blurStyle: BlurStyle.Thin,
  6612. backgroundColor: Color.Transparent,
  6613. // title: { title: $r('app.string.lyric_setting') }
  6614. })
  6615. }
  6616. .width('18%')
  6617. }
  6618. .width('82%')
  6619. .height(58)
  6620. .justifyContent(FlexAlign.SpaceBetween)
  6621. }
  6622. //歌词显示
  6623. @Builder
  6624. PlayerLyrics() {
  6625. Column() {
  6626. Column() {
  6627. this.LyricsTopItem()
  6628. }
  6629. .height(this.isPuraWP() ? 15 : 58)
  6630. .visibility(this.currentBreakpoint !== BreakpointTypeEnum.SM ?
  6631. Visibility.None : Visibility.Visible)
  6632. .margin({ left: 6, top: this.isPuraWP() ? 5 : 38 })
  6633. .width("100%")
  6634. Column() {
  6635. LyricView2({
  6636. controller: this.lyricController,
  6637. enableSeek: true,
  6638. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  6639. seekLineColor: "#80ffffff", // 滑动定位线颜色
  6640. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  6641. onSeekAction: (position: number) => { // 滑动歌词触发seek定位回调
  6642. if (!this.isPlaying) {
  6643. this.startPlayOrResumePlay()
  6644. } else {
  6645. this.isSeekTo = true;
  6646. this.mDestroyPage = false;
  6647. this.showLoadIng();
  6648. this.seekTo(position + "");
  6649. this.isSeekTo = false;
  6650. }
  6651. return true
  6652. }
  6653. })
  6654. .width("100%")
  6655. .layoutWeight(1)
  6656. .margin({ left: this.currentLyricAlignMode === 0 ? 0 : 50, top: 2, bottom: this.isPhoneLan()||this.isHiCarKuanBianPing() ? 40 : 10 })
  6657. if (this.isPhoneLan()) {
  6658. Column() {
  6659. this.playProgressView()
  6660. // this.playCenterView()
  6661. }
  6662. .margin({ bottom: 30, right: this.currentLyricAlignMode == 0 ? 0 : 30 })
  6663. }
  6664. }
  6665. .position({
  6666. top: this.currentBreakpoint !== BreakpointTypeEnum.SM ? (this.isPhoneLan() ? 0 : 45) :
  6667. (this.isPuraWP() ? 58 : 99)
  6668. })
  6669. .justifyContent(FlexAlign.Center)
  6670. .height(this.isCoverOpacity() ? this.isPhoneLan()?'95%':'90%' : '82%')
  6671. }
  6672. }
  6673. @Builder
  6674. SingleLyricView() {
  6675. Column() {
  6676. Column() {
  6677. LyricView2({
  6678. controller: this.lyricControllerSingle,
  6679. enableSeek: false,
  6680. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  6681. seekLineColor: "#80ffffff", // 滑动定位线颜色
  6682. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  6683. })
  6684. }
  6685. .height(66)
  6686. .margin({ bottom: 20 })
  6687. }
  6688. }
  6689. //播放器的底部控制中心,上一首,暂停,下一首,播放进度条等
  6690. @Builder
  6691. BottomControl() {
  6692. Column() {
  6693. this.TopPlayProgressView()
  6694. //播放 暂停,下一首,上一首
  6695. this.playCenterView()
  6696. //播放进度条
  6697. this.BottomView()
  6698. }
  6699. .position({ bottom: this.isHiCarSmall()?50:(this.isCoverOpacity() ? 55 : 70) }) // 将 固定在底部
  6700. }
  6701. //播放控制上一首 下一首 暂停和播放
  6702. @Builder
  6703. playCenterView(){
  6704. Row() {
  6705. Row({ space: 20 }) {
  6706. Button({type:ButtonType.Circle,stateEffect:true}){
  6707. //更多功能
  6708. Image($r('app.media.menu'))
  6709. .width(24)
  6710. .clickEffect({level:ClickEffectLevel.MIDDLE})
  6711. .bindSheet($$this.isShowMoreView, this.PlayMoreSheet(), {
  6712. height: this.isCoverOpacity() ? '95%' : '93%',
  6713. preferType: this.currentBreakpoint!==BreakpointTypeEnum.SM?SheetType.CENTER:SheetType.BOTTOM,
  6714. dragBar: true,
  6715. showClose: true,
  6716. blurStyle: BlurStyle.Thin,
  6717. backgroundColor: Color.Transparent,
  6718. })
  6719. }
  6720. .margin({ left: 5 })
  6721. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6722. .backgroundColor(Color.Transparent)
  6723. .onClick(() => {
  6724. this.isShowMoreView = !this.isShowMoreView;
  6725. })
  6726. Button({type:ButtonType.Circle,stateEffect:true}){
  6727. Image($r('app.media.ic_previous'))
  6728. .width(33)
  6729. .clickEffect({level:ClickEffectLevel.HEAVY})
  6730. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6731. }
  6732. .onClick(async () => {
  6733. this.playPrevious()
  6734. })
  6735. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6736. .backgroundColor(Color.Transparent)
  6737. .margin({ left: 5 })
  6738. }
  6739. Button({type:ButtonType.Circle,stateEffect:true}){
  6740. Column() {
  6741. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ?
  6742. (this.isCircleBtn?$r('app.media.hm_pause'):$r('app.media.ic_public_play'))
  6743. : (this.isCircleBtn?$r('app.media.hm_play2'):$r('app.media.ic_public_pause')))
  6744. .width(this.isPhoneLan()?45:55)
  6745. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6746. .fillColor(Color.White)
  6747. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6748. .onClick(async () => {
  6749. this.playOrPause()
  6750. })
  6751. }
  6752. }
  6753. .backgroundColor(Color.Transparent)
  6754. .layoutWeight(1)
  6755. // .margin({ left: 38, right: 38 })
  6756. Row({ space: 20 }) {
  6757. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  6758. Image($r('app.media.ic_next'))
  6759. .width(33)
  6760. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6761. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6762. .onClick(() => {
  6763. this.playNext();
  6764. })
  6765. }
  6766. .backgroundColor(Color.Transparent)
  6767. .margin({ right: 5 })
  6768. .width(33)
  6769. Button({type:ButtonType.Circle,stateEffect:true}){
  6770. //添加或取消收藏
  6771. Image(Utility.getIsFav(this.favList,this.currentSong)?
  6772. $r('app.media.add_fac_light'):$r('app.media.add_fac'))
  6773. .width(24)
  6774. .clickEffect({level:ClickEffectLevel.MIDDLE})
  6775. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6776. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6777. .onClick(async () => {
  6778. if(this.currentSong){
  6779. this.doFav(this.currentSong)
  6780. }
  6781. })
  6782. }
  6783. .backgroundColor(Color.Transparent)
  6784. .width(24)
  6785. }
  6786. // .margin({ left: 5 })
  6787. }
  6788. .width('95%')
  6789. .margin({ bottom:this.isCoverOpacity()?0:20 })
  6790. .justifyContent(FlexAlign.SpaceEvenly)
  6791. }
  6792. //播放进度条
  6793. @Builder
  6794. TopPlayProgressView(){
  6795. Row() {
  6796. Column(){
  6797. Row(){
  6798. Slider({
  6799. value: this.progressValue,
  6800. min: 0,
  6801. max: this.PROGRESS_MAX_VALUE,
  6802. step: 1,
  6803. style: SliderStyle.InSet
  6804. })
  6805. .blockColor('rgba(255,255,255,1)')
  6806. .trackColor('rgba(255,255,255,0.3)')
  6807. .selectedColor(Color.White)
  6808. .trackThickness(4)
  6809. .layoutWeight(1)
  6810. .showSteps(false)
  6811. .showTips(true)
  6812. .enabled(this.slideEnable)
  6813. .onChange((value: number, mode: SliderChangeMode) => {
  6814. // if (mode == 2) {
  6815. this.isSeekTo = true;
  6816. this.mDestroyPage = false;
  6817. this.showLoadIng();
  6818. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  6819. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  6820. this.seekTo(seekValue + "");
  6821. // this.setProgress()
  6822. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  6823. this.isSeekTo = false;
  6824. // }
  6825. })
  6826. }
  6827. .padding({ right: 7,left:14 })
  6828. Row(){
  6829. Text(this.currentTime)
  6830. .fontSize(10)
  6831. .fontColor(Color.White)
  6832. Blank()
  6833. .layoutWeight(1)
  6834. Text(this.totalTime)
  6835. .fontSize(10)
  6836. .fontColor(Color.White)
  6837. }
  6838. .justifyContent(FlexAlign.Start)
  6839. .padding({ right: 18,left:36 })
  6840. }
  6841. }
  6842. //x5的竖屏模式需要99%
  6843. .width(this.isLandscape?'80%':'93%')
  6844. .justifyContent(FlexAlign.Center)
  6845. .margin({bottom:5})
  6846. .animation({
  6847. duration: 666,
  6848. curve: 'ease-in-out' // 可选动画曲线
  6849. })
  6850. }
  6851. //播放进度条
  6852. @Builder
  6853. BottomView(){
  6854. Row() {
  6855. Button({type:ButtonType.Circle,stateEffect:true}){
  6856. Column() {
  6857. if (this.playType === 0) {
  6858. Image($r('app.media.loop'))
  6859. .width(27)
  6860. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6861. } else if (this.playType === 1) {
  6862. Image($r('app.media.single'))
  6863. .width(27)
  6864. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6865. } else if (this.playType === 2) {
  6866. Image($r('app.media.normal_play'))
  6867. .width(27)
  6868. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6869. } else if (this.playType === 3) {
  6870. Image($r('app.media.random'))
  6871. .width(27)
  6872. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6873. }
  6874. }
  6875. }
  6876. .layoutWeight(1)
  6877. .margin({ left: 5 })
  6878. .backgroundColor(Color.Transparent)
  6879. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6880. .onClick(async () => {
  6881. this.setLoopMode()
  6882. })
  6883. Button({type:ButtonType.Circle,stateEffect:true}){
  6884. Column() {
  6885. Image($r('app.media.full_4'))
  6886. .width(25)
  6887. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6888. }
  6889. }
  6890. .layoutWeight(1)
  6891. .backgroundColor(Color.Transparent)
  6892. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6893. .onClick(async () => {
  6894. if (this.isLandscape) {
  6895. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  6896. } else {
  6897. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  6898. }
  6899. })
  6900. Button({type:ButtonType.Circle,stateEffect:true}){
  6901. Column() {
  6902. Image($r('app.media.lyric'))
  6903. .width(26)
  6904. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6905. }
  6906. }
  6907. .layoutWeight(1)
  6908. .backgroundColor(Color.Transparent)
  6909. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6910. .onClick(async () => {
  6911. this.isLyricSetting = !this.isLyricSetting;
  6912. })
  6913. //播放列表
  6914. Button({type:ButtonType.Circle,stateEffect:true}){
  6915. Image($r('app.media.hm_playlist'))
  6916. .width(24)
  6917. .fillColor(Color.White)
  6918. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6919. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  6920. height: '95%',
  6921. dragBar: true,
  6922. showClose: true,
  6923. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  6924. blurStyle: BlurStyle.Thin,
  6925. backgroundColor: this.isPlayListBgGrass?Color.Transparent:$r('app.color.silvery'),
  6926. title: {
  6927. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  6928. + `(${this.songList.length}首)`
  6929. }
  6930. })
  6931. }
  6932. .layoutWeight(1)
  6933. .backgroundColor(Color.Transparent)
  6934. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6935. .onClick(() => {
  6936. this.isShowSheetView = !this.isShowSheetView;
  6937. if(this.isPlayListBgGrass){
  6938. this.isFrontWhite = true
  6939. }else{
  6940. this.isFrontWhite = false
  6941. }
  6942. setTimeout(() => {
  6943. this.playListScroller.scrollToIndex(this.curIndex,true, ScrollAlign.CENTER)
  6944. }, 123)
  6945. })
  6946. }
  6947. .width(this.isLandscape?'88%':'95%')
  6948. .justifyContent(FlexAlign.SpaceAround)
  6949. .height(30)
  6950. .margin({top:3})
  6951. .animation({
  6952. duration: 666,
  6953. curve: 'ease-in-out' // 可选动画曲线
  6954. })
  6955. }
  6956. //旧版本播放进度条
  6957. @Builder
  6958. playProgressView() {
  6959. Row() {
  6960. Button({ type: ButtonType.Circle, stateEffect: true }) {
  6961. Column() {
  6962. if (this.playType === 0) {
  6963. Image($r('app.media.loop'))
  6964. .width($r('app.float.control_image_width'))
  6965. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6966. } else if (this.playType === 1) {
  6967. Image($r('app.media.single'))
  6968. .width($r('app.float.control_image_width'))
  6969. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6970. } else if (this.playType === 2) {
  6971. Image($r('app.media.normal_play'))
  6972. .width($r('app.float.control_image_width'))
  6973. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6974. } else if (this.playType === 3) {
  6975. Image($r('app.media.random'))
  6976. .width($r('app.float.control_image_width'))
  6977. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6978. }
  6979. }
  6980. }
  6981. .visibility(this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  6982. .animation({
  6983. duration: 666,
  6984. curve: 'ease-in-out' // 可选动画曲线
  6985. })
  6986. .backgroundColor(Color.Transparent)
  6987. .margin({ right: 10 })
  6988. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6989. .onClick(async () => {
  6990. this.setLoopMode()
  6991. })
  6992. Text(this.currentTime)
  6993. .fontSize($r('app.float.slider_font_size'))
  6994. .fontColor(Color.White)
  6995. .margin(3)
  6996. Slider({
  6997. value: this.progressValue,
  6998. min: 0,
  6999. max: this.PROGRESS_MAX_VALUE,
  7000. step: 1,
  7001. style: SliderStyle.OutSet
  7002. })
  7003. .width('600px')
  7004. .blockColor('rgba(255,255,255,1)')
  7005. .trackColor('rgba(255,255,255,0.3)')
  7006. .selectedColor(Color.White)
  7007. .trackThickness(PlayConstants.PROGRESS_TRACK_THICKNESS)
  7008. .layoutWeight(1)
  7009. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  7010. .showSteps(false)
  7011. .showTips(true)
  7012. .enabled(this.slideEnable)
  7013. .onChange((value: number, mode: SliderChangeMode) => {
  7014. // if (mode == 2) {
  7015. this.isSeekTo = true;
  7016. this.mDestroyPage = false;
  7017. this.showLoadIng();
  7018. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  7019. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  7020. this.seekTo(seekValue + "");
  7021. // this.setProgress()
  7022. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  7023. this.isSeekTo = false;
  7024. // }
  7025. })
  7026. Text(this.totalTime)
  7027. .fontSize($r('app.float.slider_font_size'))
  7028. .fontColor(Color.White)
  7029. .margin(3)
  7030. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  7031. //播放列表
  7032. Button({ type: ButtonType.Circle, stateEffect: true }) {
  7033. Image($r('app.media.hm_playlist'))
  7034. .width($r('app.float.control_image_width'))
  7035. .fillColor(Color.White)
  7036. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7037. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  7038. height: '95%',
  7039. dragBar: true,
  7040. showClose: true,
  7041. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7042. blurStyle: BlurStyle.Thin,
  7043. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  7044. title: {
  7045. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  7046. + `(${this.songList.length}首)`
  7047. }
  7048. })
  7049. }
  7050. .visibility( this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  7051. .animation({
  7052. duration: 666,
  7053. curve: 'ease-in-out' // 可选动画曲线
  7054. })
  7055. .backgroundColor(Color.Transparent)
  7056. .margin({ right: 20, left: 10 })
  7057. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7058. .onClick(() => {
  7059. this.isShowSheetView = !this.isShowSheetView;
  7060. if (this.isPlayListBgGrass) {
  7061. this.isFrontWhite = true
  7062. } else {
  7063. this.isFrontWhite = false
  7064. }
  7065. setTimeout(() => {
  7066. this.playListScroller.scrollToIndex(this.curIndex, true, ScrollAlign.CENTER)
  7067. }, 123)
  7068. })
  7069. }
  7070. //x5的竖屏模式需要99%
  7071. .width(this.isPhonePortrait() ? '93.4%'
  7072. : this.currentHeightBreakpoint == 1 && this.currentWidthBreakpoint == 2 ? '99%' : '82%')
  7073. .height(this.isPhoneLan() ? 25 : 33)
  7074. .animation({
  7075. duration: 666,
  7076. curve: 'ease-in-out' // 可选动画曲线
  7077. })
  7078. }
  7079. isBigScreen() {
  7080. if (this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_LG) {
  7081. return true
  7082. }
  7083. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  7084. && this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  7085. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG) {
  7086. return false
  7087. } else {
  7088. return true
  7089. }
  7090. return false
  7091. }
  7092. @State is_auto_hide_progress: boolean = false //手机横屏自动隐藏播放进退条,点击屏幕可以显示,倒计时4秒后又自动隐藏
  7093. @State isCoverRectangle: boolean = false
  7094. @State isCoverTop: boolean = true
  7095. // 添加控制缩放的状态变量
  7096. @State scaleValueImage: number = 1
  7097. @Builder
  7098. CoverInfo() {
  7099. Column() {
  7100. //如果是方形,判断是不是封面在顶部,如果不是顶部,显示musicNameInfo, 如果是圆形显示musicNameInfo
  7101. if (this.isCoverRectangle) {
  7102. if (!this.isCoverTop) {
  7103. this.musicNameInfo(false)
  7104. }
  7105. } else {
  7106. this.musicNameInfo(false)
  7107. }
  7108. Stack() {
  7109. // 唱片旋转效果
  7110. Image($r('app.media.ic_music_disc'))
  7111. .width(245)
  7112. .height(245)
  7113. .margin({ right: 20, left: 20 })
  7114. .aspectRatio(1)
  7115. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  7116. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  7117. .borderRadius('100%')
  7118. .align(Alignment.Center)
  7119. .clip(true)// .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
  7120. .rotate({
  7121. angle: this.rotateAngle,
  7122. centerX: "50%",
  7123. centerY: "50%",
  7124. })
  7125. .animation({
  7126. duration: 100,
  7127. curve: Curve.Linear
  7128. })
  7129. .shadow({
  7130. radius: 30,
  7131. color: this.randomColor
  7132. })
  7133. Column() {
  7134. if (this.isCoverTop && !this.isCoverOpacity() && this.isCoverRectangle) {
  7135. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)// .height(this.isCoverOpacity() ? 250 : this.isCoverRectangle ? 320 : 162)
  7136. .width(this.isBigScreen() ? '72%' : this.isCoverTopBig ? '100%' : '86%')
  7137. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  7138. .alt(this.imageLabel)
  7139. .margin({ right: 8, left: 8, top: 8 })
  7140. .aspectRatio(1)
  7141. .opacity(this.opacityValueImage)
  7142. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7143. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  7144. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  7145. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  7146. .align(Alignment.Center)//
  7147. .clip(true)
  7148. .rotate({
  7149. x: 0,
  7150. y: 0,
  7151. z: 1,
  7152. angle: this.rotateAngle
  7153. })
  7154. .onClick(() => {
  7155. this.getImageColor()
  7156. })
  7157. this.musicNameInfo(false)
  7158. } else {
  7159. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  7160. .height(this.isHiCarSmall()?(this.isHiCarKuanBianPing()?140:px2vp(this.windowHeight)*0.38):(this.isCoverOpacity() ? 250 : this.isCoverRectangle ? 320 : 162))
  7161. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  7162. .alt(this.imageLabel)
  7163. .margin({ right: 20, left: 20 })
  7164. .aspectRatio(1)
  7165. .opacity(this.opacityValueImage)
  7166. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7167. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  7168. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  7169. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  7170. .align(Alignment.Center)//
  7171. .clip(true)
  7172. .rotate({
  7173. x: 0,
  7174. y: 0,
  7175. z: 1,
  7176. angle: this.rotateAngle
  7177. })
  7178. .onClick(() => {
  7179. this.getImageColor()
  7180. })
  7181. if (this.isPhoneLan()) {
  7182. Text(this.name)
  7183. .fontSize(18)
  7184. .fontWeight(FontWeight.Bold)
  7185. .margin({ top: 13 })
  7186. .textOverflow({ overflow: TextOverflow.Ellipsis })
  7187. .maxLines(1)
  7188. .width('99%')
  7189. .textAlign(TextAlign.Center)
  7190. .fontColor(Color.White)
  7191. }
  7192. }
  7193. }
  7194. // 唱针以左上角为点选择逆时针40度
  7195. Image($r('app.media.ic_music_cover_hand'))
  7196. .height(130)
  7197. .margin({ bottom: 220, top: 0 })
  7198. .align(Alignment.Top)
  7199. .rotate({ angle: this.rotateAngle2, centerX: 0, centerY: 0 })
  7200. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  7201. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  7202. Column({ space: 8 }) {
  7203. Text(this.name)
  7204. .fontSize(this.isPuraWP() ? 24 : (this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22))
  7205. .fontWeight(FontWeight.Bold)
  7206. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7207. .maxLines(1)
  7208. .width('48%')
  7209. .textAlign(TextAlign.Center)
  7210. .fontColor(Color.White)
  7211. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  7212. Text(this.artist)
  7213. .fontSize(this.isPuraWP() ? 18 : (this.isCoverOpacity() ? 12 : 15))
  7214. .fontColor(Color.White)
  7215. .fontWeight(FontWeight.Bold)
  7216. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  7217. }
  7218. .justifyContent(FlexAlign.Start)
  7219. .zIndex(1)
  7220. .visibility(this.isCoverOpacity() ? Visibility.Visible : Visibility.None)
  7221. }
  7222. .margin({
  7223. bottom: this.isCoverOpacity() || this.isCoverRectangle ?
  7224. (this.isPhonePortrait() && this.isShowSingleLineLyric ? 20 : 55) : 0,
  7225. top: this.isCoverOpacity() ? 0 : 20
  7226. })
  7227. if (this.isPhonePortrait() && this.isShowSingleLineLyric) {
  7228. this.SingleLyricView()
  7229. }
  7230. if (this.isPhoneLan()) {
  7231. Column() {
  7232. this.playCenterView()
  7233. // this.playProgressView()
  7234. }
  7235. .position({ left: 28, bottom: 38 })
  7236. } else {
  7237. this.BottomControl()
  7238. }
  7239. }
  7240. .width(CommonConstants.FULL_PERCENT)
  7241. .clip(true)
  7242. }
  7243. @Builder
  7244. private musicNameInfo(isHidden: boolean) {
  7245. Column({ space: 8 }) {
  7246. Text(this.name)
  7247. .fontSize(this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22)
  7248. .fontWeight(FontWeight.Bold)
  7249. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7250. .maxLines(1)
  7251. .width('99%')
  7252. .textAlign(TextAlign.Center)
  7253. .fontColor(Color.White)
  7254. Text(this.artist + ' ' + this.currentSong?.album)
  7255. .fontSize(this.isCoverOpacity() ? 12 : 15)
  7256. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7257. .fontColor(Color.White)
  7258. .textAlign(TextAlign.Center)
  7259. .visibility(StrUtil.isEmpty(this.artist)?Visibility.None:Visibility.Visible)
  7260. .width('99%')
  7261. .maxLines(1)
  7262. }
  7263. .margin({ top: this.isCoverOpacity() ? 20 : isHidden ? 40 : 20 })
  7264. .zIndex(1)
  7265. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7266. .visibility(this.isCoverOpacity() || isHidden ? Visibility.None : Visibility.Visible)
  7267. }
  7268. @Builder
  7269. private PlayTitle() {
  7270. Row() {
  7271. Row() {
  7272. Image($r('app.media.ic_back_down'))
  7273. .width($r('app.float.title_image_size'))// .aspectRatio(CommonConstants.ASPECT_RATIO)
  7274. .hitTestBehavior(HitTestMode.Transparent)
  7275. Text(this.name + ' ' + this.artist)
  7276. .fontColor(Color.White)
  7277. .fontSize($r('app.float.title_font_size'))
  7278. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7279. .maxLines(1)
  7280. .visibility(Visibility.None)
  7281. .margin({ left: 2, right: 30 })
  7282. }
  7283. .layoutWeight(1)
  7284. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7285. .visibility(this.isHide ? Visibility.Hidden : Visibility.Visible)
  7286. .onClick(() => {
  7287. this.isShowPlay = false;
  7288. })
  7289. Column() {
  7290. AVCastPicker({
  7291. normalColor: Color.White,
  7292. onStateChange: this.onStateVastChange
  7293. })
  7294. .width(24)
  7295. .height(24)
  7296. }
  7297. .visibility(this.isHide ? Visibility.Hidden : Visibility.None)
  7298. }
  7299. .width(PlayConstants.ROW_WIDTH)
  7300. }
  7301. @Builder
  7302. lyricSettingSheet(isPip: boolean) {
  7303. Scroll() {
  7304. this.lyricSetting(isPip)
  7305. }
  7306. .width('100%')
  7307. .height('100%')
  7308. }
  7309. @Builder
  7310. lyricSetting(isPip: boolean) {
  7311. Column() {
  7312. // 时间调节模块
  7313. if (!isPip) {
  7314. this.BuildTimeControls()
  7315. }
  7316. // 字号控制模块
  7317. this.BuildFontControls(isPip)
  7318. }
  7319. }
  7320. // 歌词时间偏移状态
  7321. @State timeOffset: number = 0.0
  7322. @State currentLyricColor: string = '#FFFFFF'
  7323. @State currentLyricColorPip: string = '#FFFFFF'
  7324. @State currentHighLightLyricColor: string = '#FF4081'
  7325. @State currentHighLightLyricColorPip: string = '#FF4081'
  7326. // 歌词字号状态
  7327. @State currentLyricSize: number = 20
  7328. @State currentLyricSizePip: number = 20
  7329. // 高亮歌词放大倍数
  7330. @State currentHightLyricSize: number = 1.2
  7331. @State currentHightLyricSizePip: number = 1.2
  7332. @State currentLyricLineSpace: number = 10
  7333. @State currentLyricLineSpacePip: number = 10
  7334. @State currentLyricAlignMode: number = 1
  7335. @State currentLyricAlignModePip: number = 1
  7336. @State blurDegree: number = 2
  7337. @State blurDegreePip: number = 2
  7338. @State isShowSelectColor: boolean = false
  7339. @State isShowHLSelectColor: boolean = false
  7340. @State isShowPipBgSelectColor: boolean = false
  7341. @State pipLyWidth: number = 330
  7342. @State pipLyHeight: number = 120
  7343. // 构建颜色选择器
  7344. @Builder
  7345. SelectColor(isHighColor: boolean, isPip: boolean, isBGPip?: boolean) {
  7346. Row({ space: 10 }) {
  7347. HSBColorPicker({
  7348. color: '#FFFFFF',
  7349. radius: 8,
  7350. layout: HSBColorPickerLayout.COLUMN,
  7351. predefine: ['#8b27f4', '#73f9fc', '#fffe55', '#f5cee3', '#eb4827', '#e93bf4', '#3e68f4', '#c5e6d3', '#e4e4e4',
  7352. '#fa7105'],
  7353. onChange: (value: string) => isHighColor ? this.changeLyricHightLightColor(value, isPip) :
  7354. this.changeLyricColor(value, isPip, isBGPip)
  7355. })
  7356. .height(250)
  7357. .layoutWeight(1)
  7358. .padding(25)
  7359. }
  7360. .width('66%')
  7361. }
  7362. @State isOpenPip: boolean = false
  7363. @State pipBgIndex: number = 0
  7364. // 构建字号控制器
  7365. @Builder
  7366. BuildFontControls(isPip: boolean) {
  7367. Column() {
  7368. if (isPip) {
  7369. Column() {
  7370. Row() {
  7371. Text('悬浮歌词')
  7372. .margin({ left: 18 })
  7373. .fontSize(15)
  7374. .fontColor(Color.White)
  7375. .fontWeight(480)
  7376. .layoutWeight(1)
  7377. Toggle({ type: ToggleType.Switch, isOn: this.isOpenPip })
  7378. .selectedColor(this.themeColor)
  7379. .switchPointColor(Color.White)
  7380. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7381. .margin({ right: 18 })
  7382. .onChange((checked: boolean) => {
  7383. this.isOpenPip = checked;
  7384. if (this.isOpenPip) {
  7385. this.startPip()
  7386. } else {
  7387. this.stopPip()
  7388. }
  7389. PreferencesUtil.put('isOpenPip', this.isOpenPip)
  7390. })
  7391. .width(50)
  7392. .height(30);
  7393. }
  7394. .height(55)
  7395. }
  7396. .backgroundColor(Color.Transparent)
  7397. .borderRadius(15)
  7398. .margin({
  7399. left: 30,
  7400. right: 30,
  7401. top: 0,
  7402. bottom: 20
  7403. })
  7404. .padding(0)
  7405. .border({
  7406. color: Color.White,
  7407. width: 1.8
  7408. })
  7409. }
  7410. Row() {
  7411. Text(`歌词居中:`)
  7412. .fontSize(14)
  7413. .fontColor(Color.White)
  7414. .margin({ left: 2 })
  7415. Row() {
  7416. ForEach(['居中', '居左'], (size: string, index: number) => {
  7417. Button(size)
  7418. .width(60)
  7419. .height(28)
  7420. .fontSize(12)
  7421. .fontColor('#FFFFFF')
  7422. .backgroundColor((!isPip && this.currentLyricAlignMode === index) ||
  7423. (isPip && this.currentLyricAlignModePip === index) ? this.themeColor : Color.Transparent)
  7424. .border({
  7425. color: (!isPip && this.currentLyricAlignMode === index) ||
  7426. (isPip && this.currentLyricAlignModePip === index) ?
  7427. '#007DFF' : '#DDDDDD',
  7428. width: 1.8
  7429. })
  7430. .onClick(() => {
  7431. this.setLyricAlignMode(index, isPip)
  7432. })
  7433. .margin({ left: 10, right: 8 })
  7434. })
  7435. }
  7436. .width('76%')
  7437. Blank()
  7438. }
  7439. .margin({
  7440. top: 10,
  7441. bottom: 10,
  7442. right: 20,
  7443. left: 20
  7444. })
  7445. if (isPip) {
  7446. Row() {
  7447. Text(`悬浮背景:`)
  7448. .fontSize(14)
  7449. .fontColor(Color.White)
  7450. Select([
  7451. { value: CommonConstants.PIP_LYRIC_BG[0] },
  7452. { value: CommonConstants.PIP_LYRIC_BG[1] }])
  7453. .font({ size: 13, weight: FontWeight.Medium })
  7454. .fontColor(Color.White)
  7455. .margin({ left: 10 })
  7456. .selected(this.pipBgIndex)
  7457. .value(CommonConstants.PIP_LYRIC_BG[this.pipBgIndex])
  7458. .onSelect(async (_index: number, text?: string | undefined) => {
  7459. this.pipBgIndex = _index
  7460. PreferencesUtil.put('pipBgIndex', this.pipBgIndex)
  7461. if (this.pipBgIndex === 0) {
  7462. if (this.cover) {
  7463. this.pipBg = this.cover
  7464. } else {
  7465. this.pipBg = this.imageColor
  7466. }
  7467. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  7468. } else {
  7469. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  7470. }
  7471. })
  7472. Column() {
  7473. }
  7474. .backgroundColor(this.pipBg)
  7475. .margin({ left: 10, right: 10 })
  7476. .borderRadius(20)
  7477. .height(28)
  7478. .width(28)
  7479. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7480. Row() {
  7481. SymbolGlyph($r('sys.symbol.paintbrush'))
  7482. .fontColor([Color.White])
  7483. .effectStrategy(1)
  7484. Text(`选择颜色`)
  7485. .fontSize(13)
  7486. .margin({ left: 10 })
  7487. .fontColor(Color.White)
  7488. }
  7489. }
  7490. .visibility(this.pipBgIndex === 1 ? Visibility.Visible : Visibility.None)
  7491. .backgroundColor(Color.Transparent)
  7492. .border({
  7493. color: '#FFFFFF',
  7494. radius: 20,
  7495. width: 1.8
  7496. })
  7497. .height(36)
  7498. .width(110)
  7499. .onClick(() => {
  7500. this.isShowPipBgSelectColor = !this.isShowPipBgSelectColor
  7501. })
  7502. .bindPopup(this.isShowPipBgSelectColor, {
  7503. builder: this.SelectColor(false, isPip, true),
  7504. placement: Placement.Top,
  7505. mask: { color: '#33000000' },
  7506. enableArrow: false, //是否显示箭头
  7507. showInSubWindow: false,
  7508. onStateChange: (e) => {
  7509. if (!e.isVisible) {
  7510. this.isShowPipBgSelectColor = false
  7511. }
  7512. }
  7513. })
  7514. }
  7515. .width('76%')
  7516. .margin({ bottom: 5, right: 45, left: 20 })
  7517. }
  7518. if (!isPip) {
  7519. Row() {
  7520. Text(`高亮居中:`)
  7521. .fontSize(14)
  7522. .fontColor(Color.White)
  7523. Column() {
  7524. Toggle({ type: ToggleType.Switch, isOn: this.isHightLightCenter })
  7525. .selectedColor(this.themeColor)
  7526. .switchPointColor(Color.White)
  7527. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7528. .onChange((checked: boolean) => {
  7529. this.isHightLightCenter = checked;
  7530. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isHightLightCenter)
  7531. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  7532. })
  7533. .width(50)
  7534. .height(30)
  7535. .alignSelf(ItemAlign.Start)
  7536. .margin({ left: 12 })
  7537. Blank()
  7538. }
  7539. .width('76%')
  7540. }
  7541. .margin({
  7542. left: 20,
  7543. right: 15,
  7544. top: 10,
  7545. bottom: 10
  7546. })
  7547. }
  7548. Row() {
  7549. Text(`歌词颜色:`)
  7550. .fontSize(14)
  7551. .fontColor(Color.White)
  7552. Text(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  7553. .fontSize(15)
  7554. .fontColor(Color.White)
  7555. .margin({ left: 12, right: 12 })
  7556. Column() {
  7557. }
  7558. .backgroundColor(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  7559. .margin({ right: 12 })
  7560. .borderRadius(20)
  7561. .height(28)
  7562. .width(28)
  7563. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7564. Row() {
  7565. SymbolGlyph($r('sys.symbol.paintbrush'))
  7566. .fontColor([Color.White])
  7567. .effectStrategy(1)
  7568. Text(`选择颜色`)
  7569. .fontSize(13)
  7570. .margin({ left: 10 })
  7571. .fontColor(Color.White)
  7572. }
  7573. }
  7574. .backgroundColor(Color.Transparent)
  7575. .border({
  7576. color: '#FFFFFF',
  7577. radius: 20,
  7578. width: 1.8
  7579. })
  7580. .height(36)
  7581. .width(110)
  7582. .onClick(() => {
  7583. this.isShowSelectColor = !this.isShowSelectColor
  7584. })
  7585. .bindPopup(this.isShowSelectColor, {
  7586. builder: this.SelectColor(false, isPip),
  7587. placement: Placement.Top,
  7588. mask: { color: '#33000000' },
  7589. enableArrow: false, //是否显示箭头
  7590. showInSubWindow: false,
  7591. onStateChange: (e) => {
  7592. if (!e.isVisible) {
  7593. this.isShowSelectColor = false
  7594. }
  7595. }
  7596. })
  7597. }
  7598. .width('76%')
  7599. .margin({
  7600. top: 10,
  7601. bottom: 10,
  7602. right: 45,
  7603. left: 20
  7604. })
  7605. Row() {
  7606. Text(`高亮颜色:`)
  7607. .fontSize(14)
  7608. .fontColor(Color.White)
  7609. Text(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  7610. .fontSize(15)
  7611. .fontColor(Color.White)
  7612. .margin({ left: 12, right: 12 })
  7613. Column() {
  7614. }
  7615. .backgroundColor(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  7616. .margin({ right: 12 })
  7617. .borderRadius(20)
  7618. .height(28)
  7619. .width(28)
  7620. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7621. Row() {
  7622. SymbolGlyph($r('sys.symbol.paintbrush'))
  7623. .fontColor([Color.White])
  7624. .effectStrategy(1)
  7625. Text(`选择颜色`)
  7626. .fontSize(13)
  7627. .margin({ left: 10 })
  7628. .fontColor(Color.White)
  7629. }
  7630. }
  7631. .backgroundColor(Color.Transparent)
  7632. .border({
  7633. color: '#FFFFFF',
  7634. radius: 20,
  7635. width: 1.8
  7636. })
  7637. .height(36)
  7638. .width(110)
  7639. .onClick(() => {
  7640. this.isShowHLSelectColor = !this.isShowHLSelectColor
  7641. })
  7642. .bindPopup(this.isShowHLSelectColor, {
  7643. builder: this.SelectColor(true, isPip),
  7644. placement: Placement.Top,
  7645. mask: { color: '#33000000' },
  7646. enableArrow: false, //是否显示箭头
  7647. showInSubWindow: false,
  7648. onStateChange: (e) => {
  7649. if (!e.isVisible) {
  7650. this.isShowHLSelectColor = false
  7651. }
  7652. }
  7653. })
  7654. }
  7655. .width('76%')
  7656. .margin({
  7657. top: 10,
  7658. bottom: 10,
  7659. right: 45,
  7660. left: 20
  7661. })
  7662. if (isPip) {
  7663. Row() {
  7664. Text(`显示宽度:`)
  7665. .fontSize(14)
  7666. .fontColor(Color.White)
  7667. Slider({
  7668. value: this.pipLyWidth,
  7669. min: 10,
  7670. max: 800,
  7671. step: 1,
  7672. style: SliderStyle.OutSet
  7673. })
  7674. .blockColor(this.themeColor)
  7675. .trackColor($r('app.color.speed_text_color'))
  7676. .selectedColor(Color.White)
  7677. .trackThickness(6)
  7678. .onChange((value: number) => {
  7679. this.pipLyWidth = value
  7680. if (this.pipController) {
  7681. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  7682. PreferencesUtil.putSync('pipLyWidth', this.pipLyWidth)
  7683. }
  7684. })
  7685. .width('76%')
  7686. }
  7687. .margin({
  7688. left: 20,
  7689. right: 15,
  7690. top: 5,
  7691. bottom: 5
  7692. })
  7693. Row() {
  7694. Text(`显示高度:`)
  7695. .fontSize(14)
  7696. .fontColor(Color.White)
  7697. Slider({
  7698. value: this.pipLyHeight,
  7699. min: 10,
  7700. max: 1000,
  7701. step: 1,
  7702. style: SliderStyle.OutSet
  7703. })
  7704. .blockColor(this.themeColor)
  7705. .trackColor($r('app.color.speed_text_color'))
  7706. .selectedColor(Color.White)
  7707. .trackThickness(6)
  7708. .onChange((value: number) => {
  7709. this.pipLyHeight = value
  7710. if (this.pipController) {
  7711. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  7712. PreferencesUtil.putSync('pipLyHeight', this.pipLyHeight)
  7713. }
  7714. })
  7715. .width('76%')
  7716. }
  7717. .margin({
  7718. left: 20,
  7719. right: 15,
  7720. top: 5,
  7721. bottom: 5
  7722. })
  7723. }
  7724. Row() {
  7725. Text(`歌词字号:`)
  7726. .fontSize(14)
  7727. .fontColor(Color.White)
  7728. Slider({
  7729. value: isPip ? this.currentLyricSizePip : this.currentLyricSize,
  7730. min: 12,
  7731. max: 30,
  7732. step: 0.1,
  7733. style: SliderStyle.OutSet
  7734. })
  7735. .blockColor(this.themeColor)
  7736. .trackColor($r('app.color.speed_text_color'))
  7737. .selectedColor(Color.White)
  7738. .trackThickness(6)
  7739. .onChange((value: number) => {
  7740. this.setLyricTextSize(value, isPip)
  7741. })
  7742. .width('76%')
  7743. }
  7744. .margin({
  7745. left: 20,
  7746. right: 15,
  7747. top: 5,
  7748. bottom: 5
  7749. })
  7750. Row() {
  7751. Text(`高亮倍数:`)
  7752. .fontSize(14)
  7753. .fontColor(Color.White)
  7754. Slider({
  7755. value: isPip ? this.currentHightLyricSizePip : this.currentHightLyricSize,
  7756. min: 1,
  7757. max: 2,
  7758. step: 0.1,
  7759. style: SliderStyle.OutSet
  7760. })
  7761. .blockColor(this.themeColor)
  7762. .trackColor($r('app.color.speed_text_color'))
  7763. .selectedColor(Color.White)
  7764. .trackThickness(6)
  7765. .onChange((value: number) => {
  7766. this.setHighLyricTextSize(value, isPip)
  7767. })
  7768. .width('76%')
  7769. }
  7770. .margin({
  7771. left: 20,
  7772. right: 15,
  7773. top: 5,
  7774. bottom: 5
  7775. })
  7776. Row() {
  7777. Text(`歌词间隙:`)
  7778. .fontSize(14)
  7779. .fontColor(Color.White)
  7780. Slider({
  7781. value: isPip ? this.currentLyricLineSpacePip : this.currentLyricLineSpace,
  7782. min: 0,
  7783. max: 100,
  7784. step: 1,
  7785. style: SliderStyle.OutSet
  7786. })
  7787. .blockColor(this.themeColor)
  7788. .trackColor($r('app.color.speed_text_color'))
  7789. .selectedColor(Color.White)
  7790. .trackThickness(6)
  7791. .onChange((value: number) => {
  7792. this.setLyricLineSpace(value, isPip)
  7793. })
  7794. .width('76%')
  7795. }
  7796. .margin({
  7797. left: 20,
  7798. right: 15,
  7799. top: 5,
  7800. bottom: 5
  7801. })
  7802. //取值间隔为100,默认为400,取值越大,字体越粗
  7803. Row() {
  7804. Text(`歌词字重:`)
  7805. .fontSize(14)
  7806. .fontColor(Color.White)
  7807. Slider({
  7808. value: isPip ? this.lyricTextWeightPip : this.lyricTextWeight,
  7809. min: 100,
  7810. max: 900,
  7811. step: 100,
  7812. style: SliderStyle.OutSet
  7813. })
  7814. .blockColor(this.themeColor)
  7815. .trackColor($r('app.color.speed_text_color'))
  7816. .selectedColor(Color.White)
  7817. .trackThickness(6)
  7818. .onChange((value: number) => {
  7819. if (isPip) {
  7820. this.lyricTextWeightPip = value
  7821. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  7822. PreferencesUtil.putSync('lyricTextWeightPip', this.lyricTextWeightPip)
  7823. } else {
  7824. this.lyricTextWeight = value
  7825. this.lyricController.setTextWeight(this.lyricTextWeight)
  7826. PreferencesUtil.putSync('lyricTextWeight', this.lyricTextWeight)
  7827. }
  7828. })
  7829. .width('76%')
  7830. }
  7831. .margin({
  7832. left: 20,
  7833. right: 15,
  7834. top: 5,
  7835. bottom: 5
  7836. })
  7837. if (!isPip) {
  7838. Row() {
  7839. Text(`歌词模糊:`)
  7840. .fontSize(14)
  7841. .fontColor(Color.White)
  7842. Slider({
  7843. value: isPip ? this.blurDegreePip : this.blurDegree,
  7844. min: 0,
  7845. max: 5,
  7846. step: 0.1,
  7847. style: SliderStyle.OutSet
  7848. })
  7849. .blockColor(this.themeColor)
  7850. .trackColor($r('app.color.speed_text_color'))
  7851. .selectedColor(Color.White)
  7852. .trackThickness(6)
  7853. .onChange((value: number) => {
  7854. this.setBlurDegree(value, isPip)
  7855. })
  7856. .width('76%')
  7857. }
  7858. .margin({
  7859. left: 20,
  7860. right: 15,
  7861. top: 5,
  7862. bottom: 15
  7863. })
  7864. }
  7865. Row() {
  7866. this.pushLyricButton($r('app.media.cut_current'), 0, '本地歌词')
  7867. this.pushLyricButton($r('app.media.white_search'), 1, '获取歌词')
  7868. }
  7869. .justifyContent(FlexAlign.Center)
  7870. .margin({ top: 3, bottom: 10 })
  7871. }
  7872. }
  7873. private setBlurDegree(index: number, isPip: boolean) {
  7874. if (isPip) {
  7875. this.blurDegreePip = index
  7876. this.lyricControllerXF.setBlurDegree(this.blurDegreePip)
  7877. PreferencesUtil.putSync('setBlurDegreePip', this.blurDegreePip)
  7878. } else {
  7879. this.blurDegree = index
  7880. this.lyricController.setBlurDegree(this.blurDegree)
  7881. PreferencesUtil.putSync('setBlurDegree', this.blurDegree)
  7882. }
  7883. }
  7884. private setLyricAlignMode(index: number, isPip: boolean) {
  7885. if (isPip) {
  7886. this.currentLyricAlignModePip = index
  7887. if (this.currentLyricAlignModePip === 1) {
  7888. this.lyricControllerXF.setAlignMode("left")
  7889. } else {
  7890. this.lyricControllerXF.setAlignMode("center")
  7891. }
  7892. PreferencesUtil.putSync('LyricAlignModePip', this.currentLyricAlignModePip)
  7893. } else {
  7894. this.currentLyricAlignMode = index
  7895. if (this.currentLyricAlignMode === 1) {
  7896. this.lyricController.setAlignMode("left")
  7897. } else {
  7898. this.lyricController.setAlignMode("center")
  7899. }
  7900. PreferencesUtil.putSync('LyricAlignMode', this.currentLyricAlignMode)
  7901. }
  7902. }
  7903. private setLyricTextSize(index: number, isPip: boolean) {
  7904. if (isPip) {
  7905. this.currentLyricSizePip = index
  7906. this.lyricControllerXF.setTextSize(this.currentLyricSizePip)
  7907. PreferencesUtil.putSync('LyricTextSizePip', this.currentLyricSizePip)
  7908. } else {
  7909. this.currentLyricSize = index
  7910. this.lyricController.setTextSize(this.currentLyricSize)
  7911. PreferencesUtil.putSync('LyricTextSize', this.currentLyricSize)
  7912. }
  7913. }
  7914. private setHighLyricTextSize(scale: number, isPip: boolean) {
  7915. if (isPip) {
  7916. this.currentHightLyricSizePip = scale
  7917. this.lyricControllerXF
  7918. .setHighlightScale(this.currentHightLyricSizePip)
  7919. PreferencesUtil.putSync('HighLyricTextSizePip', scale)
  7920. } else {
  7921. this.currentHightLyricSize = scale
  7922. this.lyricController
  7923. .setHighlightScale(this.currentHightLyricSize)
  7924. PreferencesUtil.putSync('HighLyricTextSize', scale)
  7925. }
  7926. }
  7927. private setLyricLineSpace(index: number, isPip: boolean) {
  7928. if (isPip) {
  7929. this.currentLyricLineSpacePip = index
  7930. this.lyricControllerXF.setLineSpace(this.currentLyricLineSpacePip)
  7931. PreferencesUtil.putSync('LyricLineSpacePip', this.currentLyricLineSpacePip)
  7932. } else {
  7933. this.currentLyricLineSpace = index
  7934. this.lyricController.setLineSpace(this.currentLyricLineSpace)
  7935. PreferencesUtil.putSync('LyricLineSpace', this.currentLyricLineSpace)
  7936. }
  7937. }
  7938. private changeLyricColor(color: string, isPip: boolean, isBG?: boolean) {
  7939. LogUtil.info('onecold isBG = ' + isBG)
  7940. if (isBG) { //如果是设置悬浮背景
  7941. this.pipBg = color
  7942. PreferencesUtil.putSync('BGColorPip', this.pipBg)
  7943. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  7944. return
  7945. }
  7946. if (isPip) {
  7947. this.currentLyricColorPip = color
  7948. this.lyricControllerXF
  7949. .setTextColor(this.currentLyricColorPip)
  7950. PreferencesUtil.putSync('LyricColorPip', this.currentLyricColorPip)
  7951. } else {
  7952. this.currentLyricColor = color
  7953. this.lyricController
  7954. .setTextColor(this.currentLyricColor)
  7955. PreferencesUtil.putSync('LyricColor', this.currentLyricColor)
  7956. }
  7957. }
  7958. private changeLyricHightLightColor(color: string, isPip: boolean) {
  7959. if (isPip) {
  7960. this.currentHighLightLyricColorPip = color
  7961. this.lyricControllerXF
  7962. .setHighlightColor(this.currentHighLightLyricColorPip)
  7963. PreferencesUtil.putSync('LyricHighLightColorPip', this.currentHighLightLyricColorPip)
  7964. } else {
  7965. this.currentHighLightLyricColor = color
  7966. this.lyricController
  7967. .setHighlightColor(this.currentHighLightLyricColor)
  7968. PreferencesUtil.putSync('LyricHighLightColor', this.currentHighLightLyricColor)
  7969. }
  7970. }
  7971. // 构建时间控制器
  7972. @Builder
  7973. BuildTimeControls() {
  7974. Column() {
  7975. // 时间显示
  7976. Text(this.getTimeText())
  7977. .fontSize(18)
  7978. .fontColor(Color.White)
  7979. .margin({ bottom: 10 })
  7980. Row() {
  7981. this.PrecisionTimeButton($r('app.media.ic_previous'), -0.5, ' -0.5s ')
  7982. this.PrecisionTimeButton($r('app.media.loop'), 0, '重置')
  7983. this.PrecisionTimeButton($r('app.media.ic_next'), 0.5, ' +0.5s ')
  7984. }
  7985. .justifyContent(FlexAlign.Center)
  7986. }
  7987. .margin({ top: 12, bottom: 8 })
  7988. }
  7989. // 精度按钮组件
  7990. @Builder
  7991. PrecisionTimeButton(icon: Resource, step: number, label: string) {
  7992. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7993. Column() {
  7994. Image(icon)
  7995. .width(28)
  7996. .margin({ bottom: 5 })
  7997. .opacity(this.isButtonDisabled(step) ? 0.5 : 1)
  7998. Text(label)
  7999. .fontSize(12)
  8000. .fontColor('#FFFFFF')
  8001. }
  8002. }
  8003. .backgroundColor(Color.Transparent)
  8004. .enabled(!this.isButtonDisabled(step))
  8005. .onClick(() => this.handlePrecisionAdjust(step))
  8006. .padding(5)
  8007. .width(66)
  8008. .height(66)
  8009. .margin({ left: 18, right: 18 })
  8010. .border({
  8011. color: '#FFFFFF',
  8012. width: 1.8
  8013. })
  8014. }
  8015. private handlePrecisionAdjust(step: number) {
  8016. if (step === 0) {
  8017. this.timeOffset = 0
  8018. return
  8019. }
  8020. // 精度处理:保留1位小数
  8021. const newOffset = Number((this.timeOffset + step).toFixed(5))
  8022. // 边界保护(±15.0秒)
  8023. if (newOffset < -30.0 || newOffset > 30.0) {
  8024. // this.triggerEdgeFeedback(newOffset) // 触发边界反馈
  8025. return
  8026. }
  8027. // 状态更新
  8028. this.timeOffset = newOffset
  8029. }
  8030. // 按钮禁用逻辑
  8031. private isButtonDisabled(step: number): boolean {
  8032. const futureOffset = this.timeOffset + step
  8033. return (futureOffset < -30.0) || (futureOffset > 30.0)
  8034. }
  8035. // 时间显示文本升级
  8036. private getTimeText(): string {
  8037. const absValue = Math.abs(this.timeOffset)
  8038. return this.timeOffset === 0
  8039. ? '歌词时间已重置'
  8040. : `歌词已${this.timeOffset < 0 ? '延后' : '提前'} ${absValue.toFixed(1)} 秒`
  8041. }
  8042. // 导入 本地歌词 搜索歌词
  8043. @Builder
  8044. pushLyricButton(icon: Resource, step: number, label: string) {
  8045. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8046. Row() {
  8047. Image(icon)
  8048. .width(14)
  8049. .margin({ left: 13 })
  8050. Text(label)
  8051. .fontSize(12)
  8052. .margin({ left: 6 })
  8053. .fontColor('#FFFFFF')
  8054. }
  8055. }
  8056. .onClick(() => {
  8057. switch (step) {
  8058. case 0:
  8059. this.callFilePickerSelectFileForLyric()
  8060. break;
  8061. case 1:
  8062. //判断有没有设置api
  8063. if (PreferencesUtil.getStringSync('LRC_API', '') === '') {
  8064. this.isLyricSetting = false
  8065. this.showTipsDialog()
  8066. return
  8067. }
  8068. if (StrUtil.isNotEmpty(this.videoUrl)) {
  8069. ToastUtil.showToast('正在获取')
  8070. this.isLyricSetting = false
  8071. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  8072. this.initLyric(lyricPath, true);
  8073. }
  8074. break;
  8075. }
  8076. })
  8077. .padding(5)
  8078. .width(110)
  8079. .backgroundColor(Color.Transparent)
  8080. .height(40)
  8081. .margin({ left: 6, right: 6 })
  8082. .border({
  8083. color: '#FFFFFF',
  8084. radius: 20,
  8085. width: 1.8
  8086. })
  8087. }
  8088. showVipDialog() {
  8089. DialogHelper.showCustomContentDialog({
  8090. dialogId: 'vip',
  8091. title: "友情提示",
  8092. autoCancel: false, //点击遮障层时,不关闭弹窗
  8093. backCancel: true, //点击返回键,不关闭弹窗
  8094. contentBuilder: () => {
  8095. this.customVipBuilder("该功能需开通会员,非常感谢您的支持!")
  8096. },
  8097. buttons: [],
  8098. })
  8099. }
  8100. //去赞助的自定义内容
  8101. @Builder
  8102. customVipBuilder(content: string) {
  8103. Column() {
  8104. Text(content)
  8105. .fontColor(Color.Gray)
  8106. .fontSize(16)
  8107. .alignSelf(ItemAlign.Start)
  8108. .margin({ bottom: 15 })
  8109. .fontSize(16)
  8110. Row() {
  8111. Button('取消')
  8112. .fontColor(Color.White)
  8113. .backgroundColor(this.themeColor)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  8114. .height(50)
  8115. .layoutWeight(1)
  8116. .stateEffect(true)
  8117. .margin({ right: 6 })
  8118. .onClick(() => {
  8119. DialogHelper.closeDialog('vip'); //关闭弹框
  8120. })
  8121. Button('开通')
  8122. .fontColor(Color.White)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  8123. .layoutWeight(1)
  8124. .height(50)
  8125. .backgroundColor(this.themeColor)
  8126. .stateEffect(true)
  8127. .margin({ left: 6 })
  8128. .onClick(() => {
  8129. DialogHelper.closeDialog('vip'); //关闭弹框
  8130. this.isShowPlay = false
  8131. this.mType = 1 //跳转到用户中心
  8132. // router.pushUrl({
  8133. // url: 'pages/VipPage'
  8134. // }, router.RouterMode.Single);
  8135. })
  8136. }
  8137. }
  8138. .width("100%")
  8139. .padding(10)
  8140. }
  8141. showTipsDialog() {
  8142. DialogHelper.showCustomContentDialog({
  8143. dialogId: 'tips',
  8144. title: "友情提示",
  8145. autoCancel: false, //点击遮障层时,不关闭弹窗
  8146. backCancel: true, //点击返回键,不关闭弹窗
  8147. contentBuilder: () => {
  8148. this.customTipsBuilder("请到设置界面配置API服务器地址!")
  8149. },
  8150. buttons: [],
  8151. })
  8152. }
  8153. @Builder
  8154. customTipsBuilder(content: string) {
  8155. Column() {
  8156. Text(content)
  8157. .fontColor(Color.Gray)
  8158. .fontSize(16)
  8159. .alignSelf(ItemAlign.Start)
  8160. .margin({ bottom: 15 })
  8161. .fontSize(16)
  8162. Row() {
  8163. Button('取消')
  8164. .fontColor(Color.White)
  8165. .backgroundColor(this.themeColor)
  8166. .height(50)
  8167. .layoutWeight(1)
  8168. .stateEffect(true)
  8169. .margin({ right: 6 })
  8170. .onClick(() => {
  8171. DialogHelper.closeDialog('tips'); //关闭弹框
  8172. })
  8173. Button('跳转')
  8174. .fontColor(Color.White)//
  8175. .layoutWeight(1)
  8176. .height(50)
  8177. .backgroundColor(this.themeColor)
  8178. .stateEffect(true)
  8179. .margin({ left: 6 })
  8180. .onClick(() => {
  8181. DialogHelper.closeDialog('tips'); //关闭弹框
  8182. this.isShowEdit = false
  8183. this.longItemFilePath = ''
  8184. // if(this.isGridMusic&&!this.isShowPlay){
  8185. // this.longItemFilePath== ''
  8186. // }else{
  8187. // this.isShowEdit = false
  8188. // }
  8189. this.isShowPlay = false
  8190. this.mType = 3
  8191. // router.pushUrl({
  8192. // url: 'pages/SettingPage'
  8193. // }, router.RouterMode.Single);
  8194. })
  8195. }
  8196. }
  8197. .width("100%")
  8198. .padding(10)
  8199. }
  8200. @Builder
  8201. PlayMoreSheet() {
  8202. Column() {
  8203. this.MoreList()
  8204. }
  8205. .width('100%')
  8206. .height('100%')
  8207. }
  8208. @Builder
  8209. MoreList() {
  8210. Scroll() {
  8211. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  8212. ForEach(this.moreItems, (more: MoreItem, index: number) => {
  8213. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8214. Row() {
  8215. if (more.id === 3&&this.currentSong) {
  8216. Image(more.image)
  8217. .width(24)
  8218. .height(24)
  8219. .margin({ left: 10, right: 10 })
  8220. Text(more.title)
  8221. .fontSize(16)
  8222. .fontColor(Color.White)
  8223. .bindSheet($$this.isShowDetailMore, this.detailSheet(this.currentSong), {
  8224. height: this.isCoverOpacity() ? '95%' : '95%',
  8225. dragBar: true,
  8226. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8227. showClose: true,
  8228. blurStyle: BlurStyle.Thin,
  8229. backgroundColor: Color.Transparent,
  8230. title: { title: '歌曲信息' }
  8231. })
  8232. } else if (more.id === 15 && this.currentSong) { //编辑标签
  8233. Image(more.image)
  8234. .width(24)
  8235. .height(24)
  8236. .margin({ left: 10, right: 10 })
  8237. Text(more.title)
  8238. .fontSize(16)
  8239. .fontColor(Color.White)
  8240. .bindSheet($$this.isShowEdit, this.editSheet(this.currentSong), {
  8241. height: '99%',
  8242. dragBar: true,
  8243. showClose: true,
  8244. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8245. // blurStyle:BlurStyle.Thin,
  8246. // backgroundColor:Color.Transparent,
  8247. title: { title: '编辑标签' }
  8248. })
  8249. } else if (more.id === 5) { //定时关闭
  8250. Image(more.image)
  8251. .width(24)
  8252. .height(24)
  8253. .margin({ left: 10, right: 10 })
  8254. Text(more.title)
  8255. .fontSize(16)
  8256. .fontColor(Color.White)
  8257. .onClick(() => {
  8258. this.doMore(more.id)
  8259. })
  8260. .bindSheet($$this.isShowTimeCloseMore, this.TimeCloseSheet(), {
  8261. height: this.isCoverOpacity() ? '95%' : '95%',
  8262. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8263. dragBar: true,
  8264. showClose: true,
  8265. title: { title: $r('app.string.time_close') }
  8266. })
  8267. } else if (more.id === 2) { //歌词设置
  8268. Image(more.image)
  8269. .width(24)
  8270. .height(24)
  8271. .margin({ left: 10, right: 10 })
  8272. Text(more.title)
  8273. .fontSize(16)
  8274. .fontColor(Color.White)
  8275. } else if (more.id === 16) { //悬浮歌词设置
  8276. Image(more.image)
  8277. .width(24)
  8278. .height(24)
  8279. .margin({ left: 10, right: 10 })
  8280. Text(more.title)
  8281. .fontSize(16)
  8282. .fontColor(Color.White)
  8283. .bindSheet($$this.showPipLyric, this.lyricSettingSheet(true), {
  8284. height: this.isCoverOpacity() ? '95%' : '95%',
  8285. dragBar: true,
  8286. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8287. showClose: true,
  8288. blurStyle: BlurStyle.Thin,
  8289. backgroundColor: Color.Transparent,
  8290. title: { title: '悬浮歌词' }
  8291. })
  8292. } else if (more.id === 11) {
  8293. Image(more.image)
  8294. .width(24)
  8295. .height(24)
  8296. .margin({ left: 10, right: 10 })
  8297. Text(more.title)
  8298. .fontSize(16)
  8299. .fontColor(Color.White)
  8300. .bindSheet($$this.isJumpSetting, this.JumpTopEndSheet(), {
  8301. height: this.isCoverOpacity() ? '95%' : '60%',
  8302. dragBar: true,
  8303. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8304. showClose: true,
  8305. blurStyle: BlurStyle.Thin,
  8306. backgroundColor: Color.Transparent,
  8307. title: { title: '跳过头尾' }
  8308. })
  8309. } else if (more.id === 12) { //投播
  8310. AVCastPicker({
  8311. customPicker: (): void => this.TPImageBuilder(more),
  8312. onStateChange: (state) => {
  8313. if (state == AVCastPickerState.STATE_APPEARING) {
  8314. console.log(' The picker starts showing.');
  8315. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  8316. console.log(' The picker finishes presenting.');
  8317. }
  8318. },
  8319. pickerStyle: AVCastPickerStyle.STYLE_PANEL,
  8320. sessionType: 'video'
  8321. })
  8322. .id('AVCastPicker')
  8323. } else {
  8324. Image(more.image)
  8325. .width(24)
  8326. .height(24)
  8327. .margin({ left: 10, right: 10 })
  8328. .onClick(() => {
  8329. this.doMore(more.id)
  8330. })
  8331. Text(more.id == 17 ? (this.isLandscape ? '竖屏模式' : '横屏模式') : more.title)
  8332. .fontSize(16)
  8333. .fontColor(Color.White)
  8334. .onClick(() => {
  8335. this.doMore(more.id)
  8336. })
  8337. Select([//倍速
  8338. { value: '0.25x' },
  8339. { value: '0.5x' },
  8340. { value: '0.75x' },
  8341. { value: '1x' },
  8342. { value: '1.25x' },
  8343. { value: '1.5x' },
  8344. { value: '1.75x' },
  8345. { value: '2x' },
  8346. { value: '3x' }])
  8347. .font({ size: 16, weight: FontWeight.Medium })
  8348. .fontColor($r('sys.color.white'))
  8349. .margin({ left: 25 })
  8350. .visibility(more.id === 1 ? Visibility.Visible : Visibility.None)
  8351. .selected(CommonConstants.video_speed_list.indexOf(this.playSpeed))
  8352. .value(Utility.optimizedFormat(this.playSpeed))
  8353. .onSelect(async (_index: number, text?: string | undefined) => {
  8354. let speed = parseFloat(text?.replace('x', '') || '1');
  8355. if (!CommonConstants.video_speed_list.includes(speed)) {
  8356. speed = 1;
  8357. }
  8358. this.playSpeed = speed
  8359. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  8360. })
  8361. Slider({
  8362. value: this.volume,
  8363. min: 0,
  8364. max: 1,
  8365. step: 0.1,
  8366. style: SliderStyle.OutSet
  8367. })
  8368. .margin({ left: 18, right: 8 })
  8369. .blockColor(this.themeColor)
  8370. .trackColor($r('app.color.speed_text_color'))
  8371. .selectedColor(Color.White)
  8372. .trackThickness(9)
  8373. .visibility(more.id === 9 ? Visibility.Visible : Visibility.None)
  8374. .onChange((value: number) => {
  8375. this.volume = value;
  8376. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  8377. PreferencesUtil.putSync('DefalutVolume',this.volume)
  8378. })
  8379. .layoutWeight(1)
  8380. Blank()
  8381. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  8382. .selectedColor(this.themeColor)
  8383. .switchPointColor(Color.White)
  8384. .margin({ right: 15 })
  8385. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8386. .visibility(more.id == 6 ? Visibility.Visible : Visibility.None)
  8387. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8388. if (more.id == 6) {
  8389. this.isMusicMemoryPlay = checked;
  8390. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  8391. if (this.isMusicMemoryPlay) {
  8392. ToastUtil.showToast('记忆播放已开启')
  8393. } else {
  8394. ToastUtil.showToast('记忆播放已关闭')
  8395. }
  8396. }
  8397. })
  8398. .width(48)
  8399. .height(24);
  8400. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  8401. .selectedColor(this.themeColor)
  8402. .switchPointColor(Color.White)
  8403. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8404. .margin({ right: 15 })
  8405. .visibility(more.id == 7 ? Visibility.Visible : Visibility.None)
  8406. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8407. if (more.id == 7) {
  8408. this.isMusicBGCover = checked;
  8409. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  8410. if (this.isMusicBGCover) {
  8411. ToastUtil.showToast('播放背景随音乐封面已开启')
  8412. } else {
  8413. ToastUtil.showToast('播放背景随音乐封面已关闭')
  8414. }
  8415. }
  8416. })
  8417. .width(48)
  8418. .height(24);
  8419. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  8420. .selectedColor(this.themeColor)
  8421. .switchPointColor(Color.White)
  8422. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8423. .margin({ right: 15 })
  8424. .visibility(more.id == 8 ? Visibility.Visible : Visibility.None)
  8425. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8426. if (more.id == 8) {
  8427. this.isSavePlayMode = checked;
  8428. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  8429. if (this.isSavePlayMode) {
  8430. ToastUtil.showToast('保存播放模式已开启')
  8431. } else {
  8432. ToastUtil.showToast('保存播放模式已关闭')
  8433. }
  8434. }
  8435. })
  8436. .width(48)
  8437. .height(24);
  8438. Toggle({ type: ToggleType.Switch, isOn: this.isCoverRectangle })
  8439. .selectedColor(this.themeColor)
  8440. .switchPointColor(Color.White)
  8441. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8442. .margin({ right: 15 })
  8443. .visibility(more.id == 13 ? Visibility.Visible : Visibility.None)
  8444. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8445. if (more.id == 13) {
  8446. this.isCoverRectangle = checked;
  8447. PreferencesUtil.put(SettingPage.IS_COVER_RECTANGLE, this.isCoverRectangle)
  8448. if (this.isCoverRectangle) {
  8449. ToastUtil.showToast('封面方形已开启')
  8450. this.animationRoFun()
  8451. } else {
  8452. ToastUtil.showToast('封面圆形已开启')
  8453. this.animationRoFun()
  8454. }
  8455. }
  8456. })
  8457. .width(48)
  8458. .height(24);
  8459. }
  8460. }
  8461. .width('100%')
  8462. .height(45)
  8463. .padding(15)
  8464. .backgroundColor(Color.Transparent)
  8465. .borderRadius(12)
  8466. .margin({ bottom: 6 })
  8467. }
  8468. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.9 })
  8469. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  8470. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  8471. .backgroundColor(Color.Transparent)
  8472. .onClick(() => {
  8473. this.doMore(more.id)
  8474. })
  8475. });
  8476. }
  8477. .width('100%')
  8478. .padding(16)
  8479. }.margin({ bottom: 18 })
  8480. }
  8481. @Builder
  8482. TPImageBuilder(more: MoreItem): void {
  8483. Row() {
  8484. Image($r('app.media.tuoping'))
  8485. .width(22)
  8486. .height(22)
  8487. .margin({ left: 10, right: 10 })
  8488. Text(more.title)
  8489. .fontSize(16)
  8490. .fontColor(Color.White)
  8491. }
  8492. .width('100%')
  8493. .layoutWeight(1)
  8494. .alignItems(VerticalAlign.Center)
  8495. .justifyContent(FlexAlign.Start)
  8496. }
  8497. private moreItems: MoreItem[] = [
  8498. { id: 1, image: $r('app.media.speed'), title: '倍速' },
  8499. { id: 2, image: $r('app.media.lyric'), title: '歌词' },
  8500. { id: 17, image: $r('app.media.full_4'), title: '横屏模式' },
  8501. { id: 16, image: $r('app.media.hua_zhong_hua'), title: '悬浮歌词' },
  8502. { id: 14, image: $r('app.media.cover_online'), title: '获取封面' },
  8503. { id: 15, image: $r('app.media.rename2'), title: '编辑标签' },
  8504. { id: 5, image: $r('app.media.time_close'), title: '定时关闭' },
  8505. { id: 10, image: $r('app.media.ring_tone'), title: '设为铃声' },
  8506. { id: 11, image: $r('app.media.time_close'), title: '跳过头尾' },
  8507. { id: 12, image: $r('app.media.toubo'), title: '投播' },
  8508. { id: 3, image: $r('app.media.hua_zhong_hua'), title: '详情' },
  8509. { id: 4, image: $r('app.media.share2'), title: '分享' },
  8510. { id: 9, image: $r('app.media.volume_white'), title: '调整音量' },
  8511. { id: 6, image: $r('app.media.memory'), title: '记忆播放' },
  8512. { id: 13, image: $r('app.media.rectangle'), title: '封面方形' },
  8513. { id: 8, image: $r('app.media.cut_current'), title: '保存播放模式' },
  8514. { id: 7, image: $r('app.media.playlist2'), title: '播放背景随音乐封面' },
  8515. ];
  8516. @State isShowMoreView: boolean = false;
  8517. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  8518. @State isShowTimeCloseMore: boolean = false
  8519. @State isShowDetailMore: boolean = false
  8520. @State isMusicBGCover: boolean = true
  8521. @State isSavePlayMode: boolean = true
  8522. @State isLyricSetting: boolean = false
  8523. @State isJumpSetting: boolean = false
  8524. @State isShowEdit: boolean = false
  8525. @State showPipLyric: boolean = false
  8526. async setRingTone() {
  8527. if (StrUtil.isEmpty(this.videoUrl) || StrUtil.isEmpty(this.name)) {
  8528. return
  8529. }
  8530. // 确定后的逻辑
  8531. let ringtoneTypeList: Array<ringtone.RingtoneType> = ringtone.getSupportedRingtoneTypes();
  8532. LogUtil.info('onecold getSupportedRingtoneTypes : ' + JSON.stringify(ringtoneTypeList));
  8533. let dataTypeList: Array<uniformTypeDescriptor.UniformDataType> =
  8534. ringtone.getSupportedDataTypes(ringtone.RingtoneType.NOTIFICATION);
  8535. LogUtil.info('onecold getSupportedDataTypes: ' + JSON.stringify(dataTypeList));
  8536. //let fileName: string = audioPath.substring(audioPath.lastIndexOf('/') + 1, audioPath.lastIndexOf('.'));
  8537. await ringtone.startRingtoneSetting(getContext(this) as common.UIAbilityContext
  8538. , this.videoUrl, this.name).then(res => {
  8539. LogUtil.info('onecold setFlag :' + res);
  8540. });
  8541. }
  8542. doMore(moreId: number) {
  8543. switch (moreId) {
  8544. case 2: //歌词
  8545. this.isLyricSetting = !this.isLyricSetting;
  8546. this.isShowMoreView = false
  8547. break;
  8548. case 3: //详情
  8549. this.isShowDetailMore = !this.isShowDetailMore;
  8550. break;
  8551. case 4: //分享
  8552. if (this.currentSong !== undefined) {
  8553. Utility.doShareMusic(this.currentSong, getContext(this) as common.UIAbilityContext)
  8554. }
  8555. this.isShowMoreView = false
  8556. break;
  8557. case 5: //定时关闭
  8558. this.isShowTimeCloseMore = !this.isShowTimeCloseMore;
  8559. break;
  8560. case 10: //设为铃声
  8561. this.setRingTone()
  8562. this.isShowMoreView = false
  8563. break;
  8564. case 11: //跳过头尾
  8565. this.isJumpSetting = !this.isJumpSetting;
  8566. break;
  8567. case 13: //倍速
  8568. break;
  8569. case 14: //搜索封面
  8570. if (this.currentSong !== undefined) {
  8571. this.doSearchCover(this.currentSong)
  8572. }
  8573. this.isShowMoreView = false
  8574. break;
  8575. case 15: //编辑标签
  8576. this.setEditStrEmpty()
  8577. this.tempLyricContent = this.lyricContent
  8578. this.isShowEdit = !this.isShowEdit;
  8579. break;
  8580. case 16: //悬浮歌词
  8581. this.showPipLyric = !this.showPipLyric;
  8582. break;
  8583. case 17: //横屏模式
  8584. if (this.isLandscape) {
  8585. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  8586. } else {
  8587. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  8588. }
  8589. this.isShowMoreView = false
  8590. break;
  8591. }
  8592. }
  8593. /**
  8594. * 切换横竖屏
  8595. *
  8596. */
  8597. setOrientation(orientation: number) {
  8598. this.windowClass.setPreferredOrientation(orientation).then(() => {
  8599. Logger.info('setWindowOrientation: ' + orientation + ' Succeeded.');
  8600. }).catch((err: BusinessError) => {
  8601. Logger.info('setWindowOrientation: ' + orientation + ' Failed. Cause: ' + JSON.stringify(err));
  8602. });
  8603. }
  8604. /**
  8605. * 画中画功能(悬浮歌词功能)
  8606. *
  8607. */
  8608. private nodeController: TextNodeController = new TextNodeController('#000000', this.lyricControllerXF);
  8609. pipController?: PiPWindow.PiPController;
  8610. navigationId: string = '';
  8611. @State curState: string = '';
  8612. @State curError: ResourceStr = '';
  8613. @State pipBg: string = '#E8E8E8'
  8614. @State buttonAction: string = '';
  8615. //开启画中画功能
  8616. async startPip() {
  8617. this.nodeController = new TextNodeController(this.pipBg, this.lyricControllerXF);
  8618. if (!this.pipController) {
  8619. await this.createPipController();
  8620. }
  8621. if (!this.pipController) {
  8622. Logger.info(`[${TAG}] pipController create error`);
  8623. return;
  8624. }
  8625. await this.pipController.startPiP();
  8626. }
  8627. async stopPip() {
  8628. if (!this.pipController) {
  8629. Logger.info(`[${TAG}] pipController is not exist`);
  8630. return;
  8631. }
  8632. this.isOpenPip = false
  8633. await this.pipController.stopPiP();
  8634. }
  8635. async createPipController() {
  8636. this.pipController = await PiPWindow.create({
  8637. context: getContext(this),
  8638. componentController: this.xcomponentController,
  8639. navigationId: this.navigationId,
  8640. templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY,
  8641. controlGroups: [PiPWindow.VideoPlayControlGroup.VIDEO_PREVIOUS_NEXT],
  8642. customUIController: this.nodeController,
  8643. });
  8644. this.pipLyWidth = PreferencesUtil.getNumberSync('pipLyWidth', 330)
  8645. this.pipLyHeight = PreferencesUtil.getNumberSync('pipLyHeight', 120)
  8646. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8647. this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => {
  8648. this.onStateChange(state, reason);
  8649. });
  8650. this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => {
  8651. this.onActionEvent(event, status);
  8652. });
  8653. }
  8654. destroyPipController() {
  8655. if (!this.pipController) {
  8656. return;
  8657. }
  8658. this.pipController.off('stateChange');
  8659. this.pipController.off('controlPanelActionEvent');
  8660. this.pipController = undefined;
  8661. }
  8662. onStateChange(state: PiPWindow.PiPState, reason: string) {
  8663. switch (state) {
  8664. case PiPWindow.PiPState.ABOUT_TO_START:
  8665. this.curState = 'ABOUT_TO_START';
  8666. this.curError = $r('app.string.current_error_hint');
  8667. break;
  8668. case PiPWindow.PiPState.STARTED:
  8669. this.curState = 'STARTED';
  8670. this.curError = $r('app.string.current_error_hint');
  8671. break;
  8672. case PiPWindow.PiPState.ABOUT_TO_STOP:
  8673. this.curState = 'ABOUT_TO_STOP';
  8674. this.curError = $r('app.string.current_error_hint');
  8675. break;
  8676. case PiPWindow.PiPState.STOPPED:
  8677. this.curState = 'STOPPED';
  8678. this.curError = $r('app.string.current_error_hint');
  8679. this.stopPip()
  8680. this.destroyPipController()
  8681. break;
  8682. case PiPWindow.PiPState.ABOUT_TO_RESTORE:
  8683. this.curState = 'ABOUT_TO_RESTORE';
  8684. this.curError = $r('app.string.current_error_hint');
  8685. break;
  8686. case PiPWindow.PiPState.ERROR:
  8687. this.curState = 'ERROR';
  8688. this.curError = reason;
  8689. break;
  8690. default:
  8691. break;
  8692. }
  8693. Logger.info(`[${TAG}] onecold onStateChange: ${this.curState}, reason: ${reason}`);
  8694. }
  8695. onActionEvent(event: PiPWindow.PiPActionEventType, status: number | undefined) {
  8696. LogUtil.info('onecold onActionEvent = ' + event + ' status=' + status)
  8697. switch (event) {
  8698. case 'playbackStateChanged':
  8699. if (status === 0) {
  8700. this.pause();
  8701. } else {
  8702. this.startPlayOrResumePlay();
  8703. }
  8704. break;
  8705. case 'nextVideo':
  8706. // 切换到下一个视频
  8707. this.playNext()
  8708. break;
  8709. case 'previousVideo':
  8710. // 切换到上一个视频
  8711. this.playPrevious()
  8712. break;
  8713. case 'previousVideo':
  8714. // 切换到上一个视频
  8715. this.playPrevious()
  8716. break;
  8717. default:
  8718. }
  8719. this.buttonAction = event + `-status:${status}`;
  8720. Logger.info(`[${TAG}] onActionEvent: ${this.buttonAction} status:${status}}`);
  8721. }
  8722. /**
  8723. * 画中画功能(悬浮歌词功能)结束
  8724. *
  8725. */
  8726. async doSearchCover(item: VideoItem): Promise<string> {
  8727. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  8728. this.isShowMoreView = false;
  8729. this.showTipsDialog();
  8730. return ''; // Return empty string when no API is configured
  8731. }
  8732. if (!item) {
  8733. return ''; // Return empty string if item is undefined
  8734. }
  8735. const artist = item?.artist || ''; // Use empty string if artist is missing
  8736. return this.searchCover(item, item.name, artist); // Await is not needed here as we return the promise directly
  8737. }
  8738. /**
  8739. *api搜索封面
  8740. *item,根据title和artist
  8741. */
  8742. searchCover(item: VideoItem, title: string, artist: string): Promise<string> {
  8743. return NetAxiosUtil.getLyricCover(title, artist, PreferencesUtil.getStringSync('COVER_API', '')).then(async (res) => {
  8744. LogUtil.debug("onecold res =" + res);
  8745. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  8746. if (item.filePath == this.currentSong?.filePath) {
  8747. this.cover = res;
  8748. if (this.currentSong) {
  8749. this.currentSong.pixelMapPath = res;
  8750. }
  8751. }
  8752. // Update pixel map path but always return res regardless of success
  8753. this.table.updatePixelMapPath(item.filePath, res, (success: boolean, error?: string) => {
  8754. if (success) {
  8755. this.doUpdateData();
  8756. console.log("onecold 更新音乐封面成功,数据库已同步");
  8757. } else {
  8758. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  8759. }
  8760. // Note: We don't resolve/reject here because we already returned res
  8761. });
  8762. LogUtil.debug("onecold this.cover =" + this.cover);
  8763. }
  8764. return res; // Always return res regardless of updatePixelMapPath result
  8765. });
  8766. }
  8767. @State jumpTopTime: number = 0
  8768. @State jumpEndTime: number = 0
  8769. @State isOpenJump: boolean = false
  8770. @Builder
  8771. JumpTopEndSheet() {
  8772. Scroll() {
  8773. Column() {
  8774. Column() {
  8775. Text('仅对本播放列表有效')
  8776. .fontSize(16)
  8777. .fontColor($r('app.color.text_color'))
  8778. // 跳过头尾
  8779. Column() {
  8780. Row() {
  8781. Text('跳过片头:')
  8782. .fontSize(16)
  8783. .fontColor($r('app.color.text_color'))
  8784. Text(this.jumpTopTime + 's')
  8785. .fontSize(16)
  8786. .fontColor($r('app.color.text_color'))
  8787. }
  8788. .margin({ bottom: 5 })
  8789. Row() {
  8790. Slider({
  8791. value: this.jumpTopTime,
  8792. min: 0,
  8793. max: 120,
  8794. step: 1,
  8795. style: SliderStyle.OutSet
  8796. })
  8797. .blockColor(this.themeColor)
  8798. .trackColor($r('app.color.speed_text_color'))
  8799. .selectedColor(Color.White)
  8800. .trackThickness(8)
  8801. .onChange((value: number) => {
  8802. this.jumpTopTime = value;
  8803. })
  8804. .width('85%')
  8805. }
  8806. .alignItems(VerticalAlign.Top)
  8807. }
  8808. .margin({ top: 10, bottom: 10 })
  8809. // 跳过头尾
  8810. Column() {
  8811. Row() {
  8812. Text('跳过片尾:')
  8813. .fontSize(16)
  8814. .fontColor($r('app.color.text_color'))
  8815. Text(this.jumpEndTime + 's')
  8816. .fontSize(16)
  8817. .fontColor($r('app.color.text_color'))
  8818. }
  8819. .margin({ bottom: 5 })
  8820. Row() {
  8821. Slider({
  8822. value: this.jumpEndTime,
  8823. min: 0,
  8824. max: 120,
  8825. step: 1,
  8826. style: SliderStyle.OutSet
  8827. })
  8828. .blockColor(this.themeColor)
  8829. .trackColor($r('app.color.speed_text_color'))
  8830. .selectedColor(Color.White)
  8831. .trackThickness(8)
  8832. .onChange((value: number) => {
  8833. this.jumpEndTime = value;
  8834. })
  8835. .width('85%')
  8836. }
  8837. .alignItems(VerticalAlign.Top)
  8838. }
  8839. .margin({ top: 10, bottom: 10 })
  8840. Row() {
  8841. Button('保存设置')
  8842. .fontColor(Color.White)
  8843. .layoutWeight(1)
  8844. .height(40)
  8845. .width(80)
  8846. .backgroundColor(this.themeColor)
  8847. .stateEffect(true)
  8848. .margin({ left: 0, bottom: 20 })
  8849. .onClick(async () => {
  8850. if (!Utility.isNoble()) {
  8851. this.isJumpSetting = false
  8852. this.isShowMoreView = false
  8853. this.showVipDialog()
  8854. return
  8855. }
  8856. if (this.currentSong === undefined) {
  8857. return
  8858. }
  8859. if (this.modeType === 0) {
  8860. let parentPath = FileUtil.getParentPath(this.videoUrl)
  8861. PreferencesUtil.putSync(parentPath + 'isOpenJump', true)
  8862. PreferencesUtil.putSync(parentPath + 'jumpEndTime', this.jumpEndTime)
  8863. PreferencesUtil.putSync(parentPath + 'jumpTopTime', this.jumpTopTime)
  8864. } else if (this.modeType === 1) { //媒体库
  8865. PreferencesUtil.putSync(1 + 'isOpenJump', true)
  8866. PreferencesUtil.putSync(1 + 'jumpEndTime', this.jumpEndTime)
  8867. PreferencesUtil.putSync(1 + 'jumpTopTime', this.jumpTopTime)
  8868. } else if (this.modeType === 2) { //艺术家
  8869. if (this.currentSong?.artist) {
  8870. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'isOpenJump', true)
  8871. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpEndTime', this.jumpEndTime)
  8872. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpTopTime', this.jumpTopTime)
  8873. }
  8874. } else if (this.modeType === 3) { //专辑
  8875. if (this.currentSong?.album) {
  8876. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'isOpenJump', true)
  8877. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpEndTime', this.jumpEndTime)
  8878. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpTopTime', this.jumpTopTime)
  8879. }
  8880. }
  8881. ToastUtil.showShort("保存成功")
  8882. this.isJumpSetting = false
  8883. })
  8884. }
  8885. .margin({
  8886. left: 38,
  8887. right: 38,
  8888. top: 10,
  8889. bottom: 10
  8890. })
  8891. .width(120)
  8892. .height(50)
  8893. }
  8894. }
  8895. }
  8896. .width('100%')
  8897. .height('100%')
  8898. }
  8899. // 应用可以通过onStateChange接口监听组件显示/消失状态,当组件显示时建议不要销毁AVCastPicker的显示;当组件消失时,再根据业务隐藏AVCastPicker。
  8900. private onStateVastChange(state: AVCastPickerState) {
  8901. if (state == AVCastPickerState.STATE_APPEARING) {
  8902. console.log('The picker starts showing.');
  8903. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  8904. console.log('The picker finishes presenting.');
  8905. }
  8906. }
  8907. private showSelectLyric() {
  8908. DialogHelper.showActionSheetDialog({
  8909. title: '温馨提醒:\n1.歌词文件名必须和目标歌曲文件名相同\n2.歌词文件和目标歌曲要同个歌单路径。',
  8910. // sheets: ["本地歌词", "搜索歌词"],
  8911. sheets: [
  8912. { value: "本地歌词", fontColor: $r('app.color.text_color') },
  8913. { value: "搜索歌词", fontColor: $r('app.color.text_color') },
  8914. ],
  8915. maskColor: Color.Transparent,
  8916. backgroundColor: $r('app.color.bg_card'),
  8917. transition: AnimationHelper.transitionInDown(666),
  8918. onAction: (index) => {
  8919. switch (index) {
  8920. case 0:
  8921. this.callFilePickerSelectFileForLyric()
  8922. break;
  8923. case 1:
  8924. if (StrUtil.isNotEmpty(this.videoUrl)) {
  8925. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  8926. this.initLyric(lyricPath);
  8927. }
  8928. break;
  8929. }
  8930. }
  8931. })
  8932. }
  8933. // 拉起picker选择文件管理器
  8934. async callFilePickerSelectFileForLyric(): Promise<void> {
  8935. try {
  8936. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  8937. DocumentSelectOptions.maxSelectNumber = 1
  8938. DocumentSelectOptions.fileSuffixFilters = CommonConstants.LYRIC_FORMAT
  8939. let documentPicker = new picker.DocumentViewPicker();
  8940. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  8941. Logger.info(TAG,
  8942. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  8943. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  8944. this.saveVideoDatasLyric(DocumentSelectResult)
  8945. }
  8946. }).catch((err: BusinessError) => {
  8947. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  8948. });
  8949. } catch (err) {
  8950. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  8951. }
  8952. }
  8953. async saveVideoDatasLyric(uris: string[]) {
  8954. if (ArrayUtil.isEmpty(uris)) {
  8955. return
  8956. }
  8957. let newUris: string[] = [];
  8958. for (let i = 0; i < uris.length; i++) {
  8959. let filePath = getContext(this).filesDir + '/' + Utility.getMediaNameByUri(uris[i])
  8960. Logger.info(TAG, 'filePath uri: ' + filePath);
  8961. newUris.push(filePath)
  8962. let file = fileIo.openSync(uris[i], fileIo.OpenMode.READ_ONLY)
  8963. let file2 = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  8964. fileIo.copyFileSync(file.fd, file2.fd)
  8965. fileIo.closeSync(file);
  8966. fileIo.closeSync(file2);
  8967. this.initLyric(filePath)
  8968. }
  8969. }
  8970. private initDelayPlay(context: object) {
  8971. this.mContext = context;
  8972. }
  8973. startPipLyric() {
  8974. if (this.pipController) {
  8975. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  8976. PiPWindow.PiPControlStatus.PLAY);
  8977. }
  8978. this.isOpenPip = PreferencesUtil.getBooleanSync('isOpenPip', false)
  8979. if (this.isOpenPip) {
  8980. this.startPip()
  8981. } else {
  8982. this.stopPip()
  8983. }
  8984. }
  8985. private startPlayOrResumePlay() {
  8986. this.startPipLyric()
  8987. this.mDestroyPage = false;
  8988. this.animationState = AnimationStatus.Running
  8989. LogUtils.getInstance().LOGI("startPlayOrResumePlay start this.CONTROL_PlayStatus:" + this.CONTROL_PlayStatus)
  8990. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  8991. this.stopProgressTask();
  8992. this.startProgressTask();
  8993. this.play(this.videoUrl.toString());
  8994. }
  8995. if (this.CONTROL_PlayStatus == PlayStatus.PAUSE) {
  8996. this.mIjkMediaPlayer.start();
  8997. this.setProgress()
  8998. this.CONTROL_PlayStatus = PlayStatus.PLAY
  8999. }
  9000. this.setIsPlaying(true)
  9001. this.updateSessionPlayState(true)
  9002. this.watchStatus();
  9003. this.updateLastPlayTimeStr(this.videoUrl)
  9004. }
  9005. updateLastPlayTimeStr(filePath: string) {
  9006. let lastPlayTime = DateUtil.getTodayStr('yyyy-MM-dd HH:mm:ss')
  9007. this.table.updateLastPlayedStrByFilePath(filePath, lastPlayTime, (success: boolean, error?: string) => {
  9008. if (success) {
  9009. this.getHistoryList(false)
  9010. console.log(" onecold 更新最近播放时间成功,数据库已同步");
  9011. } else {
  9012. console.error(" onecold 更新最近播放时间数据库失败原因: " + error);
  9013. }
  9014. });
  9015. }
  9016. private completionNum(num: number): string | number {
  9017. if (num < 10) {
  9018. return '0' + num;
  9019. } else {
  9020. return num;
  9021. }
  9022. }
  9023. private stringForTime(timeMs: number): string {
  9024. let totalSeconds: number | string = (timeMs / 1000);
  9025. let newSeconds: number | string = totalSeconds % 60;
  9026. let minutes: number | string = (totalSeconds / 60) % 60;
  9027. let hours: number | string = totalSeconds / 3600;
  9028. //LogUtils.getInstance().LOGI("stringForTime hours:" + hours + ",minutes:" + minutes + ",seconds:" + newSeconds);
  9029. hours = this.completionNum(Math.floor(Math.floor(hours * 100) / 100));
  9030. minutes = this.completionNum(Math.floor(Math.floor(minutes * 100) / 100));
  9031. newSeconds = Math.floor(Math.floor(newSeconds * 100) / 100)
  9032. if (this.isCurrentTime) {
  9033. if (this.oldSeconds < newSeconds || newSeconds === 0 || this.isSeekTo) {
  9034. this.oldSeconds = newSeconds
  9035. } else {
  9036. newSeconds = this.oldSeconds
  9037. }
  9038. }
  9039. newSeconds = this.completionNum(newSeconds);
  9040. if (hours > 0) {
  9041. return hours + ":" + minutes + ":" + newSeconds;
  9042. } else {
  9043. return minutes + ":" + newSeconds;
  9044. }
  9045. }
  9046. private setProgress() {
  9047. let position = this.mIjkMediaPlayer.getCurrentPosition();
  9048. let duration = this.mIjkMediaPlayer.getDuration();
  9049. let pos = 0;
  9050. if (duration > 0) {
  9051. this.slideEnable = true;
  9052. let curPercent = position / duration;
  9053. pos = curPercent * 100;
  9054. if (pos > this.PROGRESS_MAX_VALUE) {
  9055. this.progressValue = this.PROGRESS_MAX_VALUE
  9056. } else {
  9057. this.progressValue = pos;
  9058. }
  9059. }
  9060. // LogUtils.getInstance()
  9061. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  9062. this.totalTime = this.stringForTime(duration);
  9063. if (position > duration) {
  9064. position = duration;
  9065. }
  9066. this.isCurrentTime = true;
  9067. this.lyricController.updatePosition(position + this.timeOffset * 1000)
  9068. this.lyricControllerXF.updatePosition(position + this.timeOffset * 1000)
  9069. this.lyricControllerSingle.updatePosition(position + this.timeOffset * 1000)
  9070. this.currentTime = this.stringForTime(position);
  9071. this.isCurrentTime = false
  9072. if (this.mIjkMediaPlayer.isPlaying()) {
  9073. this.randomColor =
  9074. `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
  9075. // 判断是否播放到结束时间
  9076. if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
  9077. if (position >= duration - this.jumpEndTime * 1000) {
  9078. this.playNext()
  9079. }
  9080. }
  9081. } else {
  9082. this.randomColor = 'rbg(0,0,0)'
  9083. }
  9084. }
  9085. private startProgressTask() {
  9086. let that = this;
  9087. this.updateProgressTimer = setInterval(() => {
  9088. //LogUtils.getInstance().LOGI("startProgressTask");
  9089. if (!that.mDestroyPage) {
  9090. that.setProgress();
  9091. }
  9092. }, 300);
  9093. }
  9094. private stopProgressTask() {
  9095. LogUtils.getInstance().LOGI("stopProgressTask");
  9096. clearInterval(this.updateProgressTimer);
  9097. }
  9098. private showLoadIng() {
  9099. this.loadingVisible = Visibility.Visible;
  9100. this.replayVisible = Visibility.None;
  9101. }
  9102. private hideLoadIng() {
  9103. this.loadingVisible = Visibility.None;
  9104. this.replayVisible = Visibility.None;
  9105. }
  9106. private showRePlay() {
  9107. this.loadingVisible = Visibility.None;
  9108. this.replayVisible = Visibility.Visible;
  9109. }
  9110. private async play(url: string) {
  9111. let that = this;
  9112. that.showLoadIng();
  9113. //设置XComponent回调的context
  9114. if (!!this.mContext) {
  9115. this.mIjkMediaPlayer.setContext(this.mContext, 'xcomponentId');
  9116. }
  9117. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  9118. this.mIjkMediaPlayer.reset();
  9119. }
  9120. this.CONTROL_PlayStatus = PlayStatus.PLAY;
  9121. //设置debug模式
  9122. this.mIjkMediaPlayer.setDebug(false);
  9123. //初始化配置
  9124. this.mIjkMediaPlayer.native_setup();
  9125. // 初始化配置后需要重新设置音频流音量,否则音量为默认值1.0 针对dsf格式设置最大值1.0
  9126. if(this.videoUrl.toLowerCase().endsWith('.dsf')){
  9127. this.mIjkMediaPlayer.setVolume('1', '1');
  9128. }else{
  9129. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  9130. }
  9131. //设置视频源
  9132. this.mIjkMediaPlayer.setDataSource(url);
  9133. //设置视频源http请求头
  9134. let headers = new Map([
  9135. ["user_agent", "Mozilla/5.0 BiliDroid/7.30.0 (bbcallen@gmail.com)"],
  9136. ["referer", "https://www.bilibili.com"]
  9137. ]);
  9138. this.mIjkMediaPlayer.setDataSourceHeader(headers);
  9139. // if(PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN,false)){
  9140. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", "1"); // 启用硬件解码,会导致无法顺序播放
  9141. // }
  9142. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  9143. //使用精确寻帧 例如,拖动播放后,会寻找最近的关键帧进行播放,很有可能关键帧的位置不是拖动后的位置,而是较前的位置.可以设置这个参数来解决问题
  9144. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", "1");
  9145. const fileSize = await this.getFileSize(this.videoUrl);
  9146. let bufferSize = 1 * 1024 ; // 默认缓冲区大小为1MB
  9147. if (fileSize > 3 * 1024 * 1024 * 1024) { // 文件大于3GB
  9148. bufferSize = 25 * 1024 * 1024; // 设置缓冲区大小为25MB
  9149. }
  9150. // 使用软件解码(通常比硬件解码更节省内存)
  9151. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", '0');
  9152. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", '0');
  9153. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", '1024');
  9154. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", '500000');
  9155. //预读数据的缓冲区大小.修复大文件播放前几秒挂掉的bug,太大了会导致倍数播放失效
  9156. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", bufferSize + '');
  9157. //停止预读的最小帧数
  9158. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100");
  9159. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", '1'); ////重连模式,如果中途服务器断开了连接,让它重新连接
  9160. // 设置其他缓冲相关选项
  9161. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100"); // 设置最小缓冲帧数
  9162. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-frames", "1000"); // 设置最大缓冲
  9163. //启动预加载
  9164. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", "1");
  9165. // 设置无缓冲,这是播放器的缓冲区,有数据就播放
  9166. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", "0");
  9167. //跳帧处理,放CPU处理较慢时,进行跳帧处理,保证播放流程,画面和声音同步
  9168. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", "5");
  9169. // 最大缓冲cache是3s, 有时候网络波动,会突然在短时间内收到好几秒的数据
  9170. // 因此需要播放器丢包,才不会累积延时
  9171. // 这个和第三个参数packet-buffering无关。
  9172. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max_cached_duration", "3000");
  9173. // 无限制收流
  9174. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1");
  9175. this.mIjkMediaPlayer.setOptionLong(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1")
  9176. // 屏幕常亮
  9177. this.mIjkMediaPlayer.setScreenOnWhilePlaying(true);
  9178. // 设置超时
  9179. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", "10000000");
  9180. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "connect_timeout", "10000000");
  9181. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "addrinfo_timeout", "10000000");
  9182. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_timeout", "10000000");
  9183. // 变速播放
  9184. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", "1");
  9185. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  9186. let Speed = this.mIjkMediaPlayer.getSpeed()
  9187. LogUtils.getInstance().LOGI('getSpeed--' + Speed)
  9188. //是否开启循环播放
  9189. // this.mIjkMediaPlayer.setLoopCount(this.loop);
  9190. let mOnVideoSizeChangedListener: OnVideoSizeChangedListener = {
  9191. onVideoSizeChanged: (width: number, height: number, sar_num: number, sar_den: number) => {
  9192. if (height === 0) {
  9193. return;
  9194. }
  9195. const va = width / height;
  9196. const vpa = that.videoParentAspectRatio;
  9197. if (vpa > va) {
  9198. that.videoWidth = (width / (height * vpa)) * 100 + '%';
  9199. } else {
  9200. that.videoWidth = '100%';
  9201. }
  9202. if (width && height) {
  9203. that.videoAspectRatio = width / height;
  9204. }
  9205. LogUtils.getInstance()
  9206. .LOGI("setOnVideoSizeChangedListener-->go:" + width + "," + height + "," + sar_num + "," + sar_den);
  9207. that.hideLoadIng();
  9208. }
  9209. }
  9210. this.mIjkMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
  9211. let mOnPreparedListener: OnPreparedListener = {
  9212. onPrepared: async () => {
  9213. LogUtils.getInstance().LOGI("setOnPreparedListener-->go");
  9214. try {
  9215. // this.cover = this.songList[this.curIndex].pixelMapPath
  9216. // this.artist = this.songList[this.curIndex].artist
  9217. // this.videoUrl = this.songList[this.curIndex].filePath
  9218. let isBgCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  9219. if (isBgCover && this.cover !== undefined && StrUtil.isNotEmpty(this.cover)) {
  9220. this.setImageColor2(this.cover)
  9221. } else {
  9222. this.getImageColor();
  9223. }
  9224. //保存碰一碰分享的当前的歌曲
  9225. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  9226. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  9227. await this.initLyric(lyricPath);
  9228. setTimeout(() => {
  9229. this.avSessionController.initAvSession(false);
  9230. this.avSessionController.setAVMetadataMusic(this.songList[this.curIndex], this.duration, this.lyricContent);
  9231. this.setAvSessionListener();
  9232. this.updateSessionPlayState(true)
  9233. this.setCurrentPlayMode()
  9234. }, 500)
  9235. //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9236. let timeoutPlay = 0
  9237. if (StrUtil.isNotEmpty(this.videoUrl) &&
  9238. (this.videoUrl.toLowerCase().endsWith('.rmvb') || this.videoUrl.toLowerCase().endsWith('.flac'))) {
  9239. timeoutPlay = 1000
  9240. }
  9241. //跳过片头片尾关键代码,以下是跳过片头的关键代码
  9242. if (this.modeType === 0) { //文件夹
  9243. let parentPath = FileUtil.getParentPath(this.videoUrl)
  9244. this.jumpTopTime = PreferencesUtil.getNumberSync(parentPath + 'jumpTopTime')
  9245. this.jumpEndTime = PreferencesUtil.getNumberSync(parentPath + 'jumpEndTime')
  9246. this.isOpenJump = PreferencesUtil.getBooleanSync(parentPath + 'isOpenJump', false)
  9247. } else if (this.modeType === 1) { //媒体库
  9248. this.jumpTopTime = PreferencesUtil.getNumberSync(1 + 'jumpTopTime')
  9249. this.jumpEndTime = PreferencesUtil.getNumberSync(1 + 'jumpEndTime')
  9250. this.isOpenJump = PreferencesUtil.getBooleanSync(1 + 'isOpenJump', false)
  9251. } else if (this.modeType === 2) { //艺术家
  9252. if (this.currentSong?.artist) {
  9253. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpTopTime')
  9254. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpEndTime')
  9255. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.artist + 2 + 'isOpenJump', false)
  9256. }
  9257. } else if (this.modeType === 3) { //专辑
  9258. if (this.currentSong?.album) {
  9259. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpTopTime')
  9260. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpEndTime')
  9261. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.album + 3 + 'isOpenJump', false)
  9262. }
  9263. }
  9264. this.duration = this.mIjkMediaPlayer.getDuration()
  9265. if (this.isOpenJump) { //用户是否设置跳过片头片尾
  9266. if (this.mIjkMediaPlayer != null) {
  9267. if (this.jumpTopTime * 1000 <= this.duration) {
  9268. // 调用 seekTo 方法,跳到指定时间
  9269. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9270. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  9271. this.seekTo(this.jumpTopTime * 1000 + ""); // 跳到开头
  9272. }
  9273. }, timeoutPlay)
  9274. } else {
  9275. // 提示用户无法跳过
  9276. ToastUtil.showToast('跳过时间超过视频时长');
  9277. }
  9278. }
  9279. } else {
  9280. this.jumpTopTime = 0
  9281. this.jumpEndTime = 0
  9282. console.error('onecold 最后一首: isFirstStartPlay = ' + this.isFirstStartPlay);
  9283. console.error('onecold 最后一首: isMemoryLastPlay = ' + this.isMemoryLastPlay);
  9284. console.error('onecold 最后一首: PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false) = ' +
  9285. PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false));
  9286. //记忆播放(每一首都会记忆播放)
  9287. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  9288. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9289. if (PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)) {
  9290. this.restorePlaybackPosition() //读取播放记忆功能
  9291. } else if (this.isMemoryLastPlay && this.isFirstStartPlay) {
  9292. console.error('onecold 最后一首:读取播放记忆功能 = ' + this.isFirstStartPlay);
  9293. this.restorePlaybackPosition() //读取播放记忆功能
  9294. }
  9295. this.isFirstStartPlay = false
  9296. }, timeoutPlay)
  9297. } else {
  9298. this.isFirstStartPlay = false
  9299. }
  9300. }
  9301. this.saveLastPlayList()
  9302. } catch (error) {
  9303. let err: BusinessError = error as BusinessError;
  9304. console.error('onecold failed with err: ' + JSON.stringify(err));
  9305. }
  9306. }
  9307. }
  9308. this.mIjkMediaPlayer.setOnPreparedListener(mOnPreparedListener);
  9309. let mOnTimedTextListener: OnTimedTextListener = {
  9310. onTimedText: () => {
  9311. }
  9312. }
  9313. this.mIjkMediaPlayer.setOnTimedTextListener(mOnTimedTextListener)
  9314. let mOnCompletionListener: OnCompletionListener = {
  9315. onCompletion: () => {
  9316. LogUtils.getInstance().LOGI("OnCompletionListener-->go")
  9317. if (this.playType == 0) { //0:连续播放 1:单片重复播放 2:正常播放
  9318. this.playNext()
  9319. } else if (this.playType == 1) { //1:单片重复播放
  9320. this.CONTROL_PlayStatus = PlayStatus.INIT
  9321. that.startPlayOrResumePlay();
  9322. } else if (this.playType == 2) { //2:正常播放,单曲播完
  9323. that.showRePlay();
  9324. that.currentTime = that.stringForTime(this.mIjkMediaPlayer.getDuration());
  9325. that.progressValue = this.PROGRESS_MAX_VALUE;
  9326. that.slideEnable = false;
  9327. that.stop();
  9328. // ToastUtil.showToast('开始重新播放')
  9329. } else if (this.playType == 3) { //3:随机播放
  9330. this.randomPlay()
  9331. }
  9332. }
  9333. }
  9334. this.mIjkMediaPlayer.setOnCompletionListener(mOnCompletionListener);
  9335. let mOnBufferingUpdateListener: OnBufferingUpdateListener = {
  9336. onBufferingUpdate: (percent: number) => {
  9337. LogUtils.getInstance().LOGI("OnBufferingUpdateListener-->go:" + percent);
  9338. let MediaInfo = this.mIjkMediaPlayer.getMediaInfo()
  9339. LogUtils.getInstance().LOGI('getMediaInfo---' + MediaInfo);
  9340. let VideoWidth = this.mIjkMediaPlayer.getVideoWidth()
  9341. LogUtils.getInstance().LOGI('getVideoWidth---' + VideoWidth);
  9342. let VideoHeight = this.mIjkMediaPlayer.getVideoHeight()
  9343. LogUtils.getInstance().LOGI('getVideoHeight---' + VideoHeight);
  9344. let VideoSarNum = this.mIjkMediaPlayer.getVideoSarNum()
  9345. LogUtils.getInstance().LOGI('getVideoSarNum---' + VideoSarNum);
  9346. let VideoSarDen = this.mIjkMediaPlayer.getVideoSarDen()
  9347. LogUtils.getInstance().LOGI('getVideoSarDen---' + VideoSarDen);
  9348. let AudioSessionId = this.mIjkMediaPlayer.getAudioSessionId()
  9349. LogUtils.getInstance().LOGI('getAudioSessionId---' + AudioSessionId);
  9350. let Looping = this.mIjkMediaPlayer.isLooping()
  9351. LogUtils.getInstance().LOGI('isLooping---' + Looping);
  9352. }
  9353. }
  9354. this.mIjkMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
  9355. let mOnSeekCompleteListener: OnSeekCompleteListener = {
  9356. onSeekComplete: () => {
  9357. LogUtils.getInstance().LOGI("OnSeekCompleteListener-->go");
  9358. that.startPlayOrResumePlay();
  9359. }
  9360. }
  9361. this.mIjkMediaPlayer.setOnSeekCompleteListener(mOnSeekCompleteListener);
  9362. let mOnInfoListener: OnInfoListener = {
  9363. onInfo: (what: number, extra: number) => {
  9364. LogUtils.getInstance().LOGI("OnInfoListener-->go:" + what + "===" + extra);
  9365. that.hideLoadIng();
  9366. }
  9367. }
  9368. this.mIjkMediaPlayer.setOnInfoListener(mOnInfoListener);
  9369. let mOnErrorListener: OnErrorListener = {
  9370. onError: (what: number, extra: number) => {
  9371. this.stopProgressTask();
  9372. LogUtils.getInstance().LOGI("OnErrorListener-->go:" + what + "===" + extra + " this.videoUrl=" + this.videoUrl)
  9373. that.hideLoadIng();
  9374. if (StrUtil.isNotEmpty(this.videoUrl) && !FileUtil.accessSync(this.videoUrl)) {
  9375. ToastUtil.showToast(Utility.resourceToString(getContext(), $r('app.string.file_not_exist')))
  9376. } else {
  9377. ToastUtil.showToast(getContext()
  9378. .resourceManager
  9379. .getStringByNameSync("Honey_the_video_is_playing_errant_The_system_is_wandering"))
  9380. }
  9381. }
  9382. }
  9383. this.mIjkMediaPlayer.setOnErrorListener(mOnErrorListener);
  9384. this.mIjkMediaPlayer.setMessageListener();
  9385. this.mIjkMediaPlayer.prepareAsync();
  9386. this.mIjkMediaPlayer.start();
  9387. }
  9388. //保存最后播放的那首歌和已经对应的播放列表
  9389. saveLastPlayList() {
  9390. PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
  9391. PreferencesUtil.putSync('LastMusicList', this.songList)
  9392. }
  9393. // 清空播放记录
  9394. clearVideoHistory() {
  9395. this.table.clearPlayHistory((success: boolean, error?: string) => {
  9396. if (success) {
  9397. this.historyList = [];
  9398. this.updateListData(this.historyList)
  9399. // PreferencesUtil.putSync(LocalMusic.HISTORY_MUSIC, this.historyList)
  9400. ToastUtil.showToast('清空播放记录成功')
  9401. } else {
  9402. console.error(" onecold 清空播放记录数据库失败原因: " + error);
  9403. }
  9404. });
  9405. }
  9406. public async setAvSessionListener() {
  9407. if (!this.avSessionController) {
  9408. return;
  9409. }
  9410. this.avSessionController.getAvSession()?.on('play', this.sessionPlayCallback);
  9411. this.avSessionController.getAvSession()?.on('pause', this.sessionPauseCallback);
  9412. this.avSessionController.getAvSession()?.on('stop', this.sessionStopCallback);
  9413. this.avSessionController.getAvSession()?.on('playNext', this.sessionPlayNextCallback);
  9414. this.avSessionController.getAvSession()?.on('playPrevious', this.sessionPlayPreviousCallback);
  9415. this.avSessionController.getAvSession()?.on('fastForward', this.sessionFastForwardCallback);
  9416. this.avSessionController.getAvSession()?.on('rewind', this.sessionRewindCallback);
  9417. this.avSessionController.getAvSession()?.on('seek', this.sessionSeekCallback);
  9418. this.avSessionController.getAvSession()?.on('setLoopMode', this.sessionSetLoopModeCallback);
  9419. this.avSessionController.getAvSession()?.on('toggleFavorite', this.sessionToggleFavoriteCallback);
  9420. this.avSessionController.getAvSession()?.on('outputDeviceChange', this.sessionOutputDeviceChange)
  9421. }
  9422. setLoopMode() {
  9423. let itype = this.playType + 1
  9424. if (itype >= 4) {
  9425. this.playType = 0
  9426. ToastUtil.showToast('连续播放')
  9427. } else if (itype === 1) {
  9428. this.playType = 1
  9429. ToastUtil.showToast('单曲循环')
  9430. } else if (itype === 2) {
  9431. this.playType = 2
  9432. ToastUtil.showToast('单曲播完')
  9433. } else if (itype === 3) {
  9434. this.playType = 3
  9435. ToastUtil.showToast('随机播放')
  9436. } else if (itype === 0) {
  9437. this.playType = 0
  9438. ToastUtil.showToast('连续播放')
  9439. }
  9440. PreferencesUtil.putSync('musicPlayType', this.playType)
  9441. this.setCurrentPlayMode()
  9442. }
  9443. private sessionSetLoopModeCallback = (mode: number) => {
  9444. if (this.mIjkMediaPlayer != null) {
  9445. ToastUtil.showToast('当前播放模式:' + mode)
  9446. Logger.info('onecold 当前播放模式= ' + mode)
  9447. let hmPlayMode = mode + 1
  9448. if (hmPlayMode >= 4) {
  9449. hmPlayMode = 0
  9450. }
  9451. if (hmPlayMode === 1) {
  9452. this.playType = 1
  9453. ToastUtil.showToast('单曲循环')
  9454. } else if (hmPlayMode === 0) {
  9455. this.playType = 2
  9456. ToastUtil.showToast('单曲播完')
  9457. } else if (hmPlayMode === 3) {
  9458. this.playType = 3
  9459. ToastUtil.showToast('随机播放')
  9460. } else if (hmPlayMode === 2) {
  9461. this.playType = 0
  9462. ToastUtil.showToast('连续播放')
  9463. }
  9464. PreferencesUtil.putSync('musicPlayType', this.playType)
  9465. // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
  9466. let playBackState: avSession.AVPlaybackState = {
  9467. loopMode: hmPlayMode,
  9468. };
  9469. this.avSessionController.getAvSession()?.setAVPlaybackState(playBackState).then(() => {
  9470. console.info(`set setLoopMode AVPlaybackState successfully`);
  9471. }).catch((err: BusinessError) => {
  9472. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  9473. });
  9474. }
  9475. }
  9476. setCurrentPlayMode() {
  9477. if (!this.avSessionController) {
  9478. return;
  9479. }
  9480. let mLoopMode = 0
  9481. switch (this.playType) {
  9482. case 0:
  9483. mLoopMode = avSession.LoopMode.LOOP_MODE_LIST //连续播放
  9484. break;
  9485. case 1:
  9486. mLoopMode = avSession.LoopMode.LOOP_MODE_SINGLE //单曲
  9487. break;
  9488. case 2:
  9489. mLoopMode = avSession.LoopMode.LOOP_MODE_SEQUENCE //正常播放
  9490. break;
  9491. case 3:
  9492. mLoopMode = avSession.LoopMode.LOOP_MODE_SHUFFLE //随机播放
  9493. break;
  9494. }
  9495. // 应用启动时/内部切换循环模式,需要把应用内的当前的循环模式设置给AVSession。
  9496. let playBState: avSession.AVPlaybackState = {
  9497. loopMode: mLoopMode,
  9498. isFavorite: Utility.getIsFav(this.favList, this.currentSong),
  9499. };
  9500. this.avSessionController.getAvSession()?.setAVPlaybackState(playBState).then(() => {
  9501. console.info(`set setLoopMode AVPlaybackState successfully`);
  9502. }).catch((err: BusinessError) => {
  9503. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  9504. });
  9505. }
  9506. private sessionToggleFavoriteCallback = (assetId: string) => {
  9507. if (this.mIjkMediaPlayer != null && this.currentSong) {
  9508. console.info(`on toggleFavorite `);
  9509. // 应用收到收藏命令,进行收藏处理。
  9510. this.isFac = Utility.getIsFav(this.favList, this.currentSong)
  9511. this.doFav(this.currentSong)
  9512. // 应用内完成或者取消收藏,把新的收藏状态设置给AVSession。
  9513. let playbackState: avSession.AVPlaybackState = {
  9514. isFavorite: !this.isFac,
  9515. };
  9516. this.avSessionController.getAvSession()?.setAVPlaybackState(playbackState).then(() => {
  9517. console.info(`SetAVPlaybackState successfully`);
  9518. }).catch((err: BusinessError) => {
  9519. console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  9520. });
  9521. }
  9522. }
  9523. private sessionOutputDeviceChange = async (connectState: avSession.ConnectionState,
  9524. device: avSession.OutputDeviceInfo) => {
  9525. let currentDevice: avSession.DeviceInfo = device?.devices?.[0];
  9526. if (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  9527. connectState === avSession.ConnectionState.STATE_CONNECTED) {
  9528. await this.startCasting();
  9529. } else if ((currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  9530. connectState === avSession.ConnectionState.STATE_DISCONNECTED) ||
  9531. (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_LOCAL &&
  9532. connectState === avSession.ConnectionState.STATE_CONNECTED)) {
  9533. if (device) {
  9534. this.endCasting();
  9535. }
  9536. }
  9537. };
  9538. private async startCasting() {
  9539. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  9540. this.setPlaybackStateChangeListener();
  9541. this.pause();
  9542. this.initQueueItem();
  9543. this.prepare();
  9544. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  9545. refToIsCasting?.set(true);
  9546. this.castSeek = true;
  9547. this.isCastPlaying = true;
  9548. }
  9549. async changeCasting() {
  9550. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  9551. this.initQueueItem();
  9552. this.prepare();
  9553. this.setPlaybackStateChangeListener();
  9554. this.isCastPlaying = true;
  9555. this.castSeek = true;
  9556. }
  9557. public endCasting() {
  9558. this.avSessionController.getAvSession()?.stopCasting();
  9559. this.stopCast();
  9560. this.isCastPlaying = false;
  9561. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  9562. refToIsCasting?.set(false);
  9563. this.pause();
  9564. this.setIsPlaying(false);
  9565. // if (this.curIndex === this.curSource.index) {
  9566. // this.play
  9567. // this.seek(this.currentTime * 1000);
  9568. // this.setIsPlaying(true);
  9569. // } else {
  9570. // this.pauseVideo();
  9571. // this.setIsPlaying(false);
  9572. // }
  9573. }
  9574. public setIsPlaying(isPlayer: boolean) {
  9575. this.isPlaying = isPlayer;
  9576. }
  9577. private setPlaybackStateChangeListener(): void {
  9578. this.castController?.on('playbackStateChange', 'all', this.playbackStateChangeListener);
  9579. this.castController?.on('endOfStream', this.reloadCasting);
  9580. this.castController?.on('playNext', this.playNextCallback);
  9581. this.castController?.on('playPrevious', this.playPreviousCallback);
  9582. }
  9583. private updateSessionPlayState(isPlay: boolean): void {
  9584. // if(!this.isBgPlayOpen)
  9585. // return
  9586. Logger.info(TAG, `updateIsPlay isPlay: ${isPlay}`);
  9587. this.setAVSessionPlayState({
  9588. state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
  9589. position: {
  9590. elapsedTime: this.mIjkMediaPlayer.getCurrentPosition(),
  9591. updateTime: new Date().getTime()
  9592. }
  9593. });
  9594. }
  9595. private setAVSessionPlayState(playbackState: avSession.AVPlaybackState): void {
  9596. this.avSessionController.setAvSessionPlayState(playbackState)
  9597. }
  9598. private positionChange(position: number) {
  9599. this.currentTime2 = position / 1000;
  9600. this.currentStringTime = secondToTime(Math.floor(position / 1000));
  9601. }
  9602. private playDurationChange(duration: number) {
  9603. this.duration = duration;
  9604. this.durationTime = Math.floor(this.duration / 1000);
  9605. this.durationStringTime = secondToTime((this.durationTime));
  9606. }
  9607. private playbackStateChangeListener = (playbackState: avSession.AVPlaybackState) => {
  9608. const duration = playbackState?.extras?.duration;
  9609. if (typeof duration === 'number') {
  9610. this.playDurationChange(duration as number);
  9611. }
  9612. if (typeof playbackState?.position?.elapsedTime !== 'undefined') {
  9613. this.positionChange(playbackState?.position?.elapsedTime);
  9614. }
  9615. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PAUSE ||
  9616. playbackState.state === CommonConstants2.PLAYBACK_STATE_STOP ||
  9617. playbackState.state === CommonConstants2.PLAYBACK_STATE_PREPARE ||
  9618. playbackState.state === CommonConstants2.PLAYBACK_STATE_INITIAL) {
  9619. this.isCastPlaying = false;
  9620. }
  9621. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PLAY) {
  9622. this.isCastPlaying = true;
  9623. }
  9624. };
  9625. private reloadCasting = async () => {
  9626. let item = this.songList[this.curIndex];
  9627. let uri = fileUri.getUriFromPath(item.filePath);
  9628. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  9629. // description.startPosition = 0;
  9630. this.castItem = {
  9631. itemId: this.curIndex,
  9632. description: {
  9633. assetId: item.filePath,
  9634. title: item.name,
  9635. artist: '',
  9636. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  9637. // mediaUri: item.filePath,
  9638. fdSrc: {
  9639. fd: file.fd
  9640. },
  9641. // 该字段大写,音频'AUDIO',视频'VIDEO'
  9642. mediaType: 'VIDEO',
  9643. mediaSize: item.videoSize,
  9644. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  9645. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  9646. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  9647. duration: this.duration,
  9648. // albumCoverUri: 'https://www.example.jpeg',
  9649. // albumTitle: '《ExampleAlbum》',
  9650. appName: this.appName,
  9651. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  9652. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  9653. }
  9654. };
  9655. this.prepare();
  9656. this.isCastPlaying = true;
  9657. };
  9658. public playNextCallback = (): void => {
  9659. this.playNext()
  9660. };
  9661. public playPreviousCallback = (): void => {
  9662. this.playPrevious()
  9663. };
  9664. async prepare() {
  9665. await this.castController?.prepare(this.castItem);
  9666. await this.castController?.start(this.castItem);
  9667. }
  9668. public initQueueItem() {
  9669. let item = this.songList[this.curIndex];
  9670. let time = this.currentTime;
  9671. let uri = fileUri.getUriFromPath(item.filePath);
  9672. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  9673. this.castItem = {
  9674. itemId: this.curIndex,
  9675. description: {
  9676. assetId: item.filePath,
  9677. title: item.name,
  9678. artist: '',
  9679. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  9680. fdSrc: {
  9681. fd: file.fd
  9682. },
  9683. // 该字段大写,音频'AUDIO',视频'VIDEO'
  9684. mediaType: 'AUDIO',
  9685. mediaSize: item.videoSize,
  9686. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  9687. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  9688. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  9689. duration: this.duration,
  9690. // albumCoverUri: 'https://www.example.jpeg',
  9691. // albumTitle: '《ExampleAlbum》',
  9692. appName: this.appName,
  9693. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  9694. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  9695. }
  9696. };
  9697. }
  9698. async stopCast() {
  9699. try {
  9700. this.castController?.off('playbackStateChange');
  9701. this.castController?.off('endOfStream');
  9702. this.castController?.off('playNext');
  9703. this.castController?.off('playPrevious');
  9704. this.castController?.off('error');
  9705. } catch (error) {
  9706. hilog.info(0x0000, TAG, `Failed to setAVCastController. code: ${error.code}, message: ${error.message}`);
  9707. }
  9708. }
  9709. private sessionPlayCallback = (): void => {
  9710. this.playOrPause()
  9711. };
  9712. private sessionPauseCallback = (): void => {
  9713. this.playOrPause()
  9714. };
  9715. private playOrPause() {
  9716. if (!this.debounce()) {
  9717. return;
  9718. }
  9719. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  9720. this.pause();
  9721. } else {
  9722. this.startPlayOrResumePlay();
  9723. this.playChange()
  9724. }
  9725. }
  9726. private sessionPlayNextCallback = (): void => {
  9727. this.playNext()
  9728. };
  9729. private sessionPlayPreviousCallback = (): void => {
  9730. this.playPrevious()
  9731. };
  9732. private sessionStopCallback = (): void => {
  9733. this.stop()
  9734. };
  9735. private sessionFastForwardCallback = (time?: number) => {
  9736. if (!time) {
  9737. return;
  9738. }
  9739. if (this.mIjkMediaPlayer != null) {
  9740. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9741. let seeTime = curPosition + time * 1000;
  9742. // 限制 seekValue 在合法范围内
  9743. if (seeTime < 0) {
  9744. seeTime = 0;
  9745. } else if (seeTime > this.duration) {
  9746. seeTime = this.duration;
  9747. }
  9748. Logger.info('onecold seeTime= ' + seeTime)
  9749. this.setSeekToActionProgress(seeTime)
  9750. this.seekTo(seeTime + "")
  9751. }
  9752. };
  9753. /**
  9754. * Gesture method onActionUpdate.
  9755. *
  9756. * @param event Gesture event.手势拖动设置快进和后退
  9757. */
  9758. private setSeekToActionProgress(position: number) {
  9759. // let position = this.mIjkMediaPlayer.getCurrentPosition();
  9760. let duration = this.mIjkMediaPlayer.getDuration();
  9761. let pos = 0;
  9762. if (duration > 0) {
  9763. this.slideEnable = true;
  9764. let curPercent = position / duration;
  9765. pos = curPercent * 100;
  9766. if (pos > this.PROGRESS_MAX_VALUE) {
  9767. this.progressValue = this.PROGRESS_MAX_VALUE
  9768. } else {
  9769. this.progressValue = pos;
  9770. }
  9771. }
  9772. // LogUtils.getInstance()
  9773. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  9774. this.totalTime = this.stringForTime(duration);
  9775. if (position > duration) {
  9776. position = duration;
  9777. }
  9778. this.isCurrentTime = true;
  9779. this.currentTime = this.stringForTime(position);
  9780. this.isCurrentTime = false
  9781. }
  9782. private sessionRewindCallback = (time?: number) => {
  9783. if (!time) {
  9784. return;
  9785. }
  9786. if (this.mIjkMediaPlayer != null) {
  9787. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9788. let seeTime = curPosition - time * 1000;
  9789. // 限制 seekValue 在合法范围内
  9790. if (seeTime < 0) {
  9791. seeTime = 0;
  9792. } else if (seeTime > this.duration) {
  9793. seeTime = this.duration;
  9794. }
  9795. Logger.info('onecold seeTime= ' + seeTime)
  9796. this.setSeekToActionProgress(seeTime)
  9797. this.seekTo(seeTime + "")
  9798. }
  9799. };
  9800. private sessionSeekCallback = (seekTime: number) => {
  9801. if (this.mIjkMediaPlayer != null) {
  9802. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9803. this.seekTo(seekTime + "")
  9804. }
  9805. };
  9806. private async getFileSize(filePath: string): Promise<number> {
  9807. try {
  9808. const stat = await fs.stat(filePath);
  9809. return stat.size;
  9810. } catch (err) {
  9811. console.error('Failed to get file size: ' + err.message);
  9812. return 0;
  9813. }
  9814. }
  9815. private pause() {
  9816. if (this.mIjkMediaPlayer.isPlaying()) {
  9817. this.savePlaybackPosition();
  9818. this.mIjkMediaPlayer.pause();
  9819. this.setProgress();
  9820. this.mDestroyPage = true;
  9821. this.CONTROL_PlayStatus = PlayStatus.PAUSE;
  9822. this.updateSessionPlayState(false)
  9823. this.playChange()
  9824. if (this.pipController) {
  9825. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  9826. PiPWindow.PiPControlStatus.PAUSE);
  9827. }
  9828. }
  9829. }
  9830. private stop() {
  9831. this.savePlaybackPosition();
  9832. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9833. this.mIjkMediaPlayer.stop();
  9834. this.mIjkMediaPlayer.release();
  9835. this.stopProgressTask();
  9836. this.updateSessionPlayState(false)
  9837. this.playChange()
  9838. this.watchStatus();
  9839. }
  9840. //保持记忆播放功能
  9841. private savePlaybackPosition() {
  9842. if (this.mIjkMediaPlayer != null) {
  9843. const position = this.mIjkMediaPlayer.getCurrentPosition();
  9844. // ToastUtil.showToast('保存记忆播放 = ' + position)
  9845. const duration = this.mIjkMediaPlayer.getDuration();
  9846. const threshold = 5000; // 阈值,单位为毫秒(这里设为5秒)
  9847. // 如果播放位置接近视频末尾,则保存 position 为 0
  9848. const playbackPosition = (duration - position < threshold) ? 0 : position;
  9849. PreferencesUtil.putSync(this.videoUrl, playbackPosition);
  9850. }
  9851. }
  9852. //获取记忆播放功能
  9853. private restorePlaybackPosition() {
  9854. const position: number = PreferencesUtil.getNumberSync(this.videoUrl, 0);
  9855. // ToastUtil.showToast('position = ' + position)
  9856. if (this.mIjkMediaPlayer != null && position > 0) {
  9857. // ToastUtil.showToast('seekTo = ' + position)
  9858. this.seekTo(position + "");
  9859. }
  9860. }
  9861. private seekTo(value: string) {
  9862. if (StrUtil.isNotEmpty(this.videoUrl) && this.videoUrl.toLowerCase().endsWith('.wma')) {
  9863. ToastUtil.showToast('wma格式不支持拖动快进。')
  9864. return
  9865. }
  9866. this.mIjkMediaPlayer.seekTo(value);
  9867. // this.startPlayOrResumePlay()
  9868. // 在这里恢复计时器状态
  9869. this.setProgress()
  9870. // this.startProgressTask();
  9871. }
  9872. // 添加到下一首播放
  9873. private addToNextPlay(song: VideoItem) {
  9874. if (!this.debounce()) {
  9875. return;
  9876. }
  9877. if (this.currentSong) {
  9878. if (this.currentSong === song) {
  9879. ToastUtil.showToast('当前已经在播放这首歌了!')
  9880. return
  9881. }
  9882. }
  9883. // 如果未开始播放或队列为空
  9884. if (this.curIndex === -1 || this.songList.length === 0) {
  9885. this.songList = [song];
  9886. this.curIndex = 0;
  9887. this.doPlay(song)
  9888. return;
  9889. }
  9890. // 插入到当前索引+1的位置
  9891. const insertPos = this.curIndex + 1;
  9892. this.songList.splice(insertPos, 0, song);
  9893. this.songList = [...this.songList]; // 触发状态更新
  9894. this.sonDataSource.pushArrayData(this.songList)
  9895. ToastUtil.showToast('已添加至下一首播放')
  9896. }
  9897. //下一个
  9898. private playNext() {
  9899. if (!this.debounce()) {
  9900. return;
  9901. }
  9902. if (this.playType == 3) { //3:随机播放
  9903. this.randomPlay()
  9904. return;
  9905. }
  9906. if (ArrayUtil.isNotEmpty(this.songList)) {
  9907. if (this.curIndex == this.songList.length - 1) {
  9908. this.curIndex = 0;
  9909. } else {
  9910. this.curIndex++;
  9911. }
  9912. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9913. this.stop();
  9914. this.currentSong = this.songList[this.curIndex]
  9915. this.videoUrl = this.songList[this.curIndex].filePath;
  9916. this.artist = this.songList[this.curIndex].artist
  9917. this.name = this.songList[this.curIndex].name
  9918. //this.cover = this.songList[this.curIndex].pixelMapPath
  9919. this.changeImageAnimation()
  9920. }
  9921. }
  9922. changeImageAnimation() {
  9923. if(this.openSkipSongAnimate){
  9924. // 第一步:淡出动画
  9925. this.getUIContext()?.animateTo({
  9926. duration: 500,
  9927. curve: Curve.EaseOut,
  9928. }, () => {
  9929. this.opacityValueImage = 0.1;
  9930. if(this.isCoverRectangle){
  9931. this.scaleValueImage = 0.88
  9932. }
  9933. });
  9934. // 第二步:切换图片后淡入
  9935. setTimeout(() => {
  9936. this.cover = this.songList[this.curIndex].pixelMapPath
  9937. this.getUIContext()?.animateTo({
  9938. duration: 500,
  9939. curve: Curve.EaseIn,
  9940. }, () => {
  9941. this.opacityValueImage = 1;
  9942. this.scaleValueImage = 1 // 图标恢复到原始大小
  9943. this.startPlayOrResumePlay()
  9944. });
  9945. }, 500);
  9946. }else{
  9947. this.cover = this.songList[this.curIndex].pixelMapPath
  9948. this.startPlayOrResumePlay()
  9949. }
  9950. }
  9951. // 存储已播放的歌曲索引
  9952. private playedIndices: Set<number> = new Set();
  9953. //随机播放
  9954. private randomPlay() {
  9955. // if (!this.debounce()) {
  9956. // return;
  9957. // }
  9958. if (ArrayUtil.isNotEmpty(this.songList)) {
  9959. if (this.songList.length > 3) {
  9960. // 如果所有歌曲都播放过一次,清空已播放索引集合
  9961. if (this.playedIndices.size === this.songList.length) {
  9962. this.playedIndices.clear();
  9963. }
  9964. // 随机选择一个未播放的歌曲索引
  9965. let newIndex: number;
  9966. // 添加超时机制防止无限循环
  9967. let attempt = 0;
  9968. const maxAttempts = 100; // 根据需求调整
  9969. do {
  9970. newIndex = RandomUtil.getRandomNumber(0, this.songList.length - 1);
  9971. attempt++;
  9972. } while (this.playedIndices.has(newIndex) && attempt < maxAttempts);
  9973. if (attempt >= maxAttempts) {
  9974. // 处理无法找到新索引的情况(如随机选择或按顺序播放)
  9975. newIndex = Math.floor(Math.random() * this.songList.length);
  9976. }
  9977. this.curIndex = newIndex;
  9978. this.playedIndices.add(newIndex);
  9979. } else {
  9980. // 当歌曲数量小于或等于3时,直接播放下一首
  9981. if (this.curIndex == this.songList.length - 1) {
  9982. this.curIndex = 0;
  9983. } else {
  9984. this.curIndex++;
  9985. }
  9986. }
  9987. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9988. this.stop();
  9989. this.currentSong = this.songList[this.curIndex];
  9990. this.videoUrl = this.songList[this.curIndex].filePath;
  9991. this.name = this.songList[this.curIndex].name;
  9992. this.artist = this.songList[this.curIndex].artist
  9993. // this.cover = this.songList[this.curIndex].pixelMapPath
  9994. this.changeImageAnimation()
  9995. }
  9996. }
  9997. private playIndex(index: number) {
  9998. if (!this.debounce()) {
  9999. return;
  10000. }
  10001. if (ArrayUtil.isNotEmpty(this.songList)) {
  10002. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10003. this.stop();
  10004. this.currentSong = this.songList[this.curIndex]
  10005. this.videoUrl = this.songList[index].filePath;
  10006. this.name = this.songList[index].name
  10007. this.artist = this.songList[this.curIndex].artist
  10008. this.curIndex = index;
  10009. this.changeImageAnimation()
  10010. }
  10011. }
  10012. //上一个
  10013. private playPrevious() {
  10014. if (!this.debounce()) {
  10015. return;
  10016. }
  10017. if (this.playType == 3) { //3:随机播放的上一首应该应该播放历史记录的第二首
  10018. this.randomModePlayFromHistory()
  10019. return;
  10020. }
  10021. if (this.curIndex == 0) {
  10022. this.curIndex = this.songList.length - 1;
  10023. } else {
  10024. this.curIndex--;
  10025. }
  10026. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10027. this.stop();
  10028. this.currentSong = this.songList[this.curIndex]
  10029. this.videoUrl = this.songList[this.curIndex].filePath;
  10030. this.name = this.songList[this.curIndex].name
  10031. this.artist = this.songList[this.curIndex].artist
  10032. this.changeImageAnimation()
  10033. }
  10034. //随机播放模式下点击上一首: 上一首应该应该播放历史记录的第二首
  10035. private randomModePlayFromHistory() {
  10036. if (this.historyList.length >= 2) {
  10037. // 播放历史记录的第二首
  10038. const prevSong = this.historyList[1];
  10039. this.curIndex = this.songList.findIndex(song => song.filePath === prevSong.filePath);
  10040. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10041. this.stop();
  10042. this.currentSong = prevSong;
  10043. this.videoUrl = prevSong.filePath;
  10044. this.cover = prevSong.pixelMapPath
  10045. this.artist = prevSong.artist
  10046. this.name = prevSong.name;
  10047. this.startPlayOrResumePlay();
  10048. } else {
  10049. // 如果历史记录不足两首,可根据需求处理,这里简单按普通逻辑处理
  10050. if (this.curIndex === 0) {
  10051. this.curIndex = this.songList.length - 1;
  10052. } else {
  10053. this.curIndex--;
  10054. }
  10055. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10056. this.stop();
  10057. this.currentSong = this.songList[this.curIndex];
  10058. this.videoUrl = this.songList[this.curIndex].filePath;
  10059. this.artist = this.songList[this.curIndex].artist
  10060. this.name = this.songList[this.curIndex].name;
  10061. this.changeImageAnimation()
  10062. }
  10063. }
  10064. debounce() {
  10065. const delay = 600;
  10066. let cur = new Date().getTime();
  10067. if (cur - this.last > delay) {
  10068. this.last = cur;
  10069. return true;
  10070. }
  10071. return false;
  10072. }
  10073. /**
  10074. * Sets whether the screen is a constant based on the playback status.
  10075. */
  10076. watchStatus() {
  10077. // let windowClass = GlobalContext.getContext().getObject('windowClass') as window.Window;
  10078. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  10079. this.windowClass.setWindowKeepScreenOn(true);
  10080. } else {
  10081. this.windowClass.setWindowKeepScreenOn(false);
  10082. }
  10083. }
  10084. /**
  10085. * Volume gesture method onActionStart.
  10086. *
  10087. * @param event Gesture event.
  10088. */
  10089. private customDialogComponentIdMM: number = 0
  10090. @Builder
  10091. customDialogComponentMM() {
  10092. Column() {
  10093. Row() {
  10094. Blank()
  10095. Text('验证密码')
  10096. .fontSize(22)
  10097. .fontColor($r('app.color.pri_bg'))
  10098. .margin({ top: 18 })
  10099. Blank()
  10100. Image($r('app.media.close'))
  10101. .fillColor(Color.White)
  10102. .margin({ top: 18, right: 18 })
  10103. .width(20)
  10104. .onClick(() => {
  10105. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  10106. })
  10107. }
  10108. .width('100%') // 使Row占据整个宽度
  10109. .justifyContent(FlexAlign.SpaceBetween); // 在Row中创建空间
  10110. Verify({
  10111. onVerifyCompleted: this.handleVerifyCompleted.bind(this)
  10112. });
  10113. }.height('60%')
  10114. .backgroundColor($r('app.color.index_background'))
  10115. .justifyContent(FlexAlign.SpaceBetween)
  10116. }
  10117. private handleVerifyCompleted(isSuccess: boolean) {
  10118. if (isSuccess) {
  10119. console.log('验证成功');
  10120. // 在这里处理验证成功后的逻辑
  10121. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  10122. this.currentPath = this.lockPath
  10123. this.getSortedFiles(this.currentPath)
  10124. } else {
  10125. // console.log('验证失败');
  10126. ToastUtil.showToast('验证失败')
  10127. }
  10128. }
  10129. private showVerifyDialog() {
  10130. promptAction.openCustomDialog({
  10131. transition: TransitionEffect.asymmetric(
  10132. TransitionEffect.OPACITY.animation({ duration: 888 }).combine(
  10133. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  10134. ,
  10135. TransitionEffect.OPACITY.animation({ delay: 888, duration: 888 }).combine(
  10136. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  10137. ),
  10138. builder: () => {
  10139. this.customDialogComponentMM()
  10140. },
  10141. isModal: true,
  10142. autoCancel: true,
  10143. maskColor: Color.Transparent,
  10144. alignment: DialogAlignment.Bottom,
  10145. onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
  10146. console.info("reason" + JSON.stringify(dismissDialogAction.reason))
  10147. console.log("dialog onWillDismiss")
  10148. if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
  10149. dismissDialogAction.dismiss()
  10150. }
  10151. if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
  10152. dismissDialogAction.dismiss()
  10153. }
  10154. }
  10155. }).then((dialogId: number) => {
  10156. this.customDialogComponentIdMM = dialogId
  10157. })
  10158. }
  10159. //左滑操作 移动文件 重命名 删除等操作
  10160. @Builder
  10161. DeleteButton(item: VideoItem, index: number, filePath: string) {
  10162. Row() {
  10163. //加入收藏
  10164. Button() {
  10165. Image(Utility.getIsFav(this.favList, item) ? $r('app.media.add_fac_light2') : $r('app.media.add_fac'))
  10166. .fillColor(Color.White)
  10167. .width(20)
  10168. }
  10169. .width(40)
  10170. .height(40)
  10171. .type(ButtonType.Circle)
  10172. .backgroundColor(this.themeColor)
  10173. .margin(5)
  10174. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10175. .onClick(() => {
  10176. if (item) {
  10177. this.doFav(item)
  10178. }
  10179. })
  10180. //加入下一首播放
  10181. Button() {
  10182. Image($r('app.media.next_to_play'))
  10183. .fillColor(Color.White)
  10184. .width(20)
  10185. }
  10186. .width(40)
  10187. .height(40)
  10188. .type(ButtonType.Circle)
  10189. .backgroundColor(this.themeColor)
  10190. .margin(5)
  10191. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10192. .onClick(() => {
  10193. this.addToNextPlay(item);
  10194. })
  10195. //复制文件
  10196. Button() {
  10197. Image($r('app.media.copy'))
  10198. .fillColor(Color.White)
  10199. .width(20)
  10200. }
  10201. .width(40)
  10202. .height(40)
  10203. .type(ButtonType.Circle)
  10204. .backgroundColor(this.themeColor)
  10205. .margin(5)
  10206. .id(filePath + 'copy')
  10207. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10208. .onClick(() => {
  10209. this.showCopyDialog(false, item, index, filePath + 'copy');
  10210. })
  10211. //移动文件
  10212. Button() {
  10213. Image($r('app.media.cut'))
  10214. .fillColor(Color.White)
  10215. .width(20)
  10216. }
  10217. .width(40)
  10218. .height(40)
  10219. .type(ButtonType.Circle)
  10220. .backgroundColor(this.themeColor)
  10221. .margin(5)
  10222. .id(filePath)
  10223. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10224. .onClick(() => {
  10225. this.showCutDialog(false, item, index, filePath);
  10226. })
  10227. Button() {
  10228. Image($r('app.media.cut_current'))
  10229. .fillColor(Color.White)
  10230. .width(20)
  10231. }
  10232. .width(40)
  10233. .height(40)
  10234. .type(ButtonType.Circle)
  10235. .backgroundColor(this.themeColor)
  10236. .margin(5)
  10237. .id(filePath + 'current')
  10238. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None :
  10239. (this.isHasDir ? Visibility.Visible : Visibility.None))
  10240. .onClick(() => {
  10241. this.showCutDialog(true, item, index, filePath + 'current');
  10242. })
  10243. //重命名
  10244. Button() {
  10245. Image($r('app.media.rename2'))
  10246. .fillColor(Color.White)
  10247. .width(20)
  10248. }
  10249. .width(40)
  10250. .height(40)
  10251. .type(ButtonType.Circle)
  10252. .backgroundColor(this.themeColor)
  10253. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  10254. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  10255. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  10256. .margin(5)
  10257. .onClick(() => {
  10258. this.showReNameDialog(item, index + '', filePath)
  10259. })
  10260. Button() {
  10261. Image($r('app.media.delete2'))
  10262. .fillColor(Color.White)
  10263. .width(20)
  10264. }
  10265. .width(40)
  10266. .height(40)
  10267. .type(ButtonType.Circle)
  10268. .backgroundColor(this.themeColor)
  10269. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  10270. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  10271. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  10272. .margin(5)
  10273. .onClick(() => {
  10274. this.showWarnIsDeleteFile(item, index + '', filePath)
  10275. })
  10276. Button() {
  10277. Image($r('app.media.share2'))
  10278. .fillColor(Color.White)
  10279. .width(20)
  10280. }
  10281. .width(40)
  10282. .height(40)
  10283. .type(ButtonType.Circle)
  10284. .backgroundColor(this.themeColor)
  10285. .margin(5)
  10286. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10287. .onClick(() => {
  10288. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  10289. })
  10290. }
  10291. }
  10292. /**
  10293. * 穿山甲banner广告
  10294. */
  10295. // private declare bannerAd: CSJNativeExpressAd;
  10296. // @State private status: string = "未加载"
  10297. // @State private isShowAd: boolean = false
  10298. // private declare mAdSlot: AdSlot;
  10299. // private mBiddingAdm = '' //服务端bidding才需要设置
  10300. // private expressLoadAdListener: NativeExpressAdListener = {
  10301. // /**
  10302. // * 加载失败的回调
  10303. // *
  10304. // * @param code
  10305. // * @param message
  10306. // */
  10307. // onError: (code: number, message: string) => {
  10308. // console.error("加载广告失败,code=" + code + ",message=" + message);
  10309. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  10310. // },
  10311. //
  10312. // /**
  10313. // * 广告加载成功的回调,接入方可以在这个回调中进行渲染
  10314. // *
  10315. // * @param ads 返回的广告列表
  10316. // */
  10317. //
  10318. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  10319. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  10320. // if (ads && ads.length > 0) {
  10321. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  10322. // ad.setExpressInteractionListener({
  10323. // /**
  10324. // *广告的点击回调
  10325. // * @param type 广告的交互类型
  10326. // */
  10327. // onAdClicked: (type: number) => {
  10328. // console.log("BannerExpressAdPage==onAdClicked......");
  10329. // },
  10330. //
  10331. // /**
  10332. // * 广告的展示回调 每个广告仅回调一次
  10333. // * @param type 广告的交互类型
  10334. // */
  10335. // onAdShow: (type: number) => {
  10336. // console.log("BannerExpressAdPage==onAdShow......");
  10337. // },
  10338. //
  10339. // /**
  10340. // * 模板渲染失败
  10341. // */
  10342. // onRenderFail: (code: number, msg: string) => {
  10343. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  10344. // },
  10345. //
  10346. // /**
  10347. // * 模板渲染成功
  10348. // * @param width 返回view的宽 单位 vp
  10349. // * @param height 返回view的高 单位 vp
  10350. // */
  10351. // onRenderSuccess: (width: number, height: number) => {
  10352. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  10353. // this.bannerAd = ad;
  10354. // this.status = "广告加载完成待展示";
  10355. //
  10356. // this.showBannerAd()
  10357. // }
  10358. // })
  10359. // //渲染广告
  10360. // ad.setSlideIntervalTime(30 * 1000); //设置轮播时间长
  10361. // this.setDislikeCallback(ad); //设置dislike
  10362. // ad.render(this.getUIContext())
  10363. // this.status = "广告加载中...";
  10364. // });
  10365. // }
  10366. // }
  10367. // }
  10368. //
  10369. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  10370. // ad.setDislikeCallback({
  10371. // /**
  10372. // * dislike show
  10373. // */
  10374. // onShow: () => {
  10375. // console.log("BannerExpressAdPage==dislike......show");
  10376. // },
  10377. //
  10378. // /**
  10379. // * @param position 选择的位置
  10380. // * @param value 选择的内容
  10381. // * @param enforceRemove 是否强制关闭广告
  10382. // */
  10383. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  10384. // this.isShowAd = false;
  10385. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value +
  10386. // ",enforce=" + enforceRemove);
  10387. // },
  10388. //
  10389. // /**
  10390. // * 点击取消
  10391. // */
  10392. // onCancel: () => {
  10393. // console.log("BannerExpressAdPage==dislike......onCancel");
  10394. // }
  10395. //
  10396. // })
  10397. // }
  10398. /**
  10399. * 加载Banner广告
  10400. */
  10401. loadBannerAd(rit: string) {
  10402. // if (Utility.isNoble()) {
  10403. // return
  10404. // }
  10405. // if (!Utility.isPassInstallTime(2)) {
  10406. // return
  10407. // }
  10408. // this.isShowAd = false;
  10409. // let adCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
  10410. // this.mAdSlot = new AdSlotBuilder()
  10411. // .setCodeId(rit)
  10412. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  10413. // .setAdCount(1)
  10414. // .setBidAdm(this.mBiddingAdm)
  10415. // .build()
  10416. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  10417. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  10418. // this.status = "广告加载中..."
  10419. }
  10420. /**
  10421. * 展示Banner广告
  10422. */
  10423. // showBannerAd() {
  10424. // if (!this.bannerAd) {
  10425. // return
  10426. // }
  10427. // this.isShowAd = true
  10428. // this.status = "已展示"
  10429. // }
  10430. /**
  10431. * 穿山甲广告代码结束
  10432. */
  10433. }
  10434. //视频气泡窗口的布局
  10435. @Builder
  10436. function customPopupBuilder(dataBu: BubbleBean) {
  10437. List() {
  10438. LazyForEach(new LazyDataSource(dataBu.data), (item: string, index: number) => {
  10439. ListItem() {
  10440. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  10441. Row() {
  10442. Column() {
  10443. Image(dataBu.imageRes[index])
  10444. .height(28)
  10445. .fillColor(dataBu.color)
  10446. .alignSelf(ItemAlign.Center)
  10447. }
  10448. .width(32)
  10449. Text(item)
  10450. .padding({
  10451. top: 10,
  10452. bottom: 10,
  10453. right: 10,
  10454. left: 10
  10455. })
  10456. .fontColor(dataBu.modeType == index ? dataBu.color : $r('app.color.index_tab_font_color'))
  10457. .textAlign(TextAlign.Start)
  10458. .width("100%")
  10459. }
  10460. }
  10461. .backgroundColor($r('app.color.settings_background_main'))
  10462. .margin({ top: 6, bottom: 6 })
  10463. }
  10464. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  10465. .animation({ duration: 500, curve: Curve.Ease, delay: 100 * index }),
  10466. TransitionEffect.scale({ x: 0, y: 0 })))
  10467. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  10468. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  10469. .onClick(() => {
  10470. dataBu.onItemClick?.(index)
  10471. })
  10472. })
  10473. }
  10474. .width(120)
  10475. .divider({
  10476. strokeWidth: 1,
  10477. color: "#22FFFFFF"
  10478. })
  10479. }
  10480. // Function to calculate a hash for the file list
  10481. function simpleHash(fileList: string[]): string {
  10482. let hash = 0;
  10483. const str = fileList.join(',');
  10484. for (let i = 0; i < str.length; i++) {
  10485. const char = str.charCodeAt(i);
  10486. hash = (hash << 5) - hash + char;
  10487. hash |= 0; // Convert to 32bit integer
  10488. }
  10489. return hash.toString();
  10490. }
  10491. interface MoreItem {
  10492. id: number;
  10493. image: Resource;
  10494. title: string;
  10495. }
  10496. //视频气泡窗口的布局
  10497. @Builder
  10498. function cutPopupBuilder(dataBu: BubbleBean) {
  10499. Column() {
  10500. Text(dataBu.isCopy ? '将文件复制到' : '将文件移动到')
  10501. .padding({
  10502. top: 10,
  10503. bottom: 10,
  10504. right: 10,
  10505. left: 10
  10506. })
  10507. .textAlign(TextAlign.Start)
  10508. .width(160)
  10509. .fontWeight(666)
  10510. .fontSize(16)
  10511. List() {
  10512. ForEach(dataBu.data, (item: string, index: number) => {
  10513. ListItem() {
  10514. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  10515. Row() {
  10516. Column() {
  10517. Image($r('app.media.music_group'))
  10518. .height(28)
  10519. .fillColor(dataBu.color)
  10520. .alignSelf(ItemAlign.Center)
  10521. }
  10522. .width(32)
  10523. Text(item.startsWith('.') ? item.replace(/\./g, '') : item)
  10524. .padding({
  10525. top: 10,
  10526. bottom: 10,
  10527. right: 10,
  10528. left: 10
  10529. })
  10530. .textAlign(TextAlign.Start).width("100%")// .fontColor(Color.Gray)
  10531. .fontSize(15)
  10532. }
  10533. }
  10534. .backgroundColor(Color.Transparent)
  10535. .margin({ top: 7, bottom: 7 })
  10536. }
  10537. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  10538. .animation({ duration: 500 }),
  10539. TransitionEffect.scale({ x: 0, y: 0 })))
  10540. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  10541. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  10542. .onClick(() => {
  10543. dataBu.onItemClick?.(index)
  10544. })
  10545. })
  10546. }
  10547. .width(150)
  10548. .divider({
  10549. strokeWidth: 1,
  10550. color: "#22FFFFFF"
  10551. })
  10552. }
  10553. .height(300)
  10554. .padding({
  10555. bottom: 30
  10556. })
  10557. }
  10558. function getFileDirName(filePath: string,rootPath:string): string{
  10559. if(filePath===rootPath){
  10560. return '首页'
  10561. }
  10562. let result = FileUtil.getFileName(filePath)
  10563. if(StrUtil.isEmpty(result))
  10564. return ''
  10565. if(result.startsWith('.'))
  10566. result = result.replace(/\./g, '')
  10567. return result
  10568. }