LocalMusic.ets 401 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890
  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 { TagsContentCover } from '../view/TagsContentCover';
  41. import {
  42. // DeviceChangeReason,
  43. IjkMediaPlayer,
  44. InterruptEvent,
  45. InterruptHintType,
  46. LogUtils,
  47. OnBufferingUpdateListener,
  48. OnCompletionListener,
  49. OnErrorListener,
  50. OnInfoListener,
  51. OnPreparedListener,
  52. OnSeekCompleteListener,
  53. OnTimedTextListener,
  54. OnVideoSizeChangedListener
  55. } from '@ohos/ijkplayer';
  56. import { PlayStatus } from '../common/PlayStatus';
  57. import fs from '@ohos.file.fs';
  58. import { image } from '@kit.ImageKit';
  59. import { AVCastPicker, AVCastPickerState, AVCastPickerStyle, avSession } from '@kit.AVSessionKit';
  60. import { UniversalDetector } from '@ohos/juniversalchardet';
  61. import { SettingPage } from '../pages/SettingPage';
  62. import { secondToTime } from '../common/util/CommUtils';
  63. import { CommonConstants2 } from '../common/util/CommonConstants2';
  64. import { hilog } from '@kit.PerformanceAnalysisKit';
  65. import { LazyDataSource } from '../common/util/LazyDataSource';
  66. import MediaTable from '../common/util/MediaTable';
  67. import NetAxiosUtil from '../common/util/NetAxiosUtil';
  68. import ImageUtils from '../common/util/ImageUtils';
  69. import { ringtone } from '@kit.RingtoneKit';
  70. import { BreakpointType, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
  71. import { resourceManager } from '@kit.LocalizationKit';
  72. import { deviceInfo } from '@kit.BasicServicesKit';
  73. import { HSBColorPicker, HSBColorPickerLayout } from '@keke/color-picker'
  74. import app from '@system.app';
  75. import { TextNodeController } from './PipLyricTextBuilder';
  76. import { IndexerView } from './IndexerView';
  77. import { KeyCode } from '@kit.InputKit';
  78. import { KnockController } from '../controller/KnockController';
  79. // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
  80. const TAG = 'LocalMusic';
  81. const DEFAULT_INDEX =
  82. ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  83. 'X', 'Y', 'Z']
  84. //排序类型
  85. function getTypeOrder(type: number) {
  86. switch (type) {
  87. case CommonConstants.TYPE_IS_DIR:
  88. return 1; // First
  89. case CommonConstants.TYPE_IS_CSJAD:
  90. return 2; // Middle
  91. case CommonConstants.TYPE_LOCAL:
  92. return 3; // Last
  93. default:
  94. return 4; // Unknown types, if any, go last
  95. }
  96. }
  97. const workerInstance = new worker.ThreadWorker("entry/ets/workers/Worker.ets");
  98. // 定义接口
  99. interface HiCarAspectRatio {
  100. ratio: number;
  101. name: string;
  102. }
  103. interface GeneratedObjectLiteralInterface_1 {
  104. assetId: string;
  105. title: string;
  106. artist: string;
  107. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  108. mediaUri: string;
  109. // 该字段大写,音频'AUDIO',视频'VIDEO'
  110. mediaType: string;
  111. mediaSize: number;
  112. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  113. startPosition: number;
  114. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  115. duration: number;
  116. albumCoverUri: string;
  117. albumTitle: string;
  118. appName: string;
  119. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  120. drmScheme: string;
  121. }
  122. const ITEM_HEIGHT_SMALL: number = 48; // 列表项小高度
  123. const ITEM_HEIGHT: number = 58; // 列表项中高度
  124. const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
  125. //功能强大的音乐播放器
  126. @Preview
  127. @Component
  128. export struct LocalMusic {
  129. @State opacityValueImage: number = 1;
  130. @State tipPopup:boolean = false
  131. @Consume mType: number;
  132. @StorageProp('themeColor') themeColor: string =
  133. PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  134. themeMode: number = 0;
  135. @State titleName: string = '首页'
  136. @State textStr: string = ''
  137. // static readonly STR_MUSIC_VIDEO: string = 'Audios';
  138. // private download_path: string = '';
  139. @Consume rootPath: string //音频根目录
  140. @Consume currentPath: string
  141. static readonly STR_LOCK_VIDEO: string = '.私密音频';
  142. static readonly STR_FAC_VIDEO: string = '.我的收藏';
  143. @State lockPath: string = ''
  144. @State favPath: string = ''
  145. static readonly STR_HISTORY_MUSIC: string = '.最近播放';
  146. @State historyPath: string = ''
  147. @State historyList: Array<VideoItem> = []
  148. @Consume isHistory: boolean
  149. static readonly HISTORY_MUSIC: string = 'music_historyList';
  150. private table: MediaTable = new MediaTable(getContext(this))
  151. @State isZero: boolean = false
  152. @State fileList: Array<string> = []
  153. @State dirList: Array<VideoItem> = []
  154. @Consume videoLocalList: Array<VideoItem>
  155. @State dataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.videoLocalList)
  156. @State mediaKuList: Array<VideoItem> = []; //媒体库文件
  157. @State artistList: Array<VideoItem> = []; //艺术家文件
  158. @State artistMap: Map<string, VideoItem[]> = new Map(); //艺术家Map
  159. @State albumList: Array<VideoItem> = []; //专辑文件
  160. @State albumMap: Map<string, VideoItem[]> = new Map(); //专辑Map
  161. private mScrollMap: Map<string, number> = new Map(); // 艺术家、专辑名->滚动index
  162. @State imageOpacities: number[] = [];
  163. @Consume isCanBack: boolean
  164. @Consume @Watch('onModeChange') modeType: number; // 0首页,1媒体库,2艺术家,3专辑
  165. @State showSingleLyric: boolean = false
  166. @State sortType: number = 4 //默认排序方式
  167. @State isShowSimi: boolean = false //是否显示私密音频
  168. @State isShowFAV: boolean = true //是否显示我的收藏
  169. @State isShowTitleBar: boolean = true //是否显示分类导航条
  170. @State isShowAllBar: boolean = true //是否显示播放全部条
  171. @State isShowHistory: boolean = true //是否显示最近播放
  172. @State isCustomizeBg: boolean = false //自定义背景界面
  173. @State isGridMusic: boolean = false //是否网格布局
  174. @State isCircleBtn: boolean = false //是否圆形播放按钮
  175. @State twoFingerType: number = 3 //双支放大缩小的类型
  176. @State isScrollHide: boolean = false //是否滚动隐藏
  177. @State isSameTimePlay: boolean = false //是否和其他app同时播放
  178. @State isStartAutoPlay: boolean = false //启动后自动播放
  179. @State isShowPlayPageBack: boolean = false //是否显示播放页返回键
  180. @State isShowHeader: boolean = true
  181. @State isPlayListBgGrass: boolean = true //是否播放列表玻璃透明效果
  182. @State isShowSingleLineLyric: boolean = false //是否显示播放页返回键
  183. @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
  184. @State isCoverTopBig: boolean = false //顶部大封面部分手机显示会和播放控制页重叠
  185. @State isSwipe: boolean = false //listItem的左滑开关
  186. @State openSkipSongAnimate: boolean = true//切歌动画效果
  187. @State customizeBgPath: string | undefined = '';
  188. @State isDarkMode: boolean = false
  189. @State lyricTextWeight: number = 400
  190. @State lyricTextWeightPip: number = 400
  191. @State currentSwiperIndex: number = 0
  192. @State blurValue: number = 0 //背景模糊
  193. @State bgBrightness: number = 0 //背景亮度
  194. private listScroller: ListScroller = new ListScroller()
  195. private playListScroller: Scroller = new Scroller()
  196. @State isOneKeyTags:boolean = false
  197. @StorageProp('isLandscape') isLandscape: boolean = false;
  198. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  199. @StorageProp('windowWidth') windowWidth: number = 0;
  200. @StorageProp('windowHeight') windowHeight: number = 0;
  201. @StorageProp('isHiCarStatus') isHiCarStatus: boolean = false;
  202. @StorageProp('curDisplayIsHiCar') curDisplayIsHiCar: boolean = false;
  203. private UNKONWN:string = '';
  204. private listArea: Area = {
  205. width: 0,
  206. height: 0,
  207. position: {},
  208. globalPosition: {}
  209. }
  210. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  211. ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET;
  212. onColorModeChange() {
  213. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  214. if (this.isCustomizeBg) {
  215. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  216. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  217. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  218. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  219. } else {
  220. if (!this.isDarkMode) {
  221. this.titleBarModel.setTitleBarBackground(this.themeColor)
  222. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  223. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  224. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  225. } else {
  226. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  227. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  228. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  229. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  230. }
  231. }
  232. }
  233. onModeChange() {
  234. this.isFavMusic = false
  235. if (this.modeType === 2 || this.modeType === 3) {
  236. this.titleBarModel.setRightIcon(null)
  237. } else {
  238. this.titleBarModel.setRightIcon(($r('app.media.add')))
  239. }
  240. LogUtil.info('onecold onModeChange = ' + this.modeType)
  241. switch (this.modeType) {
  242. case 0:
  243. this.getSortedFiles(this.currentPath)
  244. break
  245. case 1:
  246. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  247. this.updateListData(this.mediaKuList)
  248. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  249. break
  250. case 2:
  251. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  252. this.updateListData(this.artistList)
  253. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  254. break
  255. case 3:
  256. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  257. this.updateListData(this.albumList)
  258. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  259. break
  260. }
  261. }
  262. @StorageLink('currentSong') currentSong: VideoItem | undefined = undefined;
  263. // @StorageLink('isPlay') isPlay: boolean = false;
  264. @StorageLink('isShowPlay') isShowPlay: boolean = false;
  265. @StorageLink('songList') songList: Array<VideoItem> = [];
  266. @State translateY: number = 0;
  267. @State isShowSheet: boolean = false;
  268. @State isShowSheetView: boolean = false;
  269. @State isShowTimeCloseView: boolean = false;
  270. private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Vertical });
  271. @StorageLink('currIndex') curIndex: number = 0;
  272. @Consume isShowDrawer: boolean;
  273. @Consume offsetX: number;
  274. @State isFac: boolean = false;
  275. @State favList: Array<VideoItem> = []
  276. @Consume isFavMusic: boolean
  277. @State isClickedPLayAll: boolean = false;
  278. private scrollerForlist: ListScroller = new ListScroller();
  279. private knockController: KnockController | undefined = undefined;
  280. imagesF: ImageFrameInfo[] = [
  281. { src: $r("app.media.app_loading0") },
  282. { src: $r("app.media.app_loading1") },
  283. { src: $r("app.media.app_loading2") },
  284. { src: $r("app.media.app_loading3") },
  285. ]
  286. @State animationState: AnimationStatus = AnimationStatus.Initial
  287. // 缓存机制
  288. private cache: Map<string, Array<VideoItem>> = new Map();
  289. private stringCache: Map<string, string> = new Map(); // 新增字符串缓存
  290. // 持久化缓存
  291. private async saveCacheToStorage() {
  292. const cacheArray = Array.from(this.cache.entries());
  293. const stringCacheArray = Array.from(this.stringCache.entries());
  294. await PreferencesUtil.putSync('music_cache', JSON.stringify(cacheArray));
  295. await PreferencesUtil.putSync('music_string_cache', JSON.stringify(stringCacheArray));
  296. }
  297. // 载入缓存
  298. private async loadCacheFromStorage() {
  299. const cacheString = await PreferencesUtil.getStringSync('music_cache', '');
  300. const stringCacheString = await PreferencesUtil.getStringSync('music_string_cache', ''); // 载入字符串缓存
  301. if (cacheString) {
  302. const cacheArray: [string, Array<VideoItem>][] = JSON.parse(cacheString);
  303. this.cache = new Map(cacheArray);
  304. }
  305. if (stringCacheString) {
  306. const stringCacheArray: [string, string][] = JSON.parse(stringCacheString);
  307. this.stringCache = new Map(stringCacheArray);
  308. }
  309. }
  310. // 查找缓存
  311. private findCache(key: string): Array<VideoItem> | undefined {
  312. return this.cache.get(key);
  313. }
  314. // 查找字符串缓存
  315. private findStringCache(key: string): string | undefined {
  316. return this.stringCache.get(key);
  317. }
  318. // 添加缓存
  319. private addCache(key: string, value: Array<VideoItem>) {
  320. this.cache.set(key, value);
  321. }
  322. // 添加字符串缓存
  323. private addStringCache(key: string, value: string) {
  324. this.stringCache.set(key, value);
  325. }
  326. // 删除缓存
  327. private deleteCache(key: string) {
  328. this.cache.delete(key);
  329. this.saveCacheToStorage()
  330. }
  331. // 删除字符串缓存
  332. private deleteStringCache(key: string) {
  333. this.stringCache.delete(key);
  334. }
  335. // 多选机制
  336. @State selectedFiles: Array<VideoItem> = [];
  337. @State isMultiSelect: boolean = false;
  338. @State isAllSelected: boolean = false;
  339. @State appName: string = ''
  340. @State isHasDir: boolean = false
  341. @State packName: string = ''
  342. context = this.getUIContext().getHostContext() as common.UIAbilityContext
  343. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  344. .setTitleTextStyle(FontStyle.Normal)
  345. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  346. .setLeftIcon($r('app.media.menu'))
  347. .setLeftIconWidth(26)
  348. .setLeftIconHeight(26)
  349. .setTitleName('首页')
  350. .setTitleFontSize(18)
  351. .setTitleFontColor(Color.White)
  352. .setTitleBarBackground(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  353. .setTitleBarBottomLineColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  354. .setLeftTitleStateNormalStyleColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  355. .setRightIcon($r('app.media.add'))
  356. .setOnRightClickListener(() => {
  357. this.showSheelDialog()
  358. })
  359. // .setOnTitleClickListener(() => {
  360. // this.showPupDialog()
  361. // })
  362. .setOnLeftClickListener(() => {
  363. this.doSwipBack()
  364. })
  365. doSwipBack() {
  366. if (this.modeType !== 0 && this.isCanBack) {
  367. this.onModeChange()
  368. this.isCanBack = false
  369. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  370. // 返回专辑列表时恢复滚动偏移量,支持列表和网格
  371. setTimeout(() => {
  372. if (this.modeType == 2) {
  373. if (this.isGridMusic) {
  374. let lastOffset = this.mScrollMap.get('lastGridArtistScrollOffset') ?? 0
  375. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  376. } else {
  377. let lastOffset = this.mScrollMap.get('lastListArtistScrollOffset') ?? 0
  378. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  379. }
  380. } else if (this.modeType == 3) {
  381. if (this.isGridMusic) {
  382. let lastOffset = this.mScrollMap.get('lastGridAlBumScrollOffset') ?? 0
  383. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  384. } else {
  385. let lastOffset = this.mScrollMap.get('lastListAlBumScrollOffset') ?? 0
  386. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  387. }
  388. }
  389. }, 200)
  390. return
  391. }
  392. if (this.isHistory || this.isFavMusic) {
  393. this.isHistory = false
  394. this.getSortedFiles(this.currentPath)
  395. return
  396. }
  397. if (this.currentPath === this.rootPath || this.modeType !== 0) {
  398. animateTo({ duration: 555 }, () => {
  399. // 动画闭包内控制Image组件的出现和消失
  400. this.isShowDrawer = !this.isShowDrawer
  401. this.offsetX = 0
  402. })
  403. return
  404. }
  405. //返回上一级歌单的滚动位置
  406. setTimeout(() => {
  407. if (this.modeType == 0) {
  408. if (this.isGridMusic) {
  409. let lastOffset = this.mScrollMap.get('lastGridDirScrollOffset') ?? 0
  410. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  411. } else {
  412. let lastOffset = this.mScrollMap.get('lastListDirScrollOffset') ?? 0
  413. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  414. }
  415. }
  416. }, 300)
  417. this.currentPath = Utility.getParentDirectory(this.currentPath)
  418. Logger.info('this.currentPath2 = ' + this.currentPath)
  419. this.getSortedFiles(this.currentPath)
  420. }
  421. // 组件生命周期
  422. aboutToAppear() {
  423. if(PreferencesUtil.getBooleanSync('isFirstTiped',true)){
  424. this.tipPopup = !this.tipPopup
  425. PreferencesUtil.putSync('isFirstTiped',false)
  426. }
  427. this.initSetting()
  428. this.UNKONWN = Utility.resourceToString(this.context, $r('app.string.unknown'));
  429. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  430. Utility.getAppName(getContext(this)).then((appName: string) => {
  431. this.appName = appName
  432. })
  433. this.packName = AppUtil.getBundleName()
  434. this.loadCacheFromStorage(); // 加载缓存
  435. this.mkDownLoadDir()
  436. let eventMusic: emitter.InnerEvent = { eventId: 2 }
  437. // 监听广播事件(打开其他应用处理)
  438. emitter.on(eventMusic, (eventData: emitter.EventData) => {
  439. this.saveVideoDatas([eventData.data?.message], true)
  440. });
  441. //侧滑广播接收时间
  442. let eventUpdateSwipeBack: emitter.InnerEvent = { eventId: 888 }
  443. // 监听广播事件(打开其他应用处理)
  444. emitter.on(eventUpdateSwipeBack, (eventData: emitter.EventData) => {
  445. animateTo({ duration: 555 }, () => {
  446. this.doSwipBack()
  447. })
  448. });
  449. //ScanFilePage广播接收时间
  450. let eventScanUpdate: emitter.InnerEvent = { eventId: 101 }
  451. // 监听ScanFilePage广播事件(更新数据库)
  452. emitter.on(eventScanUpdate, (eventData: emitter.EventData) => {
  453. this.doUpdateData()
  454. });
  455. let eventSetting: emitter.InnerEvent = { eventId: 333 }
  456. // 监听广播事件(通用设置配置更新)
  457. emitter.on(eventSetting, (eventData: emitter.EventData) => {
  458. this.doChangeSetting()
  459. });
  460. let event: Callback<InterruptEvent> = (event) => {
  461. LogUtils.getInstance().LOGI(`onecold 与其他应用音频冲突 被截断点event: ${JSON.stringify(event)}`);
  462. this.savePlaybackPosition()
  463. if (event.hintType === InterruptHintType.INTERRUPT_HINT_PAUSE) {
  464. this.pause();
  465. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_RESUME) {
  466. this.startPlayOrResumePlay();
  467. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_STOP) {
  468. this.stop();
  469. }
  470. }
  471. this.mIjkMediaPlayer.on('audioInterrupt', event);
  472. // 音频设备断连回调处理
  473. // let deviceChangeEvent: Callback<InterruptEvent> = (event) => {
  474. // LogUtils.getInstance().LOGI(`Heanup deviceChange event: ${JSON.stringify(event)}`);
  475. // if (event.reason === DeviceChangeReason.REASON_OLD_DEVICE_UNAVAILABLE) { // 音频设备断开连接
  476. // this.pause();
  477. // }
  478. // }
  479. // this.mIjkMediaPlayer.on('deviceChange', deviceChangeEvent);
  480. this.makeWorker()
  481. //折叠屏的屏幕显示模式变化
  482. display.on('foldDisplayModeChange', (data) => {
  483. this.doChangeBarHeight()
  484. });
  485. display.on('foldStatusChange', (data) => {
  486. Logger.info('onecold foldStatusChange ')
  487. });
  488. this.isCoverRectangle = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_RECTANGLE, true)
  489. // 读取 themeMode 并同步 currentColorMode
  490. this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
  491. this.applyThemeMode(this.themeMode)
  492. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  493. AppStorage.setOrCreate('themeColor', themeColor);
  494. this.themeColor = themeColor;
  495. this.doChangeSetting()
  496. this.windowClass.on('windowSizeChange', (size) => {
  497. LogUtil.info('onecold windowSizeChange')
  498. this.doChangeBarHeight()
  499. let viewWidth = px2vp(size.width);
  500. let viewHeight = px2vp(size.height);
  501. if(this.isPhoneLan()){
  502. this.is_auto_hide_progress = false
  503. if(this.isHiCar()){
  504. return
  505. }
  506. setTimeout(() => {
  507. this.is_auto_hide_progress = true
  508. }, 6000)
  509. }else{
  510. this.startAutoHide()
  511. }
  512. });
  513. this.eventHub.on('onStateChange', (fg: boolean) => {
  514. if (fg && this.curState === 'STARTED') {
  515. this.stopPip();
  516. }
  517. });
  518. }
  519. startAutoHide() {
  520. if(this.isHiCar()){
  521. return
  522. }
  523. if(PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_HIDE_PROGRESS,false)){
  524. console.info('onecold startAutoHide')
  525. this.is_auto_hide_progress = false
  526. setTimeout(() => {
  527. this.is_auto_hide_progress = true
  528. }, 6000)
  529. }
  530. }
  531. applyThemeMode(mode: number) {
  532. let colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET
  533. if (mode === 1) {
  534. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
  535. } else if (mode === 2) {
  536. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  537. }
  538. AppStorage.setOrCreate('currentColorMode', colorMode)
  539. AppStorage.setOrCreate('isDarkMode', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK)
  540. PreferencesUtil.putSync(SettingPage.THEME_MODE, mode)
  541. AppStorage.setOrCreate('themeMode', mode)
  542. this.isDarkMode = colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  543. // 只有强制浅色/深色时才主动设置
  544. const context = getContext(this) as common.UIAbilityContext
  545. context.getApplicationContext().setColorMode(colorMode)
  546. }
  547. initSetting() {
  548. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  549. this.isCustomizeBg = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
  550. this.customizeBgPath = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
  551. this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, true)
  552. this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
  553. this.isSameTimePlay = PreferencesUtil.getBooleanSync(SettingPage.IS_SAMETIME_PLAY, false)
  554. this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
  555. this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
  556. this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
  557. this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
  558. this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
  559. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
  560. this.isShowAllBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_ALLBAR, true)
  561. this.twoFingerType = PreferencesUtil.getNumberSync(SettingPage.TWO_FINGER_TYPE, 3)
  562. this.isCoverTop = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP, false)
  563. this.isCircleBtn = PreferencesUtil.getBooleanSync(SettingPage.IS_CIRCLE_BTN, true)
  564. this.isShowPlayPageBack = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_PLAYPAGE_BACK, true)
  565. this.isCoverTopBig = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP_BIG, false)
  566. this.isShowSingleLineLyric = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SLLYRIC, false)
  567. this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
  568. this.isPlayListBgGrass = PreferencesUtil.getBooleanSync(SettingPage.IS_PLAYLIST_BG_GRASS, true)
  569. this.isShowHeader = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HEADER, true)
  570. this.volume = PreferencesUtil.getNumberSync('DefalutVolume', this.volume)
  571. this.isSwipe = PreferencesUtil.getBooleanSync(SettingPage.IS_SWIPE, false)
  572. this.openSkipSongAnimate = PreferencesUtil.getBooleanSync(SettingPage.OPEN_SKIPSONG_ANIMATE, true)
  573. this.volumeSmall = PreferencesUtil.getBooleanSync('volumeSmall', false)
  574. if(this.volumeSmall){
  575. this.volume = 0.5
  576. }else{
  577. this.volume = 1
  578. }
  579. //如果是hicar连接状态,这些都是false
  580. if(this.isHiCar()){
  581. this.isShowTitleBar = false//不显示导航栏
  582. if(!(this.windowWidth>1800&&this.windowHeight>=1200))//小屏幕不可以Grid
  583. {
  584. this.isShowHeader = false//二级菜单不显示头部
  585. this.isGridMusic= false//用list不用网格
  586. this.isCoverTopBig = false
  587. }
  588. this.isShowPlayPageBack = true //播放页返回键要显示,方便驾驶员操作
  589. }
  590. if (this.isSavePlayMode) {
  591. this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
  592. }
  593. if (this.isCustomizeBg) {
  594. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  595. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  596. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  597. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  598. } else {
  599. if (!this.isDarkMode) {
  600. this.titleBarModel.setTitleBarBackground(this.themeColor)
  601. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  602. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  603. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  604. } else {
  605. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  606. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  607. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  608. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  609. }
  610. }
  611. }
  612. doChangeSetting() {
  613. this.initSetting()
  614. this.deleteCache(this.currentPath)
  615. if (this.modeType === 0) {
  616. this.getSortedFiles(this.currentPath)
  617. }
  618. }
  619. doChangeBarHeight() {
  620. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  621. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  622. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  623. this.setBarHeightNormal()
  624. }
  625. }
  626. onPageShow() {
  627. this.knockController?.immersiveListening();
  628. app.setImageCacheCount(100);
  629. // 设置解码前图片数据内存缓存上限为100MB (100MB=100*1024*1024B=104857600B)
  630. app.setImageRawDataCacheSize(104857600);
  631. Logger.info('onecold onPageShow currentBreakpoint= ' + this.currentBreakpoint)
  632. }
  633. //开启线程查看各个数据库
  634. makeWorker() {
  635. setTimeout(() => {
  636. if (PreferencesUtil.getBooleanSync('isFirstApp', true)) {
  637. ToastUtil.showToast('请到文件扫描页面导入音乐!')
  638. //发送worker通知扫描文件入库,用户反馈4000多首用这个方法扫描会闪退。
  639. // workerInstance.postMessage({
  640. // code: 1,
  641. // data1: this.context,
  642. // data2: this.rootPath,
  643. // data3: this.lockPath,
  644. // data4: PreferencesUtil.getStringSync('COVER_API', ''),
  645. // });
  646. PreferencesUtil.putSync('isFirstApp', false)
  647. } else {
  648. workerInstance.postMessage({ code: 2, data: this.context });
  649. workerInstance.postMessage({ code: 3, data: this.context });
  650. workerInstance.postMessage({ code: 4, data: this.context });
  651. this.getHistoryList(false)
  652. }
  653. }, 1000)
  654. workerInstance.onmessage = (e: MessageEvents): void => {
  655. switch (e.data.code) {
  656. case 101: //第一次扫描文件夹入库
  657. ToastUtil.showToast('刷新同步数据库成功!')
  658. Logger.info('onecold 扫描数据库结束 this.mediaKuList length= ' + this.mediaKuList.length)
  659. this.doUpdateData()
  660. break;
  661. case 102: //查询媒体库列表
  662. this.mediaKuList = e.data.data
  663. Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
  664. Utility.doSortListAscending(this.mediaKuList)
  665. AppStorage.setOrCreate('mediaKuList', this.mediaKuList);
  666. if (this.modeType === 1) {
  667. this.updateListData(this.mediaKuList)
  668. }
  669. PreferencesUtil.putSync('mediaKuCount', this.mediaKuList.length)
  670. break;
  671. case 103: //收到查询艺术家列表
  672. this.artistMap = e.data.data1;
  673. this.artistList = e.data.data2;
  674. PreferencesUtil.putSync('artistCount', this.artistList.length)
  675. break;
  676. case 104: //收到查询专辑列表
  677. this.albumMap = e.data.data1;
  678. this.albumList = e.data.data2
  679. //查询完毕在启动是否自动播放
  680. if (this.isStartAutoPlay) {
  681. this.startPlayOrResumePlay()
  682. }
  683. PreferencesUtil.putSync('albumCount', this.albumList.length)
  684. break;
  685. }
  686. };
  687. // 在调用terminate后,执行onexit
  688. workerInstance.onexit = (code) => {
  689. console.log("main thread terminate");
  690. }
  691. //若Worker处于已销毁或正在销毁等非运行状态时,调用其功能接口,会抛出相应的错误。
  692. // 使用Worker模块时,需要在主线程中注册onerror接口,否则当worker线程出现异常时会发生jscrash问题。
  693. workerInstance.onerror = (err: ErrorEvent) => {
  694. console.log("onerror" + err.message);
  695. }
  696. // let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  697. //碰一碰分享的监听
  698. this.knockController = KnockController.getInstance(this.context);
  699. this.knockController?.immersiveListening();
  700. }
  701. onPageHide(): void {
  702. this.knockController?.immersiveDisableListening();
  703. }
  704. @State isFirstStartPlay: boolean = false
  705. //获取download_path
  706. async mkDownLoadDir() {
  707. const documentViewPicker = new picker.DocumentViewPicker()
  708. let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
  709. this.rootPath = new fileUri.FileUri(documentSaveResult[0]).path
  710. // this.rootPath = this.download_path
  711. this.lockPath = this.rootPath + '/' + LocalMusic.STR_LOCK_VIDEO
  712. this.favPath = this.rootPath + '/' + LocalMusic.STR_FAC_VIDEO
  713. this.historyPath = this.rootPath + '/' + LocalMusic.STR_HISTORY_MUSIC
  714. Logger.info('onecold rootPath = ' + this.rootPath)
  715. Logger.info('onecold lockPath = ' + this.lockPath)
  716. if (!FileUtil.accessSync(this.lockPath)) {
  717. FileUtil.mkdirSync(this.lockPath)
  718. }
  719. if (!FileUtil.accessSync(this.favPath)) {
  720. FileUtil.mkdirSync(this.favPath)
  721. }
  722. if (!FileUtil.accessSync(this.historyPath)) {
  723. FileUtil.mkdirSync(this.historyPath)
  724. }
  725. this.getSortedFiles(this.rootPath).then(() => {
  726. this.isFavMusic = false
  727. //穿山甲
  728. // this.loadBannerAd(CSJUtil.getBannerID())
  729. this.songList = PreferencesUtil.getSync('LastMusicList', []) as Array<VideoItem>
  730. this.currentSong = PreferencesUtil.getSync('LastMusicInfo', undefined) as VideoItem
  731. if (ArrayUtil.isEmpty(this.songList)) {
  732. this.songList = this.getCurFileList()
  733. } else {
  734. this.curIndex = Utility.getIndexFromList(this.songList, this.currentSong.filePath)
  735. }
  736. if (ArrayUtil.isNotEmpty(this.songList)) {
  737. this.isFirstStartPlay = true
  738. this.sonDataSource.pushArrayData(this.songList)
  739. if (this.currentSong === undefined) {
  740. this.isFirstStartPlay = false
  741. this.currentSong = this.songList[0]
  742. }
  743. this.videoUrl = this.currentSong.filePath
  744. this.name = this.currentSong.name
  745. this.cover = this.currentSong.pixelMapPath
  746. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  747. } else {
  748. this.name = '空空如也'
  749. }
  750. })
  751. this.getFavList(false)
  752. }
  753. getFavList(isFavRefresh: boolean) {
  754. this.table.queryByisFav(1, async (result: VideoItem[]) => {
  755. this.favList = result
  756. if (isFavRefresh || this.isFavMusic) { //如果是我的收藏,更新我的收藏数据
  757. this.videoLocalList = this.favList
  758. this.updateListData(this.videoLocalList)
  759. }
  760. })
  761. }
  762. getHistoryList(isRefresh: boolean) {
  763. this.table.queryRecentPlayedRecords(50, async (result: VideoItem[]) => {
  764. this.historyList = result
  765. // for (let i = 0; i < this.historyList.length; i++) {
  766. //
  767. // console.info(`onecold gengxin 1: ${this.historyList[i].name}`);
  768. // console.info(`onecold gengxin 1: ${this.historyList[i].lastPlayedStr}`);
  769. // }
  770. if (isRefresh) {
  771. this.videoLocalList = this.historyList
  772. this.updateListData(this.videoLocalList, true)
  773. }
  774. })
  775. }
  776. // 组件消失生命周期
  777. aboutToDisappear() {
  778. console.info('LifeCycleComponent aboutToDisappear');
  779. this.knockController?.immersiveDisableListening();
  780. this.curIndex = 0
  781. emitter.off(2);
  782. emitter.off(101);
  783. emitter.off(888);
  784. emitter.off(333);
  785. this.mDestroyPage = true;
  786. this.mIjkMediaPlayer.setScreenOnWhilePlaying(false);
  787. if (this.CONTROL_PlayStatus != PlayStatus.INIT) {
  788. this.stop();
  789. }
  790. this.mIjkMediaPlayer.off('audioInterrupt');
  791. if (workerInstance) {
  792. workerInstance.terminate();
  793. }
  794. this.stopPip();
  795. this.destroyPipController()
  796. }
  797. async getSortedFiles(curPath: string, isWorkerPost?: boolean, destPath?: string, isOpen?: boolean) {
  798. this.isFavMusic = false
  799. if (isWorkerPost) {
  800. workerInstance.postMessage({ code: 2, data: this.context }); //刷新媒体库列表
  801. }
  802. if (this.modeType !== 0) {
  803. return
  804. }
  805. this.isCanBack = false
  806. this.currentPath = curPath
  807. this.titleBarModel.setTitleName(getFileDirName(this.currentPath, this.rootPath))
  808. if (curPath === this.rootPath) {
  809. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  810. } else {
  811. this.currentTitleName = getFileDirName(this.currentPath, this.rootPath)
  812. if (this.rootPath === Utility.getParentDirectory(curPath)) {
  813. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  814. }
  815. }
  816. // Get the current file list and calculate its hash
  817. this.fileList = FileUtil.listFileSync(curPath);
  818. const currentHash = simpleHash(this.fileList);
  819. // Check cache
  820. const cachedValue = this.findCache(curPath);
  821. Logger.info('onecold cachedValue = ' + cachedValue)
  822. const cachedHash = this.findStringCache(curPath + '_hash');
  823. const cachedDirList = this.findCache(curPath + "_dirList");
  824. if (cachedValue !== undefined) {
  825. // this.videoLocalList = cachedValue;
  826. Logger.info('onecold 有缓存 cachedValue = ' + cachedValue)
  827. if (this.currentPath != this.rootPath) { //第一个封面赋值给currentTitleCover
  828. this.currentTitleCover = Utility.getFirstCoverFromList(cachedValue)
  829. }
  830. this.updateListData(cachedValue)
  831. }
  832. if (cachedDirList !== undefined) {
  833. this.dirList = cachedDirList
  834. }
  835. //通过当前hash值和缓存hash判断list有没有变化
  836. if (cachedValue && cachedHash === currentHash) {
  837. return;
  838. }
  839. this.fileList = FileUtil.listFileSync(curPath)
  840. let directories: Array<VideoItem> = [];
  841. let files: Array<VideoItem> = [];
  842. for (let i = 0; i < this.fileList.length; i++) {
  843. console.info(`The name of file: ${this.fileList[i]}`);
  844. let path = curPath + '/' + this.fileList[i]
  845. if (FileUtil.isDirectory(path)) {
  846. let item: VideoItem =
  847. new VideoItem(this.fileList[i].toString(), this.fileList[i].toString(), path, CommonConstants.TYPE_IS_DIR, 0,
  848. '')
  849. if (this.isShowDir(item.name)) {
  850. directories.push(item);
  851. }
  852. // directories.sort((a, b) => a.cTime.localeCompare(b.cTime));
  853. // Utility.doSortListAscending(directories)
  854. } else {
  855. if (this.currentPath === this.lockPath&&Utility.isMeidaByExtension(path)) {
  856. let item: VideoItem =
  857. await Utility.uriGetMusicAssetsFromFile(this.context, path, CommonConstants.TYPE_LOCAL, false);
  858. if (!path.endsWith('.lrc') && Utility.isMeidaByExtension(path) && !path.endsWith('.srt')) {
  859. files.push(item);
  860. // files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  861. // this.doSortListAscending(files)
  862. }
  863. }
  864. }
  865. }
  866. this.table.queryByParentPath(curPath, async (result: VideoItem[]) => {
  867. if (this.currentPath !== this.lockPath) {
  868. files = result;
  869. }
  870. files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  871. Utility.doSortListAscending(files)
  872. if (this.currentPath === this.rootPath) {
  873. this.dirList = directories
  874. this.addCache(curPath + "_dirList", this.dirList);
  875. }
  876. //插入广告先注释掉
  877. // if (this.isShowAd && ArrayUtil.isNotEmpty(directories)) {
  878. // let adItem: VideoItem = new VideoItem('', '', '', CommonConstants.TYPE_IS_CSJAD, 0, '')
  879. // directories.push(adItem)
  880. // }
  881. // 合并文件夹和文件,文件夹在前,文件在后,广告在中间
  882. this.videoLocalList = directories.concat(files);
  883. this.updateListData(this.videoLocalList)
  884. if (ArrayUtil.isNotEmpty(files)) {
  885. if (this.currentPath != this.rootPath) {
  886. if (files) {
  887. this.currentTitleCover = Utility.getFirstCoverFromList(files)
  888. }
  889. }
  890. // 缓存结果
  891. this.addCache(curPath, this.videoLocalList);
  892. await this.saveCacheToStorage(); // 保存缓存至本地存储
  893. this.addStringCache(curPath + '_hash', currentHash);
  894. }
  895. console.info(`onecold gengxin 1: ${this.videoLocalList.length}`);
  896. // for (let i = 0; i < this.videoLocalList.length; i++) {
  897. //
  898. // console.info(`onecold gengxin 1: ${this.videoLocalList[i].pixelMapPath}`);
  899. //
  900. // }
  901. // this.setButtonStatus()
  902. if (isOpen) {
  903. if (destPath === undefined) {
  904. // 处理 destPath 为 undefined 的情况
  905. return
  906. }
  907. if (destPath.endsWith('.lrc')) {
  908. ToastUtil.showToast('导入歌词成功!请注意歌词文件和歌曲要同个歌单路径。')
  909. if (StrUtil.isNotEmpty(this.videoUrl)) {
  910. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  911. this.initLyric(lyricPath);
  912. }
  913. return
  914. }
  915. let item2 = new VideoItem(Utility.getMediaNameByUri(destPath), destPath, destPath, 0, 0, '')
  916. this.doPlay(item2)
  917. this.isShowPlay = true
  918. }
  919. });
  920. }
  921. //扫描文件夹入库
  922. async scanDirectory(curPath: string): Promise<VideoItem[]> {
  923. const files = FileUtil.listFileSync(curPath);
  924. let mediaItems: VideoItem[] = [];
  925. Logger.info('onecold scanDirectory start ')
  926. for (const file of files) {
  927. const fPath = `${curPath}/${file}`;
  928. if (fPath === this.lockPath) {
  929. Logger.info(`Skipping locked path: ${fPath}`);
  930. continue;
  931. }
  932. if (FileUtil.isDirectory(fPath)) {
  933. // Recursively scan subdirectories
  934. const subDirItems = await this.scanDirectory(fPath);
  935. mediaItems = mediaItems.concat(subDirItems);
  936. } else {
  937. Logger.info('onecold scanDirectory filePath = ' + fPath)
  938. // Process media files
  939. if (!fPath.endsWith('.lrc') && Utility.isMeidaByExtension(fPath) && !fPath.endsWith('.srt')) {
  940. let mediaItem: VideoItem =
  941. await Utility.uriGetMusicAssetsFromFile(this.context, fPath, CommonConstants.TYPE_LOCAL, true);
  942. mediaItems.push(mediaItem);
  943. this.table.insert(mediaItem, (id: number) => {
  944. });
  945. }
  946. }
  947. }
  948. return mediaItems;
  949. }
  950. updateListData(mList: Array<VideoItem>, noSort?: boolean) {
  951. animateTo({ duration: 888 }, () => {
  952. this.opacityItem = 0;
  953. });
  954. setTimeout(() => {
  955. this.videoLocalList = mList;
  956. if (!noSort) {
  957. if (this.modeType === 0 || this.modeType === 1) {
  958. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  959. this.doSortType(this.sortType)
  960. }
  961. }
  962. this.dataSource.pushArrayData(this.videoLocalList)
  963. animateTo({ duration: 888 }, () => {
  964. this.opacityItem = 1;
  965. });
  966. this.setButtonStatus()
  967. }, 200);
  968. }
  969. //排序模式和多选模式
  970. showPupDialog() {
  971. if (this.modeType === 2 || this.modeType === 3) {
  972. this.titleBarModel.setRightIcon(null)
  973. } else {
  974. this.titleBarModel.setRightIcon(($r('app.media.add')))
  975. }
  976. let dataBean = new BubbleBean()
  977. dataBean.data = ["首页", "媒体库", "艺术家", "专辑", "同步数据"]
  978. dataBean.color = this.themeColor
  979. dataBean.modeType = this.modeType
  980. dataBean.imageRes =
  981. [$r('app.media.home_press'), $r('app.media.kp_music'), $r('app.media.music_menu'), $r('app.media.llq'),
  982. $r('app.media.refresh')]
  983. let pup: XPopup;
  984. if (this.isDarkMode) {
  985. pup = XPopup.Builder()
  986. .setPopupPosition(PopupPosition.BOTTOM)
  987. .atView('pup_positon_music')
  988. .setBackgroundColor(Color.Black)
  989. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  990. .show()
  991. } else {
  992. pup = XPopup.Builder()
  993. .setPopupPosition(PopupPosition.BOTTOM)
  994. .atView('pup_positon_music')
  995. .setBackgroundColor(Color.White)
  996. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  997. .show()
  998. }
  999. dataBean.onItemClick = (i) => {
  1000. XPopup.dismissTop()
  1001. switch (i) {
  1002. case 0: //首页
  1003. this.modeType = 0
  1004. this.getSortedFiles(this.currentPath)
  1005. break
  1006. case 1:
  1007. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1008. this.modeType = 1
  1009. this.updateListData(this.mediaKuList)
  1010. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  1011. break
  1012. case 2:
  1013. this.modeType = 2
  1014. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1015. this.updateListData(this.artistList)
  1016. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  1017. break
  1018. case 3:
  1019. this.modeType = 3
  1020. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1021. this.updateListData(this.albumList)
  1022. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  1023. break
  1024. case 4: //同步数据
  1025. this.asyncCurrentPathData()
  1026. break
  1027. }
  1028. }
  1029. }
  1030. getCurFileList(): Array<VideoItem> {
  1031. let files: Array<VideoItem> = [];
  1032. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1033. for (let i = 0; i < this.videoLocalList.length; i++) {
  1034. if (this.videoLocalList[i].type === CommonConstants.TYPE_LOCAL) {
  1035. files.push(this.videoLocalList[i]);
  1036. }
  1037. }
  1038. }
  1039. return files
  1040. }
  1041. setButtonStatus() {
  1042. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1043. this.isZero = false
  1044. } else {
  1045. this.isZero = true
  1046. }
  1047. if (this.currentPath !== this.rootPath &&
  1048. ArrayUtil.isNotEmpty(Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR))) {
  1049. this.isHasDir = true //不为空,说明有子文件夹
  1050. } else {
  1051. this.isHasDir = false
  1052. }
  1053. }
  1054. showRankDialog() {
  1055. if (this.modeType === 2 || this.modeType === 3) {
  1056. //动作面板
  1057. DialogHelper.showBottomSheetDialog({
  1058. title: "请选择排序模式",
  1059. maskColor: Color.Transparent,
  1060. // sheets: ["按名称升序", "按名称降序"],
  1061. sheets: [
  1062. { value: '按名称升序', fontColor: $r('app.color.text_color') },
  1063. { value: '按名称降序', fontColor: $r('app.color.text_color') },
  1064. ],
  1065. backgroundColor: $r('app.color.bg_card'),
  1066. height: '30%',
  1067. transition: AnimationHelper.transitionInDown(555),
  1068. onAction: (index) => {
  1069. switch (index) {
  1070. case 0:
  1071. Utility.doSortListAscending(this.videoLocalList)
  1072. break;
  1073. case 1:
  1074. Utility.doSortListDescending(this.videoLocalList)
  1075. break;
  1076. }
  1077. this.updateListData(this.videoLocalList)
  1078. }
  1079. })
  1080. return
  1081. }
  1082. //动作面板
  1083. DialogHelper.showBottomSheetDialog({
  1084. title: "请选择排序模式",
  1085. maskColor: Color.Transparent,
  1086. height: '75%',
  1087. // sheets: ["按艺术家升序", "按艺术家降序", "按专辑升序", "按专辑降序", "按名称升序", "按名称降序", "按添加时间升序","按添加时间降序"],
  1088. sheets: [
  1089. { value: "按艺术家升序", fontColor: $r('app.color.text_color') },
  1090. { value: "按艺术家降序", fontColor: $r('app.color.text_color') },
  1091. { value: "按专辑升序", fontColor: $r('app.color.text_color') },
  1092. { value: "按专辑降序", fontColor: $r('app.color.text_color') },
  1093. { value: "按名称升序", fontColor: $r('app.color.text_color') },
  1094. { value: "按名称降序", fontColor: $r('app.color.text_color') },
  1095. { value: "按添加时间升序", fontColor: $r('app.color.text_color') },
  1096. { value: "按添加时间降序", fontColor: $r('app.color.text_color') },
  1097. ],
  1098. backgroundColor: $r('app.color.bg_card'),
  1099. transition: AnimationHelper.transitionInDown(555),
  1100. onAction: (index) => {
  1101. this.doSortType(index)
  1102. PreferencesUtil.put(SettingPage.SORT_TYPE, index)
  1103. this.updateListData(this.videoLocalList, true)
  1104. }
  1105. })
  1106. }
  1107. doSortType(index: number) {
  1108. switch (index) {
  1109. case 0:
  1110. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1111. // 类型排序优先级
  1112. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1113. if (typeOrder !== 0) {
  1114. return typeOrder;
  1115. }
  1116. // 处理艺术家可能为undefined的字符串比较
  1117. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1118. const artistB = b.artist?.trim() || '';
  1119. return artistA.localeCompare(artistB);
  1120. });
  1121. break;
  1122. case 1:
  1123. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1124. // 类型排序优先级
  1125. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1126. if (typeOrder !== 0) {
  1127. return typeOrder;
  1128. }
  1129. // 处理艺术家可能为undefined的字符串比较
  1130. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1131. const artistB = b.artist?.trim() || '';
  1132. return artistB.localeCompare(artistA);
  1133. });
  1134. break;
  1135. case 2:
  1136. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1137. // 类型排序优先级
  1138. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1139. if (typeOrder !== 0) {
  1140. return typeOrder;
  1141. }
  1142. // 处理专辑可能为undefined的字符串比较
  1143. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1144. const albumB = b.album?.trim() || '';
  1145. return albumA.localeCompare(albumB);
  1146. });
  1147. break;
  1148. case 3:
  1149. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1150. // 类型排序优先级
  1151. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1152. if (typeOrder !== 0) {
  1153. return typeOrder;
  1154. }
  1155. // 处理专辑可能为undefined的字符串比较
  1156. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1157. const albumB = b.album?.trim() || '';
  1158. return albumB.localeCompare(albumA);
  1159. });
  1160. break;
  1161. case 4:
  1162. Utility.doSortListAscending(this.videoLocalList)
  1163. break;
  1164. case 5:
  1165. Utility.doSortListDescending(this.videoLocalList)
  1166. break;
  1167. case 6:
  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 ascending order
  1175. return a.cTime.localeCompare(b.cTime);
  1176. });
  1177. break;
  1178. case 7:
  1179. this.videoLocalList.sort((a, b) => {
  1180. // First, sort by type
  1181. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1182. if (typeOrder !== 0) {
  1183. return typeOrder;
  1184. }
  1185. // If types are the same, sort by cTime in descending order
  1186. return b.cTime.localeCompare(a.cTime);
  1187. });
  1188. break;
  1189. }
  1190. }
  1191. showSheelDialog() {
  1192. // if(PreferencesUtil.getBooleanSync('isFirstMusic',true)) {
  1193. // this.showTips()
  1194. // return
  1195. // }
  1196. this.showAddDialog()
  1197. }
  1198. showAddDialog() {
  1199. if (this.modeType === 2 || this.modeType === 3) {
  1200. return
  1201. }
  1202. DialogHelper.showActionSheetDialog({
  1203. title: "请选择添加方式(建议歌词文件一起导入)",
  1204. // sheets: ["新建歌单", "手动导入", "自动导入"],
  1205. sheets: [
  1206. { value: "新建歌单", fontColor: $r('app.color.text_color') },
  1207. { value: "手动导入", fontColor: $r('app.color.text_color') },
  1208. { value: "自动导入", fontColor: $r('app.color.text_color') },
  1209. { value: "全选导入", fontColor: $r('app.color.text_color') },
  1210. ],
  1211. maskColor: Color.Transparent,
  1212. backgroundColor: $r('app.color.bg_card'),
  1213. transition: AnimationHelper.transitionInDown(555),
  1214. onAction: (index) => {
  1215. switch (index) {
  1216. case 0:
  1217. if (this.modeType === 0) {
  1218. this.showMkDialog()
  1219. } else {
  1220. ToastUtil.showToast('请切换到首页才能新建歌单!')
  1221. }
  1222. break;
  1223. case 1:
  1224. this.callFilePickerSelectFile()
  1225. break;
  1226. case 2:
  1227. this.showTips()
  1228. break;
  1229. case 3:
  1230. this.goSelectMusic()
  1231. break;
  1232. }
  1233. }
  1234. })
  1235. }
  1236. //拉起音频
  1237. goSelectMusic() {
  1238. if (DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_TABLET ||
  1239. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_PC ||
  1240. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1
  1241. ) {
  1242. ToastUtil.showToast('暂时不支持该设备')
  1243. return
  1244. }
  1245. try {
  1246. let documentSelectOptions = new picker.DocumentSelectOptions();
  1247. documentSelectOptions.authMode = true
  1248. documentSelectOptions.multiAuthMode = true
  1249. documentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO;
  1250. let documentPicker = new picker.DocumentViewPicker(this.context);
  1251. documentPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => {
  1252. if (documentSelectResult !== null && documentSelectResult !== undefined) {
  1253. this.saveVideoDatas(documentSelectResult)
  1254. }
  1255. console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' +
  1256. JSON.stringify(documentSelectResult));
  1257. }).catch((err: BusinessError) => {
  1258. console.error(`DocumentViewPicker.select failed with err, code is: ${err.code}, message is: ${err.message}`);
  1259. });
  1260. } catch (error) {
  1261. let err: BusinessError = error as BusinessError;
  1262. console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1263. }
  1264. }
  1265. async showTips() {
  1266. DialogHelper.showTipsDialog({
  1267. title: '使用提示:自动导入教程',
  1268. content: '用系统自带的文件管理器将:\n\n1、音频文件放入' + '\n\n我的设备/Download/'
  1269. + this.appName + '\n\n2、无需繁琐的勾选和分类步骤。\n\n3、每个子文件夹将被组成一个分组。' +
  1270. '\n\n4、歌词文件的文件名必须和目标歌曲文件名相同(不包含后缀名)。\n\n5、歌词文件和目标歌曲文件必须同个目录。' +
  1271. '\n\n6、电脑上Download的目录是\nDownload/' + this.packName + '。\n\n7、放好文件后如果没显示点击刷新按钮。\n',
  1272. onAction: (action) => {
  1273. if (action == DialogAction.TWO) {
  1274. PreferencesUtil.putSync('isFirstMusic', false)
  1275. router.pushUrl({
  1276. url: 'pages/ScanFilePage'
  1277. });
  1278. }
  1279. }
  1280. })
  1281. }
  1282. showMkDialog() {
  1283. DialogHelper.showTextInputDialog({
  1284. title: '新建歌单',
  1285. maskColor: Color.Transparent,
  1286. text: '',
  1287. transition: AnimationHelper.transitionInDown(666),
  1288. onChange: (text) => {
  1289. console.error("onChange: " + text);
  1290. },
  1291. onAction: (action, dialogId, content) => {
  1292. // ToastUtil.showToast('content = ' +content)
  1293. if (action == DialogAction.TWO) {
  1294. const newName = content
  1295. const newPath = this.currentPath + '/' + newName
  1296. FileUtil.mkdir(newPath, true).then(() => {
  1297. this.cache.delete(this.currentPath); // 删除目标路径缓存
  1298. this.getSortedFiles(this.currentPath)
  1299. }).catch((error: BusinessError) => {
  1300. console.error(error.message);
  1301. });
  1302. }
  1303. }
  1304. })
  1305. }
  1306. @State progress: number = 0;
  1307. async saveVideoDatas(uris: string[], isOpen?: boolean) {
  1308. if (ArrayUtil.isEmpty(uris)) {
  1309. return;
  1310. }
  1311. let newUris: string[] = [];
  1312. this.progress = 0
  1313. DialogHelper.showLoadingProgress({
  1314. progress: this.progress,
  1315. backCancel: false,
  1316. autoCancel: false,
  1317. loadColor: this.themeColor,
  1318. fontColor: this.themeColor
  1319. });
  1320. // 计算所有文件的总大小
  1321. let totalSize = 0;
  1322. for (let uri of uris) {
  1323. const sourceFile = await fileIo.open(uri, fileIo.OpenMode.READ_ONLY);
  1324. totalSize += (await fileIo.stat(sourceFile.fd)).size;
  1325. await fileIo.close(sourceFile.fd);
  1326. }
  1327. let totalRead = 0;
  1328. let destPath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[0]);
  1329. Logger.info(TAG, 'destPath uri: ' + destPath);
  1330. for (let i = 0; i < uris.length; i++) {
  1331. let filePath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[i]);
  1332. Logger.info(TAG, 'filePath uri: ' + filePath);
  1333. newUris.push(filePath);
  1334. try {
  1335. const sourceFile = await fileIo.open(uris[i], fileIo.OpenMode.READ_ONLY);
  1336. const destFile = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  1337. const buffSize = 1024 * 1024; // 1MB 缓冲区大小
  1338. const buffer = new ArrayBuffer(buffSize);
  1339. let len = await fileIo.read(sourceFile.fd, buffer);
  1340. while (len > 0) {
  1341. await fileIo.write(destFile.fd, buffer.slice(0, len));
  1342. totalRead += len;
  1343. // 计算总进度
  1344. this.progress = Math.floor((totalRead / totalSize) * 100);
  1345. DialogHelper.updateLoading('正在导入', this.progress);
  1346. len = await fileIo.read(sourceFile.fd, buffer);
  1347. }
  1348. await fileIo.close(sourceFile.fd);
  1349. await fileIo.close(destFile.fd);
  1350. if (this.currentPath !== this.lockPath) { //判断不是私密音乐,才入库
  1351. if (!filePath.endsWith('.lrc') && Utility.isMeidaByExtension(filePath) && !filePath.endsWith('.srt')) {
  1352. let mediaItem: VideoItem =
  1353. await Utility.uriGetMusicAssetsFromFile(this.context, filePath, CommonConstants.TYPE_LOCAL, true);
  1354. this.table.insert(mediaItem, (id: number) => {
  1355. // 删除目标路径缓存
  1356. this.cache.delete(this.currentPath);
  1357. this.getSortedFiles(this.currentPath, true, destPath, isOpen)
  1358. });
  1359. }
  1360. }
  1361. } catch (error) {
  1362. Logger.error(TAG, 'saveVideoDatas failed with err: ' + JSON.stringify(error));
  1363. }
  1364. }
  1365. DialogHelper.closeLoading()
  1366. this.isZero = false
  1367. // setTimeout(() => {
  1368. // // 删除目标路径缓存
  1369. // this.cache.delete(this.currentPath);
  1370. // this.getSortedFiles(this.currentPath,true,destPath,isOpen)
  1371. // }, 500);
  1372. Logger.info(TAG, 'scan select video result:' + newUris)
  1373. }
  1374. //拉起音频
  1375. // goSelectMusic(){
  1376. //
  1377. // try {
  1378. // let audioSelectOptions = new picker.AudioSelectOptions();
  1379. // let audioPicker = new picker.AudioViewPicker(this.context);
  1380. // audioPicker.select(audioSelectOptions).then((audioSelectResult: Array<string>) => {
  1381. // if (audioSelectResult !== null && audioSelectResult !== undefined) {
  1382. // this.saveVideoDatas(audioSelectResult)
  1383. // }
  1384. // console.info('AudioViewPicker.select successfully, audioSelectResult uri: ' + JSON.stringify(audioSelectResult));
  1385. // }).catch((err: BusinessError) => {
  1386. //
  1387. // console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
  1388. // });
  1389. // } catch (error) {
  1390. // let err: BusinessError = error as BusinessError;
  1391. // console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1392. // }
  1393. //
  1394. //
  1395. //
  1396. // }
  1397. async goSelectImage(item: VideoItem): Promise<string | undefined> {
  1398. if (!item) {
  1399. return undefined;
  1400. }
  1401. try {
  1402. let selectUris: Array<string> = [];
  1403. let photoPicker = new photoAccessHelper.PhotoViewPicker();
  1404. let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  1405. photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
  1406. photoSelectOptions.maxSelectNumber = 1;
  1407. const photoSelectResult = await photoPicker.select(photoSelectOptions);
  1408. selectUris = photoSelectResult.photoUris;
  1409. console.info('photoViewPicker.select to file succeed and uris are:' + selectUris);
  1410. let file = fs.openSync(selectUris[0], fs.OpenMode.READ_ONLY);
  1411. console.info('file fd: ' + file.fd);
  1412. let name = await MD5.digestSync(this.videoUrl)+'.jpg'
  1413. let imagePath = this.context.filesDir + FileUtil.separator + name
  1414. imagePath = fileUri.getUriFromPath(imagePath)
  1415. let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  1416. fileIo.copyFileSync(file.fd, file2.fd)
  1417. fileIo.closeSync(file);
  1418. fileIo.closeSync(file2);
  1419. if (item.filePath == this.currentSong?.filePath) {
  1420. this.cover = imagePath
  1421. }
  1422. if (item) {
  1423. item.pixelMapPath = imagePath
  1424. }
  1425. this.table.updatePixelMapPath(item.filePath, imagePath, (success: boolean, error?: string) => {
  1426. if (success) {
  1427. this.doUpdateData()
  1428. console.log("onecold 更新音乐封面成功,数据库已同步");
  1429. } else {
  1430. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  1431. }
  1432. });
  1433. LogUtil.debug("onecold this.cover =" + this.cover)
  1434. return FileUtil.getFilePath(imagePath); // Return the image path here
  1435. } catch (err) {
  1436. console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
  1437. return undefined;
  1438. }
  1439. }
  1440. // 拉起picker选择文件管理器
  1441. async callFilePickerSelectFile(): Promise<void> {
  1442. try {
  1443. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  1444. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE) {
  1445. DocumentSelectOptions.fileSuffixFilters = CommonConstants.MEDIA_FORMAT
  1446. } else {
  1447. DocumentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO
  1448. }
  1449. let documentPicker = new picker.DocumentViewPicker();
  1450. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  1451. Logger.info(TAG,
  1452. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  1453. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  1454. this.saveVideoDatas(DocumentSelectResult)
  1455. }
  1456. }).catch((err: BusinessError) => {
  1457. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  1458. });
  1459. } catch (err) {
  1460. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  1461. }
  1462. }
  1463. showWarnIsDeleteFile(item: VideoItem, index: string, filePath: string) {
  1464. //操作确认类弹出框
  1465. DialogHelper.showAlertDialog({
  1466. maskColor: Color.Transparent,
  1467. content: "确定要删除这个文件吗?",
  1468. backgroundColor: Color.Grey,
  1469. transition: AnimationHelper.transitionInUp(555),
  1470. onAction: (action) => {
  1471. if (action == DialogAction.ONE) {
  1472. // ToastUtil.showToast(`您点击了取消按钮`);
  1473. } else if (action == DialogAction.TWO) {
  1474. // ToastUtil.showToast(`您点击了确认按钮`);
  1475. this.doDelete(item, index + '', filePath)
  1476. }
  1477. }
  1478. })
  1479. }
  1480. //删除单个索引index的视频
  1481. doDelete(item: VideoItem, index: string, filePath: string) {
  1482. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1483. Logger.info(TAG, 'delete filePath = ' + filePath);
  1484. if (item.type === CommonConstants.TYPE_IS_DIR) {
  1485. //旧文件删除
  1486. this.table.deleteDataForParentPath(item.filePath, () => {
  1487. FileUtil.rmdir(filePath).then(() => {
  1488. this.videoLocalList.splice(Number(index), 1)
  1489. this.deleteCache(this.currentPath)
  1490. this.getSortedFiles(this.currentPath, true)
  1491. }).catch((error: BusinessError) => {
  1492. console.error(error.message);
  1493. });
  1494. });
  1495. } else {
  1496. this.table.deleteData(item, () => {
  1497. FileUtil.unlink(filePath)
  1498. .catch((error: BusinessError) => {
  1499. console.error(error.message);
  1500. // 可以根据 error.code 判断是否为"文件不存在",如需特殊处理
  1501. })
  1502. .finally(() => {
  1503. this.videoLocalList.splice(Number(index), 1)
  1504. this.deleteCache(this.currentPath)
  1505. this.getSortedFiles(this.currentPath, true)
  1506. });
  1507. });
  1508. }
  1509. }
  1510. }
  1511. //重命名的对话框
  1512. showReNameDialog(item: VideoItem, index: string, filePath: string) {
  1513. DialogHelper.showTextInputDialog({
  1514. title: '重命名',
  1515. text: item.type === CommonConstants.TYPE_IS_DIR ? item.name : item.fileName,
  1516. maskColor: Color.Transparent,
  1517. backgroundColor: Color.Grey,
  1518. transition: AnimationHelper.transitionInDown(666),
  1519. onChange: (text) => {
  1520. console.error("onChange: " + text);
  1521. },
  1522. onAction: (action, dialogId, content) => {
  1523. // ToastUtil.showToast('content = ' +content)
  1524. if (action == DialogAction.TWO) {
  1525. const newName = content
  1526. const newPath = this.currentPath + '/' + newName
  1527. console.log("onecold item = " + item.type);
  1528. this.doReName(index, newName, filePath, newPath, item)
  1529. }
  1530. }
  1531. })
  1532. }
  1533. //剪切 移动到另个文件夹的对话框
  1534. showCutDialog(isCurrent: boolean, item: VideoItem, index: number, id: string) {
  1535. Logger.info('onecold showCutDialog')
  1536. let mList: Array<string> = []
  1537. let rPath = this.rootPath
  1538. if (isCurrent) {
  1539. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1540. rPath = this.currentPath
  1541. } else {
  1542. mList = Utility.getNameList(this.dirList);
  1543. rPath = this.rootPath
  1544. }
  1545. let dataBean = new BubbleBean()
  1546. dataBean.data = mList
  1547. dataBean.color = this.themeColor
  1548. dataBean.onItemClick = (i) => {
  1549. const newPath = rPath + '/' + mList[i] + '/' + item.fileName
  1550. Logger.info('newPath = ' + newPath)
  1551. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  1552. ToastUtil.showToast('移动成功')
  1553. this.table.deleteData(item, () => {
  1554. });
  1555. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  1556. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  1557. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  1558. CommonConstants.TYPE_LOCAL, true);
  1559. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  1560. this.table.insert(newItem, (id: number) => {
  1561. //加入数据库
  1562. });
  1563. }
  1564. this.cache.delete(this.currentPath); // 删除原路径缓存
  1565. this.cache.delete(rPath + '/' + mList[i]); // 删除目标路径缓存
  1566. this.getSortedFiles(this.currentPath, true)
  1567. }).catch((error: BusinessError) => {
  1568. console.error(error.message);
  1569. });
  1570. XPopup.dismissTop()
  1571. }
  1572. let popupPosition: PopupPosition = PopupPosition.BOTTOM
  1573. if (ArrayUtil.isNotEmpty(this.videoLocalList) && this.videoLocalList.length > 7) {
  1574. popupPosition = PopupPosition.TOP
  1575. }
  1576. if (index <= 3) {
  1577. popupPosition = PopupPosition.BOTTOM
  1578. }
  1579. let pup: XPopup
  1580. if (this.isDarkMode) {
  1581. pup = XPopup.Builder()
  1582. .setPopupPosition(popupPosition)
  1583. .atView(id)// .setHeight(this.isCoverOpacity()?100:420)
  1584. .setBackgroundColor(Color.Black)
  1585. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1586. .show()
  1587. } else {
  1588. pup = XPopup.Builder()
  1589. .setPopupPosition(popupPosition)
  1590. .atView(id)// .setHeight(this.isCoverOpacity()?280:420)
  1591. .setBackgroundColor(Color.White)
  1592. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1593. .show()
  1594. }
  1595. }
  1596. //复制 到另个文件夹的对话框
  1597. showCopyDialog(isCurrent: boolean, item: VideoItem, index: number, id: string) {
  1598. Logger.info('onecoldv showCopyDialog')
  1599. let mList: Array<string> = []
  1600. let rPath = this.rootPath
  1601. if (isCurrent) {
  1602. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1603. rPath = this.currentPath
  1604. } else {
  1605. mList = Utility.getNameList(this.dirList);
  1606. rPath = this.rootPath
  1607. }
  1608. let dataBean = new BubbleBean()
  1609. dataBean.data = mList
  1610. dataBean.isCopy = true
  1611. dataBean.color = this.themeColor
  1612. dataBean.onItemClick = (i) => {
  1613. const newPath = rPath + '/' + mList[i] + '/' + item.fileName
  1614. Logger.info('newPath = ' + newPath)
  1615. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  1616. ToastUtil.showToast('复制成功')
  1617. this.cache.delete(rPath + '/' + mList[i]); // 删除目标路径缓存
  1618. this.getSortedFiles(this.currentPath)
  1619. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  1620. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  1621. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  1622. CommonConstants.TYPE_LOCAL, true);
  1623. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  1624. this.table.insert(newItem, (id: number) => {
  1625. //加入数据库
  1626. });
  1627. }
  1628. }).catch((error: BusinessError) => {
  1629. console.error(error.message);
  1630. });
  1631. XPopup.dismissTop()
  1632. }
  1633. let popupPosition: PopupPosition = PopupPosition.BOTTOM
  1634. if (ArrayUtil.isNotEmpty(this.videoLocalList) && this.videoLocalList.length > 7) {
  1635. popupPosition = PopupPosition.TOP
  1636. }
  1637. if (index <= 3) {
  1638. popupPosition = PopupPosition.BOTTOM
  1639. }
  1640. let pup: XPopup
  1641. if (this.isDarkMode) {
  1642. pup = XPopup.Builder()
  1643. .setPopupPosition(popupPosition)
  1644. .atView(id)
  1645. .setMaxHeight('60%')
  1646. .setBackgroundColor(Color.Black)
  1647. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1648. .show();
  1649. } else {
  1650. pup = XPopup.Builder()
  1651. .setPopupPosition(popupPosition)
  1652. .atView(id)
  1653. .setMaxHeight('60%')
  1654. .setBackgroundColor(Color.White)
  1655. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1656. .show();
  1657. }
  1658. }
  1659. //重命名索引index的视频
  1660. doReName(index: string, newName: string, oldPath: string, newPath: string, info: VideoItem) {
  1661. FileUtil.rename(oldPath, newPath).then(async () => {
  1662. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1663. if (info.type === CommonConstants.TYPE_IS_DIR) {
  1664. //如果是文件夹先删除源数据,再添加新数据
  1665. this.table.deleteDataForParentPath(oldPath, (success: boolean, error?: string) => {
  1666. if (success) {
  1667. console.log(" onecold deleteDataForParentPath 文件夹重命名成功,数据库已同步");
  1668. } else {
  1669. console.error(" onecold deleteDataForParentPath 文件夹重命名数据库失败原因: " + error);
  1670. }
  1671. });
  1672. this.scanDirectory(newPath)
  1673. } else if (info.type === CommonConstants.TYPE_LOCAL) {
  1674. this.table.updateRename(newName, oldPath, newPath, (success: boolean, error?: string) => {
  1675. if (success) {
  1676. console.log(" onecold 重命名成功,数据库已同步");
  1677. } else {
  1678. console.error(" onecold 重命名数据库失败原因: " + error);
  1679. }
  1680. });
  1681. }
  1682. let mediaItem: VideoItem =
  1683. await Utility.uriGetMusicAssetsFromFile(this.context, newPath, CommonConstants.TYPE_LOCAL, true);
  1684. this.videoLocalList[index] = mediaItem;
  1685. }
  1686. this.cache.delete(this.currentPath)
  1687. this.getSortedFiles(this.currentPath, true)
  1688. }).catch((error: BusinessError) => {
  1689. console.error(error.message);
  1690. });
  1691. }
  1692. build() {
  1693. Scroll() {
  1694. Column() {
  1695. if (!this.isShowCoverHeader()) {
  1696. Column() {
  1697. Line().width('100%').height('100%')
  1698. }
  1699. .height(this.topRectHeight)
  1700. .backgroundColor(this.isCustomizeBg ? Color.Transparent :
  1701. (this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor))
  1702. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  1703. TitleBar({ model: $titleBarModel })
  1704. .id('pup_positon_music')
  1705. }
  1706. Stack() {
  1707. Column() {
  1708. XComponent({
  1709. id: 'xcomponentId',
  1710. type: 'surface',
  1711. libraryname: 'ijkplayer_napi',
  1712. controller: this.xcomponentController
  1713. })
  1714. .onLoad((event?: object) => {
  1715. if (!!event) {
  1716. this.initDelayPlay(event);
  1717. }
  1718. })
  1719. .onKeyEvent((event?: KeyEvent) => {
  1720. // If the button type is pressed, the subsequent code will not be executed; the specific button logic will be executed upon release.
  1721. if (!event || event.type !== KeyType.Down) {
  1722. return;
  1723. }
  1724. //空格键 Space key controls pause/play
  1725. if (event.keyCode === KeyCode.KEYCODE_SPACE) {
  1726. this.playOrPause()
  1727. }
  1728. // Right-click to fast forward
  1729. if (event.keyCode === KeyCode.KEYCODE_DPAD_RIGHT) {
  1730. this.sessionFastForwardCallback(15);
  1731. }
  1732. // Left-click to rewind
  1733. if (event.keyCode === KeyCode.KEYCODE_DPAD_LEFT) {
  1734. this.sessionRewindCallback(15);
  1735. }
  1736. })
  1737. .onDestroy(() => {
  1738. })
  1739. .width('100%')// .width(this.videoWidth)
  1740. .aspectRatio(this.videoAspectRatio)
  1741. }
  1742. .aspectRatio(this.videoAspectRatio)
  1743. .justifyContent(FlexAlign.Center)
  1744. .backgroundColor(Color.Transparent)
  1745. .visibility(Visibility.Hidden)
  1746. .height(CommonConstants.FULL_PERCENT)
  1747. .width(CommonConstants.FULL_PERCENT)
  1748. Stack() {
  1749. Row() {
  1750. Blank()
  1751. .layoutWeight(1)
  1752. IndexerView(
  1753. {
  1754. indexArray: DEFAULT_INDEX,
  1755. selectedIndex: this.selectedIndex,
  1756. textSize: 12,
  1757. selectedColor: "#ff419ee5",
  1758. normalColor: "#ffa0a0a0",
  1759. floatSelectedTextColor: "#ffffff",
  1760. floatSelectedViewColor: "#ff419ee5",
  1761. onIndexChanged: (index) => {
  1762. this.listScroller.scrollToIndex(index)
  1763. }
  1764. })
  1765. .width(24)
  1766. .height("50%")
  1767. }.visibility(Visibility.None)
  1768. Column() {
  1769. if (!this.isShowCoverHeader()) {
  1770. this.tabTitle()
  1771. }
  1772. if (this.isGridMusic) {
  1773. this.getGridView()
  1774. } else {
  1775. this.getListView()
  1776. }
  1777. if (this.modeType == 0) {
  1778. Column() {
  1779. Button('同步数据', { type: ButtonType.Capsule, stateEffect: true })
  1780. .width(130)
  1781. .height(50)
  1782. .margin({ top: 100, bottom: 40 })
  1783. .backgroundColor(this.themeColor)
  1784. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  1785. .onClick(() => {
  1786. this.asyncCurrentPathData()
  1787. })
  1788. }
  1789. .height(100)
  1790. .position({ top: 260 })
  1791. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  1792. .animation({ duration: 500 }),
  1793. TransitionEffect.scale({ x: 0, y: 0 })))
  1794. .justifyContent(FlexAlign.Center)
  1795. .opacity(this.isZero ? 1 : 0)
  1796. .visibility(this.isZero && !this.isFavMusic && !this.isHistory
  1797. && this.modeType === 0 ? Visibility.Visible : Visibility.None)
  1798. .animation({
  1799. duration: 500,
  1800. curve: 'ease-in-out' // 可选动画曲线
  1801. })
  1802. .width('100%')
  1803. }
  1804. }
  1805. .layoutWeight(1)
  1806. .height('100%')
  1807. }
  1808. .layoutWeight(1)
  1809. .height('100%')
  1810. Row() {
  1811. Button(this.isAllSelected ? '全不选' : '全选', { type: ButtonType.Circle, stateEffect: true })
  1812. .width('35%')
  1813. .height(60)
  1814. .margin({ top: 10, bottom: 10, right: 6 })
  1815. .backgroundColor(this.themeColor)
  1816. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1817. .onClick(() => {
  1818. if (this.isAllSelected) {
  1819. // 全不选
  1820. this.selectedFiles = [];
  1821. } else {
  1822. // 全选
  1823. this.selectedFiles = [...this.getCurFileList()];
  1824. }
  1825. this.isAllSelected = !this.isAllSelected;
  1826. })
  1827. Button('内嵌标签', { type: ButtonType.Capsule, stateEffect: true })
  1828. .width(100)
  1829. .height(60)
  1830. .margin({ top: 10, bottom: 10, right: 6 })
  1831. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1832. .backgroundColor(this.themeColor)
  1833. .bindContentCover($$this.isOneKeyTags, this.TagsContentCoverBuilder(), {
  1834. transition: TransitionEffect.translate({ x: 500 }).animation({ curve: curves.springMotion(0.6, 0.8) })
  1835. })
  1836. .onClick(() => {
  1837. this.isOneKeyTags = !this.isOneKeyTags
  1838. })
  1839. // Button('剪切', { type: ButtonType.Circle, stateEffect: true })
  1840. // .width('35%')
  1841. // .height(60)
  1842. // .id('music_cut')
  1843. // .margin({ top: 10, bottom: 10, right: 6 })
  1844. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1845. // .backgroundColor(this.themeColor)
  1846. // .onClick(() => {
  1847. // this.showCutDialogForMultipleFiles(false, 'music_cut')
  1848. // })
  1849. //
  1850. // Button('移动', { type: ButtonType.Circle, stateEffect: true })
  1851. // .width('35%')
  1852. // .height(60)
  1853. // .id('music_cut_current')
  1854. // .visibility(this.isHasDir ? Visibility.Visible : Visibility.None)
  1855. // .margin({ top: 10, bottom: 10, right: 6 })
  1856. // .backgroundColor(this.themeColor)
  1857. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1858. // .onClick(() => {
  1859. //
  1860. // this.showCutDialogForMultipleFiles(true, 'music_cut_current')
  1861. // })
  1862. // Button('复制', { type: ButtonType.Circle, stateEffect: true })
  1863. // .width('35%')
  1864. // .height(60)
  1865. // .id('music_copy_current')// .visibility(this.isHasDir?Visibility.None:Visibility.None)
  1866. // .margin({ top: 10, bottom: 10, right: 6 })
  1867. // .backgroundColor(this.themeColor)
  1868. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1869. // .onClick(() => {
  1870. // this.showCopyDialogForMultipleFiles(false, 'music_copy_current')
  1871. // })
  1872. Button('删除', { type: ButtonType.Circle, stateEffect: true })
  1873. .width('35%')
  1874. .height(60)
  1875. .margin({ top: 10, bottom: 10, right: 6 })
  1876. .visibility(this.isFavMusic ? Visibility.None : Visibility.Visible)
  1877. .backgroundColor(this.themeColor)
  1878. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1879. .onClick(() => {
  1880. this.showWarnIsDelete()
  1881. })
  1882. Button('取消', { type: ButtonType.Circle, stateEffect: true })
  1883. .width('35%')
  1884. .height(60)
  1885. .margin({ top: 10, bottom: 10, right: 6 })
  1886. .backgroundColor(this.themeColor)
  1887. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1888. .onClick(() => {
  1889. this.selectedFiles = [];
  1890. this.isAllSelected = false
  1891. this.isMultiSelect = false
  1892. })
  1893. }
  1894. .width('100%')
  1895. .justifyContent(FlexAlign.Center)
  1896. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  1897. .opacity(this.isMultiSelect ? 1 : 0)
  1898. .animation({
  1899. duration: 666,
  1900. curve: 'ease-in-out' // 可选动画曲线
  1901. })
  1902. .position(this.isShowCoverHeader() ? { bottom: 78 }
  1903. : { bottom: this.isPhoneLan() ? 130 : 168 }) // 将 Row 固定在底部
  1904. }
  1905. .width('100%')
  1906. .height('100%')
  1907. .alignContent(Alignment.Top)
  1908. Column() {
  1909. this.PlayController()
  1910. }
  1911. .hitTestBehavior(HitTestMode.Transparent)
  1912. .position({ bottom: 0 }) // 将 Row 固定在底部
  1913. .opacity(this.barBottomOpacity)
  1914. }
  1915. .width('100%')
  1916. .height('100%')
  1917. .backgroundImage(this.isCustomizeBg ? this.customizeBgPath : $r('app.color.bottom_control_background'))
  1918. .backgroundImageSize(this.isCoverOpacity() ? { width: '100%' } : { height: '100%' })
  1919. .backgroundImagePosition(Alignment.Center)
  1920. .backdropBlur(this.blurValue)
  1921. .backgroundBrightness({ rate: this.isCustomizeBg ? 0.1 : 0, lightUpDegree: this.bgBrightness })
  1922. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
  1923. }
  1924. }
  1925. @Builder
  1926. TagsContentCoverBuilder() {
  1927. Scroll() {
  1928. Column() {
  1929. TagsContentCover(
  1930. {
  1931. selectedFiles:this.selectedFiles,
  1932. isShowDrawer:this.isOneKeyTags,
  1933. onTagsResult:(result: boolean)=>{
  1934. this.isMultiSelect = false
  1935. if(result){//如果嵌入成功,更新数据
  1936. this.doUpdateData()
  1937. }
  1938. }
  1939. }
  1940. )
  1941. }
  1942. }
  1943. .width('100%')
  1944. .height('100%')
  1945. }
  1946. asyncCurrentPathData() {
  1947. if (this.modeType == 0) {
  1948. workerInstance.postMessage({
  1949. code: 1,
  1950. data1: this.context,
  1951. data2: this.currentPath,
  1952. data3: this.lockPath,
  1953. data4: PreferencesUtil.getStringSync('COVER_API', ''),
  1954. });
  1955. }
  1956. }
  1957. // 处理文件选择的函数
  1958. handleFileSelection(item: VideoItem, checked: boolean) {
  1959. if (checked) {
  1960. if (!this.selectedFiles.some(x => x.filePath == item.filePath)) {
  1961. this.selectedFiles.push(item);
  1962. }
  1963. } else {
  1964. const index = this.selectedFiles.findIndex(x => x.filePath == item.filePath);
  1965. if (index > -1) {
  1966. this.selectedFiles.splice(index, 1);
  1967. }
  1968. }
  1969. }
  1970. showWarnIsDelete() {
  1971. //操作确认类弹出框
  1972. DialogHelper.showAlertDialog({
  1973. content: "确定要删除这些文件吗?",
  1974. transition: AnimationHelper.transitionInUp(666),
  1975. maskColor: Color.Transparent,
  1976. backgroundColor: Color.Grey,
  1977. onAction: (action) => {
  1978. if (action == DialogAction.ONE) {
  1979. // ToastUtil.showToast(`您点击了取消按钮`);
  1980. } else if (action == DialogAction.TWO) {
  1981. // ToastUtil.showToast(`您点击了确认按钮`);
  1982. this.deleteMultipleFiles()
  1983. }
  1984. }
  1985. })
  1986. }
  1987. //多选删除文件
  1988. deleteMultipleFiles() {
  1989. if (ArrayUtil.isNotEmpty(this.selectedFiles)) {
  1990. this.selectedFiles.forEach((item) => {
  1991. Logger.info(TAG, 'delete filePath = ' + item.filePath);
  1992. if (item.type === CommonConstants.TYPE_IS_DIR) {
  1993. this.table.deleteDataForParentPath(item.filePath, () => {
  1994. FileUtil.rmdir(item.filePath).then(() => {
  1995. this.videoLocalList = this.videoLocalList.filter(v => v !== item);
  1996. this.selectedFiles = [];
  1997. this.isMultiSelect = false
  1998. this.isAllSelected = false
  1999. this.cache.delete(this.currentPath);
  2000. this.getSortedFiles(this.currentPath, true);
  2001. }).catch((error: Error) => {
  2002. console.error(error.message);
  2003. });
  2004. });
  2005. } else {
  2006. this.table.deleteData(item, () => {
  2007. FileUtil.unlink(item.filePath).catch((error: Error) => {
  2008. console.error(error.message);
  2009. }).finally(() => {
  2010. this.videoLocalList = this.videoLocalList.filter(v => v !== item);
  2011. this.selectedFiles = [];
  2012. this.isMultiSelect = false
  2013. this.isAllSelected = false
  2014. this.cache.delete(this.currentPath);
  2015. this.getSortedFiles(this.currentPath, true);
  2016. });
  2017. });
  2018. }
  2019. });
  2020. }
  2021. }
  2022. //多选移动文件
  2023. showCutDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  2024. Logger.info('onecold showCutDialogForMultipleFiles')
  2025. let mList: Array<string> = []
  2026. let rPath = this.rootPath
  2027. if (isCurrent) {
  2028. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  2029. rPath = this.currentPath
  2030. } else {
  2031. mList = Utility.getNameList(this.dirList);
  2032. rPath = this.rootPath
  2033. }
  2034. let dataBean = new BubbleBean();
  2035. dataBean.data = mList;
  2036. dataBean.color = this.themeColor
  2037. dataBean.onItemClick = (i) => {
  2038. const newDirPath = rPath + '/' + mList[i];
  2039. // Logger.info('newDirPath = ' + newDirPath)
  2040. this.selectedFiles.forEach((item) => {
  2041. const newPath = newDirPath + '/' + item.fileName;
  2042. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  2043. ToastUtil.showToast('移动成功');
  2044. this.table.deleteData(item, () => {
  2045. this.cache.delete(this.currentPath); // 删除原路径缓存
  2046. this.cache.delete(newDirPath); // 删除目标路径缓存
  2047. this.getSortedFiles(this.currentPath, true);
  2048. });
  2049. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2050. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2051. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2052. CommonConstants.TYPE_LOCAL, true);
  2053. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2054. this.table.insert(newItem, (id: number) => {
  2055. //加入数据库
  2056. });
  2057. }
  2058. }).catch((error: Error) => {
  2059. console.error(error.message);
  2060. });
  2061. });
  2062. this.isMultiSelect = false
  2063. this.selectedFiles = [];
  2064. this.isAllSelected = false
  2065. XPopup.dismissTop();
  2066. };
  2067. let pup: XPopup
  2068. if (this.isDarkMode) {
  2069. pup = XPopup.Builder()
  2070. .setPopupPosition(PopupPosition.TOP)
  2071. .atView(viewId)
  2072. .setBackgroundColor(Color.Black)
  2073. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2074. .show();
  2075. } else {
  2076. pup = XPopup.Builder()
  2077. .setPopupPosition(PopupPosition.TOP)
  2078. .atView(viewId)
  2079. .setBackgroundColor(Color.White)
  2080. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2081. .show();
  2082. }
  2083. }
  2084. doFav(item: VideoItem) {
  2085. LogUtil.info('onecold doFav isFav=' + item.isFav)
  2086. let isFav = 0
  2087. if (Utility.getIsFav(this.favList, item)) {
  2088. isFav = 0
  2089. } else {
  2090. isFav = 1
  2091. }
  2092. this.table.updateIsFavByFilePath(item.filePath, isFav, async (result: boolean) => {
  2093. if (result) {
  2094. if (isFav === 1) {
  2095. ToastUtil.showToast('收藏成功');
  2096. } else {
  2097. ToastUtil.showToast('取消收藏成功');
  2098. }
  2099. this.deleteCache(this.currentPath)
  2100. this.getFavList(false)
  2101. if (this.modeType === 0 && !this.isFavMusic) {
  2102. LogUtil.info('onecold doFav currentPath =' + this.currentPath)
  2103. this.getSortedFiles(this.currentPath)
  2104. }
  2105. workerInstance.postMessage({ code: 2, data: this.context });
  2106. workerInstance.postMessage({ code: 3, data: this.context });
  2107. workerInstance.postMessage({ code: 4, data: this.context });
  2108. }
  2109. })
  2110. }
  2111. //多选复制文件
  2112. showCopyDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  2113. console.log('onecold showCopyDialogForMultipleFiles');
  2114. let mList: Array<string> = []
  2115. let rPath = this.rootPath
  2116. if (isCurrent) {
  2117. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  2118. rPath = this.currentPath
  2119. } else {
  2120. mList = Utility.getNameList(this.dirList);
  2121. rPath = this.rootPath
  2122. }
  2123. let dataBean = new BubbleBean();
  2124. dataBean.data = mList;
  2125. dataBean.isCopy = true
  2126. dataBean.color = this.themeColor
  2127. dataBean.onItemClick = (i) => {
  2128. const newDirPath = rPath + '/' + mList[i];
  2129. // Logger.info('newDirPath = ' + newDirPath)
  2130. this.selectedFiles.forEach((item) => {
  2131. const newPath = newDirPath + '/' + item.fileName;
  2132. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  2133. ToastUtil.showToast('复制成功');
  2134. this.cache.delete(newDirPath); // 删除目标路径缓存
  2135. this.getSortedFiles(this.currentPath);
  2136. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2137. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2138. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2139. CommonConstants.TYPE_LOCAL, true);
  2140. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2141. this.table.insert(newItem, (id: number) => {
  2142. //加入数据库
  2143. });
  2144. }
  2145. }).catch((error: Error) => {
  2146. console.error(error.message);
  2147. });
  2148. });
  2149. this.isMultiSelect = false
  2150. this.selectedFiles = [];
  2151. this.isAllSelected = false
  2152. XPopup.dismissTop();
  2153. };
  2154. let pup: XPopup
  2155. if (this.isDarkMode) {
  2156. pup = XPopup.Builder()
  2157. .setPopupPosition(PopupPosition.TOP)
  2158. .atView(viewId)
  2159. .setBackgroundColor(Color.Black)
  2160. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2161. .show();
  2162. } else {
  2163. pup = XPopup.Builder()
  2164. .setPopupPosition(PopupPosition.TOP)
  2165. .atView(viewId)
  2166. .setBackgroundColor(Color.White)
  2167. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2168. .show();
  2169. }
  2170. }
  2171. @Builder
  2172. private DirItem(item: VideoItem, index?: number) {
  2173. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2174. Row() {
  2175. Image(this.modeType !== 0 && StrUtil.isNotEmpty(item.pixelMapPath) ? item.pixelMapPath :
  2176. $r('app.media.music_group'))
  2177. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2178. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2179. .fillColor(this.themeColor)// .fontSize(33)
  2180. .alt($r('app.media.music_group'))
  2181. .borderRadius('100%')
  2182. .clip(true)
  2183. .margin({ left: 20, top: 8, bottom: 8 })
  2184. Column() {
  2185. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  2186. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2187. .maxLines(1)// .width('88%')
  2188. .animation({
  2189. duration: 555,
  2190. curve: 'ease-in-out',
  2191. })
  2192. .transition({
  2193. type: TransitionType.Insert,
  2194. opacity: 0,
  2195. translate: { x: 160 }
  2196. })
  2197. .margin({ left: 10, right: 20 })
  2198. .fontColor($r('app.color.text_color'))
  2199. Row() {
  2200. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  2201. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2202. .padding({ top: 8 })
  2203. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2204. .fontColor($r('app.color.text_color'))
  2205. .margin({ left: 10 })
  2206. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  2207. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2208. .padding({ top: 8 })
  2209. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2210. .fontColor($r('app.color.text_color'))
  2211. .margin({ left: 10 })
  2212. Blank()
  2213. }
  2214. }
  2215. .height('100%')
  2216. .layoutWeight(1)
  2217. .justifyContent(FlexAlign.Center)
  2218. .alignItems(HorizontalAlign.Start)
  2219. Blank()
  2220. Image($r('app.media.arrow_right'))
  2221. .height(25)
  2222. .margin({ right: 10 })
  2223. .alignSelf(ItemAlign.Center)
  2224. .id(item.filePath)
  2225. }
  2226. }
  2227. .backgroundColor(Color.Transparent)
  2228. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2229. .width('100%')
  2230. .visibility(this.isShowDir(item.name) ? Visibility.Visible : Visibility.None)
  2231. .opacity(this.opacityItem) // 绑定透明度
  2232. }
  2233. isShowDir(dirName: string) {
  2234. this.isShowSimi = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, false)
  2235. this.isShowFAV = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_FAV, true)
  2236. this.isShowHistory = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HISTORY, true)
  2237. if (dirName === undefined) {
  2238. return true
  2239. }
  2240. if (dirName === LocalMusic.STR_LOCK_VIDEO) {
  2241. return this.isShowSimi
  2242. }
  2243. if (dirName === LocalMusic.STR_FAC_VIDEO) {
  2244. return this.isShowFAV
  2245. }
  2246. if (dirName === LocalMusic.STR_HISTORY_MUSIC) {
  2247. return this.isShowHistory
  2248. }
  2249. return true
  2250. }
  2251. @State opacityItem: number = 1; // 控制透明度的状态变量
  2252. @Builder
  2253. private MusicItem(item: VideoItem, index?: number) {
  2254. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2255. Row() {
  2256. Stack() {
  2257. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  2258. .fillColor(this.themeColor)
  2259. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2260. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2261. .alt($r('app.media.music_red'))
  2262. .borderRadius('100%')
  2263. .clip(true)
  2264. .draggable(false)
  2265. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  2266. .autoResize(true) // 重采样,可减少内存占用
  2267. .opacity(this.opacityItem)// 绑定透明度
  2268. .margin({ left: 20 })
  2269. .gesture(LongPressGesture()
  2270. .onAction(async () => {
  2271. //如果是专辑和艺术家的首页,不能长按
  2272. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2273. return
  2274. //如果是我的收藏 最近播放等也不能长按
  2275. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2276. item.name === LocalMusic.STR_HISTORY_MUSIC
  2277. )
  2278. return
  2279. this.longItemFilePath = item.filePath
  2280. this.tempLyricContent = await this.getLyricContent(item)
  2281. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2282. })
  2283. .onActionEnd((event: GestureEvent) => {
  2284. }))
  2285. }
  2286. Column() {
  2287. Column() {
  2288. Text(item.name)
  2289. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2290. .maxLines(1)
  2291. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  2292. .animation({
  2293. duration: 555,
  2294. curve: 'Linear',
  2295. })
  2296. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2297. $r('app.color.text_color'))
  2298. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2299. .bindPopup(this.longItemFilePath === item.filePath, {
  2300. builder: this.MenuBuilder(item,index,item.filePath),
  2301. placement: Placement.Top,
  2302. // autoCancel: true,
  2303. mask: {color:'#33000000'},
  2304. // popupColor: Color.Yellow,
  2305. enableArrow: false,//是否显示箭头
  2306. showInSubWindow: false,
  2307. onStateChange: (e) => {
  2308. if (!e.isVisible) {
  2309. this.longItemFilePath = ''
  2310. this.tempLyricContent = ''
  2311. }
  2312. }
  2313. })
  2314. .gesture(LongPressGesture()
  2315. .onAction(async () => {
  2316. //如果是专辑和艺术家的首页,不能长按
  2317. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2318. return
  2319. //如果是我的收藏 最近播放等也不能长按
  2320. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2321. item.name === LocalMusic.STR_HISTORY_MUSIC
  2322. )
  2323. return
  2324. this.longItemFilePath = item.filePath
  2325. this.tempLyricContent = await this.getLyricContent(item)
  2326. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2327. })
  2328. .onActionEnd((event: GestureEvent) => {
  2329. })
  2330. )
  2331. Row() {
  2332. Column(){
  2333. Text(item.md5Str?.includes('Lossless')?
  2334. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  2335. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  2336. .padding({ top: 3,right:6,left:6,bottom:3 })
  2337. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2338. $r('app.color.text_color'))
  2339. .fontWeight(500)
  2340. .borderRadius(12)
  2341. .visibility(StrUtil.isEmpty(item.md5Str)?Visibility.None:Visibility.Visible)
  2342. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2343. .backgroundColor('#FFC107')
  2344. }
  2345. .padding({ top: 8 })
  2346. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  2347. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2348. .padding({ top: 8 })
  2349. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2350. $r('app.color.text_color'))
  2351. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2352. Blank()
  2353. Text(item.size)
  2354. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2355. .padding({ top: 8 })
  2356. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  2357. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2358. $r('app.color.text_color'))
  2359. .margin({ left: 10 })
  2360. }
  2361. .gesture(LongPressGesture()
  2362. .onAction(async () => {
  2363. //如果是专辑和艺术家的首页,不能长按
  2364. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2365. return
  2366. //如果是我的收藏 最近播放等也不能长按
  2367. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2368. item.name === LocalMusic.STR_HISTORY_MUSIC
  2369. )
  2370. return
  2371. this.longItemFilePath = item.filePath
  2372. this.tempLyricContent = await this.getLyricContent(item)
  2373. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2374. })
  2375. .onActionEnd((event: GestureEvent) => {
  2376. })
  2377. )
  2378. }
  2379. .height('100%')
  2380. .width('100%')
  2381. .justifyContent(FlexAlign.Center)
  2382. .alignItems(HorizontalAlign.Start)
  2383. }
  2384. .height('100%')
  2385. .margin({ left: 5 })
  2386. .layoutWeight(1)
  2387. Column() {
  2388. Checkbox({ name: 'checkbox' + index })
  2389. .select(this.selectedFiles.some(x => x.filePath === item.filePath))
  2390. .selectedColor(this.themeColor)
  2391. .shape(CheckBoxShape.CIRCLE)
  2392. .opacity(this.isMultiSelect ? 1 : 0)
  2393. .animation({
  2394. duration: 666,
  2395. curve: 'Smooth' // 可选动画曲线
  2396. })
  2397. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  2398. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  2399. .margin({ left: 20, top: 8, bottom: 8 })
  2400. .width(22)
  2401. .height(22)
  2402. ImageAnimator()
  2403. .images(this.imagesF)// 动画数组
  2404. .duration(1000)// 持续
  2405. .state(this.animationState)// 动画状态
  2406. .fillMode(FillMode.Forwards)
  2407. .width(18)
  2408. .margin({ right: 20, top: 8, bottom: 8 })
  2409. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  2410. Visibility.None)
  2411. .height(18)
  2412. .iterations(-1) // 播放次数
  2413. }
  2414. }
  2415. }
  2416. .backgroundColor(Color.Transparent)
  2417. .width('100%')
  2418. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2419. }
  2420. private readonly tabs: string[] = ['文件夹', '媒体库', '艺术家', '专辑']
  2421. @Builder
  2422. tabTitle() {
  2423. Column() {
  2424. // 使用 Stack 布局来实现绝对定位效果
  2425. Stack() {
  2426. // 背景动画容器
  2427. Row() {
  2428. ForEach(this.tabs, (i: string, index) => {
  2429. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2430. Flex()
  2431. .backgroundColor(this.isDarkMode ? $r('app.color.tab_item_bg') : this.themeColor)
  2432. .borderRadius(20)
  2433. .padding(10)
  2434. .margin(6)
  2435. .width('100%')
  2436. .height('100%')
  2437. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2438. .visibility(this.modeType === index ? Visibility.Visible : Visibility.None)
  2439. .opacity(this.modeType === index ? 1 : 0)
  2440. .animation({
  2441. duration: 666,
  2442. playMode: PlayMode.Normal,
  2443. curve: 'ease-in-out'
  2444. });
  2445. }
  2446. .layoutWeight(1)
  2447. .margin({
  2448. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5,
  2449. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5, bottom: 1
  2450. });
  2451. });
  2452. }
  2453. .width('100%')
  2454. .height(50);
  2455. // 导航栏容器
  2456. Row() {
  2457. ForEach(this.tabs, (item: string, index) => {
  2458. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2459. Text(item)
  2460. .fontSize(16)
  2461. .fontColor(this.modeType === index ? Color.White : $r('app.color.text_color'))
  2462. .padding(15)
  2463. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2464. .onClick(() => {
  2465. this.modeType = index;
  2466. this.onModeChange();
  2467. });
  2468. }
  2469. .layoutWeight(1)
  2470. .stateStyles({
  2471. pressed: { opacity: 0.6 } // 按压反馈
  2472. });
  2473. });
  2474. }
  2475. .width('100%')
  2476. .height(this.topBarHeight)
  2477. .opacity(this.barOpacity)
  2478. .backgroundColor(Color.Transparent);
  2479. }
  2480. .width('100%')
  2481. .height(this.topBarHeight)
  2482. .opacity(this.barOpacity)
  2483. Line()
  2484. .width('100%')
  2485. .height(1)
  2486. .backgroundColor($r('app.color.index_background'))
  2487. .opacity(this.barOpacity)
  2488. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  2489. }
  2490. .visibility(this.isShowTitleBar ? Visibility.Visible : Visibility.None)
  2491. }
  2492. @State currentTitleName: string = '' //点击歌单,艺术家,专辑进去后的标题
  2493. @State currentTitleCover: string | ResourceStr = '' //点击歌单,艺术家,专辑进去后的封面
  2494. isShowCoverHeader() {
  2495. if (!this.isShowHeader) {
  2496. return false
  2497. }
  2498. if (this.modeType == 0) {
  2499. if (this.isHistory || this.isFavMusic) {
  2500. return true
  2501. }
  2502. if (this.currentPath != this.rootPath) {
  2503. return true
  2504. }
  2505. }
  2506. return (this.modeType == 2 || this.modeType == 3) && this.isCanBack
  2507. }
  2508. @Builder
  2509. coverHeader() {
  2510. if (this.isShowCoverHeader()) {
  2511. Column() {
  2512. Stack() {
  2513. // 居中标题
  2514. Text('')
  2515. .fontSize(18)
  2516. .fontColor(Color.White)
  2517. .align(Alignment.Center)
  2518. // 左右按钮
  2519. Row() {
  2520. Image($r('app.media.left_back_white'))
  2521. .width(28)
  2522. .height(28)
  2523. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2524. .margin({ left: 12, right: 8 })
  2525. .onClick(() => {
  2526. animateTo({ duration: 555 }, () => {
  2527. this.doSwipBack()
  2528. })
  2529. })
  2530. Blank().flexGrow(1)
  2531. if (this.modeType == 0 && !this.isHistory && !this.isFavMusic) {
  2532. Image($r('app.media.add'))
  2533. .width(25)
  2534. .height(25)
  2535. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2536. .margin({ left: 8, right: 15 })
  2537. .onClick(() => {
  2538. this.showAddDialog()
  2539. })
  2540. }
  2541. }
  2542. .height(48)
  2543. .width('100%')
  2544. .alignItems(VerticalAlign.Center)
  2545. }
  2546. .height(48)
  2547. .width('100%')
  2548. Row() {
  2549. Column() {
  2550. Image(this.currentTitleCover)
  2551. .height(100)
  2552. .width(100)
  2553. .alt(this.imageLabel)
  2554. .borderRadius(8)
  2555. .clickEffect({ level: ClickEffectLevel.HEAVY })
  2556. }
  2557. .alignItems(HorizontalAlign.Start)
  2558. .margin({ left: 30, top: 3, bottom: 15 })
  2559. Column() {
  2560. Column() {
  2561. Text(this.currentTitleName)
  2562. .fontSize(16)
  2563. .maxLines(1)
  2564. .fontWeight(FontWeight.Bold)
  2565. .fontColor($r('app.color.text_color'))
  2566. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2567. if (this.modeType == 3 && ArrayUtil.isNotEmpty(this.videoLocalList)) {
  2568. Text(`艺术家:${this.videoLocalList[0].artist}`)
  2569. .fontSize(14)
  2570. .padding({ top: 8 })
  2571. .maxLines(1)
  2572. .fontWeight(FontWeight.Bold)
  2573. .fontColor($r('app.color.text_color'))
  2574. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2575. if(this.videoLocalList[0].genre){
  2576. Text(`风格:${this.videoLocalList[0].genre}`)
  2577. .fontSize(14)
  2578. .padding({ top: 8 })
  2579. .maxLines(1)
  2580. .visibility(StrUtil.isEmpty(this.videoLocalList[0].genre)||
  2581. this.videoLocalList[0].genre.includes(this.UNKONWN)
  2582. ?Visibility.None:Visibility.Visible)
  2583. .fontWeight(FontWeight.Bold)
  2584. .fontColor($r('app.color.text_color'))
  2585. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2586. }
  2587. if(this.videoLocalList[0].year){
  2588. Text(`发行时间:${this.videoLocalList[0].year}`)
  2589. .fontSize(14)
  2590. .padding({ top: 8 })
  2591. .maxLines(1)
  2592. .visibility(StrUtil.isEmpty(this.videoLocalList[0].year)||
  2593. this.videoLocalList[0].year.includes(this.UNKONWN)
  2594. ?Visibility.None:Visibility.Visible)
  2595. .fontWeight(FontWeight.Bold)
  2596. .fontColor($r('app.color.text_color'))
  2597. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2598. }
  2599. }
  2600. if(this.modeType != 3){
  2601. Row() {
  2602. Text(`共${this.videoLocalList.length}首歌`)
  2603. .fontSize(13)
  2604. .fontWeight(FontWeight.Bold)
  2605. .padding({ top: 8 })
  2606. .fontColor($r('app.color.text_color'))
  2607. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2608. Blank()
  2609. }
  2610. }
  2611. }
  2612. .height('100%')
  2613. .width('100%')
  2614. .justifyContent(FlexAlign.Center)
  2615. .alignItems(HorizontalAlign.Start)
  2616. }
  2617. .height('100%')
  2618. .layoutWeight(1)
  2619. .margin({ left: 20 })
  2620. }
  2621. this.listViewTitle()
  2622. }
  2623. .backgroundImage(this.getCoverTitleBg())
  2624. .height(250)
  2625. .width('100%')
  2626. .backgroundImageSize({ height: '100%', width: '100%' })
  2627. .backgroundBlurStyle(this.isCustomizeBg ? BlurStyle.NONE : BlurStyle.BACKGROUND_ULTRA_THICK)
  2628. .padding({ top: this.topRectHeight, bottom: this.bottomBarHeight + 48 })
  2629. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  2630. .justifyContent(FlexAlign.SpaceBetween)
  2631. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.7, y: 0.7 }).animation({ duration: 500 }),
  2632. TransitionEffect.scale({ x: 0, y: 0 })))
  2633. } else {
  2634. this.listViewTitle()
  2635. }
  2636. }
  2637. getCoverTitleBg(): ResourceStr | image.PixelMap {
  2638. if (this.isCustomizeBg) {
  2639. return ('rgba(255,255,255,0.2)')
  2640. }
  2641. if (this.isDarkMode) {
  2642. return $r('app.color.user_center_card_background')
  2643. }
  2644. return this.currentTitleCover
  2645. }
  2646. @Builder
  2647. listViewTitle() {
  2648. Column() {
  2649. Row({ space: 8 }) {
  2650. Row({ space: 8 }) {
  2651. Image($r("app.media.hm_playlist"))
  2652. .width(25)
  2653. .margin({ left: 8 })
  2654. .fillColor(this.themeColor)
  2655. Text(`共找到${this.artistList.length}位艺术家`)
  2656. .fontColor($r('app.color.text_color'))
  2657. .fontSize(14)
  2658. .opacity(this.opacityItem)
  2659. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2660. Text(`共找到${this.albumList.length}张专辑`)
  2661. .fontColor($r('app.color.text_color'))
  2662. .opacity(this.opacityItem)
  2663. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2664. .fontSize(14)
  2665. }
  2666. .layoutWeight(1)
  2667. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  2668. Row() {
  2669. TextInput({
  2670. placeholder: this.modeType === 2 ? '输入艺术家名称...' : '输入专辑名称...',
  2671. text: this.searchText
  2672. })
  2673. .height(35)
  2674. .onChange((value: string) => {
  2675. this.onSearchInput(value);
  2676. })
  2677. .layoutWeight(1)
  2678. Text(`取消`)
  2679. .margin({ left: 10, right: 10 })
  2680. .fontColor($r('app.color.text_color'))
  2681. .fontSize(16)
  2682. .onClick(() => {
  2683. this.isSearchMode = false
  2684. this.searchText = ''
  2685. if (this.modeType === 2) {
  2686. this.updateListData(this.artistList)
  2687. } else {
  2688. this.updateListData(this.albumList)
  2689. }
  2690. })
  2691. }
  2692. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  2693. .animation({
  2694. duration: 666,
  2695. curve: 'ease-in-out' // 可选动画曲线
  2696. })
  2697. Blank()
  2698. Image($r("app.media.search"))
  2699. .width(25)
  2700. .visibility(this.modeType === 2 || this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2701. .animation({
  2702. duration: 666,
  2703. curve: 'ease-in-out' // 可选动画曲线
  2704. })// .opacity(this.opacityItem)
  2705. .fillColor(this.themeColor)
  2706. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2707. .onClick(() => {
  2708. this.isSearchMode = true
  2709. })
  2710. Image($r("app.media.top_rank"))
  2711. .width(25)// .opacity(this.opacityItem)
  2712. .fillColor(this.themeColor)
  2713. .animation({
  2714. duration: 666,
  2715. curve: 'ease-in-out' // 可选动画曲线
  2716. })
  2717. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2718. .onClick(() => {
  2719. this.showRankDialog()
  2720. })
  2721. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  2722. .width(25)
  2723. .animation({
  2724. duration: 666,
  2725. curve: 'ease-in-out' // 可选动画曲线
  2726. })
  2727. .fillColor(this.themeColor)
  2728. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2729. .onClick(() => {
  2730. this.isGridMusic = !this.isGridMusic
  2731. })
  2732. }
  2733. .visibility(((this.modeType === 2 || this.modeType === 3) && !this.isCanBack) ? Visibility.Visible :
  2734. Visibility.None)
  2735. .width('100%')
  2736. .padding(10)
  2737. .height(50)
  2738. .border({
  2739. width: { bottom: 1 },
  2740. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2741. })
  2742. Row({ space: 8 }) {
  2743. Row({ space: 8 }) {
  2744. Image($r("app.media.hm_play"))
  2745. .width(25)
  2746. .margin({ left: 8 })
  2747. .fillColor(this.themeColor)
  2748. Text(`播放全部`)
  2749. .fontColor($r('app.color.text_color'))
  2750. .fontSize(14)
  2751. .animation({
  2752. duration: 666,
  2753. curve: 'ease-in-out' // 可选动画曲线
  2754. })
  2755. Text(`(${Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length}首)`)
  2756. .fontColor($r('app.color.text_color'))
  2757. .fontSize(14)
  2758. .opacity(this.opacityItem)
  2759. .animation({
  2760. duration: 666,
  2761. curve: 'ease-in-out' // 可选动画曲线
  2762. })
  2763. }
  2764. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2765. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  2766. .animation({
  2767. duration: 666,
  2768. curve: 'ease-in-out' // 可选动画曲线
  2769. })
  2770. // .backgroundColor(this.isClickedPLayAll ? $r('app.color.button_click') : Color.Transparent)
  2771. .onTouch((event: TouchEvent) => {
  2772. if (event.type === TouchType.Down) {
  2773. this.isClickedPLayAll = true;
  2774. } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
  2775. this.isClickedPLayAll = false;
  2776. }
  2777. })
  2778. .onClick(() => {
  2779. // ToastUtil.showToast('当前的手机的折叠状态 ='+DisplayUtil.getFoldStatus())
  2780. if (this.modeType === 0) {
  2781. if (ArrayUtil.isNotEmpty(this.getCurFileList())) {
  2782. this.doPlay(this.getCurFileList()[0])
  2783. }
  2784. } else {
  2785. if (ArrayUtil.isNotEmpty(this.mediaKuList)) {
  2786. this.doPlay(this.mediaKuList[0])
  2787. }
  2788. }
  2789. })
  2790. Row() {
  2791. TextInput({ placeholder: '输入名称...', text: this.searchText })
  2792. .height(35)
  2793. .onChange((value: string) => {
  2794. this.onSearchInput(value);
  2795. })
  2796. .layoutWeight(1)
  2797. Text(`取消`)
  2798. .margin({ left: 10, right: 10 })
  2799. .fontColor($r('app.color.text_color'))
  2800. .fontSize(16)
  2801. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2802. .onClick(() => {
  2803. this.isSearchMode = false
  2804. this.searchText = ''
  2805. this.updateListData(this.mediaKuList)
  2806. })
  2807. }
  2808. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  2809. .animation({
  2810. duration: 666,
  2811. curve: 'ease-in-out' // 可选动画曲线
  2812. })
  2813. Blank()
  2814. Image($r("app.media.search"))
  2815. .width(25)// .visibility(this.modeType===1?Visibility.Visible:Visibility.None)
  2816. .animation({
  2817. duration: 666,
  2818. curve: 'ease-in-out' // 可选动画曲线
  2819. })// .opacity(this.opacityItem)
  2820. .fillColor(this.themeColor)
  2821. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2822. .onClick(() => {
  2823. this.isSearchMode = true
  2824. })
  2825. Image($r("app.media.refresh"))
  2826. .fillColor(this.themeColor)
  2827. .width(25)
  2828. .visibility(this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
  2829. .animation({
  2830. duration: 666,
  2831. curve: 'ease-in-out' // 可选动画曲线
  2832. })
  2833. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2834. .onClick(() => {
  2835. if (this.isFavMusic) {
  2836. this.getFavList(true)
  2837. } else {
  2838. if(this.modeType == 0){
  2839. this.asyncCurrentPathData()
  2840. }else if(this.modeType ==1){
  2841. workerInstance.postMessage({ code: 2, data: this.context });
  2842. }
  2843. }
  2844. })
  2845. Image($r("app.media.top_rank"))
  2846. .width(25)
  2847. .visibility(this.isHistory || this.isSearchMode ? Visibility.None :
  2848. Visibility.Visible)// .opacity(this.opacityItem)
  2849. .animation({
  2850. duration: 666,
  2851. curve: 'ease-in-out' // 可选动画曲线
  2852. })
  2853. .fillColor(this.themeColor)
  2854. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2855. .onClick(() => {
  2856. this.showRankDialog()
  2857. })
  2858. Image(this.isMultiSelect ? $r("app.media.cancel_multi") : $r("app.media.top_flower"))
  2859. .width(24)
  2860. .visibility(this.isHistory || this.isSearchMode ? Visibility.None : Visibility.Visible)
  2861. .animation({
  2862. duration: 666,
  2863. curve: 'ease-in-out' // 可选动画曲线
  2864. })
  2865. .fillColor(this.themeColor)
  2866. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2867. .onClick(() => {
  2868. this.isMultiSelect = !this.isMultiSelect
  2869. })
  2870. SymbolGlyph($r('sys.symbol.trash'))
  2871. .fontColor([this.themeColor])
  2872. .fontSize(25)
  2873. .effectStrategy(1)
  2874. .visibility(this.isHistory ? Visibility.Visible : Visibility.None)
  2875. .animation({
  2876. duration: 666,
  2877. curve: 'ease-in-out' // 可选动画曲线
  2878. })
  2879. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2880. .onClick(() => {
  2881. this.clearVideoHistory() //清空播放记录
  2882. })
  2883. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  2884. .width(24)
  2885. .animation({
  2886. duration: 666,
  2887. curve: 'ease-in-out' // 可选动画曲线
  2888. })
  2889. .fillColor(this.themeColor)
  2890. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2891. .bindPopup($$this.tipPopup, {
  2892. builder: this.popupBuilder,
  2893. placement: Placement.Bottom,
  2894. maskColor: 0x33000000,
  2895. enableArrow: true,
  2896. onStateChange: (e) => {
  2897. if (!e.isVisible) {
  2898. this.tipPopup = false;
  2899. }
  2900. }
  2901. })
  2902. .onClick(() => {
  2903. this.isGridMusic = !this.isGridMusic
  2904. })
  2905. }
  2906. .width('100%')
  2907. .padding(10)
  2908. .height(50)
  2909. .visibility(this.modeType === 0 || this.modeType === 1 || this.isCanBack ? Visibility.Visible : Visibility.None)
  2910. .border({
  2911. width: { bottom: 1 },
  2912. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2913. })
  2914. }
  2915. .visibility(this.isShowAllBar ? Visibility.Visible : Visibility.None)
  2916. }
  2917. // 第二步:popup构造器定义弹框内容
  2918. @Builder popupBuilder() {
  2919. Column({ space: 2 }) {
  2920. Text('友情提示:双指缩放可以放大缩小列表')
  2921. .fontSize(12)
  2922. .fontWeight(FontWeight.Regular)
  2923. .fontColor($r('app.color.text_color'))
  2924. }
  2925. .justifyContent(FlexAlign.SpaceAround)
  2926. .width(220)
  2927. .height(55)
  2928. .padding(15)
  2929. }
  2930. //搜索功能的实现
  2931. @State searchText: string = ''; // 用户输入内容
  2932. @State filteredList: Array<VideoItem> = []; // 过滤后的结果
  2933. @State isSearchMode: boolean = false
  2934. // 实时搜索逻辑(带防抖)
  2935. private onSearchInput(value: string) {
  2936. this.searchText = value.trim();
  2937. let mSearchList: Array<VideoItem> = []
  2938. switch (this.modeType) {
  2939. case 0:
  2940. mSearchList = this.videoLocalList
  2941. break;
  2942. case 1:
  2943. mSearchList = this.mediaKuList
  2944. break;
  2945. case 2:
  2946. mSearchList = this.artistList
  2947. break;
  2948. case 3:
  2949. mSearchList = this.albumList
  2950. break;
  2951. }
  2952. // 新增条件判断:空输入时显示所有数据
  2953. if (this.searchText === '') {
  2954. this.filteredList = [...mSearchList]; // 创建新数组以触发状态更新
  2955. } else {
  2956. this.filteredList = mSearchList.filter((item: VideoItem) => {
  2957. return item.name.toLowerCase().includes(this.searchText.toLowerCase());
  2958. });
  2959. }
  2960. this.updateListData(this.filteredList);
  2961. // this.isSearchMode = false; // 根据业务需求决定是否启用
  2962. }
  2963. @State dragItem: number = -1
  2964. @State scaleItem: number = -1
  2965. @State neighborItem: number = -1
  2966. @State neighborScale: number = -1
  2967. @State offsetY: number = 0
  2968. private dragRefOffset: number = 0
  2969. private ITEM_INTV: number = 78
  2970. scaleSelect(item: number): number {
  2971. if (this.scaleItem === item) {
  2972. return 1.05
  2973. } else if (this.neighborItem === item) {
  2974. return this.neighborScale
  2975. } else {
  2976. return 1
  2977. }
  2978. }
  2979. itemMove(index: number, newIndex: number): void {
  2980. if (newIndex < 0 || newIndex >= this.videoLocalList.length) {
  2981. return;
  2982. }
  2983. let tmp = this.videoLocalList.splice(index, 1);
  2984. this.videoLocalList.splice(newIndex, 0, tmp[0]);
  2985. this.dataSource.pushArrayData(this.videoLocalList)
  2986. }
  2987. // Grid布局的开始
  2988. private dragRefOffSetX: number = 0;
  2989. private dragRefOffSetY: number = 0;
  2990. private FIX_VP_X: number = 180;
  2991. private FIX_VP_Y: number = 84;
  2992. isDraggable(index: number): boolean {
  2993. return index >= 0;
  2994. }
  2995. getRowEnd(item: number) {
  2996. if (item.toString() === '0') {
  2997. return 1;
  2998. } else {
  2999. return 0;
  3000. }
  3001. }
  3002. // [Start itemMove_start]
  3003. // itemMoveGrid(index: number, newIndex: number): void {
  3004. // if (!this.isDraggable(newIndex)) {
  3005. // return;
  3006. // }
  3007. // let tmp = this.videoLocalList.splice(index, 1);
  3008. // this.videoLocalList.splice(newIndex, 0, tmp[0]);
  3009. // // this.bigItemIndex = this.videoLocalList.findIndex((item) => item === 0);
  3010. // }
  3011. isInLeft(index: number) {
  3012. return index % 2 == 0;
  3013. }
  3014. down(index: number): void {
  3015. if ([this.videoLocalList.length - 1, this.videoLocalList.length - 2].includes(index)) {
  3016. return;
  3017. }
  3018. this.offsetY -= this.FIX_VP_Y;
  3019. this.dragRefOffSetY += this.FIX_VP_Y;
  3020. this.itemMove(index, index + 1);
  3021. }
  3022. up(index: number): void {
  3023. if (!this.isDraggable(index - 2)) {
  3024. return;
  3025. }
  3026. this.offsetY += this.FIX_VP_Y;
  3027. this.dragRefOffSetY -= this.FIX_VP_Y;
  3028. this.itemMove(index, index - 1);
  3029. }
  3030. left(index: number): void {
  3031. if (this.isInLeft(index)) {
  3032. return;
  3033. }
  3034. if (!this.isDraggable(index - 1)) {
  3035. return;
  3036. }
  3037. this.offsetX += this.FIX_VP_X;
  3038. this.dragRefOffSetX -= this.FIX_VP_X;
  3039. this.itemMove(index, index - 1)
  3040. }
  3041. right(index: number): void {
  3042. if (!this.isInLeft(index)) {
  3043. return;
  3044. }
  3045. if (!this.isDraggable(index + 1)) {
  3046. return;
  3047. }
  3048. this.offsetX -= this.FIX_VP_X;
  3049. this.dragRefOffSetX += this.FIX_VP_X;
  3050. this.itemMove(index, index + 1)
  3051. }
  3052. private scroller: Scroller = new Scroller();
  3053. @State startIndex: number = 0
  3054. @State endIndex: number = 0
  3055. @State scaleValue: number = 1
  3056. @State pinchValue: number = 1
  3057. layoutOptionsForHeader: GridLayoutOptions = {
  3058. regularSize: [1, 1], // 只支持[1, 1]
  3059. irregularIndexes: [0], // 索引为0的GridItem占用一行
  3060. };
  3061. @Builder
  3062. getGridView() {
  3063. Grid(this.scroller, this.layoutOptionsForHeader) {
  3064. GridItem() {
  3065. if (this.isShowCoverHeader()) {
  3066. this.coverHeader()
  3067. } else {
  3068. this.listViewTitle()
  3069. }
  3070. }
  3071. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3072. GridItem() {
  3073. Stack({ alignContent: Alignment.Center }) {
  3074. this.MusicItemGrid(item, index)
  3075. }
  3076. }
  3077. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3078. {
  3079. preview: MenuPreviewMode.IMAGE,
  3080. previewAnimationOptions: { scale: [0.8, 1.0] },
  3081. })
  3082. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3083. {
  3084. preview: MenuPreviewMode.IMAGE,
  3085. previewAnimationOptions: { scale: [0.8, 1.0] },
  3086. })
  3087. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3088. TransitionEffect.scale({ x: 0, y: 0 })))
  3089. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3090. .scale({ x: this.scaleItem === index ? 1.02 : 1, y: this.scaleItem === index ? 1.02 : 1 })
  3091. .zIndex(this.dragItem === index ? 1 : 0)
  3092. .translate(this.dragItem === index ? { x: this.offsetX, y: this.offsetY } : { x: 0, y: 0 })
  3093. // .hitTestBehavior(this.isDraggable(this.videoLocalList.indexOf(item)) ? HitTestMode.Default : HitTestMode.None)
  3094. }, (item: VideoItem) => item.filePath)
  3095. }
  3096. .width(this.isShowHeader ? '100%' : '94%')
  3097. .height('100%')
  3098. .editMode(true)
  3099. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3100. .animation({ duration: 500, curve: Curve.Ease }))
  3101. // .margin({ bottom: this.isCoverOpacity() ? 80 : 175 })
  3102. .margin({
  3103. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+30 : this.topBarHeight+90)
  3104. : (this.isShowCoverHeader() ? this.topBarHeight+45 : this.topBarHeight+128)
  3105. })
  3106. .layoutWeight(1)
  3107. .scrollBar(BarState.Off)
  3108. .supportAnimation(true)
  3109. .cachedCount(this.twoFingerType==1?5:this.twoFingerType==2?4:3)
  3110. // .columnsTemplate('1fr '.repeat(this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM ? 2 : 5))
  3111. .columnsTemplate(
  3112. this.twoFingerType == 3 ? 'repeat(auto-fit, 160)' :
  3113. this.twoFingerType == 2 ? 'repeat(auto-fit, 110)' : 'repeat(auto-fit, 80)'
  3114. )
  3115. .rowsGap(this.isShowDrawer ? 25 : (this.twoFingerType == 3 ? 10 : this.twoFingerType == 2 ? 5 : 1))
  3116. .visibility(this.isGridMusic ? Visibility.Visible : Visibility.None)
  3117. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3118. .gesture(PinchGesture({ fingers: 2 })
  3119. .onActionEnd((event: GestureEvent) => {
  3120. this.setGridTwoFingers()
  3121. })
  3122. .onActionUpdate(e => {
  3123. this.scaleValue = this.pinchValue * e.scale
  3124. })
  3125. .onActionStart(e => {
  3126. }))
  3127. .enableScrollInteraction(true)
  3128. // 滚轴滑动,记录下滑动时的起始位置和终点位置
  3129. .onScrollIndex((start: number, end: number) => {
  3130. this.startIndex = start
  3131. this.endIndex = end
  3132. })
  3133. .onScrollFrameBegin((offset: number) => {
  3134. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  3135. // if (this.isPhoneLan()) {
  3136. // this.setBarHeightHide(offset)
  3137. // } else
  3138. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3139. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3140. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3141. if (this.isScrollHide) {
  3142. this.setBarHeightHide2(offset)
  3143. } else {
  3144. this.setBarHeightNormal()
  3145. }
  3146. } else {
  3147. this.setBarHeightHide(offset)
  3148. }
  3149. return { offsetRemain: offset };
  3150. })
  3151. //允许拖拽音乐和视频到List或Grid上自动导入视频
  3152. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3153. .onDrop((event?: DragEvent) => {
  3154. try {
  3155. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3156. if (dragData !== undefined) {
  3157. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3158. if (records.length > 0) {
  3159. for (let i = 0; i < records.length; i++) {
  3160. let types = records[i].getTypes();
  3161. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3162. const fileUriUds =
  3163. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3164. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3165. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3166. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3167. this.targetFile = fileUriUds.oriUri;
  3168. this.saveVideoDatas([this.targetFile])
  3169. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3170. }
  3171. }
  3172. }
  3173. } else {
  3174. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3175. }
  3176. } else {
  3177. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3178. }
  3179. } catch (error) {
  3180. const err = error as BusinessError;
  3181. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3182. }
  3183. })
  3184. }
  3185. @State targetFile: string = '';
  3186. setGridTwoFingers() {
  3187. this.pinchValue = this.scaleValue;
  3188. Logger.info('this.pinchValue = ' + this.pinchValue);
  3189. if (this.pinchValue >= 1) {
  3190. this.twoFingerType++
  3191. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3192. if (this.twoFingerType > 3) {
  3193. this.twoFingerType = 3
  3194. }
  3195. } else {
  3196. this.twoFingerType--
  3197. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3198. if (this.twoFingerType < 1) {
  3199. this.twoFingerType = 3
  3200. this.isGridMusic = false
  3201. }
  3202. }
  3203. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3204. this.pinchValue = 1;
  3205. this.scaleValue = 1;
  3206. }
  3207. @State longItemFilePath: string = ''
  3208. @State tempLyricContent: string = ''
  3209. @Builder
  3210. private MusicItemGrid(item: VideoItem, index: number) {
  3211. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3212. Stack() {
  3213. Column() {
  3214. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3215. .height(this.getGridHeight())
  3216. .width(this.getGridWight())
  3217. .draggable(false)
  3218. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  3219. .autoResize(true) // 重采样,可减少内存占用
  3220. .alt($r('app.media.ic_avatar2'))
  3221. .clip(true)
  3222. .borderRadius({
  3223. topLeft: 12,
  3224. topRight: 12,
  3225. bottomLeft: 0,
  3226. bottomRight: 0
  3227. })
  3228. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3229. height: '99%' ,
  3230. dragBar: true,
  3231. onDisappear: () => {
  3232. this.longItemFilePath = '';
  3233. this.tempLyricContent = ''
  3234. },
  3235. showClose: true,
  3236. preferType: SheetType.CENTER ,
  3237. title: { title: '编辑标签' }
  3238. })
  3239. .draggable(false)
  3240. .opacity(this.opacityItem)// 绑定透明度
  3241. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3242. // .animation({ duration: 500, curve: Curve.Ease }))
  3243. .animation({
  3244. duration: 666,
  3245. curve: 'ease-in-out' // 可选动画曲线
  3246. })
  3247. .margin({
  3248. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3249. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3250. })
  3251. Column() {
  3252. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3253. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  3254. .maxLines(1)
  3255. .fontWeight(FontWeight.Bold)
  3256. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3257. .animation({
  3258. duration: 555,
  3259. curve: 'Linear',
  3260. })
  3261. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3262. height: '95%',
  3263. dragBar: true,
  3264. showClose: true,
  3265. onDisappear: () => {
  3266. this.longItemFilePathDetail = '';
  3267. },
  3268. blurStyle:BlurStyle.Thin,
  3269. backgroundColor:Color.Transparent,
  3270. preferType: SheetType.CENTER ,
  3271. title: { title: '详情' }
  3272. })
  3273. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3274. $r('app.color.text_color'))
  3275. Column() {
  3276. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  3277. .fontSize(11)
  3278. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3279. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3280. .fontColor($r('app.color.text_color'))
  3281. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  3282. .fontSize(11)
  3283. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3284. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3285. .fontColor($r('app.color.text_color'))
  3286. Row(){
  3287. Column(){
  3288. Text(item.md5Str?.includes('Lossless')?
  3289. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  3290. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  3291. .padding({ top: 3,right:6,left:6,bottom:3 })
  3292. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3293. $r('app.color.text_color'))
  3294. .fontWeight(500)
  3295. .borderRadius(12)
  3296. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  3297. .backgroundColor('#FFC107')
  3298. .visibility(StrUtil.isEmpty(item.md5Str)||this.twoFingerType==1?Visibility.None:Visibility.Visible)
  3299. }
  3300. .margin({ top: 2 ,right:6})
  3301. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  3302. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  3303. Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  3304. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 13)
  3305. .maxLines(1)
  3306. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3307. .margin({ top: 2})
  3308. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  3309. || item.type == CommonConstants.TYPE_IS_ALBUM
  3310. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3311. .fontWeight(FontWeight.Medium)
  3312. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3313. $r('app.color.text_color'))
  3314. }
  3315. }
  3316. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  3317. }
  3318. .height(this.twoFingerType == 3 ? 60 : this.twoFingerType == 2 ? 48 : 35)
  3319. .width(this.getGridWight())
  3320. .justifyContent(FlexAlign.Center)
  3321. .margin({
  3322. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3323. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3324. })
  3325. }
  3326. .width(this.getGridWight())
  3327. .borderRadius(12)
  3328. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  3329. .backgroundImageSize({ height: '100%', width: '100%' })
  3330. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  3331. .animation({ curve: Curve.Sharp, duration: 300 })
  3332. Checkbox({ name: 'checkbox' + index })
  3333. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  3334. .selectedColor(this.themeColor)
  3335. .shape(CheckBoxShape.CIRCLE)
  3336. .opacity(this.isMultiSelect ? 1 : 0)
  3337. .animation({
  3338. duration: 666,
  3339. curve: 'Smooth' // 可选动画曲线
  3340. })
  3341. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  3342. Visibility.None)
  3343. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  3344. .margin({ left: 20, top: 8, bottom: 8 })
  3345. .width(38)
  3346. .height(38)
  3347. }
  3348. }
  3349. .backgroundColor(Color.Transparent)
  3350. .width('100%')
  3351. .padding({ top: 15 })
  3352. .height(this.getGridAllHeight())
  3353. .onClick(() => {
  3354. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3355. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3356. this.handleFileSelection(item, !isChecked);
  3357. } else {
  3358. this.doPlay(item, index)
  3359. }
  3360. })
  3361. }
  3362. getGridAllHeight() {
  3363. let heightG = 222
  3364. switch (this.twoFingerType) {
  3365. case 1:
  3366. heightG = 118
  3367. break;
  3368. case 2:
  3369. heightG = 168
  3370. break;
  3371. case 3:
  3372. heightG = 222
  3373. break;
  3374. }
  3375. return heightG
  3376. }
  3377. getGridHeight() {
  3378. let heightG = 150
  3379. switch (this.twoFingerType) {
  3380. case 1:
  3381. heightG = 55
  3382. break;
  3383. case 2:
  3384. heightG = 100
  3385. break;
  3386. case 3:
  3387. heightG = 150
  3388. break;
  3389. }
  3390. return heightG
  3391. }
  3392. getGridWight() {
  3393. let wightG = 158
  3394. switch (this.twoFingerType) {
  3395. case 1:
  3396. wightG = 80
  3397. break;
  3398. case 2:
  3399. wightG = 110
  3400. break;
  3401. case 3:
  3402. wightG = 158
  3403. break;
  3404. }
  3405. return wightG
  3406. }
  3407. @State isShowDetail:boolean = false
  3408. // @State isShowDetailGrid:boolean = false
  3409. // @State isShowEditGrid:boolean = false
  3410. @State longItemFilePathDetail:string =''
  3411. @Builder
  3412. MenuBuilder(item: VideoItem, index: number, filePath: string) {
  3413. if(
  3414. ((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  3415. ||(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3416. item.name === LocalMusic.STR_HISTORY_MUSIC)
  3417. ){
  3418. //如果是专辑和艺术家的首页,不能长按
  3419. //如果是我的收藏 最近播放等也不能长按
  3420. }else{
  3421. Scroll() {
  3422. Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
  3423. Menu() {
  3424. MenuItem({
  3425. symbolStartIcon: new SymbolGlyphModifier(Utility.getIsFav(this.favList, item) ?
  3426. $r('sys.symbol.heart_fill') : $r('sys.symbol.heart')),
  3427. content: Utility.getIsFav(this.favList, item) ? '取消收藏' : '收藏'
  3428. })
  3429. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3430. .onClick(() => {
  3431. if (item) {
  3432. this.doFav(item)
  3433. }
  3434. this.longItemFilePath = ''
  3435. })
  3436. MenuItem({
  3437. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.forward_end_fill')),
  3438. content: '下一首播放'
  3439. })
  3440. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3441. .onClick(() => {
  3442. this.addToNextPlay(item);
  3443. this.longItemFilePath = ''
  3444. })
  3445. MenuItem({
  3446. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
  3447. content: '编辑标签'
  3448. })
  3449. .bindSheet($$this.isShowEdit, this.editSheet(item), {
  3450. height: '99%',
  3451. dragBar: true,
  3452. showClose: true,
  3453. preferType: SheetType.CENTER ,
  3454. title: { title: '编辑标签' }
  3455. })
  3456. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3457. .onClick(async() => {
  3458. this.setEditStrEmpty()
  3459. this.tempLyricContent = await this.getLyricContent(item);
  3460. // console.info('onecold 长按this.tempLyricContent' +this.tempLyricContent)
  3461. if(this.isGridMusic){
  3462. this.longItemFilePath = item.filePath
  3463. }else{
  3464. this.isShowEdit = !this.isShowEdit;
  3465. }
  3466. })
  3467. MenuItem({
  3468. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.checkmark_square_on_square')),
  3469. content: $r('app.string.select_all')
  3470. })
  3471. .onClick(() => {
  3472. this.isMultiSelect = !this.isMultiSelect
  3473. this.longItemFilePath = ''
  3474. this.selectedFiles.push(item)
  3475. })
  3476. MenuItem({
  3477. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.rename')),
  3478. content: $r('app.string.rename')
  3479. })
  3480. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3481. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3482. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3483. .onClick(() => {
  3484. this.showReNameDialog(item, index + '', filePath)
  3485. this.longItemFilePath = ''
  3486. })
  3487. MenuItem({
  3488. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
  3489. content: $r('app.string.delete')
  3490. })
  3491. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3492. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3493. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3494. .onClick(() => {
  3495. this.showWarnIsDeleteFile(item, index + '', filePath)
  3496. this.longItemFilePath = ''
  3497. })
  3498. MenuItem({
  3499. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.info_circle')),
  3500. content: $r('app.string.detail')
  3501. })
  3502. .bindSheet($$this.isShowDetail, this.detailSheet(item), {
  3503. height:'95%',
  3504. dragBar: true,
  3505. showClose: true,
  3506. blurStyle:BlurStyle.Thin,
  3507. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  3508. backgroundColor:Color.Transparent,
  3509. title: { title: '详情信息' }
  3510. })
  3511. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3512. .onClick(() => {
  3513. if(this.isGridMusic){
  3514. this.longItemFilePathDetail = item.filePath
  3515. }else{
  3516. this.isShowDetail = !this.isShowDetail
  3517. }
  3518. })
  3519. MenuItem({
  3520. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.share')),
  3521. content: $r('app.string.share')
  3522. })
  3523. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3524. .onClick(() => {
  3525. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  3526. this.longItemFilePath = ''
  3527. })
  3528. }
  3529. .font({ size: 15, weight: FontWeight.Normal })
  3530. }
  3531. .width(180)
  3532. }
  3533. .height('auto')
  3534. }
  3535. }
  3536. private listMaxScrollOffsetY: number = 0
  3537. @State selectedIndex: number = -1
  3538. setlistTwoFingers() {
  3539. this.pinchValue = this.scaleValue;
  3540. Logger.info('this.pinchValue = ' + this.pinchValue);
  3541. if (this.pinchValue >= 1) {
  3542. this.twoFingerType++
  3543. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3544. if (this.twoFingerType > 3) {
  3545. this.twoFingerType = 1
  3546. this.isGridMusic = true
  3547. }
  3548. } else {
  3549. this.twoFingerType--
  3550. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3551. if (this.twoFingerType < 1) {
  3552. this.twoFingerType = 1
  3553. }
  3554. }
  3555. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3556. this.pinchValue = 1;
  3557. this.scaleValue = 1;
  3558. }
  3559. @Builder
  3560. getListView() {
  3561. List({ scroller: this.listScroller }) {
  3562. ListItemGroup({ header: this.coverHeader() }) {
  3563. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3564. ListItem() {
  3565. Column() {
  3566. if (item.type === CommonConstants.TYPE_IS_DIR
  3567. || item.type === CommonConstants.TYPE_IS_ARTIST || item.type === CommonConstants.TYPE_IS_ALBUM) {
  3568. this.DirItem(item, index)
  3569. } else if (item.type === CommonConstants.TYPE_IS_CSJAD) { //如果是穿山甲广告
  3570. } else {
  3571. this.MusicItem(item, index)
  3572. }
  3573. }
  3574. .shadow(this.scaleItem === index ? {
  3575. radius: 70,
  3576. color: '#15000000',
  3577. offsetX: 0,
  3578. offsetY: 0
  3579. } :
  3580. {
  3581. radius: 0,
  3582. color: '#15000000',
  3583. offsetX: 0,
  3584. offsetY: 0
  3585. })
  3586. .animation({ curve: Curve.Sharp, duration: 300 })
  3587. }
  3588. // .transition(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }))
  3589. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  3590. .animation({ duration: 500 }),
  3591. TransitionEffect.scale({ x: 0, y: 0 })))
  3592. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3593. .swipeAction((
  3594. (this.isSwipe&&this.modeType == 0 || this.modeType == 1 || ((this.modeType == 3 || this.modeType == 2) && this.isCanBack))
  3595. && item.type !== CommonConstants.TYPE_IS_CSJAD &&
  3596. !this.isHistory) ? { end: this.DeleteButton(item, index, item.filePath) } : {}) //左滑
  3597. .onClick(() => {
  3598. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3599. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3600. this.handleFileSelection(item, !isChecked);
  3601. } else {
  3602. this.doPlay(item, index)
  3603. }
  3604. })
  3605. //拖动List关键代码开始
  3606. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  3607. .zIndex(this.dragItem === index ? 1 : 0)
  3608. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  3609. .gesture(
  3610. GestureGroup(GestureMode.Sequence,
  3611. LongPressGesture({ repeat: true })
  3612. .onAction((event?: GestureEvent) => {
  3613. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3614. this.scaleItem = index
  3615. })
  3616. })
  3617. .onActionEnd(() => {
  3618. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3619. this.scaleItem = -1
  3620. })
  3621. }),
  3622. PanGesture({ fingers: 1, direction: null, distance: 0 })
  3623. .onActionStart(() => {
  3624. this.dragItem = index // 记录当前拖动项索引
  3625. this.dragRefOffset = 0 // 重置偏移基准
  3626. })
  3627. .onActionUpdate((event: GestureEvent) => {
  3628. this.offsetY = event.offsetY - this.dragRefOffset;
  3629. this.neighborItem = -1;
  3630. let indexA = this.videoLocalList.indexOf(item);
  3631. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  3632. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  3633. let value: number = 0;
  3634. if (this.offsetY < 0) {
  3635. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  3636. this.neighborItem = indexA - 1;
  3637. this.neighborScale = 1 - value / 20;
  3638. } else if (this.offsetY > 0) {
  3639. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  3640. this.neighborItem = indexA + 1;
  3641. this.neighborScale = 1 - value / 20;
  3642. }
  3643. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.videoLocalList.length) {
  3644. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3645. this.offsetY -= this.ITEM_INTV;
  3646. this.dragRefOffset += this.ITEM_INTV;
  3647. this.itemMove(indexA, indexA + 1);
  3648. });
  3649. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  3650. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3651. this.offsetY += this.ITEM_INTV;
  3652. this.dragRefOffset -= this.ITEM_INTV;
  3653. this.itemMove(indexA, indexA - 1);
  3654. });
  3655. }
  3656. let curListOffset = this.listScroller.currentOffset()
  3657. // 获取手指信息
  3658. let fingerInfo = event.fingerList[0]
  3659. let clickPercentY =
  3660. (fingerInfo.globalY - Number(this.listArea.globalPosition.y)) / Number(this.listArea.height)
  3661. if (clickPercentY > 0.8 && !this.listScroller.isAtEnd()) {
  3662. let scrollVelocity = clickPercentY > 0.9 ? 4 : 2
  3663. if (this.listMaxScrollOffsetY - curListOffset.yOffset > scrollVelocity + 5) {
  3664. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset += scrollVelocity })
  3665. }
  3666. } else if (clickPercentY < 0.2 && curListOffset.yOffset >= 0) {
  3667. let scrollVelocity = clickPercentY < 0.1 ? 4 : 2
  3668. if (curListOffset.yOffset > scrollVelocity + 5) {
  3669. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset -= scrollVelocity })
  3670. }
  3671. }
  3672. })
  3673. .onActionEnd((event: GestureEvent) => {
  3674. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3675. this.dragItem = -1
  3676. this.neighborItem = -1
  3677. })
  3678. animateTo({
  3679. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  3680. }, () => {
  3681. this.scaleItem = -1
  3682. })
  3683. })
  3684. )
  3685. .onCancel(() => {
  3686. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3687. this.dragItem = -1
  3688. this.neighborItem = -1
  3689. })
  3690. animateTo({
  3691. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  3692. }, () => {
  3693. this.scaleItem = -1
  3694. })
  3695. })
  3696. ) //拖动List关键代码结束
  3697. }, (item: VideoItem) => item.filePath)
  3698. }
  3699. }
  3700. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3701. .gesture(PinchGesture({ fingers: 2 })
  3702. .onActionEnd((event: GestureEvent) => {
  3703. this.setlistTwoFingers()
  3704. })
  3705. .onActionUpdate(e => {
  3706. this.scaleValue = this.pinchValue * e.scale
  3707. })
  3708. .onActionStart(e => {
  3709. }))
  3710. // .divider({ strokeWidth: 1, color: this.isDarkMode? '#333333':'#ffe9f0f0' })
  3711. .margin({
  3712. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+25 : this.topBarHeight+80)
  3713. : (this.isShowCoverHeader() ? this.topBarHeight+35 : this.isHiCarSmall()?this.topBarHeight+90:this.topBarHeight+125)
  3714. })
  3715. .cachedCount(6)
  3716. .borderRadius(20)
  3717. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  3718. TransitionEffect.scale({ x: 0, y: 0 })))
  3719. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3720. // .animation({ duration: 500, curve: Curve.Ease }))
  3721. .layoutWeight(1)
  3722. .onScrollIndex((start) => {
  3723. this.selectedIndex = start
  3724. })
  3725. .visibility(this.isGridMusic ? Visibility.None : Visibility.Visible)
  3726. .lanes(
  3727. new BreakpointType<number>({
  3728. sm: 1,
  3729. md: 2,
  3730. lg: 2,
  3731. xl: 3,
  3732. xxl: 4
  3733. }).getValue(this.currentBreakpoint),
  3734. new BreakpointType<number>({
  3735. sm: 0,
  3736. md: 12,
  3737. lg: 12,
  3738. xl: 16,
  3739. xxl: 20
  3740. }).getValue(this.currentBreakpoint)
  3741. )
  3742. .onAreaChange((oldValue: Area, newValue: Area) => {
  3743. this.listArea = newValue
  3744. if (this.twoFingerType == 3) {
  3745. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_BIG) - 10
  3746. } else if (this.twoFingerType == 2) {
  3747. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT) - 10
  3748. } else if (this.twoFingerType == 1) {
  3749. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_SMALL) - 10
  3750. }
  3751. })
  3752. .onScrollFrameBegin((offset: number) => {
  3753. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  3754. // if (this.isPhoneLan()) {
  3755. // this.setBarHeightHide(offset)
  3756. // } else
  3757. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3758. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3759. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3760. if (this.isScrollHide) {
  3761. this.setBarHeightHide2(offset)
  3762. } else {
  3763. this.setBarHeightNormal()
  3764. }
  3765. } else {
  3766. this.setBarHeightHide(offset)
  3767. }
  3768. return { offsetRemain: offset };
  3769. })
  3770. //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
  3771. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3772. .onDrop((event?: DragEvent) => {
  3773. try {
  3774. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3775. if (dragData !== undefined) {
  3776. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3777. if (records.length > 0) {
  3778. for (let i = 0; i < records.length; i++) {
  3779. let types = records[i].getTypes();
  3780. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3781. const fileUriUds =
  3782. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3783. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3784. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3785. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3786. this.targetFile = fileUriUds.oriUri;
  3787. this.saveVideoDatas([this.targetFile])
  3788. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3789. }
  3790. }
  3791. }
  3792. } else {
  3793. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3794. }
  3795. } else {
  3796. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3797. }
  3798. } catch (error) {
  3799. const err = error as BusinessError;
  3800. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3801. }
  3802. })
  3803. }
  3804. setBarHeightNormal() {
  3805. this.hideDone = false;
  3806. this.getUIContext().animateTo({
  3807. duration: 300
  3808. }, () => {
  3809. this.bottomBarHeight = 55 + 0;
  3810. this.topBarHeight = 50 + 0;
  3811. this.barOpacity = 1;
  3812. this.barBottomOpacity = 1
  3813. this.currentYOffset = 0;
  3814. this.isHiding = false;
  3815. });
  3816. }
  3817. setBarHeightHide(offset: number) {
  3818. if (offset > 0 && !this.hideDone) {
  3819. this.currentYOffset += offset;
  3820. if (this.currentYOffset <= 100) {
  3821. this.bottomBarHeight = this.bottomBarHeight * (1 - this.currentYOffset / 100);
  3822. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  3823. this.barOpacity = 1 - this.currentYOffset / 100;
  3824. this.barBottomOpacity = 1 - this.currentYOffset / 100;
  3825. } else {
  3826. this.topBarHeight = 0;
  3827. this.bottomBarHeight = 0;
  3828. this.barBottomOpacity = 0
  3829. this.barOpacity = 0;
  3830. this.hideDone = true;
  3831. }
  3832. this.isHiding = true;
  3833. }
  3834. if (offset < 0 && this.isHiding) {
  3835. this.hideDone = false;
  3836. this.getUIContext().animateTo({
  3837. duration: 300
  3838. }, () => {
  3839. this.bottomBarHeight = 55 + 0;
  3840. this.topBarHeight = 50 + 0;
  3841. this.barOpacity = 1;
  3842. this.barBottomOpacity = 1
  3843. this.currentYOffset = 0;
  3844. this.isHiding = false;
  3845. });
  3846. }
  3847. }
  3848. //这个方法没隐藏bottomBar,只隐藏topbar
  3849. setBarHeightHide2(offset: number) {
  3850. if (offset > 0 && !this.hideDone) {
  3851. this.currentYOffset += offset;
  3852. if (this.currentYOffset <= 100) {
  3853. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  3854. this.barOpacity = 1 - this.currentYOffset / 100;
  3855. } else {
  3856. this.topBarHeight = 0;
  3857. this.barOpacity = 0;
  3858. this.hideDone = true;
  3859. }
  3860. this.isHiding = true;
  3861. }
  3862. if (offset < 0 && this.isHiding) {
  3863. this.hideDone = false;
  3864. this.getUIContext().animateTo({
  3865. duration: 300
  3866. }, () => {
  3867. this.topBarHeight = 50 + 0;
  3868. this.barOpacity = 1;
  3869. this.currentYOffset = 0;
  3870. this.isHiding = false;
  3871. });
  3872. }
  3873. }
  3874. private doPlay(item: VideoItem, index?: number, isFromSonPlayList?: boolean) {
  3875. switch (item.type) {
  3876. case CommonConstants.TYPE_IS_DIR:
  3877. // 进入歌单前安全保存当前滚动偏移量,支持列表和网格
  3878. let offsetB = 0
  3879. if (this.isGridMusic) {
  3880. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  3881. let cur = this.scroller.currentOffset()
  3882. if (cur && typeof cur.yOffset === 'number') {
  3883. offsetB = cur.yOffset
  3884. }
  3885. }
  3886. this.mScrollMap.set('lastGridDirScrollOffset', offsetB)
  3887. } else {
  3888. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  3889. let cur = this.listScroller.currentOffset()
  3890. if (cur && typeof cur.yOffset === 'number') {
  3891. offsetB = cur.yOffset
  3892. }
  3893. }
  3894. this.mScrollMap.set('lastListDirScrollOffset', offsetB)
  3895. }
  3896. if (item.name === LocalMusic.STR_LOCK_VIDEO) {
  3897. this.showVerifyDialog()
  3898. this.currentTitleName = '私密音频'
  3899. this.currentTitleCover = $r('app.media.ic_avatar5')
  3900. } else if (item.name === LocalMusic.STR_HISTORY_MUSIC) {
  3901. this.titleBarModel.setTitleName('最近播放')
  3902. this.currentTitleCover = $r('app.media.ic_avatar2')
  3903. this.currentTitleName = '最近播放'
  3904. //加载动画效果
  3905. this.updateListData(this.historyList, true)
  3906. // this.videoLocalList = this.historyList
  3907. if (ArrayUtil.isEmpty(this.historyList)) {
  3908. ToastUtil.showToast('最近播放记录空空如也')
  3909. } else {
  3910. this.currentTitleCover = Utility.getFirstCoverFromList(this.historyList)
  3911. }
  3912. this.isHistory = true
  3913. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  3914. } else if (item.name === LocalMusic.STR_FAC_VIDEO) {
  3915. this.titleBarModel.setTitleName('我的收藏')
  3916. this.currentTitleName = '我的收藏'
  3917. this.currentTitleCover = $r('app.media.ic_avatar1')
  3918. //加载动画效果
  3919. this.updateListData(this.favList)
  3920. if (ArrayUtil.isEmpty(this.favList)) {
  3921. ToastUtil.showToast('无音乐收藏记录')
  3922. } else {
  3923. this.currentTitleCover = Utility.getFirstCoverFromList(this.favList)
  3924. }
  3925. this.isFavMusic = true
  3926. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  3927. } else {
  3928. this.currentTitleName = item.name
  3929. this.currentPath = item.filePath
  3930. this.currentTitleCover = $r('app.media.ic_avatar5')
  3931. this.getSortedFiles(this.currentPath)
  3932. }
  3933. //进入歌单的时候的滚动位置在顶部
  3934. if (this.isGridMusic) {
  3935. this.scroller.scrollToIndex(0)
  3936. }
  3937. setTimeout(() => {
  3938. if (this.modeType == 0) {
  3939. if (!this.isGridMusic) {
  3940. this.listScroller.scrollToIndex(0)
  3941. }
  3942. }
  3943. }, 200)
  3944. break;
  3945. case CommonConstants.TYPE_IS_ARTIST:
  3946. // 进入艺术家前安全保存当前滚动偏移量,支持列表和网格
  3947. let offsetA = 0
  3948. if (this.isGridMusic) {
  3949. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  3950. let cur = this.scroller.currentOffset()
  3951. if (cur && typeof cur.yOffset === 'number') {
  3952. offsetA = cur.yOffset
  3953. }
  3954. }
  3955. this.mScrollMap.set('lastGridArtistScrollOffset', offsetA)
  3956. } else {
  3957. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  3958. let cur = this.listScroller.currentOffset()
  3959. if (cur && typeof cur.yOffset === 'number') {
  3960. offsetA = cur.yOffset
  3961. }
  3962. }
  3963. this.mScrollMap.set('lastListArtistScrollOffset', offsetA)
  3964. }
  3965. let mList = this.artistMap.get(item.name)
  3966. if (mList !== undefined && ArrayUtil.isNotEmpty(mList)) {
  3967. Utility.doSortListAscending(mList)
  3968. this.isCanBack = true
  3969. this.titleBarModel.setTitleName(item.name)
  3970. this.currentTitleName = '艺术家:' + item.name
  3971. if (item.pixelMapPath) {
  3972. this.currentTitleCover = item.pixelMapPath
  3973. }
  3974. this.updateListData(mList)
  3975. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  3976. }
  3977. //进入歌单的时候的滚动位置在顶部
  3978. if (this.isGridMusic) {
  3979. this.scroller.scrollToIndex(0)
  3980. }
  3981. break;
  3982. case CommonConstants.TYPE_IS_ALBUM:
  3983. // 进入专辑前安全保存当前滚动偏移量,支持列表和网格
  3984. let offset = 0
  3985. if (this.isGridMusic) {
  3986. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  3987. let cur = this.scroller.currentOffset()
  3988. if (cur && typeof cur.yOffset === 'number') {
  3989. offset = cur.yOffset
  3990. }
  3991. }
  3992. this.mScrollMap.set('lastGridAlBumScrollOffset', offset)
  3993. } else {
  3994. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  3995. let cur = this.listScroller.currentOffset()
  3996. if (cur && typeof cur.yOffset === 'number') {
  3997. offset = cur.yOffset
  3998. }
  3999. }
  4000. this.mScrollMap.set('lastListAlBumScrollOffset', offset)
  4001. }
  4002. let albumList = this.albumMap.get(item.name)
  4003. if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
  4004. Utility.doSortListAscending(albumList)
  4005. this.isCanBack = true
  4006. this.titleBarModel.setTitleName(item.name)
  4007. this.currentTitleName = '专辑:' + item.name
  4008. if (item.pixelMapPath) {
  4009. this.currentTitleCover = item.pixelMapPath
  4010. }
  4011. this.updateListData(albumList)
  4012. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4013. this.mScrollMap.set(item.name, this.selectedIndex)
  4014. }
  4015. //进入歌单的时候的滚动位置在顶部
  4016. if (this.isGridMusic) {
  4017. this.scroller.scrollToIndex(0)
  4018. }
  4019. break;
  4020. case CommonConstants.TYPE_IS_CSJAD:
  4021. return
  4022. break;
  4023. case CommonConstants.TYPE_LOCAL:
  4024. if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
  4025. this.stop();
  4026. }
  4027. if (isFromSonPlayList) { //点击来自右下角的播放列表
  4028. this.currentSong = item
  4029. if (index !== undefined) {
  4030. this.curIndex = index
  4031. }
  4032. } else {
  4033. let globalVideoList = Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL) as VideoItem[];
  4034. this.curIndex = Utility.getCurIndexFromGlobalList(globalVideoList, item.filePath)
  4035. this.songList = globalVideoList
  4036. this.sonDataSource.pushArrayData(this.songList)
  4037. this.currentSong = globalVideoList[this.curIndex]
  4038. }
  4039. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  4040. this.videoUrl = this.currentSong.filePath
  4041. this.name = this.currentSong.name
  4042. this.cover = this.currentSong.pixelMapPath
  4043. this.artist = this.currentSong.artist
  4044. LogUtil.info('this.currentSong.duration =' + this.currentSong.duration)
  4045. LogUtil.info('this.currentSong.sampleRate =' + this.currentSong.sampleRate)
  4046. LogUtil.info('this.currentSongmimeType =' + this.currentSong.mimeType)
  4047. this.startPlayOrResumePlay()
  4048. break;
  4049. }
  4050. }
  4051. @Builder
  4052. PlayController() {
  4053. Column() {
  4054. Line().width('100%').height(1).backgroundColor($r('app.color.index_background'))
  4055. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4056. Row() {
  4057. Row() {
  4058. RotatingCover({ songLabel: this.currentSong?.pixelMapPath })
  4059. Column() {
  4060. Text(this.currentSong?.name)
  4061. .fontSize(16)
  4062. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4063. .maxLines(1)
  4064. .fontColor($r('app.color.text_color'))
  4065. .fontWeight(500)
  4066. Row() {
  4067. Text(this.currentSong?.artist)
  4068. .margin({ top: 2 })
  4069. .fontSize(13)
  4070. .maxLines(1)
  4071. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4072. .fontColor($r('app.color.text_color'))
  4073. }
  4074. }
  4075. .alignItems(HorizontalAlign.Start)
  4076. .margin({ right: 22 })
  4077. }
  4078. .padding({ right: 18 })
  4079. .layoutWeight(1)
  4080. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4081. .onClick(() => {
  4082. if (ArrayUtil.isNotEmpty(this.songList)) {
  4083. this.isShowPlay = true;
  4084. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  4085. this.initLyric(lyricPath);
  4086. this.startAutoHide()
  4087. } else {
  4088. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4089. }
  4090. })
  4091. Row() {
  4092. Image($r('app.media.hm_previous'))
  4093. .height(28)
  4094. .width(28)
  4095. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4096. .margin({ left: 8, right: 16 })
  4097. .fillColor(this.themeColor)
  4098. .displayPriority(2)
  4099. .onClick(() => {
  4100. if (ArrayUtil.isNotEmpty(this.songList)) {
  4101. this.playPrevious()
  4102. } else {
  4103. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4104. }
  4105. })
  4106. //播放进度条
  4107. Stack() {
  4108. Progress({
  4109. value: Math.floor(this.progressValue),
  4110. type: ProgressType.Ring,
  4111. })
  4112. .color(this.themeColor)// 进度条前景色为灰色
  4113. .backgroundColor($r('app.color.index_background'))
  4114. .height(40)
  4115. .aspectRatio(CommonConstants.ASPECT_RATIO)
  4116. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
  4117. .height(38)
  4118. .width(38)
  4119. .displayPriority(3)
  4120. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4121. .fillColor(this.themeColor)
  4122. .onClick(() => {
  4123. if (ArrayUtil.isNotEmpty(this.songList)) {
  4124. this.playOrPause()
  4125. } else {
  4126. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4127. }
  4128. })
  4129. }
  4130. Image($r('app.media.hm_next'))
  4131. .height(28)
  4132. .width(28)
  4133. .margin({
  4134. right: 16,
  4135. left: 16
  4136. })
  4137. .fillColor(this.themeColor)
  4138. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4139. .displayPriority(2)
  4140. .onClick(() => {
  4141. if (ArrayUtil.isNotEmpty(this.songList)) {
  4142. this.playNext()
  4143. } else {
  4144. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4145. }
  4146. })
  4147. Image($r('app.media.hm_playlist'))
  4148. .height(28)
  4149. .width(28)
  4150. .displayPriority(1)
  4151. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4152. .fillColor(this.themeColor)
  4153. .bindSheet($$this.isShowSheet, this.PlayListSheet(), {
  4154. height: '95%',
  4155. dragBar: true,
  4156. showClose: true,
  4157. blurStyle: BlurStyle.Thin,
  4158. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  4159. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  4160. title: {
  4161. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  4162. + `(${this.songList.length}首)`
  4163. }
  4164. })
  4165. .onClick(() => {
  4166. if (ArrayUtil.isNotEmpty(this.songList)) {
  4167. this.isShowSheet = !this.isShowSheet;
  4168. this.isFrontWhite = false
  4169. LogUtil.info('onecold scrollToIndex = ' + this.curIndex)
  4170. this.scrollIndex()
  4171. } else {
  4172. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4173. }
  4174. })
  4175. }
  4176. }
  4177. .width('100%')
  4178. .height(this.bottomBarHeight)
  4179. .justifyContent(FlexAlign.Center)
  4180. .hitTestBehavior(HitTestMode.Transparent)
  4181. .backgroundColor(this.isCustomizeBg ? Color.Transparent : $r('app.color.bottom_control_background'))
  4182. .bindContentCover($$this.isShowPlay, this.MusicPlayBuilder(), {
  4183. // modalTransition: ModalTransition.DEFAULT,
  4184. transition: AnimationHelper.transitionInDown(666),
  4185. backgroundColor: 'rgba(0, 0, 0, 0.9)',
  4186. })
  4187. .padding({
  4188. left: 16,
  4189. right: 16
  4190. })
  4191. Line()
  4192. .width('100%')
  4193. .height(25)
  4194. .backgroundColor($r('app.color.bottom_control_background'))// .visibility(this.isPhoneLan()?Visibility.None:this.isCustomizeBg?Visibility.Hidden:Visibility.Visible)
  4195. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4196. }
  4197. .clickEffect({ level: ClickEffectLevel.HEAVY })
  4198. }
  4199. @State isFrontWhite: boolean = false
  4200. scrollIndex(){
  4201. if(this.curIndex>500)//条数太大的时候 滚动非常卡 导致闪退,先改为不滚
  4202. return
  4203. try {
  4204. setTimeout(() => {
  4205. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  4206. this.playListScroller.scrollToIndex(this.curIndex,true, ScrollAlign.CENTER)
  4207. })
  4208. }, 123)
  4209. }catch (error) {
  4210. console.error(`onecold scrollIndex出错: ${error}`);
  4211. }
  4212. }
  4213. //播放列表布局
  4214. @Builder
  4215. PlayListSheet() {
  4216. Column() {
  4217. this.PlayList()
  4218. }
  4219. .width('100%')
  4220. .height('100%')
  4221. }
  4222. @State titleStr: string = ''
  4223. @State ablumStr: string = ''
  4224. @State artistStr: string = ''
  4225. @State lyricConStr: string = ''
  4226. @State currentEditItem: string = ''
  4227. @State yearStr: string = ''
  4228. @State trackStr: string = ''
  4229. @State genreStr: string = ''
  4230. @State imagePathStr: string = ''
  4231. @State albumArtistStr: string = ''
  4232. @State composerStr: string = ''
  4233. @State lyricistStr: string = ''
  4234. @State commentStr: string = ''
  4235. @State discStr: string = ''
  4236. doUpdateData() {
  4237. setTimeout(() => {
  4238. if (this.modeType === 0) {
  4239. this.deleteCache(this.currentPath)
  4240. this.getSortedFiles(this.currentPath)
  4241. }
  4242. workerInstance.postMessage({ code: 2, data: this.context });
  4243. workerInstance.postMessage({ code: 3, data: this.context });
  4244. workerInstance.postMessage({ code: 4, data: this.context });
  4245. }, 999)
  4246. }
  4247. //编辑信息
  4248. async doEdit(item: VideoItem) {
  4249. if (!item) {
  4250. return
  4251. }
  4252. if (StrUtil.isEmpty(this.titleStr)) {
  4253. ToastUtil.showToast('标题不能为空')
  4254. return
  4255. }
  4256. // let doChangeLyric = false
  4257. // if(item.filePath==this.currentSong?.filePath){
  4258. // if(this.lyricConStr !== this.lyricContent){
  4259. // doChangeLyric = true
  4260. // }
  4261. // }else if(this.lyricConStr !== this.tempLyricContent){
  4262. // doChangeLyric = true
  4263. // }
  4264. //用户更改了封面,那就内嵌下封面
  4265. if(StrUtil.isNotEmpty(this.imagePathStr)){
  4266. const resultCover:boolean = await changeMusicCover(this.context,
  4267. item.filePath,this.imagePathStr,true);
  4268. this.imagePathStr = ''
  4269. if(resultCover){
  4270. ToastUtil.showToast('内嵌封面成功')
  4271. }
  4272. }
  4273. const metadata:FFMpegTags = {
  4274. title: this.titleStr,
  4275. artist: this.artistStr,
  4276. album: this.ablumStr,
  4277. // LYRICS:this.lyricConStr,
  4278. // USLT:this.lyricConStr,
  4279. TYER:this.yearStr,
  4280. genre:this.genreStr,
  4281. track:this.trackStr,
  4282. album_artist:this.albumArtistStr,
  4283. TPE2:this.albumArtistStr,//ID3v2 中通常没有专门的 "专辑艺术家" 字段,但有些软件会使用 TPE2 来表示专辑艺
  4284. COMPOSER:this.composerStr,
  4285. lyricist:this.lyricistStr,
  4286. TEXT:this.lyricistStr,//ID3v2 使用 TEXT 字段来表示作词者
  4287. comment:this.commentStr,
  4288. // comm:this.commentStr,//ID3v2:使用 COMM(Comment)字段。
  4289. disc:this.discStr,
  4290. };
  4291. //内嵌下标签的值,设置overwrite为true会直接修改原文件
  4292. const result:boolean = await repairAudioMetadata(
  4293. item.filePath,
  4294. this.lyricConStr,
  4295. metadata,
  4296. true
  4297. );
  4298. if (result) {
  4299. this.table.updateMediaInfo(item.filePath, this.titleStr, this.artistStr, this.ablumStr,this.lyricConStr,
  4300. this.yearStr,this.genreStr,this.trackStr,this.albumArtistStr,this.composerStr, this.lyricistStr,this.commentStr,this.discStr,
  4301. (success: boolean, error?: string) => {
  4302. // this.isShowEdit = false
  4303. if (success) {
  4304. console.log(" onecold 编辑信息成功,数据库已同步");
  4305. ToastUtil.showToast('内嵌音乐标签成功')
  4306. this.isShowMoreView = false
  4307. this.name = this.titleStr
  4308. if (item.filePath == this.currentSong?.filePath) {
  4309. this.currentSong.name = this.titleStr
  4310. this.artist = this.artistStr
  4311. this.currentSong.artist = this.artistStr
  4312. this.currentSong.album = this.ablumStr
  4313. this.currentSong.year = this.yearStr
  4314. this.currentSong.genre = this.genreStr
  4315. this.currentSong.track = this.trackStr
  4316. this.currentSong.ALBUMARTIST = this.albumArtistStr
  4317. this.currentSong.COMPOSER = this.composerStr
  4318. this.currentSong.LYRICIST = this.lyricistStr
  4319. this.currentSong.COMMENT = this.commentStr
  4320. }
  4321. this.doUpdateData()
  4322. } else {
  4323. // ToastUtil.showToast('保存失败' + error?.toString())
  4324. console.error(" onecold 编辑信息数据库失败原因: " + error);
  4325. }
  4326. });
  4327. console.log(' onecold 元数据标签更新成功,');
  4328. } else {
  4329. ToastUtil.showToast('内嵌音乐标签失败')
  4330. console.log('onecold 内嵌音乐标签失败');
  4331. }
  4332. this.longItemFilePath = ''
  4333. this.tempLyricContent = ''
  4334. this.isShowEdit = false
  4335. }
  4336. updateLyricToDB() {
  4337. }
  4338. @Builder
  4339. editSheet(item: VideoItem) {
  4340. Scroll() {
  4341. Column() {
  4342. this.editDetail(item)
  4343. }
  4344. }
  4345. .width('100%')
  4346. .height('100%')
  4347. }
  4348. @Builder
  4349. editDetail(item: VideoItem) {
  4350. Column() {
  4351. if (item) {
  4352. Row() {
  4353. Stack() {
  4354. Image(StrUtil.isNotEmpty(this.imagePathStr)?this.imagePathStr.startsWith('http')?
  4355. this.imagePathStr:fileUri.getUriFromPath(this.imagePathStr):
  4356. StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.add') :
  4357. item.pixelMapPath)
  4358. .fillColor(this.themeColor)
  4359. .height(88)
  4360. .width(88)
  4361. .borderRadius('100%')
  4362. .clip(true)
  4363. .opacity(this.opacityItem)// 绑定透明度
  4364. .margin({ left: 25 })
  4365. }
  4366. .onClick(async () => {
  4367. const imagePath:string | undefined = await this.goSelectImage(item);
  4368. if (imagePath) {
  4369. //用户更改过图片
  4370. this.imagePathStr = imagePath
  4371. }
  4372. })
  4373. .width('28%')
  4374. Row() {
  4375. Column() {
  4376. Text(item.name)
  4377. .fontSize(18)
  4378. .maxLines(1)
  4379. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4380. .animation({
  4381. duration: 555,
  4382. curve: 'Linear',
  4383. })
  4384. .fontColor(this.themeColor)
  4385. .margin({ left: 18 })
  4386. Row() {
  4387. Text(item.artist)
  4388. .fontSize(15)
  4389. .maxLines(1)
  4390. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4391. .padding({ top: 8 })
  4392. .fontColor(this.themeColor)
  4393. .margin({ left: 18 })
  4394. }
  4395. }
  4396. .height('100%')
  4397. .width(100)
  4398. .visibility(this.isDarkMode ? Visibility.None : Visibility.Visible)
  4399. .justifyContent(FlexAlign.Center)
  4400. .alignItems(HorizontalAlign.Start)
  4401. }
  4402. .height('100%')
  4403. .justifyContent(FlexAlign.Start)
  4404. .layoutWeight(1)
  4405. }
  4406. .width('100%')
  4407. .height(98)
  4408. Row() {
  4409. Button('获取封面')
  4410. .fontColor(Color.White)
  4411. .fontSize(12)
  4412. .height(38)
  4413. .width(88)
  4414. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4415. .backgroundColor(this.themeColor)
  4416. .stateEffect(true)
  4417. .margin({ right: 15, left: 20 })
  4418. .onClick(async () => {
  4419. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  4420. this.showTipsDialog();
  4421. return; // Return empty string when no API is configured
  4422. }
  4423. const imagePath:string | undefined = await this.doSearchCover(item);
  4424. console.info('onecold imagePath = '+imagePath)
  4425. if (StrUtil.isNotEmpty(imagePath)) {
  4426. //用户更改过图片
  4427. this.imagePathStr = imagePath
  4428. ToastUtil.showToast('获取封面成功')
  4429. }else{
  4430. ToastUtil.showToast('获取封面失败,请重试')
  4431. }
  4432. })
  4433. Button('获取歌词')
  4434. .fontColor(Color.White)
  4435. .fontSize(12)
  4436. .height(38)
  4437. .width(88)
  4438. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4439. .backgroundColor(this.themeColor)
  4440. .stateEffect(true)
  4441. .margin({ right: 20, left: 15 })
  4442. .onClick(async () => {
  4443. //判断有没有设置api
  4444. let apiUrl = PreferencesUtil.getStringSync('LRC_API', '')
  4445. if (StrUtil.isEmpty(apiUrl)) {
  4446. this.isLyricSetting = false
  4447. this.showTipsDialog()
  4448. return
  4449. }
  4450. let artist = item.artist
  4451. let title = item.name
  4452. if(!artist)
  4453. artist = ''
  4454. if(!title)
  4455. title = ''
  4456. let res: string | undefined = await getApiLyric(apiUrl,title, artist, false);
  4457. if (res && StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  4458. this.lyricConStr = res;
  4459. ToastUtil.showToast('获取歌词成功')
  4460. }else{
  4461. ToastUtil.showToast('获取歌词失败,请重试')
  4462. }
  4463. })
  4464. }
  4465. .height(55)
  4466. .justifyContent(FlexAlign.Start)
  4467. Row() {
  4468. Text('标题:')
  4469. .fontSize(14)
  4470. .fontColor($r('app.color.text_color'))
  4471. .margin({ left: 22 })
  4472. TextInput({ text: item.name })
  4473. .height(40)
  4474. .maxLines(1)
  4475. .fontSize(14)
  4476. .layoutWeight(1)
  4477. .fontColor($r('app.color.text_color'))
  4478. .margin({ right: 20, left: 10 })
  4479. .onChange((val: string) => {
  4480. this.titleStr = val
  4481. })
  4482. }
  4483. .width('100%')
  4484. .margin({ top: 10, bottom: 10 })
  4485. .justifyContent(FlexAlign.Start)
  4486. Row() {
  4487. Text('艺术家:')
  4488. .fontSize(14)
  4489. .fontColor($r('app.color.text_color'))
  4490. .margin({ left: 22 })
  4491. TextInput({ text: item.artist })
  4492. .height(40)
  4493. .maxLines(1)
  4494. .fontSize(14)
  4495. .layoutWeight(1)
  4496. .fontColor($r('app.color.text_color'))
  4497. .margin({ right: 20, left: 10 })
  4498. .onChange((val: string) => {
  4499. this.artistStr = val
  4500. })
  4501. }
  4502. .width('100%')
  4503. .margin({ top: 10, bottom: 10 })
  4504. .justifyContent(FlexAlign.Start)
  4505. Row() {
  4506. Text('专辑名:')
  4507. .fontSize(14)
  4508. .fontColor($r('app.color.text_color'))
  4509. .margin({ left: 22 })
  4510. TextInput({ text: item.album })
  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.ablumStr = val
  4519. })
  4520. }
  4521. .width('100%')
  4522. .margin({ top: 10, bottom: 10 })
  4523. .justifyContent(FlexAlign.Start)
  4524. Row() {
  4525. Column(){
  4526. Text('歌词:')
  4527. .fontSize(14)
  4528. .fontColor($r('app.color.text_color'))
  4529. .margin({ left: 22 })
  4530. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  4531. SymbolGlyph($r('sys.symbol.trash_fill'))
  4532. .fontSize(25)
  4533. .alignSelf(ItemAlign.Center)
  4534. .margin({ left: 22,top:25})
  4535. }
  4536. .backgroundColor(Color.Transparent)
  4537. .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
  4538. Visibility.None:Visibility.Visible)
  4539. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4540. .onClick(()=>{
  4541. this.lyricConStr = ''
  4542. this.lyricContent = ''
  4543. this.tempLyricContent = ''
  4544. })
  4545. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  4546. SymbolGlyph($r('sys.symbol.plus'))
  4547. .fontSize(25)
  4548. .alignSelf(ItemAlign.Center)
  4549. .margin({ left: 22,top:25})
  4550. }
  4551. .backgroundColor(Color.Transparent)
  4552. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4553. .onClick( ()=>{
  4554. this.callFilePickerSelectFileForLyric()
  4555. })
  4556. }
  4557. TextArea({ text: StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr:
  4558. this.tempLyricContent })
  4559. .type(TextAreaType.NORMAL)
  4560. .height(StrUtil.isEmpty(this.lyricConStr)&&StrUtil.isEmpty(this.tempLyricContent)?100:'auto')
  4561. .fontSize(14)
  4562. .layoutWeight(1)
  4563. .fontColor($r('app.color.text_color'))
  4564. .margin({ right: 20, left: 10 })
  4565. .onChange((val: string) => {
  4566. this.lyricConStr = val
  4567. })
  4568. }
  4569. .width('100%')
  4570. .margin({ top: 10, bottom: 10 })
  4571. .justifyContent(FlexAlign.Start)
  4572. Row() {
  4573. Text('年份:')
  4574. .fontSize(14)
  4575. .fontColor($r('app.color.text_color'))
  4576. .margin({ left: 22 })
  4577. TextInput({ text: item.year })
  4578. .height(40)
  4579. .maxLines(1)
  4580. .fontSize(14)
  4581. .type(InputType.Number)
  4582. .layoutWeight(1)
  4583. .fontColor($r('app.color.text_color'))
  4584. .margin({ right: 20, left: 10 })
  4585. .onChange((val: string) => {
  4586. this.yearStr = val
  4587. })
  4588. }
  4589. .width('100%')
  4590. .margin({ top: 10, bottom: 10 })
  4591. .justifyContent(FlexAlign.Start)
  4592. Row() {
  4593. Text('音轨号:')
  4594. .fontSize(14)
  4595. .fontColor($r('app.color.text_color'))
  4596. .margin({ left: 22 })
  4597. TextInput({ text:item.track=='未知'?'': item.track })
  4598. .height(40)
  4599. .maxLines(1)
  4600. .fontSize(14)
  4601. .type(InputType.Number)
  4602. .layoutWeight(1)
  4603. .fontColor($r('app.color.text_color'))
  4604. .margin({ right: 20, left: 10 })
  4605. .onChange((val: string) => {
  4606. this.trackStr = val
  4607. })
  4608. }
  4609. .width('100%')
  4610. .margin({ top: 10, bottom: 10 })
  4611. .justifyContent(FlexAlign.Start)
  4612. Row() {
  4613. Text('碟号:')
  4614. .fontSize(14)
  4615. .fontColor($r('app.color.text_color'))
  4616. .margin({ left: 22 })
  4617. TextInput({ text:item.disc })
  4618. .height(40)
  4619. .maxLines(1)
  4620. .fontSize(14)
  4621. .type(InputType.Number)
  4622. .layoutWeight(1)
  4623. .fontColor($r('app.color.text_color'))
  4624. .margin({ right: 20, left: 10 })
  4625. .onChange((val: string) => {
  4626. this.discStr = val
  4627. })
  4628. }
  4629. .width('100%')
  4630. .margin({ top: 10, bottom: 10 })
  4631. .justifyContent(FlexAlign.Start)
  4632. Row() {
  4633. Text('风格:')
  4634. .fontSize(14)
  4635. .fontColor($r('app.color.text_color'))
  4636. .margin({ left: 22 })
  4637. TextInput({ text: item.genre })
  4638. .height(40)
  4639. .maxLines(1)
  4640. .fontSize(14)
  4641. .layoutWeight(1)
  4642. .fontColor($r('app.color.text_color'))
  4643. .margin({ right: 20, left: 10 })
  4644. .onChange((val: string) => {
  4645. this.genreStr = val
  4646. })
  4647. }
  4648. .width('100%')
  4649. .margin({ top: 10, bottom: 10 })
  4650. .justifyContent(FlexAlign.Start)
  4651. Row() {
  4652. Text('专辑艺术家:')
  4653. .fontSize(14)
  4654. .fontColor($r('app.color.text_color'))
  4655. .margin({ left: 22 })
  4656. TextInput({ text: item.ALBUMARTIST })
  4657. .height(40)
  4658. .maxLines(1)
  4659. .fontSize(14)
  4660. .layoutWeight(1)
  4661. .fontColor($r('app.color.text_color'))
  4662. .margin({ right: 20, left: 10 })
  4663. .onChange((val: string) => {
  4664. this.albumArtistStr = val
  4665. })
  4666. }
  4667. .width('100%')
  4668. .margin({ top: 10, bottom: 10 })
  4669. .justifyContent(FlexAlign.Start)
  4670. Row() {
  4671. Text('作曲:')
  4672. .fontSize(14)
  4673. .fontColor($r('app.color.text_color'))
  4674. .margin({ left: 22 })
  4675. TextInput({ text: item.COMPOSER })
  4676. .height(40)
  4677. .maxLines(1)
  4678. .fontSize(14)
  4679. .layoutWeight(1)
  4680. .fontColor($r('app.color.text_color'))
  4681. .margin({ right: 20, left: 10 })
  4682. .onChange((val: string) => {
  4683. this.composerStr = val
  4684. })
  4685. }
  4686. .width('100%')
  4687. .margin({ top: 10, bottom: 10 })
  4688. .justifyContent(FlexAlign.Start)
  4689. Row() {
  4690. Text('作词:')
  4691. .fontSize(14)
  4692. .fontColor($r('app.color.text_color'))
  4693. .margin({ left: 22 })
  4694. TextInput({ text: item.LYRICIST })
  4695. .height(40)
  4696. .maxLines(1)
  4697. .fontSize(14)
  4698. .layoutWeight(1)
  4699. .fontColor($r('app.color.text_color'))
  4700. .margin({ right: 20, left: 10 })
  4701. .onChange((val: string) => {
  4702. this.lyricistStr = val
  4703. })
  4704. }
  4705. .width('100%')
  4706. .margin({ top: 10, bottom: 10 })
  4707. .justifyContent(FlexAlign.Start)
  4708. Row() {
  4709. Text('注释:')
  4710. .fontSize(14)
  4711. .fontColor($r('app.color.text_color'))
  4712. .margin({ left: 22 })
  4713. TextInput({ text: item.COMMENT })
  4714. .height(40)
  4715. .maxLines(1)
  4716. .fontSize(14)
  4717. .layoutWeight(1)
  4718. .fontColor($r('app.color.text_color'))
  4719. .margin({ right: 20, left: 10 })
  4720. .onChange((val: string) => {
  4721. this.commentStr = val
  4722. })
  4723. }
  4724. .width('100%')
  4725. .margin({ top: 10, bottom: 10 })
  4726. .justifyContent(FlexAlign.Start)
  4727. Row() {
  4728. Button('保存')
  4729. .fontColor(Color.White)
  4730. .layoutWeight(1)
  4731. .height(50)
  4732. .width(100)
  4733. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4734. .backgroundColor(this.themeColor)
  4735. .stateEffect(true)
  4736. .margin({ right: 20, bottom: 20 })
  4737. .onClick(async () => {
  4738. this.doEdit(item)
  4739. })
  4740. Button('取消')
  4741. .fontColor(Color.White)
  4742. .layoutWeight(1)
  4743. .height(50)
  4744. .width(100)
  4745. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4746. .backgroundColor(this.themeColor)
  4747. .stateEffect(true)
  4748. .margin({ left: 20, bottom: 20 })
  4749. .onClick(async () => {
  4750. if(this.isGridMusic){
  4751. this.longItemFilePath =''
  4752. }else{
  4753. this.isShowEdit = false
  4754. }
  4755. this.setEditStrEmpty()
  4756. if(this.isShowPlay){
  4757. this.isShowEdit = false
  4758. }
  4759. })
  4760. }
  4761. .margin({
  4762. left: 38,
  4763. right: 38,
  4764. top: 10,
  4765. bottom: 10
  4766. })
  4767. .width(250)
  4768. .height(60)
  4769. }
  4770. }
  4771. .margin({ bottom: 20 })
  4772. }
  4773. setEditStrEmpty(){
  4774. this.imagePathStr = ''
  4775. this.lyricConStr = ''
  4776. this.artistStr = ''
  4777. this.titleStr = ''
  4778. this.ablumStr = ''
  4779. this.genreStr = ''
  4780. this.yearStr = ''
  4781. this.trackStr = ''
  4782. this.albumArtistStr = ''
  4783. this.composerStr = ''
  4784. this.lyricistStr = ''
  4785. this.commentStr = ''
  4786. this.discStr = ''
  4787. }
  4788. @Builder
  4789. detailSheet(item:VideoItem) {
  4790. Scroll() {
  4791. Column() {
  4792. this.songDetail(item)
  4793. }
  4794. }
  4795. .width('100%')
  4796. .height('100%')
  4797. }
  4798. @Builder
  4799. songDetail(currentItem:VideoItem) {
  4800. Column() {
  4801. if (currentItem) {
  4802. Row() {
  4803. Stack() {
  4804. Image(StrUtil.isEmpty(currentItem.pixelMapPath) ? $r('app.media.music_red') :
  4805. currentItem.pixelMapPath)
  4806. .fillColor(this.themeColor)
  4807. .height(80)
  4808. .width(80)
  4809. .borderRadius(10)
  4810. .opacity(this.opacityItem)// 绑定透明度
  4811. .margin({ left: 22 })
  4812. }
  4813. Column() {
  4814. Column() {
  4815. Text(currentItem.name)
  4816. .fontSize(16)
  4817. .maxLines(1)
  4818. .animation({
  4819. duration: 555,
  4820. curve: 'Linear',
  4821. })
  4822. .fontColor($r('app.color.text_color'))
  4823. .margin({ left: 15 })
  4824. }
  4825. .height('100%')
  4826. .width('100%')
  4827. .justifyContent(FlexAlign.Center)
  4828. .alignItems(HorizontalAlign.Start)
  4829. }
  4830. .height('100%')
  4831. }
  4832. .width('100%')
  4833. .height(90)
  4834. .justifyContent(FlexAlign.SpaceBetween)
  4835. Row() {
  4836. Text('艺术家:')
  4837. .fontSize(14)
  4838. .fontColor($r('app.color.text_color'))
  4839. .margin({ left: 22 })
  4840. Text(currentItem?.artist ? currentItem.artist : '未知歌手')
  4841. .fontSize(14)
  4842. .fontColor($r('app.color.text_color'))
  4843. .margin({ left: 10 })
  4844. .layoutWeight(1)
  4845. }
  4846. .width('100%')
  4847. .margin({ top: 10, bottom: 10 })
  4848. .justifyContent(FlexAlign.Start)
  4849. Row() {
  4850. Text('专辑名:')
  4851. .fontSize(14)
  4852. .fontColor($r('app.color.text_color'))
  4853. .margin({ left: 22 })
  4854. Text(currentItem?.album ?currentItem.album : '未知专辑')
  4855. .fontSize(14)
  4856. .margin({ left: 10 })
  4857. .fontColor($r('app.color.text_color'))
  4858. .layoutWeight(1)
  4859. }
  4860. .width('100%')
  4861. .margin({ top: 10, bottom: 10 })
  4862. .justifyContent(FlexAlign.Start)
  4863. Row() {
  4864. Text('时长:')
  4865. .fontSize(14)
  4866. .fontColor($r('app.color.text_color'))
  4867. .margin({ left: 22 })
  4868. Text(StrUtil.isEmpty(currentItem.duration)?
  4869. (this.isShowDetailMore?this.totalTime:'未知'):currentItem.duration)
  4870. .fontSize(14)
  4871. .margin({ left: 10 })
  4872. .fontColor($r('app.color.text_color'))
  4873. .layoutWeight(1)
  4874. }
  4875. .width('100%')
  4876. .margin({ top: 10, bottom: 10 })
  4877. .justifyContent(FlexAlign.Start)
  4878. Row() {
  4879. Text('采样率:')
  4880. .fontSize(14)
  4881. .fontColor($r('app.color.text_color'))
  4882. .margin({ left: 22 })
  4883. Text(Utility.convertToKHz(currentItem.sampleRate))
  4884. .fontSize(14)
  4885. .margin({ left: 10 })
  4886. .fontColor($r('app.color.text_color'))
  4887. .layoutWeight(1)
  4888. }
  4889. .width('100%')
  4890. .margin({ top: 10, bottom: 10 })
  4891. .justifyContent(FlexAlign.Start)
  4892. Row() {
  4893. Text('比特率:')
  4894. .fontSize(14)
  4895. .fontColor($r('app.color.text_color'))
  4896. .margin({ left: 22 })
  4897. Text(currentItem.bit_rate)
  4898. .fontSize(14)
  4899. .margin({ left: 10 })
  4900. .fontColor($r('app.color.text_color'))
  4901. .layoutWeight(1)
  4902. }
  4903. .width('100%')
  4904. .margin({ top: 10, bottom: 10 })
  4905. .justifyContent(FlexAlign.Start)
  4906. Row() {
  4907. Text('位深:')
  4908. .fontSize(14)
  4909. .fontColor($r('app.color.text_color'))
  4910. .margin({ left: 22 })
  4911. Text(`${currentItem.bits_per_raw_sample} bits`)
  4912. .fontSize(14)
  4913. .margin({ left: 10 })
  4914. .fontColor($r('app.color.text_color'))
  4915. .layoutWeight(1)
  4916. }
  4917. .width('100%')
  4918. .margin({ top: 10, bottom: 10 })
  4919. .justifyContent(FlexAlign.Start)
  4920. Row() {
  4921. Text('声道:')
  4922. .fontSize(14)
  4923. .fontColor($r('app.color.text_color'))
  4924. .margin({ left: 22 })
  4925. Text(`${currentItem.channels}`)
  4926. .fontSize(14)
  4927. .margin({ left: 10 })
  4928. .fontColor($r('app.color.text_color'))
  4929. .layoutWeight(1)
  4930. }
  4931. .width('100%')
  4932. .margin({ top: 10, bottom: 10 })
  4933. .justifyContent(FlexAlign.Start)
  4934. Row() {
  4935. Text('声道布局:')
  4936. .fontSize(14)
  4937. .fontColor($r('app.color.text_color'))
  4938. .margin({ left: 22 })
  4939. Text(`${currentItem.channel_layout}`)
  4940. .fontSize(14)
  4941. .margin({ left: 10 })
  4942. .fontColor($r('app.color.text_color'))
  4943. .layoutWeight(1)
  4944. }
  4945. .width('100%')
  4946. .margin({ top: 10, bottom: 10 })
  4947. .justifyContent(FlexAlign.Start)
  4948. Row() {
  4949. Text('起始播放点:')
  4950. .fontSize(14)
  4951. .fontColor($r('app.color.text_color'))
  4952. .margin({ left: 22 })
  4953. Text(`${currentItem.start_time}`)
  4954. .fontSize(14)
  4955. .margin({ left: 10 })
  4956. .fontColor($r('app.color.text_color'))
  4957. .layoutWeight(1)
  4958. }
  4959. .width('100%')
  4960. .margin({ top: 10, bottom: 10 })
  4961. .justifyContent(FlexAlign.Start)
  4962. Row() {
  4963. Text('风格:')
  4964. .fontSize(14)
  4965. .fontColor($r('app.color.text_color'))
  4966. .margin({ left: 22 })
  4967. Text(currentItem.genre)
  4968. .fontSize(14)
  4969. .margin({ left: 10 })
  4970. .fontColor($r('app.color.text_color'))
  4971. .layoutWeight(1)
  4972. }
  4973. .width('100%')
  4974. .margin({ top: 10, bottom: 10 })
  4975. .justifyContent(FlexAlign.Start)
  4976. Row() {
  4977. Text('发行时间:')
  4978. .fontSize(14)
  4979. .fontColor($r('app.color.text_color'))
  4980. .margin({ left: 22 })
  4981. Text(currentItem.year)
  4982. .fontSize(14)
  4983. .margin({ left: 10 })
  4984. .fontColor($r('app.color.text_color'))
  4985. .layoutWeight(1)
  4986. }
  4987. .width('100%')
  4988. .margin({ top: 10, bottom: 10 })
  4989. .justifyContent(FlexAlign.Start)
  4990. Row() {
  4991. Text('质量评分:')
  4992. .fontSize(14)
  4993. .fontColor($r('app.color.text_color'))
  4994. .margin({ left: 22 })
  4995. Text(currentItem.probe_score+"")
  4996. .fontSize(14)
  4997. .margin({ left: 10 })
  4998. .fontColor($r('app.color.text_color'))
  4999. .layoutWeight(1)
  5000. }
  5001. .width('100%')
  5002. .margin({ top: 10, bottom: 10 })
  5003. .justifyContent(FlexAlign.Start)
  5004. Row() {
  5005. Text('音轨号:')
  5006. .fontSize(14)
  5007. .fontColor($r('app.color.text_color'))
  5008. .margin({ left: 22 })
  5009. Text(currentItem.track)
  5010. .fontSize(14)
  5011. .margin({ left: 10 })
  5012. .fontColor($r('app.color.text_color'))
  5013. .layoutWeight(1)
  5014. }
  5015. .width('100%')
  5016. .margin({ top: 10, bottom: 10 })
  5017. .justifyContent(FlexAlign.Start)
  5018. Row() {
  5019. Text('碟号:')
  5020. .fontSize(14)
  5021. .fontColor($r('app.color.text_color'))
  5022. .margin({ left: 22 })
  5023. Text(currentItem.disc)
  5024. .fontSize(14)
  5025. .margin({ left: 10 })
  5026. .fontColor($r('app.color.text_color'))
  5027. .layoutWeight(1)
  5028. }
  5029. .width('100%')
  5030. .margin({ top: 10, bottom: 10 })
  5031. .justifyContent(FlexAlign.Start)
  5032. Row() {
  5033. Text('专辑艺术家:')
  5034. .fontSize(14)
  5035. .fontColor($r('app.color.text_color'))
  5036. .margin({ left: 22 })
  5037. Text(currentItem.ALBUMARTIST)
  5038. .fontSize(14)
  5039. .margin({ left: 10 })
  5040. .fontColor($r('app.color.text_color'))
  5041. .layoutWeight(1)
  5042. }
  5043. .width('100%')
  5044. .margin({ top: 10, bottom: 10 })
  5045. .justifyContent(FlexAlign.Start)
  5046. Row() {
  5047. Text('作曲家:')
  5048. .fontSize(14)
  5049. .fontColor($r('app.color.text_color'))
  5050. .margin({ left: 22 })
  5051. Text(currentItem.COMPOSER)
  5052. .fontSize(14)
  5053. .margin({ left: 10 })
  5054. .fontColor($r('app.color.text_color'))
  5055. .layoutWeight(1)
  5056. }
  5057. .width('100%')
  5058. .margin({ top: 10, bottom: 10 })
  5059. .justifyContent(FlexAlign.Start)
  5060. Row() {
  5061. Text('作词家:')
  5062. .fontSize(14)
  5063. .fontColor($r('app.color.text_color'))
  5064. .margin({ left: 22 })
  5065. Text(currentItem.LYRICIST)
  5066. .fontSize(14)
  5067. .margin({ left: 10 })
  5068. .fontColor($r('app.color.text_color'))
  5069. .layoutWeight(1)
  5070. }
  5071. .width('100%')
  5072. .margin({ top: 10, bottom: 10 })
  5073. .justifyContent(FlexAlign.Start)
  5074. Row() {
  5075. Text('注释:')
  5076. .fontSize(14)
  5077. .fontColor($r('app.color.text_color'))
  5078. .margin({ left: 22 })
  5079. Text(currentItem.COMMENT)
  5080. .fontSize(14)
  5081. .margin({ left: 10 })
  5082. .fontColor($r('app.color.text_color'))
  5083. .layoutWeight(1)
  5084. }
  5085. .width('100%')
  5086. .margin({ top: 10, bottom: 10 })
  5087. .justifyContent(FlexAlign.Start)
  5088. Row() {
  5089. Text('格式:')
  5090. .fontSize(14)
  5091. .fontColor($r('app.color.text_color'))
  5092. .margin({ left: 22 })
  5093. Text(Utility.formatMimeType(currentItem.mimeType))
  5094. .fontSize(14)
  5095. .margin({ left: 10 })
  5096. .fontColor($r('app.color.text_color'))
  5097. .layoutWeight(1)
  5098. }
  5099. .width('100%')
  5100. .margin({ top: 10, bottom: 10 })
  5101. .justifyContent(FlexAlign.Start)
  5102. Row() {
  5103. Text('播放次数:')
  5104. .fontSize(14)
  5105. .fontColor($r('app.color.text_color'))
  5106. .margin({ left: 22 })
  5107. Text(currentItem.playCount?.toString())
  5108. .fontSize(14)
  5109. .margin({ left: 10 })
  5110. .fontColor($r('app.color.text_color'))
  5111. .layoutWeight(1)
  5112. }
  5113. .width('100%')
  5114. .margin({ top: 10, bottom: 10 })
  5115. .justifyContent(FlexAlign.Start)
  5116. Row() {
  5117. Text('流数量:')
  5118. .fontSize(14)
  5119. .fontColor($r('app.color.text_color'))
  5120. .margin({ left: 22 })
  5121. Text(currentItem.nb_streams?.toString())
  5122. .fontSize(14)
  5123. .margin({ left: 10 })
  5124. .fontColor($r('app.color.text_color'))
  5125. .layoutWeight(1)
  5126. }
  5127. .width('100%')
  5128. .margin({ top: 10, bottom: 10 })
  5129. .justifyContent(FlexAlign.Start)
  5130. Row() {
  5131. Text('文件大小:')
  5132. .fontSize(14)
  5133. .fontColor($r('app.color.text_color'))
  5134. .margin({ left: 22 })
  5135. Text(currentItem.size)
  5136. .fontSize(14)
  5137. .margin({ left: 10 })
  5138. .fontColor($r('app.color.text_color'))
  5139. .layoutWeight(1)
  5140. }
  5141. .width('100%')
  5142. .margin({ top: 10, bottom: 10 })
  5143. .justifyContent(FlexAlign.Start)
  5144. Row() {
  5145. Text('文件名:')
  5146. .fontSize(14)
  5147. .fontColor($r('app.color.text_color'))
  5148. .margin({ left: 22 })
  5149. Text(currentItem.fileName)
  5150. .fontSize(14)
  5151. .margin({ left: 10 })
  5152. .fontColor($r('app.color.text_color'))
  5153. .layoutWeight(1)
  5154. }
  5155. .width('100%')
  5156. .margin({ top: 10, bottom: 10 })
  5157. .justifyContent(FlexAlign.Start)
  5158. Row() {
  5159. Text('修改时间:')
  5160. .fontSize(14)
  5161. .fontColor($r('app.color.text_color'))
  5162. .margin({ left: 22 })
  5163. Text(currentItem.cTime)
  5164. .fontSize(14)
  5165. .margin({ left: 10 })
  5166. .fontColor($r('app.color.text_color'))
  5167. .layoutWeight(1)
  5168. }
  5169. .width('100%')
  5170. .margin({ top: 10, bottom: 10 })
  5171. .justifyContent(FlexAlign.Start)
  5172. Row() {
  5173. Text('存放目录:')
  5174. .fontSize(14)
  5175. .fontColor($r('app.color.text_color'))
  5176. .margin({ left: 22 })
  5177. Text(currentItem.filePath)
  5178. .fontSize(12)
  5179. .margin({ left: 10 })
  5180. .fontColor($r('app.color.text_color'))
  5181. .layoutWeight(1)
  5182. }
  5183. .margin({ top: 10, bottom: 10 })
  5184. .width('100%')
  5185. .justifyContent(FlexAlign.Start)
  5186. }
  5187. }
  5188. .margin({ bottom: 20 })
  5189. }
  5190. //定时关闭布局
  5191. @Builder
  5192. TimeCloseSheet() {
  5193. Scroll() {
  5194. Column() {
  5195. this.TimeClose()
  5196. }
  5197. }
  5198. .width('100%')
  5199. .height('100%')
  5200. }
  5201. //倒计时关闭音乐,退出App功能实现。
  5202. @State selectedMinutes: number = 0 // 0表示未开启
  5203. @State remainingSeconds: number = 0
  5204. // 预设时间选项
  5205. private presetTimes: number[] = [0, 5, 15, 30, 45, 60, -1]
  5206. private formatTime(seconds: number): string {
  5207. const mins = Math.floor(seconds / 60)
  5208. const secs = seconds % 60
  5209. return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
  5210. }
  5211. // 开始倒计时
  5212. private handleTimeSelect(minutes: number) {
  5213. if (minutes === this.selectedMinutes) {
  5214. this.stopCountdown();
  5215. this.selectedMinutes = 0;
  5216. return;
  5217. }
  5218. this.selectedMinutes = minutes;
  5219. this.remainingSeconds = minutes * 60;
  5220. this.startCountdown(); // 新增调用
  5221. }
  5222. @Builder
  5223. TimeClose() {
  5224. Column() {
  5225. // 倒计时显示区域
  5226. Text(this.selectedMinutes > 0 ?
  5227. `剩余时间:${this.formatTime(this.remainingSeconds)}` :
  5228. "定时关闭未开启")
  5229. .fontSize(17)
  5230. .fontColor($r('app.color.text_color'))
  5231. .margin({ top: 2, bottom: 8 });
  5232. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  5233. ForEach(this.presetTimes, (minutes: number, index: number) => {
  5234. // 单行时间选项容器
  5235. Row() {
  5236. // 文字描述区域
  5237. Text(this.getDisplayText(minutes))
  5238. .fontSize(15)
  5239. .fontColor(minutes === this.selectedMinutes ? this.themeColor :
  5240. $r('app.color.text_color'))// 选中态颜色变化
  5241. .textAlign(TextAlign.Start)
  5242. .layoutWeight(1); // 占据剩余空间
  5243. // 复选框样式的选择器
  5244. Row() {
  5245. if (minutes === this.selectedMinutes) {
  5246. // 选中状态 - 带勾号的圆形复选框
  5247. Row() {
  5248. // 使用系统内置的勾号图标
  5249. Image($r('sys.media.ohos_ic_public_ok'))
  5250. .width(14)
  5251. .height(14)
  5252. .fillColor(Color.White)
  5253. }
  5254. .width(24)
  5255. .height(24)
  5256. .borderRadius(12)
  5257. .backgroundColor(this.themeColor)
  5258. .justifyContent(FlexAlign.Center)
  5259. .alignItems(VerticalAlign.Center)
  5260. } else {
  5261. // 未选中状态的圆形边框
  5262. Row()
  5263. .width(24)
  5264. .height(24)
  5265. .borderRadius(12)
  5266. .border({
  5267. width: 2,
  5268. color: $r('app.color.text_color'),
  5269. style: BorderStyle.Solid
  5270. })
  5271. .backgroundColor(Color.Transparent)
  5272. }
  5273. }
  5274. .width(24)
  5275. .height(24)
  5276. .margin({ left: 20 })
  5277. .justifyContent(FlexAlign.Center)
  5278. .alignItems(VerticalAlign.Center)
  5279. }
  5280. .width('100%')
  5281. .padding({
  5282. top: 18,
  5283. bottom: 18,
  5284. left: 18,
  5285. right: 18
  5286. })
  5287. .backgroundColor(minutes === this.selectedMinutes ? $r('app.color.timeColor_bg') :
  5288. $r('app.color.bottom_control_background')) // 选中背景高亮
  5289. .borderRadius(12)
  5290. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  5291. .margin({ bottom: 18 })
  5292. .onClick(() => this.handleSelect(minutes)); // 点击整行触发选择
  5293. });
  5294. }
  5295. .width('100%')
  5296. .padding(16)
  5297. }
  5298. }
  5299. // 获取显示文本
  5300. private getDisplayText(minutes: number): string {
  5301. if (minutes === -1) {
  5302. return Utility.resourceToString(getContext(this), $r('app.string.customize'));
  5303. }
  5304. return minutes === 0 ? Utility.resourceToString(getContext(this), $r('app.string.close')) :
  5305. `${minutes}` + Utility.resourceToString(getContext(this), $r('app.string.minute_after'));
  5306. }
  5307. // 处理选择事件
  5308. private handleSelect(minutes: number): void {
  5309. if (minutes === -1) { // 自定义
  5310. // 弹出自定义时间对话框
  5311. DialogHelper.showTextInputDialog({
  5312. title: '自定义时间',
  5313. maskColor: Color.Transparent,
  5314. inputType: InputType.Number,
  5315. text: '',
  5316. onChange: (text) => {
  5317. console.error("onChange: " + text);
  5318. },
  5319. onAction: (action, dialogId, content) => {
  5320. if (action == DialogAction.TWO) {
  5321. const customMinutes = Number(content);
  5322. if (customMinutes > 0) {
  5323. this.handleTimeSelect(customMinutes); // 设置自定义时间
  5324. ToastUtil.showToast("设置成功," + customMinutes + "分钟后定时关闭");
  5325. }
  5326. }
  5327. }
  5328. });
  5329. } else {
  5330. this.handleTimeSelect(minutes); // 统一调用选择处理方法
  5331. }
  5332. }
  5333. // 添加定时器引用
  5334. private timerId: number = -1;
  5335. // 启动/重置倒计时
  5336. private startCountdown() {
  5337. // 清除旧定时器
  5338. if (this.timerId !== -1) {
  5339. clearInterval(this.timerId);
  5340. }
  5341. // 创建新定时器
  5342. if (this.selectedMinutes > 0) {
  5343. this.timerId = setInterval(() => {
  5344. if (this.remainingSeconds === 15) {
  5345. this.showConfirmationDialog();
  5346. }
  5347. if (this.remainingSeconds > 0) {
  5348. this.remainingSeconds -= 1;
  5349. } else {
  5350. this.stopCountdown();
  5351. this.handleTimeout();
  5352. }
  5353. }, 1000);
  5354. }
  5355. }
  5356. // 15倒计时后再次提示显示确认是否关闭App对话框
  5357. private showConfirmationDialog() {
  5358. DialogHelper.showAlertDialog({
  5359. backgroundColor: $r('app.color.btn_green'),
  5360. title: '确认关闭',
  5361. maskColor: Color.Transparent,
  5362. content: "马上到达定时关闭时间,您是否确定要退出应用?",
  5363. borderStyle: BorderStyle.Dashed,
  5364. primaryButton: '暂不关闭',
  5365. secondaryButton: '确定',
  5366. onAction: (action) => {
  5367. if (action == DialogAction.ONE) { //暂不关闭,取消定时
  5368. this.stopCountdown();
  5369. this.selectedMinutes = 0
  5370. } else if (action == DialogAction.TWO) {
  5371. }
  5372. }
  5373. })
  5374. }
  5375. // 停止倒计时
  5376. private stopCountdown() {
  5377. if (this.timerId !== -1) {
  5378. clearInterval(this.timerId);
  5379. this.timerId = -1;
  5380. }
  5381. }
  5382. // 超时处理
  5383. private handleTimeout() {
  5384. // 执行播放器关闭逻辑
  5385. this.selectedMinutes = 0;
  5386. ToastUtil.showToast(" 定时关闭已完成");
  5387. this.stop(); // 假设存在的播放器实例
  5388. //退出APP
  5389. const mContext = getContext(this) as common.UIAbilityContext
  5390. mContext.terminateSelf();
  5391. AvSessionController.getInstance(true).unregisterSessionListener()
  5392. }
  5393. //倒计时关闭音乐,退出App功能实现结束。
  5394. //播放列表的拖动List 重新排序
  5395. @State sonDataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.songList)
  5396. //左滑操作 移动文件 重命名 删除等操作
  5397. @Builder
  5398. sonButton(item: VideoItem, index: number, filePath: string) {
  5399. Row() {
  5400. //加入下一首播放
  5401. Button() {
  5402. Image($r('app.media.next_to_play'))
  5403. .fillColor(Color.White)
  5404. .width(20)
  5405. }
  5406. .width(40)
  5407. .height(40)
  5408. .type(ButtonType.Circle)
  5409. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5410. .backgroundColor(this.themeColor)
  5411. .margin(5)
  5412. .onClick(() => {
  5413. this.addToNextPlay(item);
  5414. })
  5415. Button() {
  5416. Image($r('app.media.close'))
  5417. .fillColor(Color.White)
  5418. .width(20)
  5419. }
  5420. .width(40)
  5421. .height(40)
  5422. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5423. .type(ButtonType.Circle)
  5424. .backgroundColor(this.themeColor)
  5425. .margin(5)
  5426. .onClick(() => {
  5427. this.songList.splice(Number(index), 1)
  5428. this.sonDataSource.pushArrayData(this.songList)
  5429. })
  5430. Button() {
  5431. Image($r('app.media.share2'))
  5432. .fillColor(Color.White)
  5433. .width(20)
  5434. }
  5435. .width(40)
  5436. .height(40)
  5437. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5438. .type(ButtonType.Circle)
  5439. .backgroundColor(this.themeColor)
  5440. .margin(5)
  5441. .onClick(() => {
  5442. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  5443. })
  5444. }
  5445. }
  5446. itemMoveSon(index: number, newIndex: number): void {
  5447. if (newIndex < 0 || newIndex >= this.songList.length) {
  5448. return;
  5449. }
  5450. let tmp = this.songList.splice(index, 1);
  5451. this.songList.splice(newIndex, 0, tmp[0]);
  5452. this.sonDataSource.pushArrayData(this.songList)
  5453. this.curIndex = Utility.getIndexFromList(this.songList, this.videoUrl)
  5454. }
  5455. @Builder
  5456. PlayList() {
  5457. List({ scroller: this.playListScroller }) {
  5458. LazyForEach(this.sonDataSource, (item: VideoItem, index: number) => {
  5459. ListItem() {
  5460. this.MusicItemSon(item, index)
  5461. }
  5462. .swipeAction({ end: this.sonButton(item, index, item.filePath) }) //左滑
  5463. .animation({
  5464. duration: 666,
  5465. curve: 'ease-in-out' // 可选动画曲线
  5466. })
  5467. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 600 }),
  5468. TransitionEffect.scale({ x: 0, y: 0 })))
  5469. .clickEffect({ level: ClickEffectLevel.MIDDLE })
  5470. //拖动List关键代码开始
  5471. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  5472. .zIndex(this.dragItem === index ? 1 : 0)
  5473. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  5474. .gesture(
  5475. GestureGroup(GestureMode.Sequence,
  5476. LongPressGesture({ repeat: true })
  5477. .onAction((event?: GestureEvent) => {
  5478. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5479. this.scaleItem = index
  5480. })
  5481. })
  5482. .onActionEnd(() => {
  5483. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5484. this.scaleItem = -1
  5485. })
  5486. }),
  5487. PanGesture({ fingers: 1, direction: null, distance: 0 })
  5488. .onActionStart(() => {
  5489. this.dragItem = index // 记录当前拖动项索引
  5490. this.dragRefOffset = 0 // 重置偏移基准
  5491. })
  5492. .onActionUpdate((event: GestureEvent) => {
  5493. this.offsetY = event.offsetY - this.dragRefOffset;
  5494. this.neighborItem = -1;
  5495. let indexA = this.songList.indexOf(item);
  5496. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  5497. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  5498. let value: number = 0;
  5499. if (this.offsetY < 0) {
  5500. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  5501. this.neighborItem = indexA - 1;
  5502. this.neighborScale = 1 - value / 20;
  5503. } else if (this.offsetY > 0) {
  5504. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  5505. this.neighborItem = indexA + 1;
  5506. this.neighborScale = 1 - value / 20;
  5507. }
  5508. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.songList.length) {
  5509. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5510. this.offsetY -= this.ITEM_INTV;
  5511. this.dragRefOffset += this.ITEM_INTV;
  5512. this.itemMoveSon(indexA, indexA + 1);
  5513. });
  5514. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  5515. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5516. this.offsetY += this.ITEM_INTV;
  5517. this.dragRefOffset -= this.ITEM_INTV;
  5518. this.itemMoveSon(indexA, indexA - 1);
  5519. });
  5520. }
  5521. })
  5522. .onActionEnd((event: GestureEvent) => {
  5523. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5524. this.dragItem = -1
  5525. this.neighborItem = -1
  5526. })
  5527. animateTo({
  5528. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  5529. }, () => {
  5530. this.scaleItem = -1
  5531. })
  5532. })
  5533. )
  5534. .onCancel(() => {
  5535. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5536. this.dragItem = -1
  5537. this.neighborItem = -1
  5538. })
  5539. animateTo({
  5540. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  5541. }, () => {
  5542. this.scaleItem = -1
  5543. })
  5544. })
  5545. ) //拖动List关键代码结束
  5546. .onClick(() => {
  5547. this.doPlay(item, index, true)
  5548. })
  5549. }, (item: VideoItem) => item.filePath)
  5550. }
  5551. .width('100%')
  5552. .height('100%')
  5553. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  5554. // .animation({ duration: 500, curve: Curve.Ease }))
  5555. .cachedCount(10)
  5556. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  5557. .gesture(PinchGesture({ fingers: 2 })
  5558. .onActionEnd((event: GestureEvent) => {
  5559. this.setlistTwoFingers()
  5560. })
  5561. .onActionUpdate(e => {
  5562. this.scaleValue = this.pinchValue * e.scale
  5563. })
  5564. .onActionStart(e => {
  5565. }))
  5566. .padding({
  5567. bottom: 0
  5568. })
  5569. }
  5570. @Builder
  5571. private MusicItemSon(item: VideoItem, index?: number) {
  5572. Button({ type: ButtonType.Normal, stateEffect: true }) {
  5573. Row() {
  5574. Stack() {
  5575. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  5576. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  5577. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  5578. .alt($r('app.media.music_red'))
  5579. .fillColor(this.themeColor)
  5580. .borderRadius('100%')
  5581. .clip(true)
  5582. .margin({ left: 20 })
  5583. }
  5584. .width('15%')
  5585. Column() {
  5586. Column() {
  5587. Text(item.name)
  5588. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  5589. .fontColor(this.curIndex === index ? this.themeColor :
  5590. this.isFrontWhite ? Color.White : $r('app.color.text_color'))
  5591. .maxLines(1)
  5592. .margin({ left: this.twoFingerType == 3 ? 18 : 10 })
  5593. Row() {
  5594. Column(){
  5595. Text(item.md5Str?.includes('Lossless')?
  5596. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  5597. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  5598. .padding({ top: 3,right:6,left:6,bottom:3 })
  5599. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  5600. $r('app.color.text_color'))
  5601. .fontWeight(500)
  5602. .borderRadius(12)
  5603. .margin({ left: this.twoFingerType == 3 ? 12 : 10 })
  5604. .backgroundColor('#FFC107')
  5605. }
  5606. .padding({ top: 8 })
  5607. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  5608. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  5609. .padding({ top: 8 })
  5610. .fontColor(this.curIndex === index ? this.themeColor :
  5611. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  5612. .margin({ left: this.twoFingerType == 3 ? 5 : 3 })
  5613. Blank()
  5614. Text(item.size)
  5615. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  5616. .padding({ top: 8 })
  5617. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  5618. .fontColor(this.curIndex === index ? $r('app.color.title_bar_bg_text') :
  5619. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  5620. .margin({ left: 10 })
  5621. }
  5622. }
  5623. .height('100%')
  5624. .width('100%')
  5625. .justifyContent(FlexAlign.Center)
  5626. .alignItems(HorizontalAlign.Start)
  5627. }
  5628. .height('100%')
  5629. .width('65%')
  5630. Column() {
  5631. ImageAnimator()
  5632. .images(this.imagesF)// 动画数组
  5633. .duration(1000)// 持续
  5634. .state(this.animationState)// 动画状态
  5635. .fillMode(FillMode.Forwards)
  5636. .width(18)
  5637. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  5638. Visibility.None)
  5639. .height(18)
  5640. .iterations(-1) // 播放次数
  5641. }
  5642. .width('20%')
  5643. }
  5644. }
  5645. .backgroundColor(Color.Transparent)
  5646. .width('100%')
  5647. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  5648. .shadow(this.scaleItem === index ? {
  5649. radius: 70,
  5650. color: '#15000000',
  5651. offsetX: 0,
  5652. offsetY: 0
  5653. } :
  5654. {
  5655. radius: 0,
  5656. color: '#15000000',
  5657. offsetX: 0,
  5658. offsetY: 0
  5659. })
  5660. .animation({ curve: Curve.Sharp, duration: 300 })
  5661. }
  5662. @Builder
  5663. MusicPlayBuilder() {
  5664. Column() {
  5665. this.IjkMusicPlayerView()
  5666. }
  5667. .height('100%')
  5668. .width('100%')
  5669. .onDisAppear(() => {
  5670. this.translateY = 0;
  5671. })
  5672. .translate({ y: this.translateY })
  5673. .gesture(
  5674. PanGesture(this.panOption)
  5675. .onActionUpdate((event?: GestureEvent) => {
  5676. if (event) {
  5677. // 只允许向下滑动,向上滑动时限制为0
  5678. this.translateY = Math.max(0, event.offsetY);
  5679. }
  5680. })
  5681. .onActionEnd((event?: GestureEvent) => {
  5682. // 使用更低的阈值和滑动速度判断
  5683. const minDistance = 100; // 最小滑动距离 100vp
  5684. const minVelocity = 500; // 最小滑动速度
  5685. // 获取滑动速度(如果可用)
  5686. const velocity = event?.velocityY || 0;
  5687. // 判断是否应该关闭:距离足够 或者 速度足够快
  5688. const shouldClose = this.translateY > minDistance || velocity > minVelocity;
  5689. if (shouldClose) {
  5690. // 添加关闭动画
  5691. this.getUIContext().animateTo({
  5692. duration: 300,
  5693. curve: Curve.Smooth
  5694. }, () => {
  5695. this.isShowPlay = false;
  5696. this.translateY = 0;
  5697. })
  5698. } else {
  5699. // 回弹动画
  5700. this.getUIContext().animateTo({
  5701. duration: 300,
  5702. curve: Curve.Smooth
  5703. }, () => {
  5704. this.translateY = 0;
  5705. })
  5706. }
  5707. })
  5708. )
  5709. }
  5710. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD; //一多界面适配
  5711. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  5712. HeightBreakpoint.HEIGHT_LG;
  5713. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  5714. @State topBarHeight: number = 50
  5715. @State barOpacity: number = 1
  5716. @State barBottomOpacity: number = 1
  5717. private hideDone: boolean = false;
  5718. @State currentYOffset: number = 0;
  5719. @State bottomBarHeight: number = 60;
  5720. private isHiding: boolean = false;
  5721. //是否是Pura X外屏,或者小屏幕
  5722. isPuraWP() {
  5723. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  5724. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  5725. }
  5726. //是否是Pura X外屏,或者小屏幕,手机横屏
  5727. /**
  5728. * 是否是Pura X外屏,或者小屏幕,手机横屏
  5729. * @returns
  5730. */
  5731. isCoverOpacity() {
  5732. if (this.isPuraWP()) {
  5733. return true
  5734. }
  5735. if (this.isPhoneLan()) {
  5736. return true
  5737. }
  5738. if (deviceInfo.marketName.includes('Pura X')
  5739. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  5740. return true
  5741. }
  5742. return false
  5743. }
  5744. //是不是手机横屏
  5745. isPhoneLan() {
  5746. // LogUtil.info('twocold this.currentHeightBreakpoint = '+this.currentHeightBreakpoint)
  5747. // LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
  5748. LogUtil.info('hicar isPhoneLan width= ' + this.windowWidth);
  5749. LogUtil.info('hicar isPhoneLan height= ' + this.windowHeight);
  5750. LogUtil.info(`twocold hicarWindow size: ${this.windowWidth}x${this.windowHeight}, this.isHiCarStatus: ${this.isHiCarStatus}`);
  5751. LogUtil.info(`twocold hicar Window size: ${this.windowWidth}x${this.windowHeight}, isHiCarSmall: ${this.isHiCarSmall()}`);
  5752. if (this.isHiCarKuanBianPing()) {
  5753. return true
  5754. }
  5755. if (this.isHiCar()) {
  5756. return false
  5757. }
  5758. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  5759. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_SM
  5760. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_MD&&this.isLandscape) { //如果是手机横屏,返回true
  5761. return true
  5762. }
  5763. return false
  5764. }
  5765. //是不是1920x720的hicar的屏幕分辨率
  5766. isHiCarKuanBianPing(){
  5767. if(!this.isHiCar()){
  5768. return false
  5769. }
  5770. const hiCarAspectRatios: HiCarAspectRatio[] = [
  5771. { ratio: 1920 / 720, name: "1920x720" },
  5772. ];
  5773. const currentRatio: number = this.windowWidth / this.windowHeight;
  5774. const RATIO_TOLERANCE: number = 0.22; // 宽高比容差
  5775. LogUtil.info('twocold isHiCarKuanBianPing currentRatio = ' + currentRatio)
  5776. for (const hiCarRatio of hiCarAspectRatios) {
  5777. LogUtil.info('twocold isHiCarKuanBianPing hiCarRatio= ' + hiCarRatio.ratio)
  5778. LogUtil.info('twocold isHiCarKuanBianPing Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  5779. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  5780. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  5781. return true;
  5782. }
  5783. }
  5784. return false;
  5785. }
  5786. //是不是hicar的屏幕分辨率
  5787. isHiCarSmall() {
  5788. if(!this.isHiCar()){
  5789. return false
  5790. }
  5791. if(this.windowWidth>1800&&this.windowHeight>=1200)//大屏幕可以Grid
  5792. return false
  5793. const hiCarAspectRatios: HiCarAspectRatio[] = [
  5794. { ratio: 800 / 480, name: "800x480" },
  5795. { ratio: 1280 / 720, name: "1280x720" },
  5796. { ratio: 1920 / 1080, name: "1920x1080" },
  5797. ];
  5798. const currentRatio: number = this.windowWidth / this.windowHeight;
  5799. const RATIO_TOLERANCE: number = 0.22; // 宽高比容差
  5800. LogUtil.info('twocold isHiCarSmall currentRatio = ' + currentRatio)
  5801. for (const hiCarRatio of hiCarAspectRatios) {
  5802. LogUtil.info('twocold isHiCarSmall hiCarRatio= ' + hiCarRatio.ratio)
  5803. LogUtil.info('twocold isHiCarSmall Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  5804. LogUtil.info('twocold isHiCarSmall isHiCarStatus= ' + this.isHiCarStatus);
  5805. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  5806. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  5807. return true;
  5808. }
  5809. }
  5810. return false;
  5811. }
  5812. isHiCar() {
  5813. return this.isHiCarStatus&&this.curDisplayIsHiCar;
  5814. }
  5815. //是不是正常的手机竖屏
  5816. isPhonePortrait() {
  5817. // LogUtil.info('twocold this.currentHeightBreakpoint = ' + this.currentHeightBreakpoint)
  5818. // LogUtil.info('twocold this.currentWidthBreakpoint = ' + this.currentWidthBreakpoint)
  5819. // LogUtil.info('Heanup 当前设备类型:' + DeviceUtil.getDeviceType())
  5820. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  5821. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG
  5822. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_SM) { //如果是手机横屏,返回false
  5823. return true
  5824. }
  5825. return false
  5826. }
  5827. @State showSpeedDialog: boolean = false
  5828. @State longPressSpeed: number = 3 //长按默认倍数
  5829. @Builder
  5830. SpeedDialog() {
  5831. Stack() {
  5832. Column() {
  5833. Text('已切换至' + this.longPressSpeed + '倍速播放')
  5834. .fontColor(Color.White)
  5835. .visibility(Visibility.Hidden)
  5836. }
  5837. .backgroundColor(Color.Black)
  5838. .borderRadius(20)
  5839. .padding({
  5840. top: 10,
  5841. right: 20,
  5842. left: 15,
  5843. bottom: 20
  5844. })
  5845. .opacity(0.6)
  5846. Text('已切换至' + this.longPressSpeed + '倍速播放')
  5847. .fontColor(Color.White)
  5848. }
  5849. .transition(TransitionEffect.OPACITY.animation({ duration: 500, curve: Curve.Ease }))
  5850. .zIndex(5)
  5851. .margin({ top: 80 })
  5852. }
  5853. @Builder
  5854. IjkMusicPlayerView() {
  5855. Column() {
  5856. Column() {
  5857. Column() {
  5858. //播放标题
  5859. Column() {
  5860. this.PlayTitle()
  5861. }
  5862. .position({ x: 0, y: this.isCoverOpacity() ? 15 : 40 })
  5863. .width('100%')
  5864. .margin({ top: 0 })
  5865. .height(PlayConstants.HEIGHT)
  5866. .visibility(DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1 ?
  5867. Visibility.Visible : this.isShowPlayPageBack ? Visibility.Visible : Visibility.None)
  5868. if (this.showSpeedDialog) {
  5869. this.SpeedDialog()
  5870. }
  5871. Stack() {
  5872. //手势拖动快进
  5873. Column()
  5874. .width(CommonConstants.FULL_PERCENT)
  5875. .height('100%')
  5876. .gesture(
  5877. GestureGroup(GestureMode.Parallel,
  5878. // 长按屏幕倍数播放
  5879. LongPressGesture({ repeat: true })
  5880. .onAction(() => {
  5881. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  5882. this.showSpeedDialog = true;
  5883. this.mIjkMediaPlayer.setSpeed(this.longPressSpeed + 'f');
  5884. }
  5885. })
  5886. .onActionEnd(() => {
  5887. this.showSpeedDialog = false;
  5888. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  5889. }),
  5890. //双击屏幕暂停或者播放
  5891. TapGesture({ count: 2 })
  5892. .onAction((event: GestureEvent) => {
  5893. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  5894. ToastUtil.showToast('已暂停')
  5895. }
  5896. this.playOrPause()
  5897. })
  5898. )
  5899. )
  5900. }
  5901. .height('65%')
  5902. Swiper() {
  5903. this.CoverInfo()
  5904. this.PlayerLyrics()
  5905. }
  5906. .onChange((index: number) => {
  5907. this.currentSwiperIndex = index
  5908. })
  5909. .indicator(false)
  5910. // .indicator(this.currentBreakpoint === BreakpointTypeEnum.SM ?
  5911. // new DotIndicator()
  5912. // .top(this.isCoverOpacity()?0:10)
  5913. //
  5914. // .selectedColor($r('app.color.select_swiper'))
  5915. // .color($r('app.color.slider_track')):false
  5916. // )
  5917. .displayCount(new BreakpointType({
  5918. sm: 1,
  5919. md: 2,
  5920. lg: 2,
  5921. xl: 2,
  5922. xxl: 2
  5923. }).getValue(this.currentBreakpoint))
  5924. .clip(false)
  5925. .loop(false)
  5926. .autoPlay(false)
  5927. // .interval(8000)
  5928. .position({ x: 0, y: this.isCoverOpacity() ? 30 : 40 })
  5929. .height('100%')
  5930. .hitTestBehavior(HitTestMode.Transparent)
  5931. Image($r('app.media.icon_replay'))
  5932. .objectFit(ImageFit.Auto)
  5933. .width('120px')
  5934. .height('120px')
  5935. .position({ x: '45.1%', y: '47.5%' })// .visibility(this.replayVisible)
  5936. .border({ width: 0 })
  5937. .visibility(Visibility.None)
  5938. .borderStyle(BorderStyle.Dashed)// .hitTestBehavior(HitTestMode.Transparent)
  5939. .onClick(() => {
  5940. this.startPlayOrResumePlay();
  5941. })
  5942. }
  5943. .width(CommonConstants.FULL_PERCENT)
  5944. .height(CommonConstants.FULL_PERCENT)
  5945. .justifyContent(FlexAlign.End)
  5946. }
  5947. .justifyContent(FlexAlign.End)
  5948. .margin({ bottom: 8 })
  5949. }
  5950. // .backgroundImage(this.imageLabelBg)
  5951. .backgroundImage(this.isPuraWP() && this.currentSwiperIndex === 0 ?
  5952. (StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover) : this.imageLabelBg)
  5953. .backgroundImageSize(this.isPuraWP() ? { width: '100%' } : { height: '150%', width: '100%' })
  5954. // .backgroundImagePosition(Alignment.Center)
  5955. .animation({
  5956. duration: 666,
  5957. curve: 'ease-in-out' // 可选动画曲线
  5958. })
  5959. .backgroundBlurStyle(this.isPuraWP() && this.currentSwiperIndex === 0 ? BlurStyle.NONE :
  5960. BlurStyle.BACKGROUND_ULTRA_THICK)
  5961. .hitTestBehavior(HitTestMode.Transparent)
  5962. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  5963. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  5964. .backgroundBrightness({ rate: this.isPuraWP() ? 0.1 : 0, lightUpDegree: -0.1 })
  5965. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
  5966. .onClick(() => {
  5967. // this.startAutoHide()
  5968. if(this.isHiCar())
  5969. return
  5970. if(this.is_auto_hide_progress){
  5971. this.is_auto_hide_progress = false
  5972. }
  5973. this.startAutoHide()
  5974. })
  5975. }
  5976. @State progressValue: number = 0;
  5977. @State currentTime: string = "00:00";
  5978. @State totalTime: string = "00:00";
  5979. @State loadingVisible: Visibility = Visibility.None;
  5980. @State replayVisible: Visibility = Visibility.None;
  5981. @State slideEnable: boolean = false;
  5982. @State aspRatio: number = 0.5;
  5983. @State mContext: object | undefined = undefined;
  5984. // private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
  5985. @State mFirst: boolean = true;
  5986. @State mDestroyPage: boolean = false;
  5987. @State playSpeed: number = 1;
  5988. @State oldSeconds: number = 0;
  5989. @State isSeekTo: boolean = false;
  5990. @State isCurrentTime: boolean = false;
  5991. @State videoWidth: string = '100%';
  5992. @State videoHeight: string = '100%';
  5993. @State initAspectRatio: number = 1;
  5994. @State videoAspectRatio: number = this.initAspectRatio;
  5995. private videoUrl: string = '';
  5996. private last: number = 0;
  5997. @State videoParentAspectRatio: number = this.initAspectRatio;
  5998. private mIjkMediaPlayer = IjkMediaPlayer.getInstance();
  5999. @State CONTROL_PlayStatus: number = PlayStatus.INIT;
  6000. @State PROGRESS_MAX_VALUE: number = 100;
  6001. @State updateProgressTimer: number = 0;
  6002. @State isHide: boolean = false; //是否因此播放器的按钮,默认是进入横屏模式隐藏,点击视频的时候显示
  6003. @State name: string = '';
  6004. // @State loop: boolean = false;
  6005. @State playType: number = 0; //0:连续播放 1:单片重复播放 2:正常播放 3:随机播放
  6006. @State multiple: string = '1.0X';
  6007. xcomponentController: XComponentController = new XComponentController()
  6008. private panOptionBright: PanGestureOptions =
  6009. new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down });
  6010. private panOptionVolume: PanGestureOptions =
  6011. new PanGestureOptions({ direction: PanDirection.Vertical | PanDirection.Up | PanDirection.Down });
  6012. private panOptionSeekTo: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Horizontal });
  6013. //手势的音量控制和亮度控制
  6014. private positionX: number = PlayConstants.POSITION_X;
  6015. private positionY: number = PlayConstants.POSITION_Y;
  6016. private windowClass: window.Window = globalThis.windowClass
  6017. @State volume: number = 0.5;
  6018. @State volumeSmall: boolean = false
  6019. @State volumeShow: boolean = PlayConstants.VOLUME_SHOW;
  6020. @State bright: number = PlayConstants.BRIGHT;
  6021. @State brightShow: boolean = PlayConstants.BRIGHT_SHOW;
  6022. @State seekToShow: boolean = PlayConstants.BRIGHT_SHOW;
  6023. @State screenWidth: number = 0
  6024. @State screenHeight: number = 0
  6025. @State statusBarHeight: number = 0
  6026. @State isYesFull: boolean = false
  6027. private seekValue: number = 0
  6028. @State isVideoLock: boolean = false; // Whether the video playback is locked
  6029. eventHub = getContext().eventHub;
  6030. //投播组件
  6031. private avSessionController: AvSessionController = AvSessionController.getInstance(false);
  6032. private castController: avSession.AVCastController | undefined = undefined;
  6033. @State isCastPlaying: boolean = false;
  6034. @State currentTime2: number = 0;
  6035. @State currentStringTime: string = '00:00';
  6036. @State duration: number = 0;
  6037. @State isReady: boolean = false;
  6038. @State durationTime: number = 0;
  6039. @State durationStringTime: string = '00:00';
  6040. @StorageLink('isPlaying') @Watch('animationRoFun') isPlaying: boolean = false;
  6041. // @State isPlaying: boolean = false;
  6042. private castSeek: boolean = false;
  6043. private castItem: avSession.AVQueueItem | undefined = undefined;
  6044. // @State isBgPlayOpen:boolean = true //是否启用后台播放
  6045. @State imageLabel: PixelMap | Resource = CommonConstants.musicBgList[0];
  6046. @State imageLabelBg: PixelMap | Resource = CommonConstants.musicBgList[0];
  6047. @State rotateAngle2: number = 0
  6048. @StorageLink('imageColor') imageColor: string = 'rgba(0, 0, 2, 1.00)';
  6049. @State cover: string | undefined = '';
  6050. @State artist: string | undefined = ''
  6051. // 1.初始化controller
  6052. private lyricController: LyricController = new LyricController()
  6053. private lyricControllerXF: LyricController = new LyricController() //悬浮歌词控制器
  6054. private lyricControllerSingle: LyricController = new LyricController() //播放页单行歌词控制器
  6055. private parser = new LyricParser()
  6056. @State randomColor: string = 'rgb(0,0,0)'
  6057. @State randomShakenX: number = 0
  6058. @State randomShakenY: number = 0
  6059. @State lyricTextSize: number = 24
  6060. @State lyricContent: string = ''
  6061. @State isDebug: boolean = false
  6062. @State isHightLightCenter: boolean = true
  6063. /**
  6064. * 初始化歌词加载与展示逻辑
  6065. * @param lyricPath 歌词文件路径(支持普通.lrc和加密.lrcc)
  6066. * @param isOnLineAndToast 是否弹出Toast提示(可选)获取在线歌词为true
  6067. * @param isApi2 是否使用API2获取歌词(可选)
  6068. *
  6069. * 主要流程:
  6070. * 1. 设置歌词显示样式(字号、颜色、行距、对齐、动画等)。
  6071. * 2. 优先尝试本地读取歌词文件(支持加密和普通两种后缀)。
  6072. * 3. 若本地无歌词且满足条件(调试模式或会员且安装时间超过2天),则联网获取歌词。
  6073. * 4. 获取到歌词后,解析并设置到lyricController,并保存到本地。
  6074. * 5. 本地有歌词时,读取文件内容(自动检测编码,支持解密),解析后设置到lyricController。
  6075. * 6. 解析失败或读取失败时,清空歌词显示。
  6076. *
  6077. * 注意事项:
  6078. * - 仅会员且安装时间超过2天才可联网获取歌词(调试模式isDebug=true时跳过限制)。
  6079. * - 支持加密歌词文件(.lrcc),自动检测并解密。
  6080. * - 歌词内容解析后通过lyricController驱动UI渲染。
  6081. */
  6082. async initLyric(lyricPath: string, isOnLineAndToast?: boolean, isApi2?: boolean, isLocal?: boolean) {
  6083. if (StrUtil.isEmpty(lyricPath)) {
  6084. return
  6085. }
  6086. this.initPipLyricSetting()
  6087. this.lyricControllerSingle
  6088. .setTextSize(15)
  6089. .setCacheSize(4)
  6090. .setTextColor("#FFFFFF")
  6091. .setHighlightColor("#FFFFFF")
  6092. .setHighlightScale(1.2)
  6093. .setEmptyHint("")
  6094. .setAlignMode('center')
  6095. .setAnimationDuration(500)
  6096. .setSingleLine(true)
  6097. this.lyricContent = ''
  6098. this.lyricController
  6099. .setTextSize(this.currentLyricSize)
  6100. .setCacheSize(4)
  6101. .setTextColor("#DDDDDD")
  6102. .setHighlightColor("#FFFFFF")
  6103. .setEmptyHint("")
  6104. .setAnimationDuration(1000)
  6105. this.currentLyricAlignMode = PreferencesUtil.getNumberSync('LyricAlignMode', 1)
  6106. this.blurDegree = PreferencesUtil.getNumberSync('setBlurDegree', 3)
  6107. this.setBlurDegree(this.blurDegree, false)
  6108. this.setLyricAlignMode(this.currentLyricAlignMode, false)
  6109. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSize', 18), false)
  6110. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSize', 1.23), false)
  6111. this.lyricController.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpace', 10))
  6112. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColor', '#FFFFFF'), false)
  6113. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColor', '#FFFFFF'), false)
  6114. this.isHightLightCenter = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, true)
  6115. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  6116. this.lyricTextWeight = PreferencesUtil.getNumberSync('lyricTextWeight', 400)
  6117. this.lyricController.setTextWeight(this.lyricTextWeight)
  6118. this.showSingleLyric = false
  6119. this.timeOffset = 0
  6120. this.lyricController.setLyric(null)
  6121. this.lyricControllerSingle.setLyric(null)
  6122. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc'
  6123. console.log("onecold lyricPath =" + lyricPath)
  6124. let neiqianLrc = ''
  6125. let lyContent = this.currentSong?.lyricContent
  6126. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  6127. neiqianLrc = lyContent
  6128. }
  6129. if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast&&!isLocal&&!isLocal) {
  6130. console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
  6131. //赋值给this.lyricContent,播控中心才可以显示歌词
  6132. this.lyricContent = neiqianLrc
  6133. // 将文件内容按行分割成字符串数组
  6134. let lines = neiqianLrc.split('\n').map(line => line.trim());
  6135. // 3.解析歌词
  6136. let lyric = this.parser.parse(lines);
  6137. // 4.设置歌词
  6138. this.lyricController.setLyric(lyric);
  6139. this.lyricControllerXF.setLyric(lyric)
  6140. this.lyricControllerSingle.setLyric(lyric)
  6141. return
  6142. }
  6143. if (isOnLineAndToast || ((!FileUtil.accessSync(lyricPath) && !FileUtil.accessSync(jiaMilyricPath))
  6144. && !Utility.isVideoByExtension(this.videoUrl))) {
  6145. if (this.currentSong !== undefined) {
  6146. // ToastUtil.showShort('正在为你搜索在线歌词!')
  6147. //判断是不是赞助会员,是会员的话才开启歌词功能
  6148. // if (!this.isDebug) {
  6149. // if (!Utility.isNoble()) {
  6150. // LogUtil.debug("onecold 不是赞助会员")
  6151. // return
  6152. // }
  6153. // if(!Utility.isPassInstallTime(33)){
  6154. // LogUtil.debug("onecold not pass time")
  6155. // // LogUtil.debug("onecold 用户安装app没超过12天" )
  6156. // return
  6157. // }
  6158. // }
  6159. let artist = this.currentSong?.artist
  6160. if (artist === undefined) {
  6161. artist = ''
  6162. }
  6163. if (isApi2 === undefined) {
  6164. isApi2 = false
  6165. }
  6166. NetAxiosUtil.getLyric(this.name, artist, isApi2).then((res) => {
  6167. // LogUtil.debug("onecold res =" + res)
  6168. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  6169. if (StrUtil.isNotEmpty(res)) {
  6170. this.lyricContent = res
  6171. let lines = res.split('\n').map(line => line.trim());
  6172. // 3.解析歌词
  6173. let lyric = this.parser.parse(lines);
  6174. // 4.设置歌词
  6175. this.lyricController.setLyric(lyric);
  6176. this.lyricControllerXF.setLyric(lyric)
  6177. this.lyricControllerSingle.setLyric(lyric)
  6178. this.showSingleLyric = true
  6179. // 4.保存歌词文件lyric到本地
  6180. //2025年8月28日歌词不再加密下载
  6181. this.saveDataToFile(res, lyricPath, false)
  6182. } else {
  6183. this.lyricController.setLyric(null)
  6184. this.lyricControllerXF.setLyric(null)
  6185. this.lyricControllerSingle.setLyric(null)
  6186. if (isOnLineAndToast) {
  6187. ToastUtil.showShort('未获取到歌词!')
  6188. }
  6189. }
  6190. } else {
  6191. this.lyricController.setLyric(null)
  6192. this.lyricControllerXF.setLyric(null)
  6193. this.lyricControllerSingle.setLyric(null)
  6194. if (isOnLineAndToast) {
  6195. ToastUtil.showShort('未获取到歌词!')
  6196. }
  6197. }
  6198. })
  6199. } else {
  6200. this.lyricController.setLyric(null)
  6201. this.lyricControllerXF.setLyric(null)
  6202. this.lyricControllerSingle.setLyric(null)
  6203. if (isOnLineAndToast) {
  6204. ToastUtil.showShort('未获取到歌词!')
  6205. }
  6206. }
  6207. return
  6208. }
  6209. try {
  6210. let isJiaMi = false;
  6211. let realLyricPath = lyricPath
  6212. if (FileUtil.accessSync(jiaMilyricPath)) {
  6213. isJiaMi = true
  6214. realLyricPath = jiaMilyricPath
  6215. console.info("onecold 找到加密本地歌词 ");
  6216. } else {
  6217. isJiaMi = false
  6218. realLyricPath = lyricPath
  6219. console.info("onecold 找到本地歌词 ");
  6220. }
  6221. // 3.读取文件内容并指定编码为 UTF-8
  6222. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  6223. const stat = await fileIo.stat(file.fd);
  6224. const arrayBuffer = new ArrayBuffer(stat.size);
  6225. fs.read(file.fd, arrayBuffer)
  6226. .then((readLen: number) => {
  6227. console.info("read file data succeed");
  6228. // let buf = buffer.from(arrayBuffer, 0, readLen);
  6229. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  6230. // 检查 buf 是否为空
  6231. if (buf.length === 0) {
  6232. throw new Error("Buffer is empty after reading the file");
  6233. }
  6234. try {
  6235. // 检测文件编码
  6236. // let detectedEncoding = chardet.detect(buf);
  6237. // console.info("onecoldT Detected encoding: " + detectedEncoding);
  6238. let detectedEncoding = this.detect(arrayBuffer)
  6239. console.info("onecoldT Detected encoding: " + detectedEncoding);
  6240. // 使用检测到的编码解码,解决中文乱码问题
  6241. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  6242. console.info("onecoldT Detected textDecoder: " + textDecoder);
  6243. let fileContent = textDecoder.decode(buf);
  6244. console.info(`onecoldT The content of file1: ${fileContent}`);
  6245. //解密
  6246. if (isJiaMi) {
  6247. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent))
  6248. }
  6249. console.info(`onecold The content of file2: ${fileContent}`);
  6250. this.lyricContent = fileContent
  6251. if(isLocal){//编辑标签选择本地歌词需要赋值给this.lyricConStr
  6252. this.lyricConStr = fileContent
  6253. }
  6254. // 将文件内容按行分割成字符串数组
  6255. let lines = fileContent.split('\n').map(line => line.trim());
  6256. console.info(`onecold The content of file: ${fileContent}`);
  6257. // 3.解析歌词
  6258. let lyric = this.parser.parse(lines);
  6259. // 4.设置歌词
  6260. this.lyricController.setLyric(lyric);
  6261. this.lyricControllerXF.setLyric(lyric)
  6262. this.lyricControllerSingle.setLyric(lyric)
  6263. this.showSingleLyric = true
  6264. console.info(`The content of file: ${fileContent}`);
  6265. } catch (chardetError) {
  6266. console.error("chardet.detect failed with error: " + chardetError.message);
  6267. this.lyricController.setLyric(null);
  6268. this.lyricControllerXF.setLyric(null)
  6269. this.lyricControllerSingle.setLyric(null)
  6270. }
  6271. })
  6272. .catch((err: BusinessError) => {
  6273. this.lyricController.setLyric(null)
  6274. this.lyricControllerXF.setLyric(null)
  6275. this.lyricControllerSingle.setLyric(null)
  6276. console.error("read file data failed with error message: " + err.message + ", error code: " + err.code);
  6277. })
  6278. .catch((err: Error) => {
  6279. this.lyricController.setLyric(null)
  6280. this.lyricControllerXF.setLyric(null)
  6281. this.lyricControllerSingle.setLyric(null)
  6282. console.error("read file 2 data failed with error message: " + err.message);
  6283. })
  6284. .finally(() => {
  6285. fs.closeSync(file);
  6286. });
  6287. } catch (error) {
  6288. this.lyricController.setLyric(null)
  6289. this.lyricControllerSingle.setLyric(null)
  6290. this.lyricControllerXF.setLyric(null)
  6291. Logger.error(TAG, 'init Lyric failed with err: ' + JSON.stringify(error));
  6292. }
  6293. }
  6294. detect(data: ArrayBuffer): string {
  6295. //创建检测对象
  6296. let detector: UniversalDetector = new UniversalDetector();
  6297. // 传入检测数据并实时判断编码格式
  6298. detector.handleData(data, 0, data.byteLength);
  6299. // 标记检测数据 读取结束
  6300. detector.dataEnd();
  6301. // 获取检测结果
  6302. let detected: string = detector.getDetectedCharset();
  6303. // 释放资源
  6304. detector.reset();
  6305. return detected;
  6306. }
  6307. //初始化悬浮歌词的自定义设置
  6308. initPipLyricSetting() {
  6309. this.lyricControllerXF
  6310. .setTextSize(this.currentLyricSize)
  6311. .setCacheSize(4)
  6312. .setTextColor("#DDDDDD")
  6313. .setHighlightColor("#FFFFFF")// .setLineSpace(18)
  6314. .setEmptyHint("")
  6315. .setAnimationDuration(1000)
  6316. this.currentLyricAlignModePip = PreferencesUtil.getNumberSync('LyricAlignModePip', 0)
  6317. this.blurDegreePip = PreferencesUtil.getNumberSync('setBlurDegreePip', 3)
  6318. this.setBlurDegree(this.blurDegreePip, true)
  6319. this.setLyricAlignMode(this.currentLyricAlignModePip, true)
  6320. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSizePip', 18), true)
  6321. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSizePip', 1.23), true)
  6322. this.lyricControllerXF.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpacePip', 10))
  6323. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColorPip', '#FFFFFF'), true)
  6324. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColorPip', '#FFFFFF'), true)
  6325. this.lyricControllerXF.setHightLightCenter(true)
  6326. this.lyricTextWeightPip = PreferencesUtil.getNumberSync('lyricTextWeightPip', 400)
  6327. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  6328. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  6329. this.pipBgIndex = PreferencesUtil.getNumberSync('pipBgIndex', 0)
  6330. if (this.pipBgIndex === 0) {
  6331. if (this.cover) {
  6332. this.pipBg = this.cover
  6333. } else {
  6334. this.pipBg = this.imageColor
  6335. }
  6336. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  6337. }
  6338. }
  6339. //根据item返回歌词内容
  6340. async getLyricContent(item: VideoItem): Promise<string> {
  6341. let neiqianLrc = ''
  6342. let lyContent = item?.lyricContent
  6343. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  6344. neiqianLrc = lyContent
  6345. return neiqianLrc
  6346. }
  6347. try {
  6348. let filePath = item.filePath;
  6349. let lyricPath = filePath.substring(0, filePath.lastIndexOf('.')) + '.lrc';
  6350. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc';
  6351. let isJiaMi = false;
  6352. let realLyricPath = lyricPath;
  6353. if (FileUtil.accessSync(jiaMilyricPath)) {
  6354. isJiaMi = true;
  6355. realLyricPath = jiaMilyricPath;
  6356. console.info("onecold 找到加密本地歌词");
  6357. } else {
  6358. console.info("onecold 找到本地歌词");
  6359. }
  6360. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  6361. const stat = await fileIo.stat(file.fd);
  6362. const arrayBuffer = new ArrayBuffer(stat.size);
  6363. const readLen = await fs.read(file.fd, arrayBuffer);
  6364. console.info("read file data succeed");
  6365. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  6366. if (buf.length === 0) {
  6367. throw new Error("Buffer is empty after reading the file");
  6368. }
  6369. // let detectedEncoding = chardet.detect(buf);
  6370. let detectedEncoding = this.detect(arrayBuffer)
  6371. console.info("Detected encoding: " + detectedEncoding);
  6372. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  6373. let fileContent = textDecoder.decode(buf);
  6374. console.info(`onecold The content of file1: ${fileContent}`);
  6375. if (isJiaMi) {
  6376. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent));
  6377. }
  6378. console.info(`onecold The content of file2: ${fileContent}`);
  6379. fs.closeSync(file);
  6380. return fileContent;
  6381. } catch (error) {
  6382. console.error('init Lyric failed with err: ' + JSON.stringify(error));
  6383. return '';
  6384. }
  6385. }
  6386. async saveDataToFile(content: string, filePath: string, isJiaMi?: boolean) {
  6387. if (StrUtil.isEmpty(filePath)) {
  6388. return
  6389. }
  6390. try {
  6391. //将content进行加密
  6392. // let jiaMilyricPath = filePath.substring(0,filePath.lastIndexOf('.'))+'.lrcc'
  6393. let lyricContent = ''
  6394. if (isJiaMi) {
  6395. lyricContent = Base64Util.encodeToStrSync(StrUtil.strToUint8Array(content))
  6396. } else {
  6397. lyricContent = content
  6398. }
  6399. const file = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  6400. // 清空文件内容
  6401. await fileIo.truncate(file.fd, 0);
  6402. await fileIo.write(file.fd, lyricContent);
  6403. await fileIo.close(file);
  6404. console.log('onecold lyric file Data saved successfully.');
  6405. } catch (error) {
  6406. console.error('onecold lyric file Failed to save data:', error);
  6407. }
  6408. }
  6409. /**
  6410. * Get largest proportion color of an image.
  6411. */
  6412. getImageColor() {
  6413. if (!this.context) {
  6414. return;
  6415. }
  6416. let bg = Utility.getMusisBg()
  6417. this.imageLabel = bg
  6418. ColorConversion.setSysBarLightBackground(true);
  6419. this.context.resourceManager.getMediaContent(bg)
  6420. .then((value: Uint8Array) => {
  6421. let buffer = value.buffer as ArrayBuffer;
  6422. image.createImageSource(buffer).createPixelMap().then((pixelMap) => {
  6423. effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
  6424. if (error) {
  6425. Logger.error('Failed to create color picker.');
  6426. } else {
  6427. let color = colorPicker.getLargestProportionColor();
  6428. let colorArr = ColorConversion.dealColor(color.red, color.green, color.blue);
  6429. this.imageColor = `rgba(${colorArr[0]}, ${colorArr[1]}, ${colorArr[2]}, 1)`;
  6430. }
  6431. })
  6432. let headFilter = effectKit.createEffect(pixelMap);
  6433. if (headFilter !== null) {
  6434. headFilter.blur(15);
  6435. headFilter.getEffectPixelMap().then((value) => {
  6436. this.imageLabelBg = value;
  6437. })
  6438. }
  6439. })
  6440. .catch((error: BusinessError) => {
  6441. Logger.error(`${error.code} + ${error.message}`)
  6442. })
  6443. })
  6444. .catch((error: BusinessError) => {
  6445. Logger.error(`${error.code} + ${error.message}`)
  6446. })
  6447. }
  6448. setImageColor(cover: string) {
  6449. if (!this.context) {
  6450. return;
  6451. }
  6452. if (cover === undefined) {
  6453. return;
  6454. }
  6455. ImageUtil.imagePathToPixelMap(cover).then((value) => {
  6456. let headFilter = effectKit.createEffect(value);
  6457. if (headFilter !== null) {
  6458. headFilter.blur(15);
  6459. headFilter.getEffectPixelMap().then((value) => {
  6460. this.imageLabelBg = value;
  6461. })
  6462. }
  6463. }).catch((error: BusinessError) => {
  6464. Logger.error(`${error.code} + ${error.message}`)
  6465. })
  6466. }
  6467. setImageColor2(cover: string) {
  6468. if (!this.context) {
  6469. return;
  6470. }
  6471. if (cover === undefined) {
  6472. return;
  6473. }
  6474. LogUtils.getInstance().LOGI("setImageColor2--> cover ==" + cover);
  6475. ImageUtils.getImageDealData(getContext(this), cover, this.videoUrl).then((data) => {
  6476. this.imageColor = data.imageColor;
  6477. if (data.blurPixelMap) {
  6478. this.imageLabelBg = data.blurPixelMap;
  6479. }
  6480. })
  6481. }
  6482. // 定义开始旋转的方法
  6483. // 定时器用于一百毫秒执行一次旋转角度
  6484. @State timer: number = 0
  6485. @State rotateAngle: number = 0
  6486. //封面旋转动画
  6487. animationRoFun() {
  6488. if (this.isPlaying && !this.isCoverRectangle) {
  6489. this.timer = setInterval(() => {
  6490. this.rotateAngle += 1
  6491. }, 100)
  6492. this.startRotation()
  6493. } else {
  6494. clearInterval(this.timer)
  6495. this.stopRotation()
  6496. }
  6497. }
  6498. // 定义开始旋转的方法
  6499. startRotation() {
  6500. if (this.isPlaying) {
  6501. animateTo({
  6502. duration: 777,
  6503. iterations: 1,
  6504. curve: Curve.Linear
  6505. }, () => {
  6506. this.rotateAngle2 = 0
  6507. })
  6508. }
  6509. }
  6510. // 回调,暂停和播放按钮回调,下一首和上一首
  6511. playChange() {
  6512. // if(this.isCoverRectangle){
  6513. // return
  6514. // }
  6515. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6516. this.setIsPlaying(true)
  6517. this.animationState = AnimationStatus.Running
  6518. } else {
  6519. this.setIsPlaying(false)
  6520. this.animationState = AnimationStatus.Paused
  6521. }
  6522. }
  6523. // 定义停止旋转的方法
  6524. stopRotation() {
  6525. if (this.isCoverRectangle) {
  6526. this.rotateAngle = 0
  6527. } else {
  6528. //唱针以左上角为点选择逆时针40度
  6529. animateTo({
  6530. duration: 1000,
  6531. curve: Curve.Linear,
  6532. iterations: 1,
  6533. }, () => {
  6534. this.rotateAngle2 = -40;
  6535. });
  6536. }
  6537. }
  6538. @Builder
  6539. private LyricsTopItem() {
  6540. Row() {
  6541. Stack() {
  6542. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  6543. .height(55)
  6544. .width(55)
  6545. .alt(this.imageLabel)
  6546. .borderRadius(8)
  6547. .clickEffect({ level: ClickEffectLevel.HEAVY })
  6548. .margin({ left: this.currentLyricAlignMode === 0 ? 28 : -15 })
  6549. }
  6550. .width('18%')
  6551. Column() {
  6552. Column() {
  6553. Text(this.name)
  6554. .fontSize(16)
  6555. .maxLines(1)
  6556. .fontWeight(FontWeight.Bolder)
  6557. .fontColor(this.currentLyricColor)
  6558. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  6559. Row() {
  6560. Text(this.currentSong?.artist !== undefined ? this.currentSong?.artist : '')
  6561. .fontSize(13)
  6562. .fontWeight(FontWeight.Bold)
  6563. .padding({ top: 8 })
  6564. .fontColor(this.currentLyricColor)
  6565. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  6566. Blank()
  6567. }
  6568. }
  6569. .height('100%')
  6570. .width('100%')
  6571. .justifyContent(FlexAlign.Center)
  6572. .alignItems(HorizontalAlign.Start)
  6573. }
  6574. .height('100%')
  6575. .width('65%')
  6576. Column() {
  6577. Image($r('app.media.lyric'))
  6578. .width(28)
  6579. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6580. .margin({ right: 30 })
  6581. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6582. .onClick(() => {
  6583. this.isLyricSetting = !this.isLyricSetting;
  6584. })
  6585. .bindSheet($$this.isLyricSetting, this.lyricSettingSheet(false), {
  6586. height: this.isCoverOpacity() ? '95%' : '88%',
  6587. dragBar: true,
  6588. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  6589. showClose: true,
  6590. blurStyle: BlurStyle.Thin,
  6591. backgroundColor: Color.Transparent,
  6592. // title: { title: $r('app.string.lyric_setting') }
  6593. })
  6594. }
  6595. .width('18%')
  6596. }
  6597. .width('82%')
  6598. .height(58)
  6599. .justifyContent(FlexAlign.SpaceBetween)
  6600. }
  6601. //歌词显示
  6602. @Builder
  6603. PlayerLyrics() {
  6604. Column() {
  6605. Column() {
  6606. this.LyricsTopItem()
  6607. }
  6608. .height(this.isPuraWP() ? 15 : 58)
  6609. .visibility(this.currentBreakpoint !== BreakpointTypeEnum.SM ?
  6610. Visibility.None : Visibility.Visible)
  6611. .margin({ left: 6, top: this.isPuraWP() ? 5 : 38 })
  6612. .width("100%")
  6613. Column() {
  6614. LyricView2({
  6615. controller: this.lyricController,
  6616. enableSeek: true,
  6617. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  6618. seekLineColor: "#80ffffff", // 滑动定位线颜色
  6619. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  6620. onSeekAction: (position: number) => { // 滑动歌词触发seek定位回调
  6621. if (!this.isPlaying) {
  6622. this.startPlayOrResumePlay()
  6623. } else {
  6624. this.isSeekTo = true;
  6625. this.mDestroyPage = false;
  6626. this.showLoadIng();
  6627. this.seekTo(position + "");
  6628. this.isSeekTo = false;
  6629. }
  6630. return true
  6631. }
  6632. })
  6633. .width("100%")
  6634. .layoutWeight(1)
  6635. .margin({ left: this.currentLyricAlignMode === 0 ? 0 : 50, top: 2, bottom: this.isPhoneLan()||this.isHiCarKuanBianPing() ? 40 : 10 })
  6636. if (this.isPhoneLan()) {
  6637. Column() {
  6638. this.playProgressView()
  6639. // this.playCenterView()
  6640. }
  6641. .margin({ bottom: 30, right: this.currentLyricAlignMode == 0 ? 0 : 30 })
  6642. }
  6643. }
  6644. .position({
  6645. top: this.currentBreakpoint !== BreakpointTypeEnum.SM ? (this.isPhoneLan() ? 0 : 45) :
  6646. (this.isPuraWP() ? 58 : 99)
  6647. })
  6648. .justifyContent(FlexAlign.Center)
  6649. .height(this.isCoverOpacity() ? this.isPhoneLan()?'95%':'90%' : '82%')
  6650. }
  6651. }
  6652. @Builder
  6653. SingleLyricView() {
  6654. Column() {
  6655. Column() {
  6656. LyricView2({
  6657. controller: this.lyricControllerSingle,
  6658. enableSeek: false,
  6659. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  6660. seekLineColor: "#80ffffff", // 滑动定位线颜色
  6661. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  6662. })
  6663. }
  6664. .height(66)
  6665. .margin({ bottom: 20 })
  6666. }
  6667. }
  6668. //播放器的底部控制中心,上一首,暂停,下一首,播放进度条等
  6669. @Builder
  6670. BottomControl() {
  6671. Column() {
  6672. this.TopPlayProgressView()
  6673. //播放 暂停,下一首,上一首
  6674. this.playCenterView()
  6675. //播放进度条
  6676. this.BottomView()
  6677. }
  6678. .position({ bottom: this.isHiCarSmall()?50:(this.isCoverOpacity() ? 55 : 70) }) // 将 固定在底部
  6679. }
  6680. //播放控制上一首 下一首 暂停和播放
  6681. @Builder
  6682. playCenterView(){
  6683. Row() {
  6684. Row({ space: 20 }) {
  6685. Button({type:ButtonType.Circle,stateEffect:true}){
  6686. //更多功能
  6687. Image($r('app.media.menu'))
  6688. .width(24)
  6689. .clickEffect({level:ClickEffectLevel.MIDDLE})
  6690. .bindSheet($$this.isShowMoreView, this.PlayMoreSheet(), {
  6691. height: this.isCoverOpacity() ? '95%' : '93%',
  6692. preferType: this.currentBreakpoint!==BreakpointTypeEnum.SM?SheetType.CENTER:SheetType.BOTTOM,
  6693. dragBar: true,
  6694. showClose: true,
  6695. blurStyle: BlurStyle.Thin,
  6696. backgroundColor: Color.Transparent,
  6697. })
  6698. }
  6699. .margin({ left: 5 })
  6700. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6701. .backgroundColor(Color.Transparent)
  6702. .onClick(() => {
  6703. this.isShowMoreView = !this.isShowMoreView;
  6704. })
  6705. Button({type:ButtonType.Circle,stateEffect:true}){
  6706. Image($r('app.media.ic_previous'))
  6707. .width(33)
  6708. .clickEffect({level:ClickEffectLevel.HEAVY})
  6709. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6710. }
  6711. .onClick(async () => {
  6712. this.playPrevious()
  6713. })
  6714. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6715. .backgroundColor(Color.Transparent)
  6716. .margin({ left: 5 })
  6717. }
  6718. Button({type:ButtonType.Circle,stateEffect:true}){
  6719. Column() {
  6720. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ?
  6721. (this.isCircleBtn?$r('app.media.hm_pause'):$r('app.media.ic_public_play'))
  6722. : (this.isCircleBtn?$r('app.media.hm_play2'):$r('app.media.ic_public_pause')))
  6723. .width(this.isPhoneLan()?45:55)
  6724. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6725. .fillColor(Color.White)
  6726. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6727. .onClick(async () => {
  6728. this.playOrPause()
  6729. })
  6730. }
  6731. }
  6732. .backgroundColor(Color.Transparent)
  6733. .layoutWeight(1)
  6734. // .margin({ left: 38, right: 38 })
  6735. Row({ space: 20 }) {
  6736. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  6737. Image($r('app.media.ic_next'))
  6738. .width(33)
  6739. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6740. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6741. .onClick(() => {
  6742. this.playNext();
  6743. })
  6744. }
  6745. .backgroundColor(Color.Transparent)
  6746. .margin({ right: 5 })
  6747. .width(33)
  6748. if(this.isPhoneLan()){
  6749. this.fullButton()
  6750. }else{
  6751. Button({type:ButtonType.Circle,stateEffect:true}){
  6752. //添加或取消收藏
  6753. SymbolGlyph(Utility.getIsFav(this.favList,this.currentSong)?
  6754. $r('sys.symbol.heart_fill'):$r('sys.symbol.heart'))
  6755. .fontSize(23)
  6756. .fontColor([Color.White])
  6757. .alignSelf(ItemAlign.Center)
  6758. // .width(24)
  6759. .clickEffect({level:ClickEffectLevel.MIDDLE})
  6760. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6761. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6762. .onClick(async () => {
  6763. if(this.currentSong){
  6764. this.doFav(this.currentSong)
  6765. }
  6766. })
  6767. }
  6768. .backgroundColor(Color.Transparent)
  6769. .width(24)
  6770. }
  6771. }
  6772. // .margin({ left: 5 })
  6773. }
  6774. .width('95%')
  6775. .margin({ bottom:this.isCoverOpacity()?0:20 })
  6776. .justifyContent(FlexAlign.SpaceEvenly)
  6777. }
  6778. @Builder
  6779. TopPlayProgressView(){
  6780. Row() {
  6781. Column(){
  6782. Row(){
  6783. Slider({
  6784. value: this.progressValue,
  6785. min: 0,
  6786. max: this.PROGRESS_MAX_VALUE,
  6787. step: 1,
  6788. style: SliderStyle.InSet
  6789. })
  6790. .height(20)
  6791. .blockColor('rgba(255,255,255,1)')
  6792. .trackColor('rgba(255,255,255,0.3)')
  6793. .selectedColor(Color.White)
  6794. .trackThickness(4)
  6795. .layoutWeight(1)
  6796. .showSteps(false)
  6797. .showTips(true)
  6798. .alignSelf(ItemAlign.Center)
  6799. .enabled(this.slideEnable)
  6800. .onChange((value: number, mode: SliderChangeMode) => {
  6801. // if (mode == 2) {
  6802. this.isSeekTo = true;
  6803. this.mDestroyPage = false;
  6804. this.showLoadIng();
  6805. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  6806. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  6807. this.seekTo(seekValue + "");
  6808. // this.setProgress()
  6809. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  6810. this.isSeekTo = false;
  6811. // }
  6812. })
  6813. }
  6814. .padding({ right: 7,left:20 })
  6815. Row(){
  6816. Text(this.currentTime)
  6817. .fontSize(10)
  6818. .fontColor(Color.White)
  6819. Blank()
  6820. .layoutWeight(1)
  6821. Text(this.totalTime)
  6822. .fontSize(10)
  6823. .fontColor(Color.White)
  6824. }
  6825. .justifyContent(FlexAlign.Start)
  6826. .padding({ right: 18,left:36 })
  6827. }
  6828. }
  6829. //x5的竖屏模式需要99%
  6830. .width(this.isLandscape?'80%':'93%')
  6831. .justifyContent(FlexAlign.Center)
  6832. .margin({bottom:6})
  6833. .animation({
  6834. duration: 666,
  6835. curve: 'ease-in-out' // 可选动画曲线
  6836. })
  6837. }
  6838. //播放进度条
  6839. @Builder
  6840. BottomView(){
  6841. Row() {
  6842. Button({type:ButtonType.Circle,stateEffect:true}){
  6843. Column() {
  6844. if (this.playType === 0) {
  6845. Image($r('app.media.loop'))
  6846. .width(27)
  6847. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6848. } else if (this.playType === 1) {
  6849. Image($r('app.media.single'))
  6850. .width(27)
  6851. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6852. } else if (this.playType === 2) {
  6853. Image($r('app.media.normal_play'))
  6854. .width(27)
  6855. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6856. } else if (this.playType === 3) {
  6857. Image($r('app.media.random'))
  6858. .width(27)
  6859. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6860. }
  6861. }
  6862. }
  6863. .layoutWeight(1)
  6864. .margin({ left: 5 })
  6865. .backgroundColor(Color.Transparent)
  6866. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6867. .onClick(async () => {
  6868. this.setLoopMode()
  6869. })
  6870. this.fullButton()
  6871. Button({type:ButtonType.Circle,stateEffect:true}){
  6872. Column() {
  6873. Image($r('app.media.lyric'))
  6874. .width(26)
  6875. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6876. }
  6877. }
  6878. .layoutWeight(1)
  6879. .backgroundColor(Color.Transparent)
  6880. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6881. .onClick(async () => {
  6882. this.isLyricSetting = !this.isLyricSetting;
  6883. })
  6884. //播放列表
  6885. Button({type:ButtonType.Circle,stateEffect:true}){
  6886. Image($r('app.media.hm_playlist'))
  6887. .width(24)
  6888. .fillColor(Color.White)
  6889. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6890. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  6891. height: '95%',
  6892. dragBar: true,
  6893. showClose: true,
  6894. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  6895. blurStyle: BlurStyle.Thin,
  6896. backgroundColor: this.isPlayListBgGrass?Color.Transparent:$r('app.color.silvery'),
  6897. title: {
  6898. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  6899. + `(${this.songList.length}首)`
  6900. }
  6901. })
  6902. }
  6903. .layoutWeight(1)
  6904. .backgroundColor(Color.Transparent)
  6905. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6906. .onClick(() => {
  6907. this.isShowSheetView = !this.isShowSheetView;
  6908. if(this.isPlayListBgGrass){
  6909. this.isFrontWhite = true
  6910. }else{
  6911. this.isFrontWhite = false
  6912. }
  6913. this.scrollIndex()
  6914. })
  6915. }
  6916. .width(this.isLandscape?'88%':'95%')
  6917. .justifyContent(FlexAlign.SpaceAround)
  6918. .height(30)
  6919. .margin({top:3})
  6920. .animation({
  6921. duration: 666,
  6922. curve: 'ease-in-out' // 可选动画曲线
  6923. })
  6924. }
  6925. @Builder
  6926. fullButton(){
  6927. Button({type:ButtonType.Circle,stateEffect:true}){
  6928. Column() {
  6929. Image($r('app.media.full_4'))
  6930. .width(25)
  6931. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6932. }
  6933. }
  6934. .layoutWeight(1)
  6935. .backgroundColor(Color.Transparent)
  6936. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6937. .onClick(async () => {
  6938. if (this.isLandscape) {
  6939. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  6940. } else {
  6941. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  6942. }
  6943. })
  6944. }
  6945. //旧版本播放进度条
  6946. @Builder
  6947. playProgressView() {
  6948. Row() {
  6949. Button({ type: ButtonType.Circle, stateEffect: true }) {
  6950. Column() {
  6951. if (this.playType === 0) {
  6952. Image($r('app.media.loop'))
  6953. .width($r('app.float.control_image_width'))
  6954. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6955. } else if (this.playType === 1) {
  6956. Image($r('app.media.single'))
  6957. .width($r('app.float.control_image_width'))
  6958. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6959. } else if (this.playType === 2) {
  6960. Image($r('app.media.normal_play'))
  6961. .width($r('app.float.control_image_width'))
  6962. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6963. } else if (this.playType === 3) {
  6964. Image($r('app.media.random'))
  6965. .width($r('app.float.control_image_width'))
  6966. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6967. }
  6968. }
  6969. }
  6970. .visibility(this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  6971. .animation({
  6972. duration: 666,
  6973. curve: 'ease-in-out' // 可选动画曲线
  6974. })
  6975. .backgroundColor(Color.Transparent)
  6976. .margin({ right: 10 })
  6977. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6978. .onClick(async () => {
  6979. this.setLoopMode()
  6980. })
  6981. Text(this.currentTime)
  6982. .fontSize($r('app.float.slider_font_size'))
  6983. .fontColor(Color.White)
  6984. .margin(3)
  6985. Slider({
  6986. value: this.progressValue,
  6987. min: 0,
  6988. max: this.PROGRESS_MAX_VALUE,
  6989. step: 1,
  6990. style: SliderStyle.OutSet
  6991. })
  6992. .width('600px')
  6993. .blockColor('rgba(255,255,255,1)')
  6994. .trackColor('rgba(255,255,255,0.3)')
  6995. .selectedColor(Color.White)
  6996. .trackThickness(PlayConstants.PROGRESS_TRACK_THICKNESS)
  6997. .layoutWeight(1)
  6998. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  6999. .showSteps(false)
  7000. .showTips(true)
  7001. .enabled(this.slideEnable)
  7002. .onChange((value: number, mode: SliderChangeMode) => {
  7003. // if (mode == 2) {
  7004. this.isSeekTo = true;
  7005. this.mDestroyPage = false;
  7006. this.showLoadIng();
  7007. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  7008. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  7009. this.seekTo(seekValue + "");
  7010. // this.setProgress()
  7011. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  7012. this.isSeekTo = false;
  7013. // }
  7014. })
  7015. Text(this.totalTime)
  7016. .fontSize($r('app.float.slider_font_size'))
  7017. .fontColor(Color.White)
  7018. .margin(3)
  7019. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  7020. //播放列表
  7021. Button({ type: ButtonType.Circle, stateEffect: true }) {
  7022. Image($r('app.media.hm_playlist'))
  7023. .width($r('app.float.control_image_width'))
  7024. .fillColor(Color.White)
  7025. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7026. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  7027. height: '95%',
  7028. dragBar: true,
  7029. showClose: true,
  7030. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7031. blurStyle: BlurStyle.Thin,
  7032. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  7033. title: {
  7034. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  7035. + `(${this.songList.length}首)`
  7036. }
  7037. })
  7038. }
  7039. .visibility( this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  7040. .animation({
  7041. duration: 666,
  7042. curve: 'ease-in-out' // 可选动画曲线
  7043. })
  7044. .backgroundColor(Color.Transparent)
  7045. .margin({ right: 20, left: 10 })
  7046. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7047. .onClick(() => {
  7048. this.isShowSheetView = !this.isShowSheetView;
  7049. if (this.isPlayListBgGrass) {
  7050. this.isFrontWhite = true
  7051. } else {
  7052. this.isFrontWhite = false
  7053. }
  7054. this.scrollIndex()
  7055. })
  7056. }
  7057. //x5的竖屏模式需要99%
  7058. .width(this.isPhonePortrait() ? '93.4%'
  7059. : this.currentHeightBreakpoint == 1 && this.currentWidthBreakpoint == 2 ? '99%' : '82%')
  7060. .height(this.isPhoneLan() ? 25 : 33)
  7061. .animation({
  7062. duration: 666,
  7063. curve: 'ease-in-out' // 可选动画曲线
  7064. })
  7065. }
  7066. isBigScreen() {
  7067. if (this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_LG) {
  7068. return true
  7069. }
  7070. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  7071. && this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  7072. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG) {
  7073. return false
  7074. } else {
  7075. return true
  7076. }
  7077. return false
  7078. }
  7079. @State is_auto_hide_progress: boolean = false //手机横屏自动隐藏播放进退条,点击屏幕可以显示,倒计时4秒后又自动隐藏
  7080. @State isCoverRectangle: boolean = false
  7081. @State isCoverTop: boolean = true
  7082. // 添加控制缩放的状态变量
  7083. @State scaleValueImage: number = 1
  7084. @Builder
  7085. CoverInfo() {
  7086. Column() {
  7087. //如果是方形,判断是不是封面在顶部,如果不是顶部,显示musicNameInfo, 如果是圆形显示musicNameInfo
  7088. if (this.isCoverRectangle) {
  7089. if (!this.isCoverTop) {
  7090. this.musicNameInfo(false)
  7091. }
  7092. } else {
  7093. this.musicNameInfo(false)
  7094. }
  7095. Stack() {
  7096. // 唱片旋转效果
  7097. Image($r('app.media.ic_music_disc'))
  7098. .width(245)
  7099. .height(245)
  7100. .margin({ right: 20, left: 20 })
  7101. .aspectRatio(1)
  7102. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  7103. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  7104. .borderRadius('100%')
  7105. .align(Alignment.Center)
  7106. .clip(true)// .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
  7107. .rotate({
  7108. angle: this.rotateAngle,
  7109. centerX: "50%",
  7110. centerY: "50%",
  7111. })
  7112. .animation({
  7113. duration: 100,
  7114. curve: Curve.Linear
  7115. })
  7116. .shadow({
  7117. radius: 30,
  7118. color: this.randomColor
  7119. })
  7120. Column() {
  7121. if (this.isCoverTop && !this.isCoverOpacity() && this.isCoverRectangle) {
  7122. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)// .height(this.isCoverOpacity() ? 250 : this.isCoverRectangle ? 320 : 162)
  7123. .width(this.isBigScreen() ? '72%' : this.isCoverTopBig ? '100%' : '86%')
  7124. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  7125. .alt(this.imageLabel)
  7126. .margin({ right: 8, left: 8, top: 8 })
  7127. .aspectRatio(1)
  7128. .opacity(this.opacityValueImage)
  7129. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7130. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  7131. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  7132. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  7133. .align(Alignment.Center)//
  7134. .clip(true)
  7135. .rotate({
  7136. x: 0,
  7137. y: 0,
  7138. z: 1,
  7139. angle: this.rotateAngle
  7140. })
  7141. .onClick(() => {
  7142. this.getImageColor()
  7143. })
  7144. this.musicNameInfo(false)
  7145. } else {
  7146. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  7147. .height(this.isHiCarSmall()?(this.isHiCarKuanBianPing()?140:px2vp(this.windowHeight)*0.38):(this.isCoverOpacity() ? 250 : this.isCoverRectangle ? 320 : 162))
  7148. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  7149. .alt(this.imageLabel)
  7150. .margin({ right: 20, left: 20 })
  7151. .aspectRatio(1)
  7152. .opacity(this.opacityValueImage)
  7153. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7154. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  7155. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  7156. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  7157. .align(Alignment.Center)//
  7158. .clip(true)
  7159. .rotate({
  7160. x: 0,
  7161. y: 0,
  7162. z: 1,
  7163. angle: this.rotateAngle
  7164. })
  7165. .onClick(() => {
  7166. this.getImageColor()
  7167. })
  7168. if (this.isPhoneLan()) {
  7169. Text(this.name)
  7170. .fontSize(18)
  7171. .fontWeight(FontWeight.Bold)
  7172. .margin({ top: 13 })
  7173. .textOverflow({ overflow: TextOverflow.Ellipsis })
  7174. .maxLines(1)
  7175. .width('99%')
  7176. .textAlign(TextAlign.Center)
  7177. .fontColor(Color.White)
  7178. }
  7179. }
  7180. }
  7181. // 唱针以左上角为点选择逆时针40度
  7182. Image($r('app.media.ic_music_cover_hand'))
  7183. .height(130)
  7184. .margin({ bottom: 220, top: 0 })
  7185. .align(Alignment.Top)
  7186. .rotate({ angle: this.rotateAngle2, centerX: 0, centerY: 0 })
  7187. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  7188. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  7189. Column({ space: 8 }) {
  7190. Text(this.name)
  7191. .fontSize(this.isPuraWP() ? 24 : (this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22))
  7192. .fontWeight(FontWeight.Bold)
  7193. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7194. .maxLines(1)
  7195. .width('48%')
  7196. .textAlign(TextAlign.Center)
  7197. .fontColor(Color.White)
  7198. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  7199. Text(this.artist)
  7200. .fontSize(this.isPuraWP() ? 18 : (this.isCoverOpacity() ? 12 : 15))
  7201. .fontColor(Color.White)
  7202. .fontWeight(FontWeight.Bold)
  7203. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  7204. }
  7205. .justifyContent(FlexAlign.Start)
  7206. .zIndex(1)
  7207. .visibility(this.isCoverOpacity() ? Visibility.Visible : Visibility.None)
  7208. }
  7209. .margin({
  7210. bottom: this.isCoverOpacity() || this.isCoverRectangle ?
  7211. (this.isPhonePortrait() && this.isShowSingleLineLyric ? 20 : 55) : 0,
  7212. top: this.isCoverOpacity() ? 0 : 20
  7213. })
  7214. if (this.isPhonePortrait() && this.isShowSingleLineLyric) {
  7215. this.SingleLyricView()
  7216. }
  7217. if (this.isPhoneLan()) {
  7218. Column() {
  7219. this.playCenterView()
  7220. // this.playProgressView()
  7221. }
  7222. .position({ left: 28, bottom: 38 })
  7223. } else {
  7224. this.BottomControl()
  7225. }
  7226. }
  7227. .width(CommonConstants.FULL_PERCENT)
  7228. .clip(true)
  7229. }
  7230. @Builder
  7231. private musicNameInfo(isHidden: boolean) {
  7232. Column({ space: 8 }) {
  7233. Text(this.name)
  7234. .fontSize(this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22)
  7235. .fontWeight(FontWeight.Bold)
  7236. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7237. .maxLines(1)
  7238. .width('99%')
  7239. .textAlign(TextAlign.Center)
  7240. .fontColor(Color.White)
  7241. Text(this.artist + ' ' + this.currentSong?.album)
  7242. .fontSize(this.isCoverOpacity() ? 12 : 15)
  7243. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7244. .fontColor(Color.White)
  7245. .textAlign(TextAlign.Center)
  7246. .visibility(StrUtil.isEmpty(this.artist)?Visibility.None:Visibility.Visible)
  7247. .width('99%')
  7248. .maxLines(1)
  7249. }
  7250. .margin({ top: this.isCoverOpacity() ? 20 : isHidden ? 40 : 20 })
  7251. .zIndex(1)
  7252. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7253. .visibility(this.isCoverOpacity() || isHidden ? Visibility.None : Visibility.Visible)
  7254. }
  7255. @Builder
  7256. private PlayTitle() {
  7257. Row() {
  7258. Row() {
  7259. Image($r('app.media.ic_back_down'))
  7260. .width($r('app.float.title_image_size'))// .aspectRatio(CommonConstants.ASPECT_RATIO)
  7261. .hitTestBehavior(HitTestMode.Transparent)
  7262. Text(this.name + ' ' + this.artist)
  7263. .fontColor(Color.White)
  7264. .fontSize($r('app.float.title_font_size'))
  7265. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7266. .maxLines(1)
  7267. .visibility(Visibility.None)
  7268. .margin({ left: 2, right: 30 })
  7269. }
  7270. .layoutWeight(1)
  7271. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7272. .visibility(this.isHide ? Visibility.Hidden : Visibility.Visible)
  7273. .onClick(() => {
  7274. this.isShowPlay = false;
  7275. })
  7276. Column() {
  7277. AVCastPicker({
  7278. normalColor: Color.White,
  7279. onStateChange: this.onStateVastChange
  7280. })
  7281. .width(24)
  7282. .height(24)
  7283. }
  7284. .visibility(this.isHide ? Visibility.Hidden : Visibility.None)
  7285. }
  7286. .width(PlayConstants.ROW_WIDTH)
  7287. }
  7288. @Builder
  7289. lyricSettingSheet(isPip: boolean) {
  7290. Scroll() {
  7291. this.lyricSetting(isPip)
  7292. }
  7293. .width('100%')
  7294. .height('100%')
  7295. }
  7296. @Builder
  7297. lyricSetting(isPip: boolean) {
  7298. Column() {
  7299. // 时间调节模块
  7300. if (!isPip) {
  7301. this.BuildTimeControls()
  7302. }
  7303. // 字号控制模块
  7304. this.BuildFontControls(isPip)
  7305. }
  7306. }
  7307. // 歌词时间偏移状态
  7308. @State timeOffset: number = 0.0
  7309. @State currentLyricColor: string = '#FFFFFF'
  7310. @State currentLyricColorPip: string = '#FFFFFF'
  7311. @State currentHighLightLyricColor: string = '#FF4081'
  7312. @State currentHighLightLyricColorPip: string = '#FF4081'
  7313. // 歌词字号状态
  7314. @State currentLyricSize: number = 20
  7315. @State currentLyricSizePip: number = 20
  7316. // 高亮歌词放大倍数
  7317. @State currentHightLyricSize: number = 1.2
  7318. @State currentHightLyricSizePip: number = 1.2
  7319. @State currentLyricLineSpace: number = 10
  7320. @State currentLyricLineSpacePip: number = 10
  7321. @State currentLyricAlignMode: number = 1
  7322. @State currentLyricAlignModePip: number = 1
  7323. @State blurDegree: number = 2
  7324. @State blurDegreePip: number = 2
  7325. @State isShowSelectColor: boolean = false
  7326. @State isShowHLSelectColor: boolean = false
  7327. @State isShowPipBgSelectColor: boolean = false
  7328. @State pipLyWidth: number = 330
  7329. @State pipLyHeight: number = 120
  7330. // 构建颜色选择器
  7331. @Builder
  7332. SelectColor(isHighColor: boolean, isPip: boolean, isBGPip?: boolean) {
  7333. Row({ space: 10 }) {
  7334. HSBColorPicker({
  7335. color: '#FFFFFF',
  7336. radius: 8,
  7337. layout: HSBColorPickerLayout.COLUMN,
  7338. predefine: ['#8b27f4', '#73f9fc', '#fffe55', '#f5cee3', '#eb4827', '#e93bf4', '#3e68f4', '#c5e6d3', '#e4e4e4',
  7339. '#fa7105'],
  7340. onChange: (value: string) => isHighColor ? this.changeLyricHightLightColor(value, isPip) :
  7341. this.changeLyricColor(value, isPip, isBGPip)
  7342. })
  7343. .height(250)
  7344. .layoutWeight(1)
  7345. .padding(25)
  7346. }
  7347. .width('66%')
  7348. }
  7349. @State isOpenPip: boolean = false
  7350. @State pipBgIndex: number = 0
  7351. // 构建字号控制器
  7352. @Builder
  7353. BuildFontControls(isPip: boolean) {
  7354. Column() {
  7355. if (isPip) {
  7356. Column() {
  7357. Row() {
  7358. Text('悬浮歌词')
  7359. .margin({ left: 18 })
  7360. .fontSize(15)
  7361. .fontColor(Color.White)
  7362. .fontWeight(480)
  7363. .layoutWeight(1)
  7364. Toggle({ type: ToggleType.Switch, isOn: this.isOpenPip })
  7365. .selectedColor(this.themeColor)
  7366. .switchPointColor(Color.White)
  7367. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7368. .margin({ right: 18 })
  7369. .onChange((checked: boolean) => {
  7370. this.isOpenPip = checked;
  7371. if (this.isOpenPip) {
  7372. this.startPip()
  7373. } else {
  7374. this.stopPip()
  7375. }
  7376. PreferencesUtil.put('isOpenPip', this.isOpenPip)
  7377. })
  7378. .width(50)
  7379. .height(30);
  7380. }
  7381. .height(55)
  7382. }
  7383. .backgroundColor(Color.Transparent)
  7384. .borderRadius(15)
  7385. .margin({
  7386. left: 30,
  7387. right: 30,
  7388. top: 0,
  7389. bottom: 20
  7390. })
  7391. .padding(0)
  7392. .border({
  7393. color: Color.White,
  7394. width: 1.8
  7395. })
  7396. }
  7397. Row() {
  7398. Text(`歌词居中:`)
  7399. .fontSize(14)
  7400. .fontColor(Color.White)
  7401. .margin({ left: 2 })
  7402. Row() {
  7403. ForEach(['居中', '居左'], (size: string, index: number) => {
  7404. Button(size)
  7405. .width(60)
  7406. .height(28)
  7407. .fontSize(12)
  7408. .fontColor('#FFFFFF')
  7409. .backgroundColor((!isPip && this.currentLyricAlignMode === index) ||
  7410. (isPip && this.currentLyricAlignModePip === index) ? this.themeColor : Color.Transparent)
  7411. .border({
  7412. color: (!isPip && this.currentLyricAlignMode === index) ||
  7413. (isPip && this.currentLyricAlignModePip === index) ?
  7414. '#007DFF' : '#DDDDDD',
  7415. width: 1.8
  7416. })
  7417. .onClick(() => {
  7418. this.setLyricAlignMode(index, isPip)
  7419. })
  7420. .margin({ left: 10, right: 8 })
  7421. })
  7422. }
  7423. .width('76%')
  7424. Blank()
  7425. }
  7426. .margin({
  7427. top: 10,
  7428. bottom: 10,
  7429. right: 20,
  7430. left: 20
  7431. })
  7432. if (isPip) {
  7433. Row() {
  7434. Text(`悬浮背景:`)
  7435. .fontSize(14)
  7436. .fontColor(Color.White)
  7437. Select([
  7438. { value: CommonConstants.PIP_LYRIC_BG[0] },
  7439. { value: CommonConstants.PIP_LYRIC_BG[1] }])
  7440. .font({ size: 13, weight: FontWeight.Medium })
  7441. .fontColor(Color.White)
  7442. .margin({ left: 10 })
  7443. .selected(this.pipBgIndex)
  7444. .value(CommonConstants.PIP_LYRIC_BG[this.pipBgIndex])
  7445. .onSelect(async (_index: number, text?: string | undefined) => {
  7446. this.pipBgIndex = _index
  7447. PreferencesUtil.put('pipBgIndex', this.pipBgIndex)
  7448. if (this.pipBgIndex === 0) {
  7449. if (this.cover) {
  7450. this.pipBg = this.cover
  7451. } else {
  7452. this.pipBg = this.imageColor
  7453. }
  7454. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  7455. } else {
  7456. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  7457. }
  7458. })
  7459. Column() {
  7460. }
  7461. .backgroundColor(this.pipBg)
  7462. .margin({ left: 10, right: 10 })
  7463. .borderRadius(20)
  7464. .height(28)
  7465. .width(28)
  7466. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7467. Row() {
  7468. SymbolGlyph($r('sys.symbol.paintbrush'))
  7469. .fontColor([Color.White])
  7470. .effectStrategy(1)
  7471. Text(`选择颜色`)
  7472. .fontSize(13)
  7473. .margin({ left: 10 })
  7474. .fontColor(Color.White)
  7475. }
  7476. }
  7477. .visibility(this.pipBgIndex === 1 ? Visibility.Visible : Visibility.None)
  7478. .backgroundColor(Color.Transparent)
  7479. .border({
  7480. color: '#FFFFFF',
  7481. radius: 20,
  7482. width: 1.8
  7483. })
  7484. .height(36)
  7485. .width(110)
  7486. .onClick(() => {
  7487. this.isShowPipBgSelectColor = !this.isShowPipBgSelectColor
  7488. })
  7489. .bindPopup(this.isShowPipBgSelectColor, {
  7490. builder: this.SelectColor(false, isPip, true),
  7491. placement: Placement.Top,
  7492. mask: { color: '#33000000' },
  7493. enableArrow: false, //是否显示箭头
  7494. showInSubWindow: false,
  7495. onStateChange: (e) => {
  7496. if (!e.isVisible) {
  7497. this.isShowPipBgSelectColor = false
  7498. }
  7499. }
  7500. })
  7501. }
  7502. .width('76%')
  7503. .margin({ bottom: 5, right: 45, left: 20 })
  7504. }
  7505. if (!isPip) {
  7506. Row() {
  7507. Text(`高亮居中:`)
  7508. .fontSize(14)
  7509. .fontColor(Color.White)
  7510. Column() {
  7511. Toggle({ type: ToggleType.Switch, isOn: this.isHightLightCenter })
  7512. .selectedColor(this.themeColor)
  7513. .switchPointColor(Color.White)
  7514. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7515. .onChange((checked: boolean) => {
  7516. this.isHightLightCenter = checked;
  7517. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isHightLightCenter)
  7518. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  7519. })
  7520. .width(50)
  7521. .height(30)
  7522. .alignSelf(ItemAlign.Start)
  7523. .margin({ left: 12 })
  7524. Blank()
  7525. }
  7526. .width('76%')
  7527. }
  7528. .margin({
  7529. left: 20,
  7530. right: 15,
  7531. top: 10,
  7532. bottom: 10
  7533. })
  7534. }
  7535. Row() {
  7536. Text(`歌词颜色:`)
  7537. .fontSize(14)
  7538. .fontColor(Color.White)
  7539. Text(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  7540. .fontSize(15)
  7541. .fontColor(Color.White)
  7542. .margin({ left: 12, right: 12 })
  7543. Column() {
  7544. }
  7545. .backgroundColor(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  7546. .margin({ right: 12 })
  7547. .borderRadius(20)
  7548. .height(28)
  7549. .width(28)
  7550. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7551. Row() {
  7552. SymbolGlyph($r('sys.symbol.paintbrush'))
  7553. .fontColor([Color.White])
  7554. .effectStrategy(1)
  7555. Text(`选择颜色`)
  7556. .fontSize(13)
  7557. .margin({ left: 10 })
  7558. .fontColor(Color.White)
  7559. }
  7560. }
  7561. .backgroundColor(Color.Transparent)
  7562. .border({
  7563. color: '#FFFFFF',
  7564. radius: 20,
  7565. width: 1.8
  7566. })
  7567. .height(36)
  7568. .width(110)
  7569. .onClick(() => {
  7570. this.isShowSelectColor = !this.isShowSelectColor
  7571. })
  7572. .bindPopup(this.isShowSelectColor, {
  7573. builder: this.SelectColor(false, isPip),
  7574. placement: Placement.Top,
  7575. mask: { color: '#33000000' },
  7576. enableArrow: false, //是否显示箭头
  7577. showInSubWindow: false,
  7578. onStateChange: (e) => {
  7579. if (!e.isVisible) {
  7580. this.isShowSelectColor = false
  7581. }
  7582. }
  7583. })
  7584. }
  7585. .width('76%')
  7586. .margin({
  7587. top: 10,
  7588. bottom: 10,
  7589. right: 45,
  7590. left: 20
  7591. })
  7592. Row() {
  7593. Text(`高亮颜色:`)
  7594. .fontSize(14)
  7595. .fontColor(Color.White)
  7596. Text(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  7597. .fontSize(15)
  7598. .fontColor(Color.White)
  7599. .margin({ left: 12, right: 12 })
  7600. Column() {
  7601. }
  7602. .backgroundColor(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  7603. .margin({ right: 12 })
  7604. .borderRadius(20)
  7605. .height(28)
  7606. .width(28)
  7607. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7608. Row() {
  7609. SymbolGlyph($r('sys.symbol.paintbrush'))
  7610. .fontColor([Color.White])
  7611. .effectStrategy(1)
  7612. Text(`选择颜色`)
  7613. .fontSize(13)
  7614. .margin({ left: 10 })
  7615. .fontColor(Color.White)
  7616. }
  7617. }
  7618. .backgroundColor(Color.Transparent)
  7619. .border({
  7620. color: '#FFFFFF',
  7621. radius: 20,
  7622. width: 1.8
  7623. })
  7624. .height(36)
  7625. .width(110)
  7626. .onClick(() => {
  7627. this.isShowHLSelectColor = !this.isShowHLSelectColor
  7628. })
  7629. .bindPopup(this.isShowHLSelectColor, {
  7630. builder: this.SelectColor(true, isPip),
  7631. placement: Placement.Top,
  7632. mask: { color: '#33000000' },
  7633. enableArrow: false, //是否显示箭头
  7634. showInSubWindow: false,
  7635. onStateChange: (e) => {
  7636. if (!e.isVisible) {
  7637. this.isShowHLSelectColor = false
  7638. }
  7639. }
  7640. })
  7641. }
  7642. .width('76%')
  7643. .margin({
  7644. top: 10,
  7645. bottom: 10,
  7646. right: 45,
  7647. left: 20
  7648. })
  7649. if (isPip) {
  7650. Row() {
  7651. Text(`显示宽度:`)
  7652. .fontSize(14)
  7653. .fontColor(Color.White)
  7654. Slider({
  7655. value: this.pipLyWidth,
  7656. min: 10,
  7657. max: 800,
  7658. step: 1,
  7659. style: SliderStyle.OutSet
  7660. })
  7661. .blockColor(this.themeColor)
  7662. .trackColor($r('app.color.speed_text_color'))
  7663. .selectedColor(Color.White)
  7664. .trackThickness(6)
  7665. .onChange((value: number) => {
  7666. this.pipLyWidth = value
  7667. if (this.pipController) {
  7668. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  7669. PreferencesUtil.putSync('pipLyWidth', this.pipLyWidth)
  7670. }
  7671. })
  7672. .width('76%')
  7673. }
  7674. .margin({
  7675. left: 20,
  7676. right: 15,
  7677. top: 5,
  7678. bottom: 5
  7679. })
  7680. Row() {
  7681. Text(`显示高度:`)
  7682. .fontSize(14)
  7683. .fontColor(Color.White)
  7684. Slider({
  7685. value: this.pipLyHeight,
  7686. min: 10,
  7687. max: 1000,
  7688. step: 1,
  7689. style: SliderStyle.OutSet
  7690. })
  7691. .blockColor(this.themeColor)
  7692. .trackColor($r('app.color.speed_text_color'))
  7693. .selectedColor(Color.White)
  7694. .trackThickness(6)
  7695. .onChange((value: number) => {
  7696. this.pipLyHeight = value
  7697. if (this.pipController) {
  7698. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  7699. PreferencesUtil.putSync('pipLyHeight', this.pipLyHeight)
  7700. }
  7701. })
  7702. .width('76%')
  7703. }
  7704. .margin({
  7705. left: 20,
  7706. right: 15,
  7707. top: 5,
  7708. bottom: 5
  7709. })
  7710. }
  7711. Row() {
  7712. Text(`歌词字号:`)
  7713. .fontSize(14)
  7714. .fontColor(Color.White)
  7715. Slider({
  7716. value: isPip ? this.currentLyricSizePip : this.currentLyricSize,
  7717. min: 12,
  7718. max: 30,
  7719. step: 0.1,
  7720. style: SliderStyle.OutSet
  7721. })
  7722. .blockColor(this.themeColor)
  7723. .trackColor($r('app.color.speed_text_color'))
  7724. .selectedColor(Color.White)
  7725. .trackThickness(6)
  7726. .onChange((value: number) => {
  7727. this.setLyricTextSize(value, isPip)
  7728. })
  7729. .width('76%')
  7730. }
  7731. .margin({
  7732. left: 20,
  7733. right: 15,
  7734. top: 5,
  7735. bottom: 5
  7736. })
  7737. Row() {
  7738. Text(`高亮倍数:`)
  7739. .fontSize(14)
  7740. .fontColor(Color.White)
  7741. Slider({
  7742. value: isPip ? this.currentHightLyricSizePip : this.currentHightLyricSize,
  7743. min: 1,
  7744. max: 2,
  7745. step: 0.1,
  7746. style: SliderStyle.OutSet
  7747. })
  7748. .blockColor(this.themeColor)
  7749. .trackColor($r('app.color.speed_text_color'))
  7750. .selectedColor(Color.White)
  7751. .trackThickness(6)
  7752. .onChange((value: number) => {
  7753. this.setHighLyricTextSize(value, isPip)
  7754. })
  7755. .width('76%')
  7756. }
  7757. .margin({
  7758. left: 20,
  7759. right: 15,
  7760. top: 5,
  7761. bottom: 5
  7762. })
  7763. Row() {
  7764. Text(`歌词间隙:`)
  7765. .fontSize(14)
  7766. .fontColor(Color.White)
  7767. Slider({
  7768. value: isPip ? this.currentLyricLineSpacePip : this.currentLyricLineSpace,
  7769. min: 0,
  7770. max: 100,
  7771. step: 1,
  7772. style: SliderStyle.OutSet
  7773. })
  7774. .blockColor(this.themeColor)
  7775. .trackColor($r('app.color.speed_text_color'))
  7776. .selectedColor(Color.White)
  7777. .trackThickness(6)
  7778. .onChange((value: number) => {
  7779. this.setLyricLineSpace(value, isPip)
  7780. })
  7781. .width('76%')
  7782. }
  7783. .margin({
  7784. left: 20,
  7785. right: 15,
  7786. top: 5,
  7787. bottom: 5
  7788. })
  7789. //取值间隔为100,默认为400,取值越大,字体越粗
  7790. Row() {
  7791. Text(`歌词字重:`)
  7792. .fontSize(14)
  7793. .fontColor(Color.White)
  7794. Slider({
  7795. value: isPip ? this.lyricTextWeightPip : this.lyricTextWeight,
  7796. min: 100,
  7797. max: 900,
  7798. step: 100,
  7799. style: SliderStyle.OutSet
  7800. })
  7801. .blockColor(this.themeColor)
  7802. .trackColor($r('app.color.speed_text_color'))
  7803. .selectedColor(Color.White)
  7804. .trackThickness(6)
  7805. .onChange((value: number) => {
  7806. if (isPip) {
  7807. this.lyricTextWeightPip = value
  7808. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  7809. PreferencesUtil.putSync('lyricTextWeightPip', this.lyricTextWeightPip)
  7810. } else {
  7811. this.lyricTextWeight = value
  7812. this.lyricController.setTextWeight(this.lyricTextWeight)
  7813. PreferencesUtil.putSync('lyricTextWeight', this.lyricTextWeight)
  7814. }
  7815. })
  7816. .width('76%')
  7817. }
  7818. .margin({
  7819. left: 20,
  7820. right: 15,
  7821. top: 5,
  7822. bottom: 5
  7823. })
  7824. if (!isPip) {
  7825. Row() {
  7826. Text(`歌词模糊:`)
  7827. .fontSize(14)
  7828. .fontColor(Color.White)
  7829. Slider({
  7830. value: isPip ? this.blurDegreePip : this.blurDegree,
  7831. min: 0,
  7832. max: 5,
  7833. step: 0.1,
  7834. style: SliderStyle.OutSet
  7835. })
  7836. .blockColor(this.themeColor)
  7837. .trackColor($r('app.color.speed_text_color'))
  7838. .selectedColor(Color.White)
  7839. .trackThickness(6)
  7840. .onChange((value: number) => {
  7841. this.setBlurDegree(value, isPip)
  7842. })
  7843. .width('76%')
  7844. }
  7845. .margin({
  7846. left: 20,
  7847. right: 15,
  7848. top: 5,
  7849. bottom: 15
  7850. })
  7851. }
  7852. Row() {
  7853. this.pushLyricButton($r('app.media.cut_current'), 0, '本地歌词')
  7854. this.pushLyricButton($r('app.media.white_search'), 1, '获取歌词')
  7855. }
  7856. .justifyContent(FlexAlign.Center)
  7857. .margin({ top: 3, bottom: 10 })
  7858. }
  7859. }
  7860. private setBlurDegree(index: number, isPip: boolean) {
  7861. if (isPip) {
  7862. this.blurDegreePip = index
  7863. this.lyricControllerXF.setBlurDegree(this.blurDegreePip)
  7864. PreferencesUtil.putSync('setBlurDegreePip', this.blurDegreePip)
  7865. } else {
  7866. this.blurDegree = index
  7867. this.lyricController.setBlurDegree(this.blurDegree)
  7868. PreferencesUtil.putSync('setBlurDegree', this.blurDegree)
  7869. }
  7870. }
  7871. private setLyricAlignMode(index: number, isPip: boolean) {
  7872. if (isPip) {
  7873. this.currentLyricAlignModePip = index
  7874. if (this.currentLyricAlignModePip === 1) {
  7875. this.lyricControllerXF.setAlignMode("left")
  7876. } else {
  7877. this.lyricControllerXF.setAlignMode("center")
  7878. }
  7879. PreferencesUtil.putSync('LyricAlignModePip', this.currentLyricAlignModePip)
  7880. } else {
  7881. this.currentLyricAlignMode = index
  7882. if (this.currentLyricAlignMode === 1) {
  7883. this.lyricController.setAlignMode("left")
  7884. } else {
  7885. this.lyricController.setAlignMode("center")
  7886. }
  7887. PreferencesUtil.putSync('LyricAlignMode', this.currentLyricAlignMode)
  7888. }
  7889. }
  7890. private setLyricTextSize(index: number, isPip: boolean) {
  7891. if (isPip) {
  7892. this.currentLyricSizePip = index
  7893. this.lyricControllerXF.setTextSize(this.currentLyricSizePip)
  7894. PreferencesUtil.putSync('LyricTextSizePip', this.currentLyricSizePip)
  7895. } else {
  7896. this.currentLyricSize = index
  7897. this.lyricController.setTextSize(this.currentLyricSize)
  7898. PreferencesUtil.putSync('LyricTextSize', this.currentLyricSize)
  7899. }
  7900. }
  7901. private setHighLyricTextSize(scale: number, isPip: boolean) {
  7902. if (isPip) {
  7903. this.currentHightLyricSizePip = scale
  7904. this.lyricControllerXF
  7905. .setHighlightScale(this.currentHightLyricSizePip)
  7906. PreferencesUtil.putSync('HighLyricTextSizePip', scale)
  7907. } else {
  7908. this.currentHightLyricSize = scale
  7909. this.lyricController
  7910. .setHighlightScale(this.currentHightLyricSize)
  7911. PreferencesUtil.putSync('HighLyricTextSize', scale)
  7912. }
  7913. }
  7914. private setLyricLineSpace(index: number, isPip: boolean) {
  7915. if (isPip) {
  7916. this.currentLyricLineSpacePip = index
  7917. this.lyricControllerXF.setLineSpace(this.currentLyricLineSpacePip)
  7918. PreferencesUtil.putSync('LyricLineSpacePip', this.currentLyricLineSpacePip)
  7919. } else {
  7920. this.currentLyricLineSpace = index
  7921. this.lyricController.setLineSpace(this.currentLyricLineSpace)
  7922. PreferencesUtil.putSync('LyricLineSpace', this.currentLyricLineSpace)
  7923. }
  7924. }
  7925. private changeLyricColor(color: string, isPip: boolean, isBG?: boolean) {
  7926. LogUtil.info('onecold isBG = ' + isBG)
  7927. if (isBG) { //如果是设置悬浮背景
  7928. this.pipBg = color
  7929. PreferencesUtil.putSync('BGColorPip', this.pipBg)
  7930. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  7931. return
  7932. }
  7933. if (isPip) {
  7934. this.currentLyricColorPip = color
  7935. this.lyricControllerXF
  7936. .setTextColor(this.currentLyricColorPip)
  7937. PreferencesUtil.putSync('LyricColorPip', this.currentLyricColorPip)
  7938. } else {
  7939. this.currentLyricColor = color
  7940. this.lyricController
  7941. .setTextColor(this.currentLyricColor)
  7942. PreferencesUtil.putSync('LyricColor', this.currentLyricColor)
  7943. }
  7944. }
  7945. private changeLyricHightLightColor(color: string, isPip: boolean) {
  7946. if (isPip) {
  7947. this.currentHighLightLyricColorPip = color
  7948. this.lyricControllerXF
  7949. .setHighlightColor(this.currentHighLightLyricColorPip)
  7950. PreferencesUtil.putSync('LyricHighLightColorPip', this.currentHighLightLyricColorPip)
  7951. } else {
  7952. this.currentHighLightLyricColor = color
  7953. this.lyricController
  7954. .setHighlightColor(this.currentHighLightLyricColor)
  7955. PreferencesUtil.putSync('LyricHighLightColor', this.currentHighLightLyricColor)
  7956. }
  7957. }
  7958. // 构建时间控制器
  7959. @Builder
  7960. BuildTimeControls() {
  7961. Column() {
  7962. // 时间显示
  7963. Text(this.getTimeText())
  7964. .fontSize(18)
  7965. .fontColor(Color.White)
  7966. .margin({ bottom: 10 })
  7967. Row() {
  7968. this.PrecisionTimeButton($r('app.media.ic_previous'), -0.5, ' -0.5s ')
  7969. this.PrecisionTimeButton($r('app.media.loop'), 0, '重置')
  7970. this.PrecisionTimeButton($r('app.media.ic_next'), 0.5, ' +0.5s ')
  7971. }
  7972. .justifyContent(FlexAlign.Center)
  7973. }
  7974. .margin({ top: 12, bottom: 8 })
  7975. }
  7976. // 精度按钮组件
  7977. @Builder
  7978. PrecisionTimeButton(icon: Resource, step: number, label: string) {
  7979. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7980. Column() {
  7981. Image(icon)
  7982. .width(28)
  7983. .margin({ bottom: 5 })
  7984. .opacity(this.isButtonDisabled(step) ? 0.5 : 1)
  7985. Text(label)
  7986. .fontSize(12)
  7987. .fontColor('#FFFFFF')
  7988. }
  7989. }
  7990. .backgroundColor(Color.Transparent)
  7991. .enabled(!this.isButtonDisabled(step))
  7992. .onClick(() => this.handlePrecisionAdjust(step))
  7993. .padding(5)
  7994. .width(66)
  7995. .height(66)
  7996. .margin({ left: 18, right: 18 })
  7997. .border({
  7998. color: '#FFFFFF',
  7999. width: 1.8
  8000. })
  8001. }
  8002. private handlePrecisionAdjust(step: number) {
  8003. if (step === 0) {
  8004. this.timeOffset = 0
  8005. return
  8006. }
  8007. // 精度处理:保留1位小数
  8008. const newOffset = Number((this.timeOffset + step).toFixed(5))
  8009. // 边界保护(±15.0秒)
  8010. if (newOffset < -30.0 || newOffset > 30.0) {
  8011. // this.triggerEdgeFeedback(newOffset) // 触发边界反馈
  8012. return
  8013. }
  8014. // 状态更新
  8015. this.timeOffset = newOffset
  8016. }
  8017. // 按钮禁用逻辑
  8018. private isButtonDisabled(step: number): boolean {
  8019. const futureOffset = this.timeOffset + step
  8020. return (futureOffset < -30.0) || (futureOffset > 30.0)
  8021. }
  8022. // 时间显示文本升级
  8023. private getTimeText(): string {
  8024. const absValue = Math.abs(this.timeOffset)
  8025. return this.timeOffset === 0
  8026. ? '歌词时间已重置'
  8027. : `歌词已${this.timeOffset < 0 ? '延后' : '提前'} ${absValue.toFixed(1)} 秒`
  8028. }
  8029. // 导入 本地歌词 搜索歌词
  8030. @Builder
  8031. pushLyricButton(icon: Resource, step: number, label: string) {
  8032. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8033. Row() {
  8034. Image(icon)
  8035. .width(14)
  8036. .margin({ left: 13 })
  8037. Text(label)
  8038. .fontSize(12)
  8039. .margin({ left: 6 })
  8040. .fontColor('#FFFFFF')
  8041. }
  8042. }
  8043. .onClick(() => {
  8044. switch (step) {
  8045. case 0:
  8046. this.callFilePickerSelectFileForLyric()
  8047. break;
  8048. case 1:
  8049. //判断有没有设置api
  8050. if (PreferencesUtil.getStringSync('LRC_API', '') === '') {
  8051. this.isLyricSetting = false
  8052. this.showTipsDialog()
  8053. return
  8054. }
  8055. if (StrUtil.isNotEmpty(this.videoUrl)) {
  8056. ToastUtil.showToast('正在获取')
  8057. this.isLyricSetting = false
  8058. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  8059. this.initLyric(lyricPath, true);
  8060. }
  8061. break;
  8062. }
  8063. })
  8064. .padding(5)
  8065. .width(110)
  8066. .backgroundColor(Color.Transparent)
  8067. .height(40)
  8068. .margin({ left: 6, right: 6 })
  8069. .border({
  8070. color: '#FFFFFF',
  8071. radius: 20,
  8072. width: 1.8
  8073. })
  8074. }
  8075. showVipDialog() {
  8076. DialogHelper.showCustomContentDialog({
  8077. dialogId: 'vip',
  8078. title: "友情提示",
  8079. autoCancel: false, //点击遮障层时,不关闭弹窗
  8080. backCancel: true, //点击返回键,不关闭弹窗
  8081. contentBuilder: () => {
  8082. this.customVipBuilder("该功能需开通会员,非常感谢您的支持!")
  8083. },
  8084. buttons: [],
  8085. })
  8086. }
  8087. //去赞助的自定义内容
  8088. @Builder
  8089. customVipBuilder(content: string) {
  8090. Column() {
  8091. Text(content)
  8092. .fontColor(Color.Gray)
  8093. .fontSize(16)
  8094. .alignSelf(ItemAlign.Start)
  8095. .margin({ bottom: 15 })
  8096. .fontSize(16)
  8097. Row() {
  8098. Button('取消')
  8099. .fontColor(Color.White)
  8100. .backgroundColor(this.themeColor)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  8101. .height(50)
  8102. .layoutWeight(1)
  8103. .stateEffect(true)
  8104. .margin({ right: 6 })
  8105. .onClick(() => {
  8106. DialogHelper.closeDialog('vip'); //关闭弹框
  8107. })
  8108. Button('开通')
  8109. .fontColor(Color.White)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  8110. .layoutWeight(1)
  8111. .height(50)
  8112. .backgroundColor(this.themeColor)
  8113. .stateEffect(true)
  8114. .margin({ left: 6 })
  8115. .onClick(() => {
  8116. DialogHelper.closeDialog('vip'); //关闭弹框
  8117. this.isShowPlay = false
  8118. this.mType = 1 //跳转到用户中心
  8119. // router.pushUrl({
  8120. // url: 'pages/VipPage'
  8121. // }, router.RouterMode.Single);
  8122. })
  8123. }
  8124. }
  8125. .width("100%")
  8126. .padding(10)
  8127. }
  8128. showTipsDialog() {
  8129. DialogHelper.showCustomContentDialog({
  8130. dialogId: 'tips',
  8131. title: "友情提示",
  8132. autoCancel: false, //点击遮障层时,不关闭弹窗
  8133. backCancel: true, //点击返回键,不关闭弹窗
  8134. contentBuilder: () => {
  8135. this.customTipsBuilder("请到设置界面配置API服务器地址!")
  8136. },
  8137. buttons: [],
  8138. })
  8139. }
  8140. @Builder
  8141. customTipsBuilder(content: string) {
  8142. Column() {
  8143. Text(content)
  8144. .fontColor(Color.Gray)
  8145. .fontSize(16)
  8146. .alignSelf(ItemAlign.Start)
  8147. .margin({ bottom: 15 })
  8148. .fontSize(16)
  8149. Row() {
  8150. Button('取消')
  8151. .fontColor(Color.White)
  8152. .backgroundColor(this.themeColor)
  8153. .height(50)
  8154. .layoutWeight(1)
  8155. .stateEffect(true)
  8156. .margin({ right: 6 })
  8157. .onClick(() => {
  8158. DialogHelper.closeDialog('tips'); //关闭弹框
  8159. })
  8160. Button('跳转')
  8161. .fontColor(Color.White)//
  8162. .layoutWeight(1)
  8163. .height(50)
  8164. .backgroundColor(this.themeColor)
  8165. .stateEffect(true)
  8166. .margin({ left: 6 })
  8167. .onClick(() => {
  8168. DialogHelper.closeDialog('tips'); //关闭弹框
  8169. this.isShowEdit = false
  8170. this.longItemFilePath = ''
  8171. // if(this.isGridMusic&&!this.isShowPlay){
  8172. // this.longItemFilePath== ''
  8173. // }else{
  8174. // this.isShowEdit = false
  8175. // }
  8176. this.isShowMoreView = false;
  8177. this.isShowPlay = false
  8178. this.mType = 4
  8179. // router.pushUrl({
  8180. // url: 'pages/SettingPage'
  8181. // }, router.RouterMode.Single);
  8182. })
  8183. }
  8184. }
  8185. .width("100%")
  8186. .padding(10)
  8187. }
  8188. @Builder
  8189. PlayMoreSheet() {
  8190. Column() {
  8191. this.MoreList()
  8192. }
  8193. .width('100%')
  8194. .height('100%')
  8195. }
  8196. @Builder
  8197. MoreList() {
  8198. Scroll() {
  8199. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  8200. ForEach(this.moreItems, (more: MoreItem, index: number) => {
  8201. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8202. Row() {
  8203. if (more.id === 3&&this.currentSong) {
  8204. Image(more.image)
  8205. .width(24)
  8206. .height(24)
  8207. .margin({ left: 10, right: 10 })
  8208. Text(more.title)
  8209. .fontSize(16)
  8210. .fontColor(Color.White)
  8211. .bindSheet($$this.isShowDetailMore, this.detailSheet(this.currentSong), {
  8212. height: this.isCoverOpacity() ? '95%' : '95%',
  8213. dragBar: true,
  8214. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8215. showClose: true,
  8216. blurStyle: BlurStyle.Thin,
  8217. backgroundColor: Color.Transparent,
  8218. title: { title: '歌曲信息' }
  8219. })
  8220. } else if (more.id === 15 && this.currentSong) { //编辑标签
  8221. Image(more.image)
  8222. .width(24)
  8223. .height(24)
  8224. .margin({ left: 10, right: 10 })
  8225. Text(more.title)
  8226. .fontSize(16)
  8227. .fontColor(Color.White)
  8228. .bindSheet($$this.isShowEdit, this.editSheet(this.currentSong), {
  8229. height: '99%',
  8230. dragBar: true,
  8231. showClose: true,
  8232. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8233. // blurStyle:BlurStyle.Thin,
  8234. // backgroundColor:Color.Transparent,
  8235. title: { title: '编辑标签' }
  8236. })
  8237. } else if (more.id === 5) { //定时关闭
  8238. Image(more.image)
  8239. .width(24)
  8240. .height(24)
  8241. .margin({ left: 10, right: 10 })
  8242. Text(more.title)
  8243. .fontSize(16)
  8244. .fontColor(Color.White)
  8245. .onClick(() => {
  8246. this.doMore(more.id)
  8247. })
  8248. .bindSheet($$this.isShowTimeCloseMore, this.TimeCloseSheet(), {
  8249. height: this.isCoverOpacity() ? '95%' : '95%',
  8250. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8251. dragBar: true,
  8252. showClose: true,
  8253. title: { title: $r('app.string.time_close') }
  8254. })
  8255. } else if (more.id === 2) { //歌词设置
  8256. Image(more.image)
  8257. .width(24)
  8258. .height(24)
  8259. .margin({ left: 10, right: 10 })
  8260. Text(more.title)
  8261. .fontSize(16)
  8262. .fontColor(Color.White)
  8263. } else if (more.id === 16) { //悬浮歌词设置
  8264. Image(more.image)
  8265. .width(24)
  8266. .height(24)
  8267. .margin({ left: 10, right: 10 })
  8268. Text(more.title)
  8269. .fontSize(16)
  8270. .fontColor(Color.White)
  8271. .bindSheet($$this.showPipLyric, this.lyricSettingSheet(true), {
  8272. height: this.isCoverOpacity() ? '95%' : '95%',
  8273. dragBar: true,
  8274. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8275. showClose: true,
  8276. blurStyle: BlurStyle.Thin,
  8277. backgroundColor: Color.Transparent,
  8278. title: { title: '悬浮歌词' }
  8279. })
  8280. } else if (more.id === 11) {
  8281. Image(more.image)
  8282. .width(24)
  8283. .height(24)
  8284. .margin({ left: 10, right: 10 })
  8285. Text(more.title)
  8286. .fontSize(16)
  8287. .fontColor(Color.White)
  8288. .bindSheet($$this.isJumpSetting, this.JumpTopEndSheet(), {
  8289. height: this.isCoverOpacity() ? '95%' : '60%',
  8290. dragBar: true,
  8291. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8292. showClose: true,
  8293. blurStyle: BlurStyle.Thin,
  8294. backgroundColor: Color.Transparent,
  8295. title: { title: '跳过头尾' }
  8296. })
  8297. } else if (more.id === 12) { //投播
  8298. AVCastPicker({
  8299. customPicker: (): void => this.TPImageBuilder(more),
  8300. onStateChange: (state) => {
  8301. if (state == AVCastPickerState.STATE_APPEARING) {
  8302. console.log(' The picker starts showing.');
  8303. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  8304. console.log(' The picker finishes presenting.');
  8305. }
  8306. },
  8307. pickerStyle: AVCastPickerStyle.STYLE_PANEL,
  8308. sessionType: 'video'
  8309. })
  8310. .id('AVCastPicker')
  8311. } else {
  8312. Image(more.image)
  8313. .width(24)
  8314. .height(24)
  8315. .margin({ left: 10, right: 10 })
  8316. .onClick(() => {
  8317. this.doMore(more.id)
  8318. })
  8319. Text(more.id == 17 ? (this.isLandscape ? '竖屏模式' : '横屏模式') : more.title)
  8320. .fontSize(16)
  8321. .fontColor(Color.White)
  8322. .onClick(() => {
  8323. this.doMore(more.id)
  8324. })
  8325. Select([//倍速
  8326. { value: '0.25x' },
  8327. { value: '0.5x' },
  8328. { value: '0.75x' },
  8329. { value: '1x' },
  8330. { value: '1.25x' },
  8331. { value: '1.5x' },
  8332. { value: '1.75x' },
  8333. { value: '2x' },
  8334. { value: '3x' }])
  8335. .font({ size: 16, weight: FontWeight.Medium })
  8336. .fontColor($r('sys.color.white'))
  8337. .margin({ left: 25 })
  8338. .visibility(more.id === 1 ? Visibility.Visible : Visibility.None)
  8339. .selected(CommonConstants.video_speed_list.indexOf(this.playSpeed))
  8340. .value(Utility.optimizedFormat(this.playSpeed))
  8341. .onSelect(async (_index: number, text?: string | undefined) => {
  8342. let speed = parseFloat(text?.replace('x', '') || '1');
  8343. if (!CommonConstants.video_speed_list.includes(speed)) {
  8344. speed = 1;
  8345. }
  8346. this.playSpeed = speed
  8347. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  8348. })
  8349. Slider({
  8350. value: this.volume,
  8351. min: 0,
  8352. max: 1,
  8353. step: 0.1,
  8354. style: SliderStyle.OutSet
  8355. })
  8356. .margin({ left: 18, right: 8 })
  8357. .blockColor(this.themeColor)
  8358. .trackColor($r('app.color.speed_text_color'))
  8359. .selectedColor(Color.White)
  8360. .trackThickness(9)
  8361. .visibility(more.id === 9 ? Visibility.Visible : Visibility.None)
  8362. .onChange((value: number) => {
  8363. this.volume = value;
  8364. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  8365. PreferencesUtil.putSync('DefalutVolume',this.volume)
  8366. })
  8367. .layoutWeight(1)
  8368. Blank()
  8369. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  8370. .selectedColor(this.themeColor)
  8371. .switchPointColor(Color.White)
  8372. .margin({ right: 15 })
  8373. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8374. .visibility(more.id == 6 ? Visibility.Visible : Visibility.None)
  8375. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8376. if (more.id == 6) {
  8377. this.isMusicMemoryPlay = checked;
  8378. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  8379. if (this.isMusicMemoryPlay) {
  8380. ToastUtil.showToast('记忆播放已开启')
  8381. } else {
  8382. ToastUtil.showToast('记忆播放已关闭')
  8383. }
  8384. }
  8385. })
  8386. .width(48)
  8387. .height(24);
  8388. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  8389. .selectedColor(this.themeColor)
  8390. .switchPointColor(Color.White)
  8391. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8392. .margin({ right: 15 })
  8393. .visibility(more.id == 7 ? Visibility.Visible : Visibility.None)
  8394. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8395. if (more.id == 7) {
  8396. this.isMusicBGCover = checked;
  8397. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  8398. if (this.isMusicBGCover) {
  8399. ToastUtil.showToast('播放背景随音乐封面已开启')
  8400. } else {
  8401. ToastUtil.showToast('播放背景随音乐封面已关闭')
  8402. }
  8403. }
  8404. })
  8405. .width(48)
  8406. .height(24);
  8407. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  8408. .selectedColor(this.themeColor)
  8409. .switchPointColor(Color.White)
  8410. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8411. .margin({ right: 15 })
  8412. .visibility(more.id == 8 ? Visibility.Visible : Visibility.None)
  8413. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8414. if (more.id == 8) {
  8415. this.isSavePlayMode = checked;
  8416. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  8417. if (this.isSavePlayMode) {
  8418. ToastUtil.showToast('保存播放模式已开启')
  8419. } else {
  8420. ToastUtil.showToast('保存播放模式已关闭')
  8421. }
  8422. }
  8423. })
  8424. .width(48)
  8425. .height(24);
  8426. Toggle({ type: ToggleType.Switch, isOn: this.isCoverRectangle })
  8427. .selectedColor(this.themeColor)
  8428. .switchPointColor(Color.White)
  8429. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8430. .margin({ right: 15 })
  8431. .visibility(more.id == 13 ? Visibility.Visible : Visibility.None)
  8432. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8433. if (more.id == 13) {
  8434. this.isCoverRectangle = checked;
  8435. PreferencesUtil.put(SettingPage.IS_COVER_RECTANGLE, this.isCoverRectangle)
  8436. if (this.isCoverRectangle) {
  8437. ToastUtil.showToast('封面方形已开启')
  8438. this.animationRoFun()
  8439. } else {
  8440. ToastUtil.showToast('封面圆形已开启')
  8441. this.animationRoFun()
  8442. }
  8443. }
  8444. })
  8445. .width(48)
  8446. .height(24);
  8447. }
  8448. }
  8449. .width('100%')
  8450. .height(45)
  8451. .padding(15)
  8452. .backgroundColor(Color.Transparent)
  8453. .borderRadius(12)
  8454. .margin({ bottom: 6 })
  8455. }
  8456. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.9 })
  8457. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  8458. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  8459. .backgroundColor(Color.Transparent)
  8460. .onClick(() => {
  8461. this.doMore(more.id)
  8462. })
  8463. });
  8464. }
  8465. .width('100%')
  8466. .padding(16)
  8467. }.margin({ bottom: 18 })
  8468. }
  8469. @Builder
  8470. TPImageBuilder(more: MoreItem): void {
  8471. Row() {
  8472. Image($r('app.media.tuoping'))
  8473. .width(22)
  8474. .height(22)
  8475. .margin({ left: 10, right: 10 })
  8476. Text(more.title)
  8477. .fontSize(16)
  8478. .fontColor(Color.White)
  8479. }
  8480. .width('100%')
  8481. .layoutWeight(1)
  8482. .alignItems(VerticalAlign.Center)
  8483. .justifyContent(FlexAlign.Start)
  8484. }
  8485. private moreItems: MoreItem[] = [
  8486. { id: 1, image: $r('app.media.speed'), title: '倍速' },
  8487. { id: 2, image: $r('app.media.lyric'), title: '歌词' },
  8488. { id: 17, image: $r('app.media.full_4'), title: '横屏模式' },
  8489. { id: 16, image: $r('app.media.hua_zhong_hua'), title: '悬浮歌词' },
  8490. { id: 14, image: $r('app.media.cover_online'), title: '获取封面' },
  8491. { id: 15, image: $r('app.media.rename2'), title: '编辑标签' },
  8492. { id: 5, image: $r('app.media.time_close'), title: '定时关闭' },
  8493. { id: 10, image: $r('app.media.ring_tone'), title: '设为铃声' },
  8494. { id: 11, image: $r('app.media.time_close'), title: '跳过头尾' },
  8495. { id: 12, image: $r('app.media.toubo'), title: '投播' },
  8496. { id: 3, image: $r('app.media.hua_zhong_hua'), title: '详情' },
  8497. { id: 4, image: $r('app.media.share2'), title: '分享' },
  8498. { id: 9, image: $r('app.media.volume_white'), title: '调整音量' },
  8499. // { id: 6, image: $r('app.media.memory'), title: '记忆播放' },
  8500. { id: 13, image: $r('app.media.rectangle'), title: '封面方形' },
  8501. { id: 8, image: $r('app.media.cut_current'), title: '保存播放模式' },
  8502. { id: 7, image: $r('app.media.playlist2'), title: '播放背景随音乐封面' },
  8503. ];
  8504. @State isShowMoreView: boolean = false;
  8505. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  8506. @State isShowTimeCloseMore: boolean = false
  8507. @State isShowDetailMore: boolean = false
  8508. @State isMusicBGCover: boolean = true
  8509. @State isSavePlayMode: boolean = true
  8510. @State isLyricSetting: boolean = false
  8511. @State isJumpSetting: boolean = false
  8512. @State isShowEdit: boolean = false
  8513. @State showPipLyric: boolean = false
  8514. async setRingTone() {
  8515. if (StrUtil.isEmpty(this.videoUrl) || StrUtil.isEmpty(this.name)) {
  8516. return
  8517. }
  8518. // 确定后的逻辑
  8519. let ringtoneTypeList: Array<ringtone.RingtoneType> = ringtone.getSupportedRingtoneTypes();
  8520. LogUtil.info('onecold getSupportedRingtoneTypes : ' + JSON.stringify(ringtoneTypeList));
  8521. let dataTypeList: Array<uniformTypeDescriptor.UniformDataType> =
  8522. ringtone.getSupportedDataTypes(ringtone.RingtoneType.NOTIFICATION);
  8523. LogUtil.info('onecold getSupportedDataTypes: ' + JSON.stringify(dataTypeList));
  8524. //let fileName: string = audioPath.substring(audioPath.lastIndexOf('/') + 1, audioPath.lastIndexOf('.'));
  8525. await ringtone.startRingtoneSetting(getContext(this) as common.UIAbilityContext
  8526. , this.videoUrl, this.name).then(res => {
  8527. LogUtil.info('onecold setFlag :' + res);
  8528. });
  8529. }
  8530. doMore(moreId: number) {
  8531. switch (moreId) {
  8532. case 2: //歌词
  8533. this.isLyricSetting = !this.isLyricSetting;
  8534. this.isShowMoreView = false
  8535. break;
  8536. case 3: //详情
  8537. this.isShowDetailMore = !this.isShowDetailMore;
  8538. break;
  8539. case 4: //分享
  8540. if (this.currentSong !== undefined) {
  8541. Utility.doShareMusic(this.currentSong, getContext(this) as common.UIAbilityContext)
  8542. }
  8543. this.isShowMoreView = false
  8544. break;
  8545. case 5: //定时关闭
  8546. this.isShowTimeCloseMore = !this.isShowTimeCloseMore;
  8547. break;
  8548. case 10: //设为铃声
  8549. this.setRingTone()
  8550. this.isShowMoreView = false
  8551. break;
  8552. case 11: //跳过头尾
  8553. this.isJumpSetting = !this.isJumpSetting;
  8554. break;
  8555. case 13: //倍速
  8556. break;
  8557. case 14: //搜索封面
  8558. if (this.currentSong !== undefined) {
  8559. this.doSearchCover(this.currentSong)
  8560. }
  8561. this.isShowMoreView = false
  8562. break;
  8563. case 15: //编辑标签
  8564. this.setEditStrEmpty()
  8565. this.tempLyricContent = this.lyricContent
  8566. this.isShowEdit = !this.isShowEdit;
  8567. break;
  8568. case 16: //悬浮歌词
  8569. this.showPipLyric = !this.showPipLyric;
  8570. break;
  8571. case 17: //横屏模式
  8572. if (this.isLandscape) {
  8573. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  8574. } else {
  8575. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  8576. }
  8577. this.isShowMoreView = false
  8578. break;
  8579. }
  8580. }
  8581. /**
  8582. * 切换横竖屏
  8583. *
  8584. */
  8585. setOrientation(orientation: number) {
  8586. this.windowClass.setPreferredOrientation(orientation).then(() => {
  8587. Logger.info('setWindowOrientation: ' + orientation + ' Succeeded.');
  8588. }).catch((err: BusinessError) => {
  8589. Logger.info('setWindowOrientation: ' + orientation + ' Failed. Cause: ' + JSON.stringify(err));
  8590. });
  8591. }
  8592. /**
  8593. * 画中画功能(悬浮歌词功能)
  8594. *
  8595. */
  8596. private nodeController: TextNodeController = new TextNodeController('#000000', this.lyricControllerXF);
  8597. pipController?: PiPWindow.PiPController;
  8598. navigationId: string = '';
  8599. @State curState: string = '';
  8600. @State curError: ResourceStr = '';
  8601. @State pipBg: string = '#E8E8E8'
  8602. @State buttonAction: string = '';
  8603. //开启画中画功能
  8604. async startPip() {
  8605. this.nodeController = new TextNodeController(this.pipBg, this.lyricControllerXF);
  8606. if (!this.pipController) {
  8607. await this.createPipController();
  8608. }
  8609. if (!this.pipController) {
  8610. Logger.info(`[${TAG}] pipController create error`);
  8611. return;
  8612. }
  8613. await this.pipController.startPiP();
  8614. }
  8615. async stopPip() {
  8616. if (!this.pipController) {
  8617. Logger.info(`[${TAG}] pipController is not exist`);
  8618. return;
  8619. }
  8620. this.isOpenPip = false
  8621. await this.pipController.stopPiP();
  8622. }
  8623. async createPipController() {
  8624. this.pipController = await PiPWindow.create({
  8625. context: getContext(this),
  8626. componentController: this.xcomponentController,
  8627. navigationId: this.navigationId,
  8628. templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY,
  8629. controlGroups: [PiPWindow.VideoPlayControlGroup.VIDEO_PREVIOUS_NEXT],
  8630. customUIController: this.nodeController,
  8631. });
  8632. this.pipLyWidth = PreferencesUtil.getNumberSync('pipLyWidth', 330)
  8633. this.pipLyHeight = PreferencesUtil.getNumberSync('pipLyHeight', 120)
  8634. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8635. this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => {
  8636. this.onStateChange(state, reason);
  8637. });
  8638. this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => {
  8639. this.onActionEvent(event, status);
  8640. });
  8641. }
  8642. destroyPipController() {
  8643. if (!this.pipController) {
  8644. return;
  8645. }
  8646. this.pipController.off('stateChange');
  8647. this.pipController.off('controlPanelActionEvent');
  8648. this.pipController = undefined;
  8649. }
  8650. onStateChange(state: PiPWindow.PiPState, reason: string) {
  8651. switch (state) {
  8652. case PiPWindow.PiPState.ABOUT_TO_START:
  8653. this.curState = 'ABOUT_TO_START';
  8654. this.curError = $r('app.string.current_error_hint');
  8655. break;
  8656. case PiPWindow.PiPState.STARTED:
  8657. this.curState = 'STARTED';
  8658. this.curError = $r('app.string.current_error_hint');
  8659. break;
  8660. case PiPWindow.PiPState.ABOUT_TO_STOP:
  8661. this.curState = 'ABOUT_TO_STOP';
  8662. this.curError = $r('app.string.current_error_hint');
  8663. break;
  8664. case PiPWindow.PiPState.STOPPED:
  8665. this.curState = 'STOPPED';
  8666. this.curError = $r('app.string.current_error_hint');
  8667. this.stopPip()
  8668. this.destroyPipController()
  8669. break;
  8670. case PiPWindow.PiPState.ABOUT_TO_RESTORE:
  8671. this.curState = 'ABOUT_TO_RESTORE';
  8672. this.curError = $r('app.string.current_error_hint');
  8673. break;
  8674. case PiPWindow.PiPState.ERROR:
  8675. this.curState = 'ERROR';
  8676. this.curError = reason;
  8677. break;
  8678. default:
  8679. break;
  8680. }
  8681. Logger.info(`[${TAG}] onecold onStateChange: ${this.curState}, reason: ${reason}`);
  8682. }
  8683. onActionEvent(event: PiPWindow.PiPActionEventType, status: number | undefined) {
  8684. LogUtil.info('onecold onActionEvent = ' + event + ' status=' + status)
  8685. switch (event) {
  8686. case 'playbackStateChanged':
  8687. if (status === 0) {
  8688. this.pause();
  8689. } else {
  8690. this.startPlayOrResumePlay();
  8691. }
  8692. break;
  8693. case 'nextVideo':
  8694. // 切换到下一个视频
  8695. this.playNext()
  8696. break;
  8697. case 'previousVideo':
  8698. // 切换到上一个视频
  8699. this.playPrevious()
  8700. break;
  8701. case 'previousVideo':
  8702. // 切换到上一个视频
  8703. this.playPrevious()
  8704. break;
  8705. default:
  8706. }
  8707. this.buttonAction = event + `-status:${status}`;
  8708. Logger.info(`[${TAG}] onActionEvent: ${this.buttonAction} status:${status}}`);
  8709. }
  8710. /**
  8711. * 画中画功能(悬浮歌词功能)结束
  8712. *
  8713. */
  8714. async doSearchCover(item: VideoItem): Promise<string> {
  8715. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  8716. this.isShowMoreView = false;
  8717. this.showTipsDialog();
  8718. return ''; // Return empty string when no API is configured
  8719. }
  8720. if (!item) {
  8721. return ''; // Return empty string if item is undefined
  8722. }
  8723. const artist = item?.artist || ''; // Use empty string if artist is missing
  8724. return this.searchCover(item, item.name, artist); // Await is not needed here as we return the promise directly
  8725. }
  8726. /**
  8727. *api搜索封面
  8728. *item,根据title和artist
  8729. */
  8730. searchCover(item: VideoItem, title: string, artist: string): Promise<string> {
  8731. return NetAxiosUtil.getLyricCover(title, artist, PreferencesUtil.getStringSync('COVER_API', '')).then(async (res) => {
  8732. LogUtil.debug("onecold res =" + res);
  8733. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  8734. if (item.filePath == this.currentSong?.filePath) {
  8735. this.cover = res;
  8736. if (this.currentSong) {
  8737. this.currentSong.pixelMapPath = res;
  8738. }
  8739. }
  8740. // Update pixel map path but always return res regardless of success
  8741. this.table.updatePixelMapPath(item.filePath, res, (success: boolean, error?: string) => {
  8742. if (success) {
  8743. this.doUpdateData();
  8744. console.log("onecold 更新音乐封面成功,数据库已同步");
  8745. } else {
  8746. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  8747. }
  8748. // Note: We don't resolve/reject here because we already returned res
  8749. });
  8750. LogUtil.debug("onecold this.cover =" + this.cover);
  8751. }
  8752. return res; // Always return res regardless of updatePixelMapPath result
  8753. });
  8754. }
  8755. @State jumpTopTime: number = 0
  8756. @State jumpEndTime: number = 0
  8757. @State isOpenJump: boolean = false
  8758. @Builder
  8759. JumpTopEndSheet() {
  8760. Scroll() {
  8761. Column() {
  8762. Column() {
  8763. Text('仅对本播放列表有效')
  8764. .fontSize(16)
  8765. .fontColor($r('app.color.text_color'))
  8766. // 跳过头尾
  8767. Column() {
  8768. Row() {
  8769. Text('跳过片头:')
  8770. .fontSize(16)
  8771. .fontColor($r('app.color.text_color'))
  8772. Text(this.jumpTopTime + 's')
  8773. .fontSize(16)
  8774. .fontColor($r('app.color.text_color'))
  8775. }
  8776. .margin({ bottom: 5 })
  8777. Row() {
  8778. Slider({
  8779. value: this.jumpTopTime,
  8780. min: 0,
  8781. max: 120,
  8782. step: 1,
  8783. style: SliderStyle.OutSet
  8784. })
  8785. .blockColor(this.themeColor)
  8786. .trackColor($r('app.color.speed_text_color'))
  8787. .selectedColor(Color.White)
  8788. .trackThickness(8)
  8789. .onChange((value: number) => {
  8790. this.jumpTopTime = value;
  8791. })
  8792. .width('85%')
  8793. }
  8794. .alignItems(VerticalAlign.Top)
  8795. }
  8796. .margin({ top: 10, bottom: 10 })
  8797. // 跳过头尾
  8798. Column() {
  8799. Row() {
  8800. Text('跳过片尾:')
  8801. .fontSize(16)
  8802. .fontColor($r('app.color.text_color'))
  8803. Text(this.jumpEndTime + 's')
  8804. .fontSize(16)
  8805. .fontColor($r('app.color.text_color'))
  8806. }
  8807. .margin({ bottom: 5 })
  8808. Row() {
  8809. Slider({
  8810. value: this.jumpEndTime,
  8811. min: 0,
  8812. max: 120,
  8813. step: 1,
  8814. style: SliderStyle.OutSet
  8815. })
  8816. .blockColor(this.themeColor)
  8817. .trackColor($r('app.color.speed_text_color'))
  8818. .selectedColor(Color.White)
  8819. .trackThickness(8)
  8820. .onChange((value: number) => {
  8821. this.jumpEndTime = value;
  8822. })
  8823. .width('85%')
  8824. }
  8825. .alignItems(VerticalAlign.Top)
  8826. }
  8827. .margin({ top: 10, bottom: 10 })
  8828. Row() {
  8829. Button('保存设置')
  8830. .fontColor(Color.White)
  8831. .layoutWeight(1)
  8832. .height(40)
  8833. .width(80)
  8834. .backgroundColor(this.themeColor)
  8835. .stateEffect(true)
  8836. .margin({ left: 0, bottom: 20 })
  8837. .onClick(async () => {
  8838. if (!Utility.isNoble()) {
  8839. this.isJumpSetting = false
  8840. this.isShowMoreView = false
  8841. this.showVipDialog()
  8842. return
  8843. }
  8844. if (this.currentSong === undefined) {
  8845. return
  8846. }
  8847. if (this.modeType === 0) {
  8848. let parentPath = FileUtil.getParentPath(this.videoUrl)
  8849. PreferencesUtil.putSync(parentPath + 'isOpenJump', true)
  8850. PreferencesUtil.putSync(parentPath + 'jumpEndTime', this.jumpEndTime)
  8851. PreferencesUtil.putSync(parentPath + 'jumpTopTime', this.jumpTopTime)
  8852. } else if (this.modeType === 1) { //媒体库
  8853. PreferencesUtil.putSync(1 + 'isOpenJump', true)
  8854. PreferencesUtil.putSync(1 + 'jumpEndTime', this.jumpEndTime)
  8855. PreferencesUtil.putSync(1 + 'jumpTopTime', this.jumpTopTime)
  8856. } else if (this.modeType === 2) { //艺术家
  8857. if (this.currentSong?.artist) {
  8858. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'isOpenJump', true)
  8859. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpEndTime', this.jumpEndTime)
  8860. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpTopTime', this.jumpTopTime)
  8861. }
  8862. } else if (this.modeType === 3) { //专辑
  8863. if (this.currentSong?.album) {
  8864. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'isOpenJump', true)
  8865. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpEndTime', this.jumpEndTime)
  8866. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpTopTime', this.jumpTopTime)
  8867. }
  8868. }
  8869. ToastUtil.showShort("保存成功")
  8870. this.isJumpSetting = false
  8871. })
  8872. }
  8873. .margin({
  8874. left: 38,
  8875. right: 38,
  8876. top: 10,
  8877. bottom: 10
  8878. })
  8879. .width(120)
  8880. .height(50)
  8881. }
  8882. }
  8883. }
  8884. .width('100%')
  8885. .height('100%')
  8886. }
  8887. // 应用可以通过onStateChange接口监听组件显示/消失状态,当组件显示时建议不要销毁AVCastPicker的显示;当组件消失时,再根据业务隐藏AVCastPicker。
  8888. private onStateVastChange(state: AVCastPickerState) {
  8889. if (state == AVCastPickerState.STATE_APPEARING) {
  8890. console.log('The picker starts showing.');
  8891. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  8892. console.log('The picker finishes presenting.');
  8893. }
  8894. }
  8895. private showSelectLyric() {
  8896. DialogHelper.showActionSheetDialog({
  8897. title: '温馨提醒:\n1.歌词文件名必须和目标歌曲文件名相同\n2.歌词文件和目标歌曲要同个歌单路径。',
  8898. // sheets: ["本地歌词", "搜索歌词"],
  8899. sheets: [
  8900. { value: "本地歌词", fontColor: $r('app.color.text_color') },
  8901. { value: "搜索歌词", fontColor: $r('app.color.text_color') },
  8902. ],
  8903. maskColor: Color.Transparent,
  8904. backgroundColor: $r('app.color.bg_card'),
  8905. transition: AnimationHelper.transitionInDown(666),
  8906. onAction: (index) => {
  8907. switch (index) {
  8908. case 0:
  8909. this.callFilePickerSelectFileForLyric()
  8910. break;
  8911. case 1:
  8912. if (StrUtil.isNotEmpty(this.videoUrl)) {
  8913. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  8914. this.initLyric(lyricPath);
  8915. }
  8916. break;
  8917. }
  8918. }
  8919. })
  8920. }
  8921. // 拉起picker选择文件管理器
  8922. async callFilePickerSelectFileForLyric(): Promise<void> {
  8923. try {
  8924. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  8925. DocumentSelectOptions.maxSelectNumber = 1
  8926. DocumentSelectOptions.fileSuffixFilters = CommonConstants.LYRIC_FORMAT
  8927. let documentPicker = new picker.DocumentViewPicker();
  8928. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  8929. Logger.info(TAG,
  8930. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  8931. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  8932. this.saveVideoDatasLyric(DocumentSelectResult)
  8933. }
  8934. }).catch((err: BusinessError) => {
  8935. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  8936. });
  8937. } catch (err) {
  8938. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  8939. }
  8940. }
  8941. async saveVideoDatasLyric(uris: string[]) {
  8942. if (ArrayUtil.isEmpty(uris)) {
  8943. return
  8944. }
  8945. let newUris: string[] = [];
  8946. for (let i = 0; i < uris.length; i++) {
  8947. let filePath = getContext(this).filesDir + '/' + Utility.getMediaNameByUri(uris[i])
  8948. Logger.info(TAG, 'filePath uri: ' + filePath);
  8949. newUris.push(filePath)
  8950. let file = fileIo.openSync(uris[i], fileIo.OpenMode.READ_ONLY)
  8951. let file2 = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  8952. fileIo.copyFileSync(file.fd, file2.fd)
  8953. fileIo.closeSync(file);
  8954. fileIo.closeSync(file2);
  8955. this.initLyric(filePath,false,false,true)
  8956. }
  8957. }
  8958. private initDelayPlay(context: object) {
  8959. this.mContext = context;
  8960. }
  8961. startPipLyric() {
  8962. if (this.pipController) {
  8963. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  8964. PiPWindow.PiPControlStatus.PLAY);
  8965. }
  8966. this.isOpenPip = PreferencesUtil.getBooleanSync('isOpenPip', false)
  8967. if (this.isOpenPip) {
  8968. this.startPip()
  8969. } else {
  8970. this.stopPip()
  8971. }
  8972. }
  8973. private startPlayOrResumePlay() {
  8974. this.startPipLyric()
  8975. this.mDestroyPage = false;
  8976. this.animationState = AnimationStatus.Running
  8977. LogUtils.getInstance().LOGI("startPlayOrResumePlay start this.CONTROL_PlayStatus:" + this.CONTROL_PlayStatus)
  8978. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  8979. this.stopProgressTask();
  8980. this.startProgressTask();
  8981. this.play(this.videoUrl.toString());
  8982. }
  8983. if (this.CONTROL_PlayStatus == PlayStatus.PAUSE) {
  8984. this.mIjkMediaPlayer.start();
  8985. this.setProgress()
  8986. this.CONTROL_PlayStatus = PlayStatus.PLAY
  8987. }
  8988. this.setIsPlaying(true)
  8989. this.updateSessionPlayState(true)
  8990. this.watchStatus();
  8991. this.updateLastPlayTimeStr(this.videoUrl)
  8992. }
  8993. updateLastPlayTimeStr(filePath: string) {
  8994. let lastPlayTime = DateUtil.getTodayStr('yyyy-MM-dd HH:mm:ss')
  8995. this.table.updateLastPlayedStrByFilePath(filePath, lastPlayTime, (success: boolean, error?: string) => {
  8996. if (success) {
  8997. this.getHistoryList(false)
  8998. console.log(" onecold 更新最近播放时间成功,数据库已同步");
  8999. } else {
  9000. console.error(" onecold 更新最近播放时间数据库失败原因: " + error);
  9001. }
  9002. });
  9003. }
  9004. private completionNum(num: number): string | number {
  9005. if (num < 10) {
  9006. return '0' + num;
  9007. } else {
  9008. return num;
  9009. }
  9010. }
  9011. private stringForTime(timeMs: number): string {
  9012. let totalSeconds: number | string = (timeMs / 1000);
  9013. let newSeconds: number | string = totalSeconds % 60;
  9014. let minutes: number | string = (totalSeconds / 60) % 60;
  9015. let hours: number | string = totalSeconds / 3600;
  9016. //LogUtils.getInstance().LOGI("stringForTime hours:" + hours + ",minutes:" + minutes + ",seconds:" + newSeconds);
  9017. hours = this.completionNum(Math.floor(Math.floor(hours * 100) / 100));
  9018. minutes = this.completionNum(Math.floor(Math.floor(minutes * 100) / 100));
  9019. newSeconds = Math.floor(Math.floor(newSeconds * 100) / 100)
  9020. if (this.isCurrentTime) {
  9021. if (this.oldSeconds < newSeconds || newSeconds === 0 || this.isSeekTo) {
  9022. this.oldSeconds = newSeconds
  9023. } else {
  9024. newSeconds = this.oldSeconds
  9025. }
  9026. }
  9027. newSeconds = this.completionNum(newSeconds);
  9028. if (hours > 0) {
  9029. return hours + ":" + minutes + ":" + newSeconds;
  9030. } else {
  9031. return minutes + ":" + newSeconds;
  9032. }
  9033. }
  9034. private setProgress() {
  9035. let position = this.mIjkMediaPlayer.getCurrentPosition();
  9036. let duration = this.mIjkMediaPlayer.getDuration();
  9037. let pos = 0;
  9038. if (duration > 0) {
  9039. this.slideEnable = true;
  9040. let curPercent = position / duration;
  9041. pos = curPercent * 100;
  9042. if (pos > this.PROGRESS_MAX_VALUE) {
  9043. this.progressValue = this.PROGRESS_MAX_VALUE
  9044. } else {
  9045. this.progressValue = pos;
  9046. }
  9047. }
  9048. // LogUtils.getInstance()
  9049. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  9050. this.totalTime = this.stringForTime(duration);
  9051. if (position > duration) {
  9052. position = duration;
  9053. }
  9054. this.isCurrentTime = true;
  9055. this.lyricController.updatePosition(position + this.timeOffset * 1000)
  9056. this.lyricControllerXF.updatePosition(position + this.timeOffset * 1000)
  9057. this.lyricControllerSingle.updatePosition(position + this.timeOffset * 1000)
  9058. this.currentTime = this.stringForTime(position);
  9059. this.isCurrentTime = false
  9060. if (this.mIjkMediaPlayer.isPlaying()) {
  9061. this.randomColor =
  9062. `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
  9063. // 判断是否播放到结束时间
  9064. if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
  9065. if (position >= duration - this.jumpEndTime * 1000) {
  9066. this.playNext()
  9067. }
  9068. }
  9069. } else {
  9070. this.randomColor = 'rbg(0,0,0)'
  9071. }
  9072. }
  9073. private startProgressTask() {
  9074. let that = this;
  9075. this.updateProgressTimer = setInterval(() => {
  9076. //LogUtils.getInstance().LOGI("startProgressTask");
  9077. if (!that.mDestroyPage) {
  9078. that.setProgress();
  9079. }
  9080. }, 300);
  9081. }
  9082. private stopProgressTask() {
  9083. LogUtils.getInstance().LOGI("stopProgressTask");
  9084. clearInterval(this.updateProgressTimer);
  9085. }
  9086. private showLoadIng() {
  9087. this.loadingVisible = Visibility.Visible;
  9088. this.replayVisible = Visibility.None;
  9089. }
  9090. private hideLoadIng() {
  9091. this.loadingVisible = Visibility.None;
  9092. this.replayVisible = Visibility.None;
  9093. }
  9094. private showRePlay() {
  9095. this.loadingVisible = Visibility.None;
  9096. this.replayVisible = Visibility.Visible;
  9097. }
  9098. private async play(url: string) {
  9099. let that = this;
  9100. that.showLoadIng();
  9101. //设置XComponent回调的context
  9102. if (!!this.mContext) {
  9103. this.mIjkMediaPlayer.setContext(this.mContext, 'xcomponentId');
  9104. }
  9105. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  9106. this.mIjkMediaPlayer.reset();
  9107. }
  9108. this.CONTROL_PlayStatus = PlayStatus.PLAY;
  9109. //设置debug模式
  9110. this.mIjkMediaPlayer.setDebug(false);
  9111. //初始化配置
  9112. this.mIjkMediaPlayer.native_setup();
  9113. // 初始化配置后需要重新设置音频流音量,否则音量为默认值1.0 针对dsf格式设置最大值1.0
  9114. if(this.volumeSmall){
  9115. if(this.videoUrl.toLowerCase().endsWith('.dsf')){
  9116. this.mIjkMediaPlayer.setVolume('1', '1');
  9117. }else{
  9118. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  9119. }
  9120. }else{
  9121. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  9122. }
  9123. //设置视频源
  9124. this.mIjkMediaPlayer.setDataSource(url);
  9125. //设置视频源http请求头
  9126. let headers = new Map([
  9127. ["user_agent", "Mozilla/5.0 BiliDroid/7.30.0 (bbcallen@gmail.com)"],
  9128. ["referer", "https://www.bilibili.com"]
  9129. ]);
  9130. this.mIjkMediaPlayer.setDataSourceHeader(headers);
  9131. // if(PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN,false)){
  9132. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", "1"); // 启用硬件解码,会导致无法顺序播放
  9133. // }
  9134. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  9135. //使用精确寻帧 例如,拖动播放后,会寻找最近的关键帧进行播放,很有可能关键帧的位置不是拖动后的位置,而是较前的位置.可以设置这个参数来解决问题
  9136. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", "1");
  9137. const fileSize = await this.getFileSize(this.videoUrl);
  9138. let bufferSize = 1 * 1024 ; // 默认缓冲区大小为1MB
  9139. if (fileSize > 3 * 1024 * 1024 * 1024) { // 文件大于3GB
  9140. bufferSize = 25 * 1024 * 1024; // 设置缓冲区大小为25MB
  9141. }
  9142. // 使用软件解码(通常比硬件解码更节省内存)
  9143. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", '0');
  9144. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", '0');
  9145. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", '1024');
  9146. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", '500000');
  9147. //预读数据的缓冲区大小.修复大文件播放前几秒挂掉的bug,太大了会导致倍数播放失效
  9148. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", bufferSize + '');
  9149. //停止预读的最小帧数
  9150. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100");
  9151. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", '1'); ////重连模式,如果中途服务器断开了连接,让它重新连接
  9152. // 设置其他缓冲相关选项
  9153. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100"); // 设置最小缓冲帧数
  9154. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-frames", "1000"); // 设置最大缓冲
  9155. //启动预加载
  9156. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", "1");
  9157. // 设置无缓冲,这是播放器的缓冲区,有数据就播放
  9158. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", "0");
  9159. //跳帧处理,放CPU处理较慢时,进行跳帧处理,保证播放流程,画面和声音同步
  9160. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", "5");
  9161. // 最大缓冲cache是3s, 有时候网络波动,会突然在短时间内收到好几秒的数据
  9162. // 因此需要播放器丢包,才不会累积延时
  9163. // 这个和第三个参数packet-buffering无关。
  9164. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max_cached_duration", "3000");
  9165. // 无限制收流
  9166. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1");
  9167. this.mIjkMediaPlayer.setOptionLong(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1")
  9168. // 屏幕常亮
  9169. this.mIjkMediaPlayer.setScreenOnWhilePlaying(true);
  9170. // 设置超时
  9171. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", "10000000");
  9172. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "connect_timeout", "10000000");
  9173. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "addrinfo_timeout", "10000000");
  9174. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_timeout", "10000000");
  9175. // 变速播放
  9176. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", "1");
  9177. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  9178. let Speed = this.mIjkMediaPlayer.getSpeed()
  9179. LogUtils.getInstance().LOGI('getSpeed--' + Speed)
  9180. //是否开启循环播放
  9181. // this.mIjkMediaPlayer.setLoopCount(this.loop);
  9182. let mOnVideoSizeChangedListener: OnVideoSizeChangedListener = {
  9183. onVideoSizeChanged: (width: number, height: number, sar_num: number, sar_den: number) => {
  9184. if (height === 0) {
  9185. return;
  9186. }
  9187. const va = width / height;
  9188. const vpa = that.videoParentAspectRatio;
  9189. if (vpa > va) {
  9190. that.videoWidth = (width / (height * vpa)) * 100 + '%';
  9191. } else {
  9192. that.videoWidth = '100%';
  9193. }
  9194. if (width && height) {
  9195. that.videoAspectRatio = width / height;
  9196. }
  9197. LogUtils.getInstance()
  9198. .LOGI("setOnVideoSizeChangedListener-->go:" + width + "," + height + "," + sar_num + "," + sar_den);
  9199. that.hideLoadIng();
  9200. }
  9201. }
  9202. this.mIjkMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
  9203. let mOnPreparedListener: OnPreparedListener = {
  9204. onPrepared: async () => {
  9205. LogUtils.getInstance().LOGI("setOnPreparedListener-->go");
  9206. try {
  9207. // this.cover = this.songList[this.curIndex].pixelMapPath
  9208. // this.artist = this.songList[this.curIndex].artist
  9209. // this.videoUrl = this.songList[this.curIndex].filePath
  9210. let isBgCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  9211. if (isBgCover && this.cover !== undefined && StrUtil.isNotEmpty(this.cover)) {
  9212. this.setImageColor2(this.cover)
  9213. } else {
  9214. this.getImageColor();
  9215. }
  9216. //保存碰一碰分享的当前的歌曲
  9217. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  9218. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  9219. await this.initLyric(lyricPath);
  9220. setTimeout(() => {
  9221. this.avSessionController.initAvSession(false);
  9222. this.avSessionController.setAVMetadataMusic(this.songList[this.curIndex], this.duration, this.lyricContent);
  9223. this.setAvSessionListener();
  9224. this.updateSessionPlayState(true)
  9225. this.setCurrentPlayMode()
  9226. }, 500)
  9227. //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9228. let timeoutPlay = 0
  9229. if (StrUtil.isNotEmpty(this.videoUrl) &&
  9230. (this.videoUrl.toLowerCase().endsWith('.rmvb') || this.videoUrl.toLowerCase().endsWith('.flac'))) {
  9231. timeoutPlay = 1000
  9232. }
  9233. //跳过片头片尾关键代码,以下是跳过片头的关键代码
  9234. if (this.modeType === 0) { //文件夹
  9235. let parentPath = FileUtil.getParentPath(this.videoUrl)
  9236. this.jumpTopTime = PreferencesUtil.getNumberSync(parentPath + 'jumpTopTime')
  9237. this.jumpEndTime = PreferencesUtil.getNumberSync(parentPath + 'jumpEndTime')
  9238. this.isOpenJump = PreferencesUtil.getBooleanSync(parentPath + 'isOpenJump', false)
  9239. } else if (this.modeType === 1) { //媒体库
  9240. this.jumpTopTime = PreferencesUtil.getNumberSync(1 + 'jumpTopTime')
  9241. this.jumpEndTime = PreferencesUtil.getNumberSync(1 + 'jumpEndTime')
  9242. this.isOpenJump = PreferencesUtil.getBooleanSync(1 + 'isOpenJump', false)
  9243. } else if (this.modeType === 2) { //艺术家
  9244. if (this.currentSong?.artist) {
  9245. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpTopTime')
  9246. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpEndTime')
  9247. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.artist + 2 + 'isOpenJump', false)
  9248. }
  9249. } else if (this.modeType === 3) { //专辑
  9250. if (this.currentSong?.album) {
  9251. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpTopTime')
  9252. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpEndTime')
  9253. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.album + 3 + 'isOpenJump', false)
  9254. }
  9255. }
  9256. this.duration = this.mIjkMediaPlayer.getDuration()
  9257. if (this.isOpenJump) { //用户是否设置跳过片头片尾
  9258. if (this.mIjkMediaPlayer != null) {
  9259. if (this.jumpTopTime * 1000 <= this.duration) {
  9260. // 调用 seekTo 方法,跳到指定时间
  9261. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9262. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  9263. this.seekTo(this.jumpTopTime * 1000 + ""); // 跳到开头
  9264. }
  9265. }, timeoutPlay)
  9266. } else {
  9267. // 提示用户无法跳过
  9268. ToastUtil.showToast('跳过时间超过视频时长');
  9269. }
  9270. }
  9271. } else {
  9272. this.jumpTopTime = 0
  9273. this.jumpEndTime = 0
  9274. console.error('onecold 最后一首: isFirstStartPlay = ' + this.isFirstStartPlay);
  9275. console.error('onecold 最后一首: isMemoryLastPlay = ' + this.isMemoryLastPlay);
  9276. console.error('onecold 最后一首: PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false) = ' +
  9277. PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false));
  9278. //记忆播放(每一首都会记忆播放)
  9279. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  9280. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9281. if (PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)) {
  9282. this.restorePlaybackPosition() //读取播放记忆功能
  9283. } else if (this.isMemoryLastPlay && this.isFirstStartPlay) {
  9284. console.error('onecold 最后一首:读取播放记忆功能 = ' + this.isFirstStartPlay);
  9285. this.restorePlaybackPosition() //读取播放记忆功能
  9286. }
  9287. this.isFirstStartPlay = false
  9288. }, timeoutPlay)
  9289. } else {
  9290. this.isFirstStartPlay = false
  9291. }
  9292. }
  9293. this.saveLastPlayList()
  9294. } catch (error) {
  9295. let err: BusinessError = error as BusinessError;
  9296. console.error('onecold failed with err: ' + JSON.stringify(err));
  9297. }
  9298. }
  9299. }
  9300. this.mIjkMediaPlayer.setOnPreparedListener(mOnPreparedListener);
  9301. let mOnTimedTextListener: OnTimedTextListener = {
  9302. onTimedText: () => {
  9303. }
  9304. }
  9305. this.mIjkMediaPlayer.setOnTimedTextListener(mOnTimedTextListener)
  9306. let mOnCompletionListener: OnCompletionListener = {
  9307. onCompletion: () => {
  9308. LogUtils.getInstance().LOGI("OnCompletionListener-->go")
  9309. if (this.playType == 0) { //0:连续播放 1:单片重复播放 2:正常播放
  9310. this.playNext()
  9311. } else if (this.playType == 1) { //1:单片重复播放
  9312. this.CONTROL_PlayStatus = PlayStatus.INIT
  9313. that.startPlayOrResumePlay();
  9314. } else if (this.playType == 2) { //2:正常播放,单曲播完
  9315. that.showRePlay();
  9316. that.currentTime = that.stringForTime(this.mIjkMediaPlayer.getDuration());
  9317. that.progressValue = this.PROGRESS_MAX_VALUE;
  9318. that.slideEnable = false;
  9319. that.stop();
  9320. // ToastUtil.showToast('开始重新播放')
  9321. } else if (this.playType == 3) { //3:随机播放
  9322. this.randomPlay()
  9323. }
  9324. }
  9325. }
  9326. this.mIjkMediaPlayer.setOnCompletionListener(mOnCompletionListener);
  9327. let mOnBufferingUpdateListener: OnBufferingUpdateListener = {
  9328. onBufferingUpdate: (percent: number) => {
  9329. LogUtils.getInstance().LOGI("OnBufferingUpdateListener-->go:" + percent);
  9330. let MediaInfo = this.mIjkMediaPlayer.getMediaInfo()
  9331. LogUtils.getInstance().LOGI('getMediaInfo---' + MediaInfo);
  9332. let VideoWidth = this.mIjkMediaPlayer.getVideoWidth()
  9333. LogUtils.getInstance().LOGI('getVideoWidth---' + VideoWidth);
  9334. let VideoHeight = this.mIjkMediaPlayer.getVideoHeight()
  9335. LogUtils.getInstance().LOGI('getVideoHeight---' + VideoHeight);
  9336. let VideoSarNum = this.mIjkMediaPlayer.getVideoSarNum()
  9337. LogUtils.getInstance().LOGI('getVideoSarNum---' + VideoSarNum);
  9338. let VideoSarDen = this.mIjkMediaPlayer.getVideoSarDen()
  9339. LogUtils.getInstance().LOGI('getVideoSarDen---' + VideoSarDen);
  9340. let AudioSessionId = this.mIjkMediaPlayer.getAudioSessionId()
  9341. LogUtils.getInstance().LOGI('getAudioSessionId---' + AudioSessionId);
  9342. let Looping = this.mIjkMediaPlayer.isLooping()
  9343. LogUtils.getInstance().LOGI('isLooping---' + Looping);
  9344. }
  9345. }
  9346. this.mIjkMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
  9347. let mOnSeekCompleteListener: OnSeekCompleteListener = {
  9348. onSeekComplete: () => {
  9349. LogUtils.getInstance().LOGI("OnSeekCompleteListener-->go");
  9350. that.startPlayOrResumePlay();
  9351. }
  9352. }
  9353. this.mIjkMediaPlayer.setOnSeekCompleteListener(mOnSeekCompleteListener);
  9354. let mOnInfoListener: OnInfoListener = {
  9355. onInfo: (what: number, extra: number) => {
  9356. LogUtils.getInstance().LOGI("OnInfoListener-->go:" + what + "===" + extra);
  9357. that.hideLoadIng();
  9358. }
  9359. }
  9360. this.mIjkMediaPlayer.setOnInfoListener(mOnInfoListener);
  9361. let mOnErrorListener: OnErrorListener = {
  9362. onError: (what: number, extra: number) => {
  9363. this.stopProgressTask();
  9364. LogUtils.getInstance().LOGI("OnErrorListener-->go:" + what + "===" + extra + " this.videoUrl=" + this.videoUrl)
  9365. that.hideLoadIng();
  9366. if (StrUtil.isNotEmpty(this.videoUrl) && !FileUtil.accessSync(this.videoUrl)) {
  9367. ToastUtil.showToast(Utility.resourceToString(getContext(), $r('app.string.file_not_exist')))
  9368. } else {
  9369. ToastUtil.showToast(getContext()
  9370. .resourceManager
  9371. .getStringByNameSync("Honey_the_video_is_playing_errant_The_system_is_wandering"))
  9372. }
  9373. }
  9374. }
  9375. this.mIjkMediaPlayer.setOnErrorListener(mOnErrorListener);
  9376. this.mIjkMediaPlayer.setMessageListener();
  9377. this.mIjkMediaPlayer.prepareAsync();
  9378. this.mIjkMediaPlayer.start();
  9379. }
  9380. //保存最后播放的那首歌和已经对应的播放列表
  9381. saveLastPlayList() {
  9382. PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
  9383. PreferencesUtil.putSync('LastMusicList', this.songList)
  9384. }
  9385. // 清空播放记录
  9386. clearVideoHistory() {
  9387. this.table.clearPlayHistory((success: boolean, error?: string) => {
  9388. if (success) {
  9389. this.historyList = [];
  9390. this.updateListData(this.historyList)
  9391. // PreferencesUtil.putSync(LocalMusic.HISTORY_MUSIC, this.historyList)
  9392. ToastUtil.showToast('清空播放记录成功')
  9393. } else {
  9394. console.error(" onecold 清空播放记录数据库失败原因: " + error);
  9395. }
  9396. });
  9397. }
  9398. public async setAvSessionListener() {
  9399. if (!this.avSessionController) {
  9400. return;
  9401. }
  9402. this.avSessionController.getAvSession()?.on('play', this.sessionPlayCallback);
  9403. this.avSessionController.getAvSession()?.on('pause', this.sessionPauseCallback);
  9404. this.avSessionController.getAvSession()?.on('stop', this.sessionStopCallback);
  9405. this.avSessionController.getAvSession()?.on('playNext', this.sessionPlayNextCallback);
  9406. this.avSessionController.getAvSession()?.on('playPrevious', this.sessionPlayPreviousCallback);
  9407. this.avSessionController.getAvSession()?.on('fastForward', this.sessionFastForwardCallback);
  9408. this.avSessionController.getAvSession()?.on('rewind', this.sessionRewindCallback);
  9409. this.avSessionController.getAvSession()?.on('seek', this.sessionSeekCallback);
  9410. this.avSessionController.getAvSession()?.on('setLoopMode', this.sessionSetLoopModeCallback);
  9411. this.avSessionController.getAvSession()?.on('toggleFavorite', this.sessionToggleFavoriteCallback);
  9412. this.avSessionController.getAvSession()?.on('outputDeviceChange', this.sessionOutputDeviceChange)
  9413. }
  9414. setLoopMode() {
  9415. let itype = this.playType + 1
  9416. if (itype >= 4) {
  9417. this.playType = 0
  9418. ToastUtil.showToast('连续播放')
  9419. } else if (itype === 1) {
  9420. this.playType = 1
  9421. ToastUtil.showToast('单曲循环')
  9422. } else if (itype === 2) {
  9423. this.playType = 2
  9424. ToastUtil.showToast('单曲播完')
  9425. } else if (itype === 3) {
  9426. this.playType = 3
  9427. ToastUtil.showToast('随机播放')
  9428. } else if (itype === 0) {
  9429. this.playType = 0
  9430. ToastUtil.showToast('连续播放')
  9431. }
  9432. PreferencesUtil.putSync('musicPlayType', this.playType)
  9433. this.setCurrentPlayMode()
  9434. }
  9435. private sessionSetLoopModeCallback = (mode: number) => {
  9436. if (this.mIjkMediaPlayer != null) {
  9437. ToastUtil.showToast('当前播放模式:' + mode)
  9438. Logger.info('onecold 当前播放模式= ' + mode)
  9439. let hmPlayMode = mode + 1
  9440. if (hmPlayMode >= 4) {
  9441. hmPlayMode = 0
  9442. }
  9443. if (hmPlayMode === 1) {
  9444. this.playType = 1
  9445. ToastUtil.showToast('单曲循环')
  9446. } else if (hmPlayMode === 0) {
  9447. this.playType = 2
  9448. ToastUtil.showToast('单曲播完')
  9449. } else if (hmPlayMode === 3) {
  9450. this.playType = 3
  9451. ToastUtil.showToast('随机播放')
  9452. } else if (hmPlayMode === 2) {
  9453. this.playType = 0
  9454. ToastUtil.showToast('连续播放')
  9455. }
  9456. PreferencesUtil.putSync('musicPlayType', this.playType)
  9457. // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
  9458. let playBackState: avSession.AVPlaybackState = {
  9459. loopMode: hmPlayMode,
  9460. };
  9461. this.avSessionController.getAvSession()?.setAVPlaybackState(playBackState).then(() => {
  9462. console.info(`set setLoopMode AVPlaybackState successfully`);
  9463. }).catch((err: BusinessError) => {
  9464. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  9465. });
  9466. }
  9467. }
  9468. setCurrentPlayMode() {
  9469. if (!this.avSessionController) {
  9470. return;
  9471. }
  9472. let mLoopMode = 0
  9473. switch (this.playType) {
  9474. case 0:
  9475. mLoopMode = avSession.LoopMode.LOOP_MODE_LIST //连续播放
  9476. break;
  9477. case 1:
  9478. mLoopMode = avSession.LoopMode.LOOP_MODE_SINGLE //单曲
  9479. break;
  9480. case 2:
  9481. mLoopMode = avSession.LoopMode.LOOP_MODE_SEQUENCE //正常播放
  9482. break;
  9483. case 3:
  9484. mLoopMode = avSession.LoopMode.LOOP_MODE_SHUFFLE //随机播放
  9485. break;
  9486. }
  9487. // 应用启动时/内部切换循环模式,需要把应用内的当前的循环模式设置给AVSession。
  9488. let playBState: avSession.AVPlaybackState = {
  9489. loopMode: mLoopMode,
  9490. isFavorite: Utility.getIsFav(this.favList, this.currentSong),
  9491. };
  9492. this.avSessionController.getAvSession()?.setAVPlaybackState(playBState).then(() => {
  9493. console.info(`set setLoopMode AVPlaybackState successfully`);
  9494. }).catch((err: BusinessError) => {
  9495. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  9496. });
  9497. }
  9498. private sessionToggleFavoriteCallback = (assetId: string) => {
  9499. if (this.mIjkMediaPlayer != null && this.currentSong) {
  9500. console.info(`on toggleFavorite `);
  9501. // 应用收到收藏命令,进行收藏处理。
  9502. this.isFac = Utility.getIsFav(this.favList, this.currentSong)
  9503. this.doFav(this.currentSong)
  9504. // 应用内完成或者取消收藏,把新的收藏状态设置给AVSession。
  9505. let playbackState: avSession.AVPlaybackState = {
  9506. isFavorite: !this.isFac,
  9507. };
  9508. this.avSessionController.getAvSession()?.setAVPlaybackState(playbackState).then(() => {
  9509. console.info(`SetAVPlaybackState successfully`);
  9510. }).catch((err: BusinessError) => {
  9511. console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  9512. });
  9513. }
  9514. }
  9515. private sessionOutputDeviceChange = async (connectState: avSession.ConnectionState,
  9516. device: avSession.OutputDeviceInfo) => {
  9517. let currentDevice: avSession.DeviceInfo = device?.devices?.[0];
  9518. if (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  9519. connectState === avSession.ConnectionState.STATE_CONNECTED) {
  9520. await this.startCasting();
  9521. } else if ((currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  9522. connectState === avSession.ConnectionState.STATE_DISCONNECTED) ||
  9523. (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_LOCAL &&
  9524. connectState === avSession.ConnectionState.STATE_CONNECTED)) {
  9525. if (device) {
  9526. this.endCasting();
  9527. }
  9528. }
  9529. };
  9530. private async startCasting() {
  9531. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  9532. this.setPlaybackStateChangeListener();
  9533. this.pause();
  9534. this.initQueueItem();
  9535. this.prepare();
  9536. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  9537. refToIsCasting?.set(true);
  9538. this.castSeek = true;
  9539. this.isCastPlaying = true;
  9540. }
  9541. async changeCasting() {
  9542. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  9543. this.initQueueItem();
  9544. this.prepare();
  9545. this.setPlaybackStateChangeListener();
  9546. this.isCastPlaying = true;
  9547. this.castSeek = true;
  9548. }
  9549. public endCasting() {
  9550. this.avSessionController.getAvSession()?.stopCasting();
  9551. this.stopCast();
  9552. this.isCastPlaying = false;
  9553. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  9554. refToIsCasting?.set(false);
  9555. this.pause();
  9556. this.setIsPlaying(false);
  9557. // if (this.curIndex === this.curSource.index) {
  9558. // this.play
  9559. // this.seek(this.currentTime * 1000);
  9560. // this.setIsPlaying(true);
  9561. // } else {
  9562. // this.pauseVideo();
  9563. // this.setIsPlaying(false);
  9564. // }
  9565. }
  9566. public setIsPlaying(isPlayer: boolean) {
  9567. this.isPlaying = isPlayer;
  9568. }
  9569. private setPlaybackStateChangeListener(): void {
  9570. this.castController?.on('playbackStateChange', 'all', this.playbackStateChangeListener);
  9571. this.castController?.on('endOfStream', this.reloadCasting);
  9572. this.castController?.on('playNext', this.playNextCallback);
  9573. this.castController?.on('playPrevious', this.playPreviousCallback);
  9574. }
  9575. private updateSessionPlayState(isPlay: boolean): void {
  9576. // if(!this.isBgPlayOpen)
  9577. // return
  9578. Logger.info(TAG, `updateIsPlay isPlay: ${isPlay}`);
  9579. this.setAVSessionPlayState({
  9580. state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
  9581. position: {
  9582. elapsedTime: this.mIjkMediaPlayer.getCurrentPosition(),
  9583. updateTime: new Date().getTime()
  9584. }
  9585. });
  9586. }
  9587. private setAVSessionPlayState(playbackState: avSession.AVPlaybackState): void {
  9588. this.avSessionController.setAvSessionPlayState(playbackState)
  9589. }
  9590. private positionChange(position: number) {
  9591. this.currentTime2 = position / 1000;
  9592. this.currentStringTime = secondToTime(Math.floor(position / 1000));
  9593. }
  9594. private playDurationChange(duration: number) {
  9595. this.duration = duration;
  9596. this.durationTime = Math.floor(this.duration / 1000);
  9597. this.durationStringTime = secondToTime((this.durationTime));
  9598. }
  9599. private playbackStateChangeListener = (playbackState: avSession.AVPlaybackState) => {
  9600. const duration = playbackState?.extras?.duration;
  9601. if (typeof duration === 'number') {
  9602. this.playDurationChange(duration as number);
  9603. }
  9604. if (typeof playbackState?.position?.elapsedTime !== 'undefined') {
  9605. this.positionChange(playbackState?.position?.elapsedTime);
  9606. }
  9607. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PAUSE ||
  9608. playbackState.state === CommonConstants2.PLAYBACK_STATE_STOP ||
  9609. playbackState.state === CommonConstants2.PLAYBACK_STATE_PREPARE ||
  9610. playbackState.state === CommonConstants2.PLAYBACK_STATE_INITIAL) {
  9611. this.isCastPlaying = false;
  9612. }
  9613. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PLAY) {
  9614. this.isCastPlaying = true;
  9615. }
  9616. };
  9617. private reloadCasting = async () => {
  9618. let item = this.songList[this.curIndex];
  9619. let uri = fileUri.getUriFromPath(item.filePath);
  9620. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  9621. // description.startPosition = 0;
  9622. this.castItem = {
  9623. itemId: this.curIndex,
  9624. description: {
  9625. assetId: item.filePath,
  9626. title: item.name,
  9627. artist: '',
  9628. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  9629. // mediaUri: item.filePath,
  9630. fdSrc: {
  9631. fd: file.fd
  9632. },
  9633. // 该字段大写,音频'AUDIO',视频'VIDEO'
  9634. mediaType: 'VIDEO',
  9635. mediaSize: item.videoSize,
  9636. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  9637. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  9638. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  9639. duration: this.duration,
  9640. // albumCoverUri: 'https://www.example.jpeg',
  9641. // albumTitle: '《ExampleAlbum》',
  9642. appName: this.appName,
  9643. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  9644. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  9645. }
  9646. };
  9647. this.prepare();
  9648. this.isCastPlaying = true;
  9649. };
  9650. public playNextCallback = (): void => {
  9651. this.playNext()
  9652. };
  9653. public playPreviousCallback = (): void => {
  9654. this.playPrevious()
  9655. };
  9656. async prepare() {
  9657. await this.castController?.prepare(this.castItem);
  9658. await this.castController?.start(this.castItem);
  9659. }
  9660. public initQueueItem() {
  9661. let item = this.songList[this.curIndex];
  9662. let time = this.currentTime;
  9663. let uri = fileUri.getUriFromPath(item.filePath);
  9664. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  9665. this.castItem = {
  9666. itemId: this.curIndex,
  9667. description: {
  9668. assetId: item.filePath,
  9669. title: item.name,
  9670. artist: '',
  9671. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  9672. fdSrc: {
  9673. fd: file.fd
  9674. },
  9675. // 该字段大写,音频'AUDIO',视频'VIDEO'
  9676. mediaType: 'AUDIO',
  9677. mediaSize: item.videoSize,
  9678. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  9679. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  9680. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  9681. duration: this.duration,
  9682. // albumCoverUri: 'https://www.example.jpeg',
  9683. // albumTitle: '《ExampleAlbum》',
  9684. appName: this.appName,
  9685. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  9686. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  9687. }
  9688. };
  9689. }
  9690. async stopCast() {
  9691. try {
  9692. this.castController?.off('playbackStateChange');
  9693. this.castController?.off('endOfStream');
  9694. this.castController?.off('playNext');
  9695. this.castController?.off('playPrevious');
  9696. this.castController?.off('error');
  9697. } catch (error) {
  9698. hilog.info(0x0000, TAG, `Failed to setAVCastController. code: ${error.code}, message: ${error.message}`);
  9699. }
  9700. }
  9701. private sessionPlayCallback = (): void => {
  9702. this.playOrPause()
  9703. };
  9704. private sessionPauseCallback = (): void => {
  9705. this.playOrPause()
  9706. };
  9707. private playOrPause() {
  9708. if (!this.debounce()) {
  9709. return;
  9710. }
  9711. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  9712. this.pause();
  9713. } else {
  9714. this.startPlayOrResumePlay();
  9715. this.playChange()
  9716. }
  9717. }
  9718. private sessionPlayNextCallback = (): void => {
  9719. this.playNext()
  9720. };
  9721. private sessionPlayPreviousCallback = (): void => {
  9722. this.playPrevious()
  9723. };
  9724. private sessionStopCallback = (): void => {
  9725. this.stop()
  9726. };
  9727. private sessionFastForwardCallback = (time?: number) => {
  9728. if (!time) {
  9729. return;
  9730. }
  9731. if (this.mIjkMediaPlayer != null) {
  9732. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9733. let seeTime = curPosition + time * 1000;
  9734. // 限制 seekValue 在合法范围内
  9735. if (seeTime < 0) {
  9736. seeTime = 0;
  9737. } else if (seeTime > this.duration) {
  9738. seeTime = this.duration;
  9739. }
  9740. Logger.info('onecold seeTime= ' + seeTime)
  9741. this.setSeekToActionProgress(seeTime)
  9742. this.seekTo(seeTime + "")
  9743. }
  9744. };
  9745. /**
  9746. * Gesture method onActionUpdate.
  9747. *
  9748. * @param event Gesture event.手势拖动设置快进和后退
  9749. */
  9750. private setSeekToActionProgress(position: number) {
  9751. // let position = this.mIjkMediaPlayer.getCurrentPosition();
  9752. let duration = this.mIjkMediaPlayer.getDuration();
  9753. let pos = 0;
  9754. if (duration > 0) {
  9755. this.slideEnable = true;
  9756. let curPercent = position / duration;
  9757. pos = curPercent * 100;
  9758. if (pos > this.PROGRESS_MAX_VALUE) {
  9759. this.progressValue = this.PROGRESS_MAX_VALUE
  9760. } else {
  9761. this.progressValue = pos;
  9762. }
  9763. }
  9764. // LogUtils.getInstance()
  9765. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  9766. this.totalTime = this.stringForTime(duration);
  9767. if (position > duration) {
  9768. position = duration;
  9769. }
  9770. this.isCurrentTime = true;
  9771. this.currentTime = this.stringForTime(position);
  9772. this.isCurrentTime = false
  9773. }
  9774. private sessionRewindCallback = (time?: number) => {
  9775. if (!time) {
  9776. return;
  9777. }
  9778. if (this.mIjkMediaPlayer != null) {
  9779. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9780. let seeTime = curPosition - time * 1000;
  9781. // 限制 seekValue 在合法范围内
  9782. if (seeTime < 0) {
  9783. seeTime = 0;
  9784. } else if (seeTime > this.duration) {
  9785. seeTime = this.duration;
  9786. }
  9787. Logger.info('onecold seeTime= ' + seeTime)
  9788. this.setSeekToActionProgress(seeTime)
  9789. this.seekTo(seeTime + "")
  9790. }
  9791. };
  9792. private sessionSeekCallback = (seekTime: number) => {
  9793. if (this.mIjkMediaPlayer != null) {
  9794. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9795. this.seekTo(seekTime + "")
  9796. }
  9797. };
  9798. private async getFileSize(filePath: string): Promise<number> {
  9799. try {
  9800. const stat = await fs.stat(filePath);
  9801. return stat.size;
  9802. } catch (err) {
  9803. console.error('Failed to get file size: ' + err.message);
  9804. return 0;
  9805. }
  9806. }
  9807. private pause() {
  9808. if (this.mIjkMediaPlayer.isPlaying()) {
  9809. this.savePlaybackPosition();
  9810. this.mIjkMediaPlayer.pause();
  9811. this.setProgress();
  9812. this.mDestroyPage = true;
  9813. this.CONTROL_PlayStatus = PlayStatus.PAUSE;
  9814. this.updateSessionPlayState(false)
  9815. this.playChange()
  9816. if (this.pipController) {
  9817. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  9818. PiPWindow.PiPControlStatus.PAUSE);
  9819. }
  9820. }
  9821. }
  9822. private stop() {
  9823. this.savePlaybackPosition();
  9824. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9825. this.mIjkMediaPlayer.stop();
  9826. this.mIjkMediaPlayer.release();
  9827. this.stopProgressTask();
  9828. this.updateSessionPlayState(false)
  9829. this.playChange()
  9830. this.watchStatus();
  9831. }
  9832. //保持记忆播放功能
  9833. private savePlaybackPosition() {
  9834. if (this.mIjkMediaPlayer != null) {
  9835. const position = this.mIjkMediaPlayer.getCurrentPosition();
  9836. // ToastUtil.showToast('保存记忆播放 = ' + position)
  9837. const duration = this.mIjkMediaPlayer.getDuration();
  9838. const threshold = 5000; // 阈值,单位为毫秒(这里设为5秒)
  9839. // 如果播放位置接近视频末尾,则保存 position 为 0
  9840. const playbackPosition = (duration - position < threshold) ? 0 : position;
  9841. PreferencesUtil.putSync(this.videoUrl, playbackPosition);
  9842. }
  9843. }
  9844. //获取记忆播放功能
  9845. private restorePlaybackPosition() {
  9846. const position: number = PreferencesUtil.getNumberSync(this.videoUrl, 0);
  9847. // ToastUtil.showToast('position = ' + position)
  9848. if (this.mIjkMediaPlayer != null && position > 0) {
  9849. // ToastUtil.showToast('seekTo = ' + position)
  9850. this.seekTo(position + "");
  9851. }
  9852. }
  9853. private seekTo(value: string) {
  9854. if (StrUtil.isNotEmpty(this.videoUrl) && this.videoUrl.toLowerCase().endsWith('.wma')) {
  9855. ToastUtil.showToast('wma格式不支持拖动快进。')
  9856. return
  9857. }
  9858. this.mIjkMediaPlayer.seekTo(value);
  9859. // this.startPlayOrResumePlay()
  9860. // 在这里恢复计时器状态
  9861. this.setProgress()
  9862. // this.startProgressTask();
  9863. }
  9864. // 添加到下一首播放
  9865. private addToNextPlay(song: VideoItem) {
  9866. if (!this.debounce()) {
  9867. return;
  9868. }
  9869. if (this.currentSong) {
  9870. if (this.currentSong === song) {
  9871. ToastUtil.showToast('当前已经在播放这首歌了!')
  9872. return
  9873. }
  9874. }
  9875. // 如果未开始播放或队列为空
  9876. if (this.curIndex === -1 || this.songList.length === 0) {
  9877. this.songList = [song];
  9878. this.curIndex = 0;
  9879. this.doPlay(song)
  9880. return;
  9881. }
  9882. // 插入到当前索引+1的位置
  9883. const insertPos = this.curIndex + 1;
  9884. this.songList.splice(insertPos, 0, song);
  9885. this.songList = [...this.songList]; // 触发状态更新
  9886. this.sonDataSource.pushArrayData(this.songList)
  9887. ToastUtil.showToast('已添加至下一首播放')
  9888. }
  9889. //下一个
  9890. private playNext() {
  9891. if (!this.debounce()) {
  9892. return;
  9893. }
  9894. if (this.playType == 3) { //3:随机播放
  9895. this.randomPlay()
  9896. return;
  9897. }
  9898. if (ArrayUtil.isNotEmpty(this.songList)) {
  9899. if (this.curIndex == this.songList.length - 1) {
  9900. this.curIndex = 0;
  9901. } else {
  9902. this.curIndex++;
  9903. }
  9904. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9905. this.stop();
  9906. this.currentSong = this.songList[this.curIndex]
  9907. this.videoUrl = this.songList[this.curIndex].filePath;
  9908. this.artist = this.songList[this.curIndex].artist
  9909. this.name = this.songList[this.curIndex].name
  9910. //this.cover = this.songList[this.curIndex].pixelMapPath
  9911. this.changeImageAnimation()
  9912. }
  9913. }
  9914. changeImageAnimation() {
  9915. if(this.openSkipSongAnimate){
  9916. // 第一步:淡出动画
  9917. this.getUIContext()?.animateTo({
  9918. duration: 500,
  9919. curve: Curve.EaseOut,
  9920. }, () => {
  9921. this.opacityValueImage = 0.1;
  9922. if(this.isCoverRectangle){
  9923. this.scaleValueImage = 0.88
  9924. }
  9925. });
  9926. // 第二步:切换图片后淡入
  9927. setTimeout(() => {
  9928. this.cover = this.songList[this.curIndex].pixelMapPath
  9929. this.getUIContext()?.animateTo({
  9930. duration: 500,
  9931. curve: Curve.EaseIn,
  9932. }, () => {
  9933. this.opacityValueImage = 1;
  9934. this.scaleValueImage = 1 // 图标恢复到原始大小
  9935. this.startPlayOrResumePlay()
  9936. });
  9937. }, 500);
  9938. }else{
  9939. this.cover = this.songList[this.curIndex].pixelMapPath
  9940. this.startPlayOrResumePlay()
  9941. }
  9942. }
  9943. // 存储已播放的歌曲索引
  9944. private playedIndices: Set<number> = new Set();
  9945. //随机播放
  9946. private randomPlay() {
  9947. // if (!this.debounce()) {
  9948. // return;
  9949. // }
  9950. if (ArrayUtil.isNotEmpty(this.songList)) {
  9951. if (this.songList.length > 3) {
  9952. // 如果所有歌曲都播放过一次,清空已播放索引集合
  9953. if (this.playedIndices.size === this.songList.length) {
  9954. this.playedIndices.clear();
  9955. }
  9956. // 随机选择一个未播放的歌曲索引
  9957. let newIndex: number;
  9958. // 添加超时机制防止无限循环
  9959. let attempt = 0;
  9960. const maxAttempts = 100; // 根据需求调整
  9961. do {
  9962. newIndex = RandomUtil.getRandomNumber(0, this.songList.length - 1);
  9963. attempt++;
  9964. } while (this.playedIndices.has(newIndex) && attempt < maxAttempts);
  9965. if (attempt >= maxAttempts) {
  9966. // 处理无法找到新索引的情况(如随机选择或按顺序播放)
  9967. newIndex = Math.floor(Math.random() * this.songList.length);
  9968. }
  9969. this.curIndex = newIndex;
  9970. this.playedIndices.add(newIndex);
  9971. } else {
  9972. // 当歌曲数量小于或等于3时,直接播放下一首
  9973. if (this.curIndex == this.songList.length - 1) {
  9974. this.curIndex = 0;
  9975. } else {
  9976. this.curIndex++;
  9977. }
  9978. }
  9979. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9980. this.stop();
  9981. this.currentSong = this.songList[this.curIndex];
  9982. this.videoUrl = this.songList[this.curIndex].filePath;
  9983. this.name = this.songList[this.curIndex].name;
  9984. this.artist = this.songList[this.curIndex].artist
  9985. // this.cover = this.songList[this.curIndex].pixelMapPath
  9986. this.changeImageAnimation()
  9987. }
  9988. }
  9989. private playIndex(index: number) {
  9990. if (!this.debounce()) {
  9991. return;
  9992. }
  9993. if (ArrayUtil.isNotEmpty(this.songList)) {
  9994. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9995. this.stop();
  9996. this.currentSong = this.songList[this.curIndex]
  9997. this.videoUrl = this.songList[index].filePath;
  9998. this.name = this.songList[index].name
  9999. this.artist = this.songList[this.curIndex].artist
  10000. this.curIndex = index;
  10001. this.changeImageAnimation()
  10002. }
  10003. }
  10004. //上一个
  10005. private playPrevious() {
  10006. if (!this.debounce()) {
  10007. return;
  10008. }
  10009. if (this.playType == 3) { //3:随机播放的上一首应该应该播放历史记录的第二首
  10010. this.randomModePlayFromHistory()
  10011. return;
  10012. }
  10013. if (this.curIndex == 0) {
  10014. this.curIndex = this.songList.length - 1;
  10015. } else {
  10016. this.curIndex--;
  10017. }
  10018. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10019. this.stop();
  10020. this.currentSong = this.songList[this.curIndex]
  10021. this.videoUrl = this.songList[this.curIndex].filePath;
  10022. this.name = this.songList[this.curIndex].name
  10023. this.artist = this.songList[this.curIndex].artist
  10024. this.changeImageAnimation()
  10025. }
  10026. //随机播放模式下点击上一首: 上一首应该应该播放历史记录的第二首
  10027. private randomModePlayFromHistory() {
  10028. if (this.historyList.length >= 2) {
  10029. // 播放历史记录的第二首
  10030. const prevSong = this.historyList[1];
  10031. this.curIndex = this.songList.findIndex(song => song.filePath === prevSong.filePath);
  10032. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10033. this.stop();
  10034. this.currentSong = prevSong;
  10035. this.videoUrl = prevSong.filePath;
  10036. this.cover = prevSong.pixelMapPath
  10037. this.artist = prevSong.artist
  10038. this.name = prevSong.name;
  10039. this.startPlayOrResumePlay();
  10040. } else {
  10041. // 如果历史记录不足两首,可根据需求处理,这里简单按普通逻辑处理
  10042. if (this.curIndex === 0) {
  10043. this.curIndex = this.songList.length - 1;
  10044. } else {
  10045. this.curIndex--;
  10046. }
  10047. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10048. this.stop();
  10049. this.currentSong = this.songList[this.curIndex];
  10050. this.videoUrl = this.songList[this.curIndex].filePath;
  10051. this.artist = this.songList[this.curIndex].artist
  10052. this.name = this.songList[this.curIndex].name;
  10053. this.changeImageAnimation()
  10054. }
  10055. }
  10056. debounce() {
  10057. const delay = 600;
  10058. let cur = new Date().getTime();
  10059. if (cur - this.last > delay) {
  10060. this.last = cur;
  10061. return true;
  10062. }
  10063. return false;
  10064. }
  10065. /**
  10066. * Sets whether the screen is a constant based on the playback status.
  10067. */
  10068. watchStatus() {
  10069. // let windowClass = GlobalContext.getContext().getObject('windowClass') as window.Window;
  10070. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  10071. this.windowClass.setWindowKeepScreenOn(true);
  10072. } else {
  10073. this.windowClass.setWindowKeepScreenOn(false);
  10074. }
  10075. }
  10076. /**
  10077. * Volume gesture method onActionStart.
  10078. *
  10079. * @param event Gesture event.
  10080. */
  10081. private customDialogComponentIdMM: number = 0
  10082. @Builder
  10083. customDialogComponentMM() {
  10084. Column() {
  10085. Row() {
  10086. Blank()
  10087. Text('验证密码')
  10088. .fontSize(22)
  10089. .fontColor($r('app.color.pri_bg'))
  10090. .margin({ top: 18 })
  10091. Blank()
  10092. Image($r('app.media.close'))
  10093. .fillColor(Color.White)
  10094. .margin({ top: 18, right: 18 })
  10095. .width(20)
  10096. .onClick(() => {
  10097. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  10098. })
  10099. }
  10100. .width('100%') // 使Row占据整个宽度
  10101. .justifyContent(FlexAlign.SpaceBetween); // 在Row中创建空间
  10102. Verify({
  10103. onVerifyCompleted: this.handleVerifyCompleted.bind(this)
  10104. });
  10105. }.height('60%')
  10106. .backgroundColor($r('app.color.index_background'))
  10107. .justifyContent(FlexAlign.SpaceBetween)
  10108. }
  10109. private handleVerifyCompleted(isSuccess: boolean) {
  10110. if (isSuccess) {
  10111. console.log('验证成功');
  10112. // 在这里处理验证成功后的逻辑
  10113. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  10114. this.currentPath = this.lockPath
  10115. this.getSortedFiles(this.currentPath)
  10116. } else {
  10117. // console.log('验证失败');
  10118. ToastUtil.showToast('验证失败')
  10119. }
  10120. }
  10121. private showVerifyDialog() {
  10122. promptAction.openCustomDialog({
  10123. transition: TransitionEffect.asymmetric(
  10124. TransitionEffect.OPACITY.animation({ duration: 888 }).combine(
  10125. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  10126. ,
  10127. TransitionEffect.OPACITY.animation({ delay: 888, duration: 888 }).combine(
  10128. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  10129. ),
  10130. builder: () => {
  10131. this.customDialogComponentMM()
  10132. },
  10133. isModal: true,
  10134. autoCancel: true,
  10135. maskColor: Color.Transparent,
  10136. alignment: DialogAlignment.Bottom,
  10137. onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
  10138. console.info("reason" + JSON.stringify(dismissDialogAction.reason))
  10139. console.log("dialog onWillDismiss")
  10140. if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
  10141. dismissDialogAction.dismiss()
  10142. }
  10143. if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
  10144. dismissDialogAction.dismiss()
  10145. }
  10146. }
  10147. }).then((dialogId: number) => {
  10148. this.customDialogComponentIdMM = dialogId
  10149. })
  10150. }
  10151. //左滑操作 移动文件 重命名 删除等操作
  10152. @Builder
  10153. DeleteButton(item: VideoItem, index: number, filePath: string) {
  10154. Row() {
  10155. //加入收藏
  10156. Button() {
  10157. Image(Utility.getIsFav(this.favList, item) ? $r('app.media.add_fac_light2') : $r('app.media.add_fac'))
  10158. .fillColor(Color.White)
  10159. .width(20)
  10160. }
  10161. .width(40)
  10162. .height(40)
  10163. .type(ButtonType.Circle)
  10164. .backgroundColor(this.themeColor)
  10165. .margin(5)
  10166. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10167. .onClick(() => {
  10168. if (item) {
  10169. this.doFav(item)
  10170. }
  10171. })
  10172. //加入下一首播放
  10173. Button() {
  10174. Image($r('app.media.next_to_play'))
  10175. .fillColor(Color.White)
  10176. .width(20)
  10177. }
  10178. .width(40)
  10179. .height(40)
  10180. .type(ButtonType.Circle)
  10181. .backgroundColor(this.themeColor)
  10182. .margin(5)
  10183. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10184. .onClick(() => {
  10185. this.addToNextPlay(item);
  10186. })
  10187. //复制文件
  10188. Button() {
  10189. Image($r('app.media.copy'))
  10190. .fillColor(Color.White)
  10191. .width(20)
  10192. }
  10193. .width(40)
  10194. .height(40)
  10195. .type(ButtonType.Circle)
  10196. .backgroundColor(this.themeColor)
  10197. .margin(5)
  10198. .id(filePath + 'copy')
  10199. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10200. .onClick(() => {
  10201. this.showCopyDialog(false, item, index, filePath + 'copy');
  10202. })
  10203. //移动文件
  10204. Button() {
  10205. Image($r('app.media.cut'))
  10206. .fillColor(Color.White)
  10207. .width(20)
  10208. }
  10209. .width(40)
  10210. .height(40)
  10211. .type(ButtonType.Circle)
  10212. .backgroundColor(this.themeColor)
  10213. .margin(5)
  10214. .id(filePath)
  10215. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10216. .onClick(() => {
  10217. this.showCutDialog(false, item, index, filePath);
  10218. })
  10219. Button() {
  10220. Image($r('app.media.cut_current'))
  10221. .fillColor(Color.White)
  10222. .width(20)
  10223. }
  10224. .width(40)
  10225. .height(40)
  10226. .type(ButtonType.Circle)
  10227. .backgroundColor(this.themeColor)
  10228. .margin(5)
  10229. .id(filePath + 'current')
  10230. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None :
  10231. (this.isHasDir ? Visibility.Visible : Visibility.None))
  10232. .onClick(() => {
  10233. this.showCutDialog(true, item, index, filePath + 'current');
  10234. })
  10235. //重命名
  10236. Button() {
  10237. Image($r('app.media.rename2'))
  10238. .fillColor(Color.White)
  10239. .width(20)
  10240. }
  10241. .width(40)
  10242. .height(40)
  10243. .type(ButtonType.Circle)
  10244. .backgroundColor(this.themeColor)
  10245. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  10246. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  10247. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  10248. .margin(5)
  10249. .onClick(() => {
  10250. this.showReNameDialog(item, index + '', filePath)
  10251. })
  10252. Button() {
  10253. Image($r('app.media.delete2'))
  10254. .fillColor(Color.White)
  10255. .width(20)
  10256. }
  10257. .width(40)
  10258. .height(40)
  10259. .type(ButtonType.Circle)
  10260. .backgroundColor(this.themeColor)
  10261. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  10262. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  10263. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  10264. .margin(5)
  10265. .onClick(() => {
  10266. this.showWarnIsDeleteFile(item, index + '', filePath)
  10267. })
  10268. Button() {
  10269. Image($r('app.media.share2'))
  10270. .fillColor(Color.White)
  10271. .width(20)
  10272. }
  10273. .width(40)
  10274. .height(40)
  10275. .type(ButtonType.Circle)
  10276. .backgroundColor(this.themeColor)
  10277. .margin(5)
  10278. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10279. .onClick(() => {
  10280. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  10281. })
  10282. }
  10283. }
  10284. /**
  10285. * 穿山甲banner广告
  10286. */
  10287. // private declare bannerAd: CSJNativeExpressAd;
  10288. // @State private status: string = "未加载"
  10289. // @State private isShowAd: boolean = false
  10290. // private declare mAdSlot: AdSlot;
  10291. // private mBiddingAdm = '' //服务端bidding才需要设置
  10292. // private expressLoadAdListener: NativeExpressAdListener = {
  10293. // /**
  10294. // * 加载失败的回调
  10295. // *
  10296. // * @param code
  10297. // * @param message
  10298. // */
  10299. // onError: (code: number, message: string) => {
  10300. // console.error("加载广告失败,code=" + code + ",message=" + message);
  10301. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  10302. // },
  10303. //
  10304. // /**
  10305. // * 广告加载成功的回调,接入方可以在这个回调中进行渲染
  10306. // *
  10307. // * @param ads 返回的广告列表
  10308. // */
  10309. //
  10310. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  10311. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  10312. // if (ads && ads.length > 0) {
  10313. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  10314. // ad.setExpressInteractionListener({
  10315. // /**
  10316. // *广告的点击回调
  10317. // * @param type 广告的交互类型
  10318. // */
  10319. // onAdClicked: (type: number) => {
  10320. // console.log("BannerExpressAdPage==onAdClicked......");
  10321. // },
  10322. //
  10323. // /**
  10324. // * 广告的展示回调 每个广告仅回调一次
  10325. // * @param type 广告的交互类型
  10326. // */
  10327. // onAdShow: (type: number) => {
  10328. // console.log("BannerExpressAdPage==onAdShow......");
  10329. // },
  10330. //
  10331. // /**
  10332. // * 模板渲染失败
  10333. // */
  10334. // onRenderFail: (code: number, msg: string) => {
  10335. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  10336. // },
  10337. //
  10338. // /**
  10339. // * 模板渲染成功
  10340. // * @param width 返回view的宽 单位 vp
  10341. // * @param height 返回view的高 单位 vp
  10342. // */
  10343. // onRenderSuccess: (width: number, height: number) => {
  10344. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  10345. // this.bannerAd = ad;
  10346. // this.status = "广告加载完成待展示";
  10347. //
  10348. // this.showBannerAd()
  10349. // }
  10350. // })
  10351. // //渲染广告
  10352. // ad.setSlideIntervalTime(30 * 1000); //设置轮播时间长
  10353. // this.setDislikeCallback(ad); //设置dislike
  10354. // ad.render(this.getUIContext())
  10355. // this.status = "广告加载中...";
  10356. // });
  10357. // }
  10358. // }
  10359. // }
  10360. //
  10361. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  10362. // ad.setDislikeCallback({
  10363. // /**
  10364. // * dislike show
  10365. // */
  10366. // onShow: () => {
  10367. // console.log("BannerExpressAdPage==dislike......show");
  10368. // },
  10369. //
  10370. // /**
  10371. // * @param position 选择的位置
  10372. // * @param value 选择的内容
  10373. // * @param enforceRemove 是否强制关闭广告
  10374. // */
  10375. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  10376. // this.isShowAd = false;
  10377. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value +
  10378. // ",enforce=" + enforceRemove);
  10379. // },
  10380. //
  10381. // /**
  10382. // * 点击取消
  10383. // */
  10384. // onCancel: () => {
  10385. // console.log("BannerExpressAdPage==dislike......onCancel");
  10386. // }
  10387. //
  10388. // })
  10389. // }
  10390. /**
  10391. * 加载Banner广告
  10392. */
  10393. loadBannerAd(rit: string) {
  10394. // if (Utility.isNoble()) {
  10395. // return
  10396. // }
  10397. // if (!Utility.isPassInstallTime(2)) {
  10398. // return
  10399. // }
  10400. // this.isShowAd = false;
  10401. // let adCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
  10402. // this.mAdSlot = new AdSlotBuilder()
  10403. // .setCodeId(rit)
  10404. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  10405. // .setAdCount(1)
  10406. // .setBidAdm(this.mBiddingAdm)
  10407. // .build()
  10408. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  10409. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  10410. // this.status = "广告加载中..."
  10411. }
  10412. /**
  10413. * 展示Banner广告
  10414. */
  10415. // showBannerAd() {
  10416. // if (!this.bannerAd) {
  10417. // return
  10418. // }
  10419. // this.isShowAd = true
  10420. // this.status = "已展示"
  10421. // }
  10422. /**
  10423. * 穿山甲广告代码结束
  10424. */
  10425. }
  10426. //视频气泡窗口的布局
  10427. @Builder
  10428. function customPopupBuilder(dataBu: BubbleBean) {
  10429. List() {
  10430. LazyForEach(new LazyDataSource(dataBu.data), (item: string, index: number) => {
  10431. ListItem() {
  10432. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  10433. Row() {
  10434. Column() {
  10435. Image(dataBu.imageRes[index])
  10436. .height(28)
  10437. .fillColor(dataBu.color)
  10438. .alignSelf(ItemAlign.Center)
  10439. }
  10440. .width(32)
  10441. Text(item)
  10442. .padding({
  10443. top: 10,
  10444. bottom: 10,
  10445. right: 10,
  10446. left: 10
  10447. })
  10448. .fontColor(dataBu.modeType == index ? dataBu.color : $r('app.color.index_tab_font_color'))
  10449. .textAlign(TextAlign.Start)
  10450. .width("100%")
  10451. }
  10452. }
  10453. .backgroundColor($r('app.color.settings_background_main'))
  10454. .margin({ top: 6, bottom: 6 })
  10455. }
  10456. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  10457. .animation({ duration: 500, curve: Curve.Ease, delay: 100 * index }),
  10458. TransitionEffect.scale({ x: 0, y: 0 })))
  10459. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  10460. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  10461. .onClick(() => {
  10462. dataBu.onItemClick?.(index)
  10463. })
  10464. })
  10465. }
  10466. .width(120)
  10467. .divider({
  10468. strokeWidth: 1,
  10469. color: "#22FFFFFF"
  10470. })
  10471. }
  10472. // Function to calculate a hash for the file list
  10473. function simpleHash(fileList: string[]): string {
  10474. let hash = 0;
  10475. const str = fileList.join(',');
  10476. for (let i = 0; i < str.length; i++) {
  10477. const char = str.charCodeAt(i);
  10478. hash = (hash << 5) - hash + char;
  10479. hash |= 0; // Convert to 32bit integer
  10480. }
  10481. return hash.toString();
  10482. }
  10483. interface MoreItem {
  10484. id: number;
  10485. image: Resource;
  10486. title: string;
  10487. }
  10488. //视频气泡窗口的布局
  10489. @Builder
  10490. function cutPopupBuilder(dataBu: BubbleBean) {
  10491. Column() {
  10492. Text(dataBu.isCopy ? '将文件复制到' : '将文件移动到')
  10493. .padding({
  10494. top: 10,
  10495. bottom: 10,
  10496. right: 10,
  10497. left: 10
  10498. })
  10499. .textAlign(TextAlign.Start)
  10500. .width(160)
  10501. .fontWeight(666)
  10502. .fontSize(16)
  10503. List() {
  10504. ForEach(dataBu.data, (item: string, index: number) => {
  10505. ListItem() {
  10506. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  10507. Row() {
  10508. Column() {
  10509. Image($r('app.media.music_group'))
  10510. .height(28)
  10511. .fillColor(dataBu.color)
  10512. .alignSelf(ItemAlign.Center)
  10513. }
  10514. .width(32)
  10515. Text(item.startsWith('.') ? item.replace(/\./g, '') : item)
  10516. .padding({
  10517. top: 10,
  10518. bottom: 10,
  10519. right: 10,
  10520. left: 10
  10521. })
  10522. .textAlign(TextAlign.Start).width("100%")// .fontColor(Color.Gray)
  10523. .fontSize(15)
  10524. }
  10525. }
  10526. .backgroundColor(Color.Transparent)
  10527. .margin({ top: 7, bottom: 7 })
  10528. }
  10529. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  10530. .animation({ duration: 500 }),
  10531. TransitionEffect.scale({ x: 0, y: 0 })))
  10532. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  10533. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  10534. .onClick(() => {
  10535. dataBu.onItemClick?.(index)
  10536. })
  10537. })
  10538. }
  10539. .width(150)
  10540. .divider({
  10541. strokeWidth: 1,
  10542. color: "#22FFFFFF"
  10543. })
  10544. }
  10545. .height(300)
  10546. .padding({
  10547. bottom: 30
  10548. })
  10549. }
  10550. function getFileDirName(filePath: string,rootPath:string): string{
  10551. if(filePath===rootPath){
  10552. return '首页'
  10553. }
  10554. let result = FileUtil.getFileName(filePath)
  10555. if(StrUtil.isEmpty(result))
  10556. return ''
  10557. if(result.startsWith('.'))
  10558. result = result.replace(/\./g, '')
  10559. return result
  10560. }