LocalMusic.ets 459 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300
  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 { Playlist } from '../viewmodel/Playlist';
  5. import { LengthMetrics, SegmentButton,borderRadiuses, SegmentButtonOptions } from '@kit.ArkUI';
  6. import {
  7. AppUtil,
  8. ArrayUtil,
  9. Base64Util,
  10. DateUtil,
  11. DeviceUtil,
  12. DisplayUtil,
  13. FileUtil,
  14. ImageUtil,
  15. LogUtil,
  16. MD5,
  17. PreferencesUtil,
  18. RandomUtil,
  19. StrUtil,
  20. ToastUtil
  21. } from '@pura/harmony-utils';
  22. import { imagePathToPixelMap } from '../common/util/CommUtils';
  23. import { unifiedDataChannel, uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
  24. import { CommonConstants } from '../common/constants/CommonConstants';
  25. import { EventConstants } from '../common/constants/EventConstants';
  26. import Logger from '../common/util/Logger';
  27. import { photoAccessHelper } from '@kit.MediaLibraryKit';
  28. import { BusinessError, emitter } from '@kit.BasicServicesKit';
  29. import { BubbleBean } from '../viewmodel/BubbleBean';
  30. import { PopupPosition, XPopup } from '@chinalike/popup';
  31. import { common, ConfigurationConstant } from '@kit.AbilityKit';
  32. import { AnimationHelper, DialogAction, DialogHelper } from '@pura/harmony-dialog';
  33. import { fileIo, fileUri, picker } from '@kit.CoreFileKit';
  34. import { MessageEvents, util, worker, ErrorEvent } from '@kit.ArkTS';
  35. import { Verify } from './Verify';
  36. import { taskpool } from '@kit.ArkTS';
  37. import { RotatingCover } from './RotatingCover';
  38. import { PlayConstants } from '../common/constants/PlayConstants';
  39. import { effectKit } from '@kit.ArkGraphics2D';
  40. import { ColorConversion } from '../common/util/ColorConversion';
  41. import { LyricController, LyricParser, LyricView2 } from '@seagazer/cclyric';
  42. import { AvSessionController } from '../controller/AvSessionController';
  43. import { repairAudioMetadata, convertDsfToWav, getApiLyric,changeMusicCover} from '../common/util/MusicTagUtils';
  44. import { FFMpegTags,Utility } from '../common/util/Utility';
  45. import { TagsContentCover } from '../view/TagsContentCover';
  46. import { ImageFancyModifier } from '../common/util/AttributeModifierUtil'
  47. import {
  48. // DeviceChangeReason,
  49. IjkMediaPlayer,
  50. InterruptEvent,
  51. InterruptHintType,
  52. LogUtils,
  53. OnBufferingUpdateListener,
  54. OnCompletionListener,
  55. OnErrorListener,
  56. OnInfoListener,
  57. OnPreparedListener,
  58. OnSeekCompleteListener,
  59. OnTimedTextListener,
  60. OnVideoSizeChangedListener
  61. } from '@ohos/ijkplayer';
  62. import { PlayStatus } from '../common/PlayStatus';
  63. import fs from '@ohos.file.fs';
  64. import { image } from '@kit.ImageKit';
  65. import { AVCastPicker, AVCastPickerState, AVCastPickerStyle, avSession } from '@kit.AVSessionKit';
  66. import { UniversalDetector } from '@ohos/juniversalchardet';
  67. import { SettingPage } from '../pages/SettingPage';
  68. import { secondToTime,getTransverterText } from '../common/util/CommUtils';
  69. import { CommonConstants2 } from '../common/util/CommonConstants2';
  70. import { hilog } from '@kit.PerformanceAnalysisKit';
  71. import { LazyDataSource } from '../common/util/LazyDataSource';
  72. import MediaTable from '../common/util/MediaTable';
  73. import NetAxiosUtil from '../common/util/NetAxiosUtil';
  74. import ImageUtils from '../common/util/ImageUtils';
  75. import { ringtone } from '@kit.RingtoneKit';
  76. import { BreakpointType, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
  77. import { resourceManager } from '@kit.LocalizationKit';
  78. import { deviceInfo } from '@kit.BasicServicesKit';
  79. import { HSBColorPicker, HSBColorPickerLayout } from '@keke/color-picker'
  80. import app from '@system.app';
  81. import { TextNodeController } from './PipLyricTextBuilder';
  82. import { IndexerView } from './IndexerView';
  83. import { KeyCode } from '@kit.InputKit';
  84. import { KnockController } from '../controller/KnockController';
  85. import { DeleteComptent } from '../view/DeleteComptent';
  86. import { ABLoopComptent } from '../view/ABLoopComptent';
  87. import { FixMessyView } from '../view/FixMessyView';
  88. import { parseCueFile,CueTrack,CueInfo } from '../common/util/CueUtils';
  89. import { CueComptent } from '../view/CueComptent';
  90. import PlaylistTable from '../common/util/PlaylistTable';
  91. import { showAddToPlaylistDialog } from '../dialog/AddToPlaylistDialog';
  92. import { showCreatePlaylistDialog } from '../dialog/PlaylistDialog';
  93. const TAG = 'LocalMusic';
  94. /**
  95. * 歌单播放事件数据
  96. */
  97. interface PlaylistEventData {
  98. playlistId: string;
  99. playlistName: string;
  100. songCount: number;
  101. startIndex: number;
  102. songFilePaths: string[];
  103. }
  104. const DEFAULT_INDEX =
  105. ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  106. 'X', 'Y', 'Z']
  107. //排序类型
  108. function getTypeOrder(type: number) {
  109. switch (type) {
  110. case CommonConstants.TYPE_IS_DIR:
  111. return 1; // First
  112. case CommonConstants.TYPE_IS_CSJAD:
  113. return 2; // Middle
  114. case CommonConstants.TYPE_LOCAL:
  115. return 3; // Last
  116. default:
  117. return 4; // Unknown types, if any, go last
  118. }
  119. }
  120. const workerInstance = new worker.ThreadWorker("entry/ets/workers/Worker.ets");
  121. // 定义接口
  122. interface HiCarAspectRatio {
  123. ratio: number;
  124. name: string;
  125. }
  126. interface GeneratedObjectLiteralInterface_1 {
  127. assetId: string;
  128. title: string;
  129. artist: string;
  130. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  131. mediaUri: string;
  132. // 该字段大写,音频'AUDIO',视频'VIDEO'
  133. mediaType: string;
  134. mediaSize: number;
  135. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  136. startPosition: number;
  137. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  138. duration: number;
  139. albumCoverUri: string;
  140. albumTitle: string;
  141. appName: string;
  142. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  143. drmScheme: string;
  144. }
  145. const ITEM_HEIGHT_SMALL: number = 48; // 列表项小高度
  146. const ITEM_HEIGHT: number = 58; // 列表项中高度
  147. const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
  148. //功能强大的音乐播放器
  149. @Preview
  150. @Component
  151. export struct LocalMusic {
  152. @Consume currentSongList: Array<VideoItem>//当前歌单
  153. @Consume currentSongListName:string //当前歌单名称
  154. @Consume @Watch('onIDChange') currentSongListID:string //当前歌单ID
  155. @State mediaKuCount: number = 0;
  156. @State albumCount: number = 0;
  157. @State artistCount: number = 0;
  158. @State fastForwardSeconds: string = '10'
  159. @State isShowBackFast: boolean = true//快进快退按钮
  160. @State isCanAuto:boolean = true
  161. @State opacityValueImage: number = 1;
  162. @State tipPopup:boolean = false
  163. @Consume mType: number;
  164. @StorageProp('themeColor') themeColor: string =
  165. PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  166. themeMode: number = 0;
  167. @State titleName: string = '首页'
  168. @State textStr: string = ''
  169. // static readonly STR_MUSIC_VIDEO: string = 'Audios';
  170. // private download_path: string = '';
  171. @Consume rootPath: string //音频根目录
  172. @Consume currentPath: string
  173. static readonly STR_LOCK_VIDEO: string = '.私密音频';
  174. static readonly STR_FAC_VIDEO: string = '.我的收藏';
  175. @State lockPath: string = ''
  176. @State favPath: string = ''
  177. static readonly STR_HISTORY_MUSIC: string = '.最近播放';
  178. @State historyPath: string = ''
  179. @State historyList: Array<VideoItem> = []
  180. @Consume isHistory: boolean
  181. static readonly HISTORY_MUSIC: string = 'music_historyList';
  182. private table: MediaTable = new MediaTable(getContext(this))
  183. private playlistTable: PlaylistTable | null = null
  184. @State allPlaylists: Playlist[] = []
  185. @State isZero: boolean = false
  186. @State fileList: Array<string> = []
  187. @State dirList: Array<VideoItem> = []
  188. @Consume videoLocalList: Array<VideoItem>
  189. @State dataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.videoLocalList)
  190. @State mediaKuList: Array<VideoItem> = []; //媒体库文件
  191. @State artistList: Array<VideoItem> = []; //艺术家文件
  192. @State artistMap: Map<string, VideoItem[]> = new Map(); //艺术家Map
  193. @State albumList: Array<VideoItem> = []; //专辑文件
  194. @State albumMap: Map<string, VideoItem[]> = new Map(); //专辑Map
  195. private mScrollMap: Map<string, number> = new Map(); // 艺术家、专辑名->滚动index
  196. @State imageOpacities: number[] = [];
  197. @Consume isCanBack: boolean
  198. @Consume @Watch('onModeChange') modeType: number; // 0首页,1媒体库,2艺术家,3专辑
  199. @State showSingleLyric: boolean = false
  200. @State sortType: number = 4 //默认排序方式
  201. @State isShowSimi: boolean = false //是否显示私密音频
  202. @State isShowFAV: boolean = true //是否显示我的收藏
  203. @State isShowTitleBar: boolean = true //是否显示分类导航条
  204. @State isShowAllBar: boolean = true //是否显示播放全部条
  205. @State isShowSingleLineLyric: boolean = false //是否显示单行歌词
  206. @State isShowHistory: boolean = true //是否显示最近播放
  207. @State @Watch('onColorModeChange') isCustomizeBg: boolean = false //自定义背景界面
  208. @State isGridMusic: boolean = false //是否网格布局
  209. @State isCircleBtn: boolean = false //是否圆形播放按钮
  210. @State twoFingerType: number = 3 //双支放大缩小的类型
  211. @State isScrollHide: boolean = false //是否滚动隐藏
  212. @State isSameTimePlay: boolean = false //是否和其他app同时播放
  213. @State isStartAutoPlay: boolean = false //启动后自动播放
  214. @State isShowPlayPageBack: boolean = false //是否显示播放页返回键
  215. @State isShowHeader: boolean = true
  216. @State isPlayListBgGrass: boolean = true //是否播放列表玻璃透明效果
  217. @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
  218. @State isCoverTopBig: boolean = false //顶部大封面部分手机显示会和播放控制页重叠
  219. @State isSwipe: boolean = false //listItem的左滑开关
  220. @State openSkipSongAnimate: boolean = true//切歌动画效果
  221. @State customizeBgPath: string | undefined = '';
  222. @State isDarkMode: boolean = false
  223. @State lyricTextWeight: number = 400
  224. @State lyricTextWeightPip: number = 400
  225. @State currentSwiperIndex: number = 0
  226. @State blurValue: number = 0 //背景模糊
  227. @State bgBrightness: number = 0 //背景亮度
  228. private listScroller: ListScroller = new ListScroller()
  229. private playListScroller: Scroller = new Scroller()
  230. @State isOneKeyTags:boolean = false
  231. @State isFixMessy:boolean = false
  232. @StorageProp('isLandscape') @Watch('onIsLandscapeChange') isLandscape: boolean = false;
  233. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  234. @StorageProp('windowWidth') windowWidth: number = 0;
  235. @StorageProp('windowHeight') windowHeight: number = 0;
  236. @StorageProp('isHiCarStatus') isHiCarStatus: boolean = false;
  237. @StorageProp('curDisplayIsHiCar') curDisplayIsHiCar: boolean = false;
  238. private UNKONWN:string = '';
  239. private listArea: Area = {
  240. width: 0,
  241. height: 0,
  242. position: {},
  243. globalPosition: {}
  244. }
  245. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  246. ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET;
  247. //瀑布流的列数横竖屏动态切换
  248. onIsLandscapeChange() {
  249. if(this.isLandscape){
  250. this.columns = 4
  251. }else{
  252. this.columns = PreferencesUtil.getNumberSync('lastColumns', 2);
  253. }
  254. }
  255. onColorModeChange() {
  256. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  257. if (this.isCustomizeBg) {
  258. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  259. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  260. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  261. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  262. this.tabOptions.selectedBackgroundColor = Color.Transparent
  263. } else {
  264. if (!this.isDarkMode) {
  265. this.titleBarModel.setTitleBarBackground(this.themeColor)
  266. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  267. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  268. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  269. this.tabOptions.selectedBackgroundColor = this.themeColor
  270. } else {
  271. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  272. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  273. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  274. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  275. this.tabOptions.selectedBackgroundColor = $r('app.color.silvery')
  276. }
  277. }
  278. }
  279. //歌单id发生变化的时候回调
  280. onIDChange(){
  281. if(this.modeType==4){
  282. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  283. this.updateListData(this.currentSongList, true)
  284. this.titleBarModel.setTitleName(this.currentSongListName)
  285. this.isShowTitleBar = false
  286. }
  287. }
  288. onModeChange() {
  289. this.isFavMusic = false
  290. if (this.modeType === 2 || this.modeType === 3) {
  291. this.titleBarModel.setRightIcon(null)
  292. } else {
  293. this.titleBarModel.setRightIcon(($r('app.media.add')))
  294. }
  295. LogUtil.info('onecold onModeChange = ' + this.modeType)
  296. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
  297. switch (this.modeType) {
  298. case 0:
  299. this.getSortedFiles(this.currentPath)
  300. break
  301. case 1:
  302. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  303. this.updateListData(this.mediaKuList)
  304. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  305. break
  306. case 2:
  307. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  308. this.updateListData(this.artistList)
  309. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  310. break
  311. case 3:
  312. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  313. this.updateListData(this.albumList)
  314. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  315. break
  316. case 4://歌单
  317. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  318. this.updateListData(this.currentSongList, true)
  319. this.titleBarModel.setTitleName(this.currentSongListName)
  320. this.isShowTitleBar = false
  321. break
  322. }
  323. }
  324. @StorageLink('currentSong') currentSong: VideoItem | undefined = undefined;
  325. // @StorageLink('isPlay') isPlay: boolean = false;
  326. @StorageLink('isShowPlay') isShowPlay: boolean = false;
  327. @StorageLink('songList') songList: Array<VideoItem> = [];
  328. @State translateY: number = 0;
  329. @State isShowSheet: boolean = false;
  330. @State isShowSheetView: boolean = false;
  331. @State isShowTimeCloseView: boolean = false;
  332. private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Vertical });
  333. @StorageLink('currIndex') curIndex: number = 0;
  334. @Consume isShowDrawer: boolean;
  335. @Consume offsetX: number;
  336. @State isFac: boolean = false;
  337. @State favList: Array<VideoItem> = []
  338. @Consume isFavMusic: boolean
  339. @State isClickedPLayAll: boolean = false;
  340. private scrollerForlist: ListScroller = new ListScroller();
  341. private knockController: KnockController | undefined = undefined;
  342. imagesF: ImageFrameInfo[] = [
  343. { src: $r("app.media.app_loading0") },
  344. { src: $r("app.media.app_loading1") },
  345. { src: $r("app.media.app_loading2") },
  346. { src: $r("app.media.app_loading3") },
  347. ]
  348. @State animationState: AnimationStatus = AnimationStatus.Initial
  349. // 缓存机制
  350. private cache: Map<string, Array<VideoItem>> = new Map();
  351. private stringCache: Map<string, string> = new Map(); // 新增字符串缓存
  352. // 持久化缓存
  353. private async saveCacheToStorage() {
  354. const cacheArray = Array.from(this.cache.entries());
  355. const stringCacheArray = Array.from(this.stringCache.entries());
  356. await PreferencesUtil.putSync('music_cache', JSON.stringify(cacheArray));
  357. await PreferencesUtil.putSync('music_string_cache', JSON.stringify(stringCacheArray));
  358. }
  359. // 载入缓存
  360. private async loadCacheFromStorage() {
  361. const cacheString = await PreferencesUtil.getStringSync('music_cache', '');
  362. const stringCacheString = await PreferencesUtil.getStringSync('music_string_cache', ''); // 载入字符串缓存
  363. if (cacheString) {
  364. const cacheArray: [string, Array<VideoItem>][] = JSON.parse(cacheString);
  365. this.cache = new Map(cacheArray);
  366. }
  367. if (stringCacheString) {
  368. const stringCacheArray: [string, string][] = JSON.parse(stringCacheString);
  369. this.stringCache = new Map(stringCacheArray);
  370. }
  371. }
  372. // 查找缓存
  373. private findCache(key: string): Array<VideoItem> | undefined {
  374. return this.cache.get(key);
  375. }
  376. // 查找字符串缓存
  377. private findStringCache(key: string): string | undefined {
  378. return this.stringCache.get(key);
  379. }
  380. // 添加缓存
  381. private addCache(key: string, value: Array<VideoItem>) {
  382. this.cache.set(key, value);
  383. }
  384. // 添加字符串缓存
  385. private addStringCache(key: string, value: string) {
  386. this.stringCache.set(key, value);
  387. }
  388. // 删除缓存
  389. private deleteCache(key: string) {
  390. this.cache.delete(key);
  391. this.saveCacheToStorage()
  392. }
  393. // 删除字符串缓存
  394. private deleteStringCache(key: string) {
  395. this.stringCache.delete(key);
  396. }
  397. // 多选机制
  398. @State selectedFiles: Array<VideoItem> = [];
  399. @State isMultiSelect: boolean = false;
  400. @State isAllSelected: boolean = false;
  401. @State appName: string = ''
  402. @State isHasDir: boolean = false
  403. @State packName: string = ''
  404. context = this.getUIContext().getHostContext() as common.UIAbilityContext
  405. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  406. .setTitleTextStyle(FontStyle.Normal)
  407. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  408. .setLeftIcon($r('app.media.menu'))
  409. .setLeftIconWidth(26)
  410. .setLeftIconHeight(26)
  411. .setTitleName('首页')
  412. .setTitleFontSize(18)
  413. .setTitleFontColor(Color.White)
  414. .setTitleBarBackground(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  415. .setTitleBarBottomLineColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  416. .setLeftTitleStateNormalStyleColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  417. .setRightIcon($r('app.media.add'))
  418. .setOnRightClickListener(() => {
  419. this.showSheelDialog()
  420. })
  421. // .setOnTitleClickListener(() => {
  422. // this.showPupDialog()
  423. // })
  424. .setOnLeftClickListener(() => {
  425. this.doSwipBack()
  426. })
  427. doSwipBack() {
  428. this.isZero = false
  429. if (this.modeType !== 0 && this.isCanBack) {
  430. this.onModeChange()
  431. this.isCanBack = false
  432. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  433. // 返回专辑列表时恢复滚动偏移量,支持列表和网格
  434. setTimeout(() => {
  435. if (this.modeType == 2) {
  436. if (this.isGridMusic||this.twoFingerType==4) {
  437. let lastOffset = this.mScrollMap.get('lastGridArtistScrollOffset') ?? 0
  438. let lastWaterOffset = this.mScrollMap.get('lastWaterArtistScrollOffset') ?? 0
  439. if(this.twoFingerType==4){
  440. this.waterScroller.scrollTo({ xOffset: 0, yOffset: lastWaterOffset })
  441. }else{
  442. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  443. }
  444. } else {
  445. let lastOffset = this.mScrollMap.get('lastListArtistScrollOffset') ?? 0
  446. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  447. }
  448. } else if (this.modeType == 3) {
  449. if (this.isGridMusic||this.twoFingerType==4) {
  450. let lastOffset = this.mScrollMap.get('lastGridAlBumScrollOffset') ?? 0
  451. let lastWaterOffset = this.mScrollMap.get('lastWaterAlBumScrollOffset') ?? 0
  452. if(this.twoFingerType==4){
  453. this.waterScroller.scrollTo({ xOffset: 0, yOffset: lastWaterOffset })
  454. }else{
  455. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  456. }
  457. } else {
  458. let lastOffset = this.mScrollMap.get('lastListAlBumScrollOffset') ?? 0
  459. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  460. }
  461. }
  462. }, 200)
  463. return
  464. }
  465. if (this.isHistory || this.isFavMusic) {
  466. this.isHistory = false
  467. this.getSortedFiles(this.currentPath)
  468. return
  469. }
  470. if (this.currentPath === this.rootPath || this.modeType !== 0) {
  471. animateTo({ duration: 555 }, () => {
  472. // 动画闭包内控制Image组件的出现和消失
  473. this.isShowDrawer = !this.isShowDrawer
  474. this.offsetX = 0
  475. })
  476. return
  477. }
  478. //返回上一级歌单的滚动位置
  479. setTimeout(() => {
  480. if (this.modeType == 0) {
  481. if (this.isGridMusic||this.twoFingerType==4) {
  482. let lastOffset = this.mScrollMap.get('lastGridDirScrollOffset') ?? 0
  483. let lastWaterOffset = this.mScrollMap.get('lastWaterDirScrollOffset') ?? 0
  484. if(this.twoFingerType==4){
  485. this.waterScroller.scrollTo({ xOffset: 0, yOffset: lastWaterOffset })
  486. }else{
  487. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  488. }
  489. } else {
  490. let lastOffset = this.mScrollMap.get('lastListDirScrollOffset') ?? 0
  491. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  492. }
  493. }
  494. }, 300)
  495. this.currentPath = Utility.getParentDirectory(this.currentPath)
  496. Logger.info('this.currentPath2 = ' + this.currentPath)
  497. this.getSortedFiles(this.currentPath)
  498. }
  499. // 组件生命周期
  500. aboutToAppear() {
  501. // 初始化 PlaylistTable
  502. this.playlistTable = new PlaylistTable(getContext(this))
  503. this.sonTwoFingerType = PreferencesUtil.getNumberSync('sonTwoFingerType', 3);
  504. this.columns = PreferencesUtil.getNumberSync('lastColumns', 2);
  505. if(PreferencesUtil.getBooleanSync('isFirstTiped',true)){
  506. this.tipPopup = !this.tipPopup
  507. PreferencesUtil.putSync('isFirstTiped',false)
  508. }
  509. this.initSetting()
  510. this.UNKONWN = Utility.resourceToString(this.context, $r('app.string.unknown'));
  511. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  512. Utility.getAppName(getContext(this)).then((appName: string) => {
  513. this.appName = appName
  514. })
  515. this.packName = AppUtil.getBundleName()
  516. this.tabSelectedIndexes[0] = this.modeType//SegmentButton的索引
  517. this.loadCacheFromStorage(); // 加载文件夹缓存
  518. // 在首页初始化时读取媒体库,艺术家,专辑等缓存数据
  519. this.initLoadCache()
  520. this.mkDownLoadDir()
  521. let eventMusic: emitter.InnerEvent = { eventId: EventConstants.EVENT_AUDIO_OPEN }
  522. // 监听广播事件(打开其他应用处理)
  523. emitter.on(eventMusic, (eventData: emitter.EventData) => {
  524. this.saveVideoDatas([eventData.data?.message], true)
  525. });
  526. //侧滑广播接收时间
  527. let eventUpdateSwipeBack: emitter.InnerEvent = { eventId: EventConstants.EVENT_SWIPE_BACK_UPDATE }
  528. // 监听广播事件(打开其他应用处理)
  529. emitter.on(eventUpdateSwipeBack, (eventData: emitter.EventData) => {
  530. animateTo({ duration: 555 }, () => {
  531. this.doSwipBack()
  532. })
  533. });
  534. //ScanFilePage广播接收时间
  535. let eventScanUpdate: emitter.InnerEvent = { eventId: EventConstants.EVENT_SCAN_UPDATE }
  536. // 监听ScanFilePage广播事件(更新数据库)
  537. emitter.on(eventScanUpdate, (eventData: emitter.EventData) => {
  538. this.doUpdateData()
  539. });
  540. // 监听歌单播放请求事件
  541. let eventPlaylistPlay: emitter.InnerEvent = { eventId: EventConstants.EVENT_PLAYLIST_PLAY }
  542. emitter.on(eventPlaylistPlay, (eventData: emitter.EventData) => {
  543. Logger.info('heanup eventPlaylistPlay received - full eventData: ' + JSON.stringify(eventData))
  544. Logger.info('heanup eventPlaylistPlay received - eventData.data: ' + JSON.stringify(eventData.data))
  545. const data = eventData.data as Record<string, Object>
  546. if (!data) {
  547. Logger.error('heanup eventPlaylistPlay: eventData.data is undefined or null')
  548. return
  549. }
  550. // 检查歌单播放数据结构
  551. if (data.playlistId && data.songFilePaths && data.startIndex !== undefined) {
  552. Logger.info('heanup eventPlaylistPlay: 接收到歌单播放数据')
  553. // 手动构建数据对象以避免类型转换问题
  554. const playlistData: PlaylistEventData = {
  555. playlistId: data.playlistId as string,
  556. playlistName: data.playlistName as string,
  557. songCount: data.songCount as number,
  558. startIndex: data.startIndex as number,
  559. songFilePaths: data.songFilePaths as string[]
  560. }
  561. // 根据文件路径重新构建歌曲列表
  562. this.handlePlaylistPlayRequest(
  563. playlistData.playlistId,
  564. playlistData.playlistName,
  565. playlistData.songFilePaths,
  566. playlistData.startIndex
  567. )
  568. return
  569. }
  570. Logger.error('heanup eventPlaylistPlay: 接收到无效的数据结构')
  571. });
  572. let eventSetting: emitter.InnerEvent = { eventId: EventConstants.EVENT_SETTING_UPDATE }
  573. // 监听广播事件(通用设置配置更新)
  574. emitter.on(eventSetting, (eventData: emitter.EventData) => {
  575. this.doChangeSetting()
  576. });
  577. let event: Callback<InterruptEvent> = (event) => {
  578. // LogUtils.getInstance().LOGI(`onecold 与其他应用音频冲突 被截断点event: ${JSON.stringify(event)}`);
  579. console.info(`onecold 与其他应用音频冲突 被截断点event: ${JSON.stringify(event)}`)
  580. this.savePlaybackPosition()
  581. if (event.hintType === InterruptHintType.INTERRUPT_HINT_PAUSE) {
  582. this.pause();
  583. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_RESUME) {
  584. console.info(`onecold audioInterrupt startPlayOrResumePlay: ${JSON.stringify(event)}`)
  585. console.info('onecold startPlayOrResumePlay 514')
  586. this.startPlayOrResumePlay();
  587. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_STOP) {
  588. this.stop();
  589. }
  590. }
  591. this.mIjkMediaPlayer.on('audioInterrupt', event);
  592. // 音频设备断连回调处理
  593. // let deviceChangeEvent: Callback<InterruptEvent> = (event) => {
  594. // LogUtils.getInstance().LOGI(`Heanup deviceChange event: ${JSON.stringify(event)}`);
  595. // if (event.reason === DeviceChangeReason.REASON_OLD_DEVICE_UNAVAILABLE) { // 音频设备断开连接
  596. // this.pause();
  597. // }
  598. // }
  599. // this.mIjkMediaPlayer.on('deviceChange', deviceChangeEvent);
  600. this.makeWorker()
  601. //折叠屏的屏幕显示模式变化
  602. display.on('foldDisplayModeChange', (data) => {
  603. this.doChangeBarHeight()
  604. });
  605. display.on('foldStatusChange', (data) => {
  606. Logger.info('onecold foldStatusChange ')
  607. });
  608. this.isCoverRectangle = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_RECTANGLE, true)
  609. // 读取 themeMode 并同步 currentColorMode
  610. this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
  611. this.applyThemeMode(this.themeMode)
  612. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  613. AppStorage.setOrCreate('themeColor', themeColor);
  614. this.themeColor = themeColor;
  615. this.doChangeSetting()
  616. this.windowClass.on('windowSizeChange', (size) => {
  617. LogUtil.info('onecold windowSizeChange')
  618. this.doChangeBarHeight()
  619. let viewWidth = px2vp(size.width);
  620. let viewHeight = px2vp(size.height);
  621. if(this.isPhoneLan()){
  622. this.is_auto_hide_progress = false
  623. if(this.isHiCar()){
  624. return
  625. }
  626. setTimeout(() => {
  627. this.is_auto_hide_progress = true
  628. }, 6000)
  629. }else{
  630. this.startAutoHide()
  631. }
  632. });
  633. this.eventHub.on('onStateChange', (fg: boolean) => {
  634. if (fg && this.curState === 'STARTED') {
  635. this.stopPip();
  636. }
  637. });
  638. }
  639. //载入媒体库,艺术家,专辑等缓存
  640. initLoadCache(){
  641. this.mediaKuCount = PreferencesUtil.getNumberSync('mediaKuCount', 0)
  642. this.artistCount = PreferencesUtil.getNumberSync('artistCount', 0)
  643. this.albumCount = PreferencesUtil.getNumberSync('albumCount', 0)
  644. let cachedListStr:string = PreferencesUtil.getStringSync('mediaKuList', '[]');
  645. let cachedList = JSON.parse(cachedListStr) as Array<VideoItem>;
  646. if(ArrayUtil.isNotEmpty(cachedList)){
  647. this.mediaKuList = cachedList
  648. if(this.modeType==1){
  649. this.updateListData(this.mediaKuList)
  650. }
  651. }
  652. let artistListStr:string = PreferencesUtil.getStringSync('artistList', '[]');
  653. let artistCachedList = JSON.parse(artistListStr) as Array<VideoItem>;
  654. if(ArrayUtil.isNotEmpty(artistCachedList)){
  655. this.artistList = artistCachedList
  656. let artistMapStr:string = PreferencesUtil.getStringSync('artistMap', '[]');
  657. const parsedArray = JSON.parse(artistMapStr) as [string, VideoItem[]][];
  658. this.artistMap = new Map(parsedArray);
  659. // this.artistMap = JSON.parse(artistMapStr) as Map<string, VideoItem[]>;
  660. if(this.modeType==2){
  661. this.updateListData(this.artistList)
  662. }
  663. }
  664. let albumListStr:string = PreferencesUtil.getStringSync('albumList', '[]');
  665. let albumCachedList = JSON.parse(albumListStr) as Array<VideoItem>;
  666. if(ArrayUtil.isNotEmpty(albumCachedList)){
  667. this.albumList = albumCachedList
  668. let albumMapStr:string = PreferencesUtil.getStringSync('albumMap', '[]');
  669. const parsedArray = JSON.parse(albumMapStr) as [string, VideoItem[]][];
  670. this.albumMap = new Map(parsedArray);
  671. if(this.modeType==3){
  672. this.updateListData(this.albumList)
  673. }
  674. }
  675. }
  676. startAutoHide() {
  677. if(this.isHiCar()){
  678. return
  679. }
  680. if(PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_HIDE_PROGRESS,false)){
  681. console.info('onecold startAutoHide')
  682. this.is_auto_hide_progress = false
  683. setTimeout(() => {
  684. this.is_auto_hide_progress = true
  685. }, 6000)
  686. }
  687. }
  688. applyThemeMode(mode: number) {
  689. let colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET
  690. if (mode === 1) {
  691. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
  692. } else if (mode === 2) {
  693. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  694. }
  695. AppStorage.setOrCreate('currentColorMode', colorMode)
  696. AppStorage.setOrCreate('isDarkMode', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK)
  697. PreferencesUtil.putSync(SettingPage.THEME_MODE, mode)
  698. AppStorage.setOrCreate('themeMode', mode)
  699. this.isDarkMode = colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  700. // 只有强制浅色/深色时才主动设置
  701. const context = getContext(this) as common.UIAbilityContext
  702. context.getApplicationContext().setColorMode(colorMode)
  703. }
  704. initSetting() {
  705. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  706. this.isCustomizeBg = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
  707. this.customizeBgPath = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
  708. this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, false)
  709. this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
  710. this.isSameTimePlay = PreferencesUtil.getBooleanSync(SettingPage.IS_SAMETIME_PLAY, false)
  711. this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
  712. this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
  713. this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
  714. this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
  715. this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
  716. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
  717. this.isShowAllBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_ALLBAR, true)
  718. this.twoFingerType = PreferencesUtil.getNumberSync(SettingPage.TWO_FINGER_TYPE, 3)
  719. this.isCoverTop = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP, true)
  720. this.isCircleBtn = PreferencesUtil.getBooleanSync(SettingPage.IS_CIRCLE_BTN, true)
  721. this.isShowPlayPageBack = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_PLAYPAGE_BACK, true)
  722. this.isCoverTopBig = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP_BIG, false)
  723. this.isShowSingleLineLyric = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SLLYRIC, false)
  724. this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
  725. this.isPlayListBgGrass = PreferencesUtil.getBooleanSync(SettingPage.IS_PLAYLIST_BG_GRASS, true)
  726. this.isShowHeader = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HEADER, true)
  727. this.volume = PreferencesUtil.getNumberSync('DefalutVolume', this.volume)
  728. this.isSwipe = PreferencesUtil.getBooleanSync(SettingPage.IS_SWIPE, true)
  729. this.openSkipSongAnimate = PreferencesUtil.getBooleanSync(SettingPage.OPEN_SKIPSONG_ANIMATE, true)
  730. this.volumeSmall = PreferencesUtil.getBooleanSync('volumeSmall', false)
  731. this.autoParseMusicName = PreferencesUtil.getBooleanSync('autoParseMusicName', true)
  732. this.isShowFileName = PreferencesUtil.getBooleanSync('isShowFileName', false)
  733. this.isLongNameRoLL = PreferencesUtil.getBooleanSync('isLongNameRoLL', true)
  734. this.fastForwardSeconds = PreferencesUtil.getStringSync('fastForwardSeconds', '10')
  735. this.isShowBackFast = PreferencesUtil.getBooleanSync('isShowBackFast', false)
  736. if(this.volumeSmall){
  737. this.volume = 0.5
  738. }else{
  739. this.volume = 1
  740. }
  741. //如果是hicar连接状态,这些都是false
  742. if(this.isHiCar()){
  743. this.isShowTitleBar = false//不显示导航栏
  744. this.columns=4
  745. if(!(this.windowWidth>1800&&this.windowHeight>=1200))//小屏幕不可以Grid
  746. {
  747. this.isShowHeader = false//二级菜单不显示头部
  748. this.isGridMusic= false//用list不用网格
  749. this.isCoverTopBig = false
  750. }
  751. this.isShowPlayPageBack = true //播放页返回键要显示,方便驾驶员操作
  752. }
  753. if (this.isSavePlayMode) {
  754. this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
  755. }
  756. if (this.isCustomizeBg) {
  757. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  758. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  759. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  760. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  761. } else {
  762. if (!this.isDarkMode) {
  763. this.titleBarModel.setTitleBarBackground(this.themeColor)
  764. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  765. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  766. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  767. } else {
  768. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  769. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  770. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  771. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  772. }
  773. }
  774. }
  775. doChangeSetting() {
  776. this.initSetting()
  777. this.deleteCache(this.currentPath)
  778. if (this.modeType === 0) {
  779. this.getSortedFiles(this.currentPath)
  780. }
  781. }
  782. doChangeBarHeight() {
  783. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  784. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  785. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  786. this.setBarHeightNormal()
  787. }
  788. }
  789. onPageShow() {
  790. this.knockController?.immersiveListening();
  791. app.setImageCacheCount(100);
  792. // 设置解码前图片数据内存缓存上限为100MB (100MB=100*1024*1024B=104857600B)
  793. app.setImageRawDataCacheSize(104857600);
  794. Logger.info('onecold onPageShow currentBreakpoint= ' + this.currentBreakpoint)
  795. }
  796. //开启线程查看各个数据库
  797. makeWorker() {
  798. setTimeout(() => {
  799. if (PreferencesUtil.getBooleanSync('isFirstApp', true)) {
  800. ToastUtil.showToast('请到文件扫描页面导入音乐!')
  801. //发送worker通知扫描文件入库,用户反馈4000多首用这个方法扫描会闪退。
  802. // workerInstance.postMessage({
  803. // code: 1,
  804. // data1: this.context,
  805. // data2: this.rootPath,
  806. // data3: this.lockPath,
  807. // data4: PreferencesUtil.getStringSync('COVER_API', ''),
  808. // data5: PreferencesUtil.getBooleanSync('autoParseMusicName', true),
  809. // });
  810. PreferencesUtil.putSync('isFirstApp', false)
  811. } else {
  812. workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
  813. workerInstance.postMessage({ code: 3, data: this.context });
  814. workerInstance.postMessage({ code: 4, data: this.context });
  815. this.getHistoryList(false)
  816. }
  817. }, 1000)
  818. workerInstance.onmessage = (e: MessageEvents): void => {
  819. switch (e.data.code) {
  820. case 101: //第一次扫描文件夹入库
  821. ToastUtil.showToast('刷新同步数据库成功!')
  822. Logger.info('onecold 扫描数据库结束 this.mediaKuList length= ' + this.mediaKuList.length)
  823. this.doUpdateData()
  824. break;
  825. case 102: //查询媒体库列表
  826. this.mediaKuList = e.data.data
  827. Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
  828. Utility.doSortListAscending(this.mediaKuList)
  829. // AppStorage.setOrCreate('mediaKuList', this.mediaKuList);
  830. if (this.modeType === 1) {
  831. this.updateListData(this.mediaKuList)
  832. }
  833. PreferencesUtil.putSync('mediaKuCount', this.mediaKuList.length)
  834. // 处理媒体库前100条记录,列表长度并存储到PreferencesUtil
  835. if (ArrayUtil.isNotEmpty(this.mediaKuList)&&this.mediaKuList.length > 100) {
  836. // 只保存前100条记录到缓存中
  837. let truncatedList = this.mediaKuList.slice(0, 100);
  838. PreferencesUtil.putSync('mediaKuList', JSON.stringify(truncatedList));
  839. } else {
  840. PreferencesUtil.putSync('mediaKuList', JSON.stringify(this.mediaKuList));
  841. }
  842. break;
  843. case 103: //收到查询艺术家列表
  844. this.artistMap = e.data.data1;
  845. this.artistList = e.data.data2;
  846. PreferencesUtil.putSync('artistCount', this.artistList.length)
  847. // 处理艺术家前100条记录,列表长度并存储到PreferencesUtil
  848. if (ArrayUtil.isNotEmpty(this.artistList)&&this.artistList.length > 100) {
  849. // 只保存前100条记录到缓存中
  850. let truncatedList = this.artistList.slice(0, 100);
  851. PreferencesUtil.putSync('artistList', JSON.stringify(truncatedList));
  852. } else {
  853. PreferencesUtil.putSync('artistList', JSON.stringify(this.artistList));
  854. }
  855. // 处理并缓存前60条艺术家数据
  856. const sortedEntries = Array.from(this.artistMap.entries())
  857. .sort((a, b) => b[1].length - a[1].length)
  858. .slice(0, 60);
  859. PreferencesUtil.putSync('artistMap', JSON.stringify(sortedEntries));
  860. break;
  861. case 104: //收到查询专辑列表
  862. this.albumMap = e.data.data1;
  863. this.albumList = e.data.data2
  864. //查询完毕在启动是否自动播放
  865. if (this.isStartAutoPlay&&this.isCanAuto) {
  866. this.isCanAuto = false
  867. console.info('onecold startPlayOrResumePlay 757')
  868. this.startPlayOrResumePlay()
  869. }
  870. PreferencesUtil.putSync('albumCount', this.albumList.length)
  871. // 处理专辑前100条记录,列表长度并存储到PreferencesUtil
  872. if (ArrayUtil.isNotEmpty(this.albumList)&&this.albumList.length > 100) {
  873. // 只保存前100条记录到缓存中
  874. let truncatedList = this.albumList.slice(0, 100);
  875. PreferencesUtil.putSync('albumList', JSON.stringify(truncatedList));
  876. } else {
  877. PreferencesUtil.putSync('albumList', JSON.stringify(this.albumList));
  878. }
  879. const mapArrayAlbum = Array.from(this.albumMap.entries())
  880. .sort((a, b) => b[1].length - a[1].length)
  881. .slice(0, 60);
  882. PreferencesUtil.putSync('albumMap', JSON.stringify(mapArrayAlbum));
  883. break;
  884. }
  885. };
  886. // 在调用terminate后,执行onexit
  887. workerInstance.onexit = (code) => {
  888. console.log("main thread terminate");
  889. }
  890. //若Worker处于已销毁或正在销毁等非运行状态时,调用其功能接口,会抛出相应的错误。
  891. // 使用Worker模块时,需要在主线程中注册onerror接口,否则当worker线程出现异常时会发生jscrash问题。
  892. workerInstance.onerror = (err: ErrorEvent) => {
  893. console.log("onerror" + err.message);
  894. }
  895. // let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  896. //碰一碰分享的监听
  897. this.knockController = KnockController.getInstance(this.context);
  898. this.knockController?.immersiveListening();
  899. }
  900. onPageHide(): void {
  901. this.knockController?.immersiveDisableListening();
  902. }
  903. @State isFirstStartPlay: boolean = false
  904. //获取download_path
  905. async mkDownLoadDir() {
  906. const documentViewPicker = new picker.DocumentViewPicker()
  907. let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
  908. this.rootPath = new fileUri.FileUri(documentSaveResult[0]).path
  909. this.currentPath = this.rootPath
  910. this.lockPath = this.rootPath + '/' + LocalMusic.STR_LOCK_VIDEO
  911. this.favPath = this.rootPath + '/' + LocalMusic.STR_FAC_VIDEO
  912. this.historyPath = this.rootPath + '/' + LocalMusic.STR_HISTORY_MUSIC
  913. Logger.info('onecold rootPath = ' + this.rootPath)
  914. Logger.info('onecold lockPath = ' + this.lockPath)
  915. if (!FileUtil.accessSync(this.lockPath)) {
  916. FileUtil.mkdirSync(this.lockPath)
  917. }
  918. if (!FileUtil.accessSync(this.favPath)) {
  919. FileUtil.mkdirSync(this.favPath)
  920. }
  921. if (!FileUtil.accessSync(this.historyPath)) {
  922. FileUtil.mkdirSync(this.historyPath)
  923. }
  924. this.getSortedFiles(this.rootPath).then(() => {
  925. this.isFavMusic = false
  926. //穿山甲
  927. // this.loadBannerAd(CSJUtil.getBannerID())
  928. this.songList = PreferencesUtil.getSync('LastMusicList', []) as Array<VideoItem>
  929. this.currentSong = PreferencesUtil.getSync('LastMusicInfo', undefined) as VideoItem
  930. if (ArrayUtil.isEmpty(this.songList)) {
  931. this.songList = this.getCurFileList()
  932. } else {
  933. this.curIndex = Utility.getIndexFromList(this.songList, this.currentSong.filePath)
  934. }
  935. if (ArrayUtil.isNotEmpty(this.songList)) {
  936. this.isFirstStartPlay = true
  937. this.sonDataSource.pushArrayData(this.songList)
  938. if (this.currentSong === undefined) {
  939. this.isFirstStartPlay = false
  940. this.currentSong = this.songList[0]
  941. }
  942. this.videoUrl = this.currentSong.filePath
  943. this.name = this.currentSong.name
  944. this.cover = this.currentSong.pixelMapPath
  945. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  946. } else {
  947. this.name = '空空如也'
  948. }
  949. })
  950. this.getFavList(false)
  951. }
  952. getFavList(isFavRefresh: boolean) {
  953. this.table.queryByisFav(1, async (result: VideoItem[]) => {
  954. this.favList = result
  955. if (isFavRefresh || this.isFavMusic) { //如果是我的收藏,更新我的收藏数据
  956. this.videoLocalList = this.favList
  957. this.updateListData(this.videoLocalList)
  958. }
  959. })
  960. }
  961. getHistoryList(isRefresh: boolean) {
  962. this.table.queryRecentPlayedRecords(50, async (result: VideoItem[]) => {
  963. this.historyList = result
  964. // for (let i = 0; i < this.historyList.length; i++) {
  965. //
  966. // console.info(`onecold gengxin 1: ${this.historyList[i].name}`);
  967. // console.info(`onecold gengxin 1: ${this.historyList[i].lastPlayedStr}`);
  968. // }
  969. if (isRefresh) {
  970. this.videoLocalList = this.historyList
  971. this.updateListData(this.videoLocalList, true)
  972. }
  973. })
  974. }
  975. // 组件消失生命周期
  976. aboutToDisappear() {
  977. console.info('LifeCycleComponent aboutToDisappear');
  978. this.knockController?.immersiveDisableListening();
  979. this.curIndex = 0
  980. emitter.off(EventConstants.EVENT_AUDIO_OPEN);
  981. emitter.off(EventConstants.EVENT_SCAN_UPDATE);
  982. emitter.off(EventConstants.EVENT_SWIPE_BACK_UPDATE);
  983. emitter.off(EventConstants.EVENT_SETTING_UPDATE);
  984. this.mDestroyPage = true;
  985. this.mIjkMediaPlayer.setScreenOnWhilePlaying(false);
  986. if (this.CONTROL_PlayStatus != PlayStatus.INIT) {
  987. this.stop();
  988. }
  989. this.mIjkMediaPlayer.off('audioInterrupt');
  990. if (workerInstance) {
  991. workerInstance.terminate();
  992. }
  993. this.stopPip();
  994. this.destroyPipController()
  995. }
  996. async getSortedFiles(curPath: string, isWorkerPost?: boolean, destPath?: string, isOpen?: boolean) {
  997. this.isFavMusic = false
  998. console.info('onecold getSortedFiles 1 curPath '+curPath)
  999. if (isWorkerPost) {
  1000. workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
  1001. }
  1002. if (this.modeType !== 0) {
  1003. this.openMusic(isOpen, destPath)
  1004. return
  1005. }
  1006. console.info('onecold getSortedFiles 2')
  1007. this.isCanBack = false
  1008. this.currentPath = curPath
  1009. console.info('onecold getSortedFiles this.currentPath ='+this.currentPath)
  1010. this.titleBarModel.setTitleName(getFileDirName(this.currentPath, this.rootPath))
  1011. if (curPath === this.rootPath) {
  1012. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1013. } else {
  1014. this.currentTitleName = getFileDirName(this.currentPath, this.rootPath)
  1015. if (this.rootPath === Utility.getParentDirectory(curPath)) {
  1016. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  1017. }
  1018. }
  1019. // Get the current file list and calculate its hash
  1020. this.fileList = FileUtil.listFileSync(curPath);
  1021. const currentHash = simpleHash(this.fileList);
  1022. // Check cache
  1023. const cachedValue = this.findCache(curPath);
  1024. Logger.info('onecold cachedValue = ' + cachedValue)
  1025. const cachedHash = this.findStringCache(curPath + '_hash');
  1026. const cachedDirList = this.findCache(curPath + "_dirList");
  1027. if (cachedValue !== undefined) {
  1028. // this.videoLocalList = cachedValue;
  1029. Logger.info('onecold 有缓存 cachedValue = ' + cachedValue)
  1030. if (this.currentPath != this.rootPath) { //第一个封面赋值给currentTitleCover
  1031. this.currentTitleCover = Utility.getFirstCoverFromList(cachedValue)
  1032. }
  1033. this.updateListData(cachedValue)
  1034. }
  1035. if (cachedDirList !== undefined) {
  1036. this.dirList = cachedDirList
  1037. }
  1038. //通过当前hash值和缓存hash判断list有没有变化
  1039. if (cachedValue && cachedHash === currentHash) {
  1040. return;
  1041. }
  1042. this.fileList = FileUtil.listFileSync(curPath)
  1043. let directories: Array<VideoItem> = [];
  1044. let files: Array<VideoItem> = [];
  1045. for (let i = 0; i < this.fileList.length; i++) {
  1046. console.info(`The name of file: ${this.fileList[i]}`);
  1047. let path = curPath + '/' + this.fileList[i]
  1048. if (FileUtil.isDirectory(path)) {
  1049. let item: VideoItem =
  1050. new VideoItem(this.fileList[i].toString(), this.fileList[i].toString(), path, CommonConstants.TYPE_IS_DIR, 0,
  1051. '')
  1052. if (this.isShowDir(item.name)) {
  1053. directories.push(item);
  1054. }
  1055. // directories.sort((a, b) => a.cTime.localeCompare(b.cTime));
  1056. // Utility.doSortListAscending(directories)
  1057. } else {
  1058. if (this.currentPath === this.lockPath&&Utility.isMeidaByExtension(path)) {
  1059. let item: VideoItem =
  1060. await Utility.uriGetMusicAssetsFromFile(this.context, path, CommonConstants.TYPE_LOCAL, false);
  1061. if (!path.endsWith('.lrc') && Utility.isMeidaByExtension(path) && !path.endsWith('.srt')) {
  1062. files.push(item);
  1063. // files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  1064. // this.doSortListAscending(files)
  1065. }
  1066. }
  1067. }
  1068. }
  1069. this.table.queryByParentPath(curPath, async (result: VideoItem[]) => {
  1070. if (this.currentPath !== this.lockPath) {
  1071. files = result;
  1072. }
  1073. files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  1074. Utility.doSortListAscending(files)
  1075. if (this.currentPath === this.rootPath) {
  1076. this.dirList = directories
  1077. this.addCache(curPath + "_dirList", this.dirList);
  1078. }
  1079. //插入广告先注释掉
  1080. // if (this.isShowAd && ArrayUtil.isNotEmpty(directories)) {
  1081. // let adItem: VideoItem = new VideoItem('', '', '', CommonConstants.TYPE_IS_CSJAD, 0, '')
  1082. // directories.push(adItem)
  1083. // }
  1084. // 合并文件夹和文件,文件夹在前,文件在后,广告在中间
  1085. this.videoLocalList = directories.concat(files);
  1086. this.updateListData(this.videoLocalList)
  1087. if (ArrayUtil.isNotEmpty(files)) {
  1088. if (this.currentPath != this.rootPath) {
  1089. if (files) {
  1090. this.currentTitleCover = Utility.getFirstCoverFromList(files)
  1091. }
  1092. }
  1093. // 缓存结果
  1094. this.addCache(curPath, this.videoLocalList);
  1095. await this.saveCacheToStorage(); // 保存缓存至本地存储
  1096. this.addStringCache(curPath + '_hash', currentHash);
  1097. }
  1098. console.info(`onecold gengxin 1: ${this.videoLocalList.length}`);
  1099. // for (let i = 0; i < this.videoLocalList.length; i++) {
  1100. //
  1101. // console.info(`onecold gengxin 1: ${this.videoLocalList[i].pixelMapPath}`);
  1102. //
  1103. // }
  1104. // this.setButtonStatus()
  1105. this.openMusic(isOpen, destPath)
  1106. });
  1107. }
  1108. //第三方app打开天天静听导入音乐后播放
  1109. openMusic(isOpen?: boolean, destPath?: string){
  1110. if (isOpen&&destPath) {
  1111. if (destPath === undefined) {
  1112. // 处理 destPath 为 undefined 的情况
  1113. return
  1114. }
  1115. if (destPath.endsWith('.lrc')) {
  1116. ToastUtil.showToast('导入歌词成功!请注意歌词文件和歌曲要同个歌单路径。')
  1117. if (StrUtil.isNotEmpty(this.videoUrl)) {
  1118. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  1119. this.initLyric(lyricPath);
  1120. }
  1121. return
  1122. }
  1123. let item2 = new VideoItem(Utility.getMediaNameByUri(destPath), destPath, destPath, 0, 0, '')
  1124. this.doPlay(item2,0,false,true)
  1125. this.isShowPlay = true
  1126. }
  1127. }
  1128. //扫描文件夹入库
  1129. async scanDirectory(curPath: string): Promise<VideoItem[]> {
  1130. const files = FileUtil.listFileSync(curPath);
  1131. let mediaItems: VideoItem[] = [];
  1132. Logger.info('onecold scanDirectory start ')
  1133. for (const file of files) {
  1134. const fPath = `${curPath}/${file}`;
  1135. if (fPath === this.lockPath) {
  1136. Logger.info(`Skipping locked path: ${fPath}`);
  1137. continue;
  1138. }
  1139. if (FileUtil.isDirectory(fPath)) {
  1140. // Recursively scan subdirectories
  1141. const subDirItems = await this.scanDirectory(fPath);
  1142. mediaItems = mediaItems.concat(subDirItems);
  1143. } else {
  1144. Logger.info('onecold scanDirectory filePath = ' + fPath)
  1145. // Process media files
  1146. if (!fPath.endsWith('.lrc') && Utility.isMeidaByExtension(fPath) && !fPath.endsWith('.srt')) {
  1147. let mediaItem: VideoItem =
  1148. await Utility.uriGetMusicAssetsFromFile(this.context, fPath, CommonConstants.TYPE_LOCAL, this.autoParseMusicName);
  1149. mediaItems.push(mediaItem);
  1150. this.table.insert(mediaItem, (id: number) => {
  1151. });
  1152. }
  1153. }
  1154. }
  1155. return mediaItems;
  1156. }
  1157. updateListData(mList: Array<VideoItem>, noSort?: boolean) {
  1158. animateTo({ duration: 888 }, () => {
  1159. this.opacityItem = 0;
  1160. });
  1161. setTimeout(() => {
  1162. this.videoLocalList = mList;
  1163. if (!noSort) {
  1164. if (this.modeType === 0 || this.modeType === 1) {
  1165. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  1166. this.doSortType(this.sortType)
  1167. }
  1168. }
  1169. this.dataSource.pushArrayData(this.videoLocalList)
  1170. animateTo({ duration: 888 }, () => {
  1171. this.opacityItem = 1;
  1172. });
  1173. this.setButtonStatus()
  1174. }, 200);
  1175. }
  1176. //排序模式和多选模式
  1177. showPupDialog() {
  1178. if (this.modeType === 2 || this.modeType === 3) {
  1179. this.titleBarModel.setRightIcon(null)
  1180. } else {
  1181. this.titleBarModel.setRightIcon(($r('app.media.add')))
  1182. }
  1183. let dataBean = new BubbleBean()
  1184. dataBean.data = ["首页", "媒体库", "艺术家", "专辑", "同步数据"]
  1185. dataBean.color = this.themeColor
  1186. dataBean.modeType = this.modeType
  1187. dataBean.imageRes =
  1188. [$r('app.media.home_press'), $r('app.media.kp_music'), $r('app.media.music_menu'), $r('app.media.llq'),
  1189. $r('app.media.refresh')]
  1190. let pup: XPopup;
  1191. if (this.isDarkMode) {
  1192. pup = XPopup.Builder()
  1193. .setPopupPosition(PopupPosition.BOTTOM)
  1194. .atView('pup_positon_music')
  1195. .setBackgroundColor(Color.Black)
  1196. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  1197. .show()
  1198. } else {
  1199. pup = XPopup.Builder()
  1200. .setPopupPosition(PopupPosition.BOTTOM)
  1201. .atView('pup_positon_music')
  1202. .setBackgroundColor(Color.White)
  1203. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  1204. .show()
  1205. }
  1206. dataBean.onItemClick = (i) => {
  1207. XPopup.dismissTop()
  1208. switch (i) {
  1209. case 0: //首页
  1210. this.modeType = 0
  1211. this.getSortedFiles(this.currentPath)
  1212. break
  1213. case 1:
  1214. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1215. this.modeType = 1
  1216. this.updateListData(this.mediaKuList)
  1217. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  1218. break
  1219. case 2:
  1220. this.modeType = 2
  1221. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1222. this.updateListData(this.artistList)
  1223. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  1224. break
  1225. case 3:
  1226. this.modeType = 3
  1227. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1228. this.updateListData(this.albumList)
  1229. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  1230. break
  1231. case 4: //同步数据
  1232. // this.asyncCurrentPathData()
  1233. break
  1234. }
  1235. }
  1236. }
  1237. getCurFileList(): Array<VideoItem> {
  1238. if(this.isSearchMode){
  1239. return this.filteredList
  1240. }
  1241. let files: Array<VideoItem> = [];
  1242. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1243. for (let i = 0; i < this.videoLocalList.length; i++) {
  1244. if (this.videoLocalList[i].type === CommonConstants.TYPE_LOCAL) {
  1245. files.push(this.videoLocalList[i]);
  1246. }
  1247. }
  1248. }
  1249. return files
  1250. }
  1251. setButtonStatus() {
  1252. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1253. this.isZero = false
  1254. } else {
  1255. this.isZero = true
  1256. }
  1257. if (this.currentPath !== this.rootPath &&
  1258. ArrayUtil.isNotEmpty(Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR))) {
  1259. this.isHasDir = true //不为空,说明有子文件夹
  1260. } else {
  1261. this.isHasDir = false
  1262. }
  1263. }
  1264. showRankDialog() {
  1265. if ((this.modeType === 2&&!this.isCanBack) || (this.modeType === 3&&!this.isCanBack)) {
  1266. //动作面板
  1267. DialogHelper.showBottomSheetDialog({
  1268. title: "请选择排序模式",
  1269. maskColor: Color.Transparent,
  1270. // sheets: ["按名称升序", "按名称降序"],
  1271. sheets: [
  1272. { value: '按名称升序', fontColor: $r('app.color.text_color') },
  1273. { value: '按名称降序', fontColor: $r('app.color.text_color') },
  1274. { value: '按数量升序', fontColor: $r('app.color.text_color') },
  1275. { value: '按数量降序', fontColor: $r('app.color.text_color') },
  1276. ],
  1277. backgroundColor: $r('app.color.bg_card'),
  1278. height: '45%',
  1279. transition: AnimationHelper.transitionInDown(555),
  1280. onAction: (index) => {
  1281. switch (index) {
  1282. case 0:
  1283. Utility.doSortListAscending(this.videoLocalList,this.isShowFileName)
  1284. break;
  1285. case 1:
  1286. Utility.doSortListDescending(this.videoLocalList,this.isShowFileName)
  1287. break;
  1288. case 2:
  1289. this.videoLocalList.sort((a: VideoItem, b: VideoItem): number => {
  1290. // 1. Sort by type first
  1291. const typeOrder: number = getTypeOrder(a.type) - getTypeOrder(b.type);
  1292. if (typeOrder !== 0) {
  1293. return typeOrder;
  1294. }
  1295. // 2. Then sort by artist count (numeric comparison)
  1296. let sortMap:Map<string, VideoItem[]>= new Map<string, VideoItem[]>();
  1297. if(this.modeType === 2){
  1298. sortMap = this.artistMap
  1299. }else{
  1300. sortMap = this.albumMap
  1301. }
  1302. const aArtistCount: number = sortMap.get(a.name)?.length || 0;
  1303. const bArtistCount: number = sortMap.get(b.name)?.length || 0;
  1304. return aArtistCount - bArtistCount;
  1305. });
  1306. break;
  1307. case 3:
  1308. this.videoLocalList.sort((a: VideoItem, b: VideoItem): number => {
  1309. // 1. Sort by type first
  1310. const typeOrder: number = getTypeOrder(a.type) - getTypeOrder(b.type);
  1311. if (typeOrder !== 0) {
  1312. return typeOrder;
  1313. }
  1314. let sortMap:Map<string, VideoItem[]>= new Map<string, VideoItem[]>();
  1315. if(this.modeType === 2){
  1316. sortMap = this.artistMap
  1317. }else{
  1318. sortMap = this.albumMap
  1319. }
  1320. const aArtistCount: number = sortMap.get(a.name)?.length || 0;
  1321. const bArtistCount: number = sortMap.get(b.name)?.length || 0;
  1322. return bArtistCount - aArtistCount;
  1323. });
  1324. break;
  1325. }
  1326. this.updateListData(this.videoLocalList)
  1327. }
  1328. })
  1329. return
  1330. }
  1331. //动作面板
  1332. DialogHelper.showBottomSheetDialog({
  1333. title: "请选择排序模式",
  1334. maskColor: Color.Transparent,
  1335. height: '75%',
  1336. // sheets: ["按艺术家升序", "按艺术家降序", "按专辑升序", "按专辑降序", "按名称升序", "按名称降序", "按添加时间升序","按添加时间降序"],
  1337. sheets: [
  1338. { value: "按艺术家升序", fontColor: $r('app.color.text_color') },
  1339. { value: "按艺术家降序", fontColor: $r('app.color.text_color') },
  1340. { value: "按专辑升序", fontColor: $r('app.color.text_color') },
  1341. { value: "按专辑降序", fontColor: $r('app.color.text_color') },
  1342. { value: "按名称升序", fontColor: $r('app.color.text_color') },
  1343. { value: "按名称降序", fontColor: $r('app.color.text_color') },
  1344. { value: "按添加时间升序", fontColor: $r('app.color.text_color') },
  1345. { value: "按添加时间降序", fontColor: $r('app.color.text_color') },
  1346. ],
  1347. backgroundColor: $r('app.color.bg_card'),
  1348. transition: AnimationHelper.transitionInDown(555),
  1349. onAction: (index) => {
  1350. this.doSortType(index)
  1351. PreferencesUtil.put(SettingPage.SORT_TYPE, index)
  1352. this.updateListData(this.videoLocalList, true)
  1353. }
  1354. })
  1355. }
  1356. doSortType(index: number) {
  1357. switch (index) {
  1358. case 0:
  1359. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1360. // 类型排序优先级
  1361. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1362. if (typeOrder !== 0) {
  1363. return typeOrder;
  1364. }
  1365. // 处理艺术家可能为undefined的字符串比较
  1366. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1367. const artistB = b.artist?.trim() || '';
  1368. return artistA.localeCompare(artistB);
  1369. });
  1370. break;
  1371. case 1:
  1372. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1373. // 类型排序优先级
  1374. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1375. if (typeOrder !== 0) {
  1376. return typeOrder;
  1377. }
  1378. // 处理艺术家可能为undefined的字符串比较
  1379. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1380. const artistB = b.artist?.trim() || '';
  1381. return artistB.localeCompare(artistA);
  1382. });
  1383. break;
  1384. case 2:
  1385. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1386. // 类型排序优先级
  1387. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1388. if (typeOrder !== 0) {
  1389. return typeOrder;
  1390. }
  1391. // 处理专辑可能为undefined的字符串比较
  1392. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1393. const albumB = b.album?.trim() || '';
  1394. return albumA.localeCompare(albumB);
  1395. });
  1396. break;
  1397. case 3:
  1398. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1399. // 类型排序优先级
  1400. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1401. if (typeOrder !== 0) {
  1402. return typeOrder;
  1403. }
  1404. // 处理专辑可能为undefined的字符串比较
  1405. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1406. const albumB = b.album?.trim() || '';
  1407. return albumB.localeCompare(albumA);
  1408. });
  1409. break;
  1410. case 4:
  1411. Utility.doSortListAscending(this.videoLocalList,this.isShowFileName)
  1412. break;
  1413. case 5:
  1414. Utility.doSortListDescending(this.videoLocalList,this.isShowFileName)
  1415. break;
  1416. case 6:
  1417. this.videoLocalList.sort((a, b) => {
  1418. // First, sort by type
  1419. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1420. if (typeOrder !== 0) {
  1421. return typeOrder;
  1422. }
  1423. // If types are the same, sort by cTime in ascending order
  1424. return a.cTime.localeCompare(b.cTime);
  1425. });
  1426. break;
  1427. case 7:
  1428. this.videoLocalList.sort((a, b) => {
  1429. // First, sort by type
  1430. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1431. if (typeOrder !== 0) {
  1432. return typeOrder;
  1433. }
  1434. // If types are the same, sort by cTime in descending order
  1435. return b.cTime.localeCompare(a.cTime);
  1436. });
  1437. break;
  1438. }
  1439. }
  1440. showSheelDialog() {
  1441. // if(PreferencesUtil.getBooleanSync('isFirstMusic',true)) {
  1442. // this.showTips()
  1443. // return
  1444. // }
  1445. this.showAddDialog()
  1446. }
  1447. showAddDialog() {
  1448. if (this.modeType === 2 || this.modeType === 3) {
  1449. return
  1450. }
  1451. DialogHelper.showActionSheetDialog({
  1452. title: "请选择添加方式(建议歌词文件一起导入)",
  1453. // sheets: ["新建歌单", "手动导入", "自动导入"],
  1454. sheets: [
  1455. { value: "新建歌单", fontColor: $r('app.color.text_color') },
  1456. { value: "手动导入", fontColor: $r('app.color.text_color') },
  1457. { value: "自动导入", fontColor: $r('app.color.text_color') },
  1458. { value: "全选导入", fontColor: $r('app.color.text_color') },
  1459. ],
  1460. maskColor: Color.Transparent,
  1461. backgroundColor: $r('app.color.bg_card'),
  1462. transition: AnimationHelper.transitionInDown(555),
  1463. onAction: (index) => {
  1464. switch (index) {
  1465. case 0:
  1466. if (this.modeType === 0) {
  1467. this.showMkDialog()
  1468. } else {
  1469. ToastUtil.showToast('请切换到首页才能新建歌单!')
  1470. }
  1471. break;
  1472. case 1:
  1473. this.callFilePickerSelectFile()
  1474. break;
  1475. case 2:
  1476. this.showTips()
  1477. break;
  1478. case 3:
  1479. this.goSelectMusic()
  1480. break;
  1481. }
  1482. }
  1483. })
  1484. }
  1485. //拉起音频
  1486. goSelectMusic() {
  1487. if (DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_TABLET ||
  1488. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_PC ||
  1489. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1
  1490. ) {
  1491. ToastUtil.showToast('暂时不支持该设备')
  1492. return
  1493. }
  1494. try {
  1495. let documentSelectOptions = new picker.DocumentSelectOptions();
  1496. documentSelectOptions.authMode = true
  1497. documentSelectOptions.multiAuthMode = true
  1498. documentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO;
  1499. let documentPicker = new picker.DocumentViewPicker(this.context);
  1500. documentPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => {
  1501. if (documentSelectResult !== null && documentSelectResult !== undefined) {
  1502. this.saveVideoDatas(documentSelectResult)
  1503. }
  1504. console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' +
  1505. JSON.stringify(documentSelectResult));
  1506. }).catch((err: BusinessError) => {
  1507. console.error(`DocumentViewPicker.select failed with err, code is: ${err.code}, message is: ${err.message}`);
  1508. });
  1509. } catch (error) {
  1510. let err: BusinessError = error as BusinessError;
  1511. console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1512. }
  1513. }
  1514. async showTips() {
  1515. DialogHelper.showTipsDialog({
  1516. title: '使用提示:自动导入教程',
  1517. content: '用系统自带的文件管理器将:\n\n1、音频文件放入' + '\n\n我的设备/Download/'
  1518. + this.appName + '\n\n2、无需繁琐的勾选和分类步骤。\n\n3、每个子文件夹将被组成一个分组。' +
  1519. '\n\n4、歌词文件的文件名必须和目标歌曲文件名相同(不包含后缀名)。\n\n5、歌词文件和目标歌曲文件必须同个目录。' +
  1520. '\n\n6、电脑上Download的目录是\nDownload/' + this.packName + '。\n\n7、放好文件后如果没显示点击刷新按钮。\n',
  1521. onAction: (action) => {
  1522. if (action == DialogAction.TWO) {
  1523. PreferencesUtil.putSync('isFirstMusic', false)
  1524. router.pushUrl({
  1525. url: 'pages/ScanFilePage'
  1526. });
  1527. }
  1528. }
  1529. })
  1530. }
  1531. showMkDialog() {
  1532. DialogHelper.showTextInputDialog({
  1533. title: '新建歌单',
  1534. maskColor: Color.Transparent,
  1535. text: '',
  1536. transition: AnimationHelper.transitionInDown(666),
  1537. onChange: (text) => {
  1538. console.error("onChange: " + text);
  1539. },
  1540. onAction: (action, dialogId, content) => {
  1541. // ToastUtil.showToast('content = ' +content)
  1542. if (action == DialogAction.TWO) {
  1543. const newName = content
  1544. const newPath = this.currentPath + '/' + newName
  1545. FileUtil.mkdir(newPath, true).then(() => {
  1546. this.cache.delete(this.currentPath); // 删除目标路径缓存
  1547. this.getSortedFiles(this.currentPath)
  1548. }).catch((error: BusinessError) => {
  1549. console.error(error.message);
  1550. });
  1551. }
  1552. }
  1553. })
  1554. }
  1555. @State progress: number = 0;
  1556. async saveVideoDatas(uris: string[], isOpen?: boolean) {
  1557. if (ArrayUtil.isEmpty(uris)) {
  1558. return;
  1559. }
  1560. let newUris: string[] = [];
  1561. this.progress = 0
  1562. DialogHelper.showLoadingProgress({
  1563. progress: this.progress,
  1564. backCancel: false,
  1565. autoCancel: false,
  1566. loadColor: this.themeColor,
  1567. fontColor: this.themeColor
  1568. });
  1569. // 计算所有文件的总大小
  1570. let totalSize = 0;
  1571. for (let uri of uris) {
  1572. const sourceFile = await fileIo.open(uri, fileIo.OpenMode.READ_ONLY);
  1573. totalSize += (await fileIo.stat(sourceFile.fd)).size;
  1574. await fileIo.close(sourceFile.fd);
  1575. }
  1576. let totalRead = 0;
  1577. let destPath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[0]);
  1578. Logger.info(TAG, 'destPath uri: ' + destPath);
  1579. for (let i = 0; i < uris.length; i++) {
  1580. let filePath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[i]);
  1581. Logger.info(TAG, 'filePath uri: ' + filePath);
  1582. newUris.push(filePath);
  1583. try {
  1584. const sourceFile = await fileIo.open(uris[i], fileIo.OpenMode.READ_ONLY);
  1585. const destFile = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  1586. const buffSize = 1024 * 1024; // 1MB 缓冲区大小
  1587. const buffer = new ArrayBuffer(buffSize);
  1588. let len = await fileIo.read(sourceFile.fd, buffer);
  1589. while (len > 0) {
  1590. await fileIo.write(destFile.fd, buffer.slice(0, len));
  1591. totalRead += len;
  1592. // 计算总进度
  1593. this.progress = Math.floor((totalRead / totalSize) * 100);
  1594. DialogHelper.updateLoading('正在导入', this.progress);
  1595. len = await fileIo.read(sourceFile.fd, buffer);
  1596. }
  1597. await fileIo.close(sourceFile.fd);
  1598. await fileIo.close(destFile.fd);
  1599. if (this.currentPath !== this.lockPath) { //判断不是私密音乐,才入库
  1600. if (!filePath.endsWith('.lrc') && Utility.isMeidaByExtension(filePath) && !filePath.endsWith('.srt')) {
  1601. let mediaItem: VideoItem =
  1602. await Utility.uriGetMusicAssetsFromFile(this.context, filePath, CommonConstants.TYPE_LOCAL, this.autoParseMusicName);
  1603. this.table.insert(mediaItem, (id: number) => {
  1604. // 删除目标路径缓存
  1605. this.cache.delete(this.currentPath);
  1606. this.getSortedFiles(this.currentPath, true, destPath, isOpen)
  1607. });
  1608. }
  1609. }
  1610. } catch (error) {
  1611. Logger.error(TAG, 'saveVideoDatas failed with err: ' + JSON.stringify(error));
  1612. }
  1613. }
  1614. DialogHelper.closeLoading()
  1615. this.isZero = false
  1616. // setTimeout(() => {
  1617. // // 删除目标路径缓存
  1618. // this.cache.delete(this.currentPath);
  1619. // this.getSortedFiles(this.currentPath,true,destPath,isOpen)
  1620. // }, 500);
  1621. Logger.info(TAG, 'scan select video result:' + newUris)
  1622. }
  1623. //拉起音频
  1624. // goSelectMusic(){
  1625. //
  1626. // try {
  1627. // let audioSelectOptions = new picker.AudioSelectOptions();
  1628. // let audioPicker = new picker.AudioViewPicker(this.context);
  1629. // audioPicker.select(audioSelectOptions).then((audioSelectResult: Array<string>) => {
  1630. // if (audioSelectResult !== null && audioSelectResult !== undefined) {
  1631. // this.saveVideoDatas(audioSelectResult)
  1632. // }
  1633. // console.info('AudioViewPicker.select successfully, audioSelectResult uri: ' + JSON.stringify(audioSelectResult));
  1634. // }).catch((err: BusinessError) => {
  1635. //
  1636. // console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
  1637. // });
  1638. // } catch (error) {
  1639. // let err: BusinessError = error as BusinessError;
  1640. // console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1641. // }
  1642. //
  1643. //
  1644. //
  1645. // }
  1646. async goSelectImage(item: VideoItem): Promise<string | undefined> {
  1647. if (!item) {
  1648. return undefined;
  1649. }
  1650. try {
  1651. let selectUris: Array<string> = [];
  1652. let photoPicker = new photoAccessHelper.PhotoViewPicker();
  1653. let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  1654. photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
  1655. photoSelectOptions.maxSelectNumber = 1;
  1656. const photoSelectResult = await photoPicker.select(photoSelectOptions);
  1657. selectUris = photoSelectResult.photoUris;
  1658. console.info('photoViewPicker.select to file succeed and uris are:' + selectUris);
  1659. let file = fs.openSync(selectUris[0], fs.OpenMode.READ_ONLY);
  1660. console.info('file fd: ' + file.fd);
  1661. let name = await MD5.digestSync(this.videoUrl)+'.jpg'
  1662. let imagePath = this.context.filesDir + FileUtil.separator + name
  1663. imagePath = fileUri.getUriFromPath(imagePath)
  1664. let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  1665. fileIo.copyFileSync(file.fd, file2.fd)
  1666. fileIo.closeSync(file);
  1667. fileIo.closeSync(file2);
  1668. if (item.filePath == this.currentSong?.filePath) {
  1669. this.cover = imagePath
  1670. }
  1671. if (item) {
  1672. item.pixelMapPath = imagePath
  1673. }
  1674. this.table.updatePixelMapPath(item.filePath, imagePath, (success: boolean, error?: string) => {
  1675. if (success) {
  1676. this.doUpdateData()
  1677. console.log("onecold 更新音乐封面成功,数据库已同步");
  1678. } else {
  1679. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  1680. }
  1681. });
  1682. LogUtil.debug("onecold this.cover =" + this.cover)
  1683. return FileUtil.getFilePath(imagePath); // Return the image path here
  1684. } catch (err) {
  1685. console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
  1686. return undefined;
  1687. }
  1688. }
  1689. // 拉起picker选择文件管理器
  1690. async callFilePickerSelectFile(): Promise<void> {
  1691. try {
  1692. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  1693. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE) {
  1694. DocumentSelectOptions.fileSuffixFilters = CommonConstants.MEDIA_FORMAT
  1695. } else {
  1696. DocumentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO
  1697. }
  1698. let documentPicker = new picker.DocumentViewPicker();
  1699. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  1700. Logger.info(TAG,
  1701. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  1702. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  1703. this.saveVideoDatas(DocumentSelectResult)
  1704. }
  1705. }).catch((err: BusinessError) => {
  1706. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  1707. });
  1708. } catch (err) {
  1709. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  1710. }
  1711. }
  1712. //重命名的对话框
  1713. showReNameDialog(item: VideoItem, index: string, filePath: string) {
  1714. DialogHelper.showTextInputDialog({
  1715. title: '重命名',
  1716. text: item.type === CommonConstants.TYPE_IS_DIR ? item.name : item.fileName,
  1717. maskColor: Color.Transparent,
  1718. backgroundColor: Color.Grey,
  1719. transition: AnimationHelper.transitionInDown(666),
  1720. onChange: (text) => {
  1721. console.error("onChange: " + text);
  1722. },
  1723. onAction: (action, dialogId, content) => {
  1724. // ToastUtil.showToast('content = ' +content)
  1725. if (action == DialogAction.TWO) {
  1726. const newName = content
  1727. const newPath = this.currentPath + '/' + newName
  1728. console.log("onecold item = " + item.type);
  1729. this.doReName(index, newName, filePath, newPath, item)
  1730. }
  1731. }
  1732. })
  1733. }
  1734. //剪切 移动到另个文件夹的对话框
  1735. showCutDialog(isCurrent: boolean, item: VideoItem, index: number, id: string) {
  1736. Logger.info('onecold showCutDialog')
  1737. let mList: Array<string> = []
  1738. let rPath = this.rootPath
  1739. if (isCurrent) {
  1740. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1741. rPath = this.currentPath
  1742. } else {
  1743. mList = Utility.getNameList(this.dirList);
  1744. rPath = this.rootPath
  1745. }
  1746. let dataBean = new BubbleBean()
  1747. dataBean.data = mList
  1748. dataBean.color = this.themeColor
  1749. dataBean.onItemClick = (i) => {
  1750. const newPath = rPath + '/' + mList[i] + '/' + item.fileName
  1751. Logger.info('newPath = ' + newPath)
  1752. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  1753. ToastUtil.showToast('移动成功')
  1754. this.table.deleteData(item, () => {
  1755. });
  1756. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  1757. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  1758. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  1759. CommonConstants.TYPE_LOCAL, this.autoParseMusicName);
  1760. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  1761. this.table.insert(newItem, (id: number) => {
  1762. //加入数据库
  1763. });
  1764. }
  1765. this.cache.delete(this.currentPath); // 删除原路径缓存
  1766. this.cache.delete(rPath + '/' + mList[i]); // 删除目标路径缓存
  1767. this.getSortedFiles(this.currentPath, true)
  1768. }).catch((error: BusinessError) => {
  1769. console.error(error.message);
  1770. });
  1771. XPopup.dismissTop()
  1772. }
  1773. let popupPosition: PopupPosition = PopupPosition.BOTTOM
  1774. if (ArrayUtil.isNotEmpty(this.videoLocalList) && this.videoLocalList.length > 7) {
  1775. popupPosition = PopupPosition.TOP
  1776. }
  1777. if (index <= 3) {
  1778. popupPosition = PopupPosition.BOTTOM
  1779. }
  1780. let pup: XPopup
  1781. if (this.isDarkMode) {
  1782. pup = XPopup.Builder()
  1783. .setPopupPosition(popupPosition)
  1784. .atView(id)// .setHeight(this.isCoverOpacity()?100:420)
  1785. .setBackgroundColor(Color.Black)
  1786. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1787. .show()
  1788. } else {
  1789. pup = XPopup.Builder()
  1790. .setPopupPosition(popupPosition)
  1791. .atView(id)// .setHeight(this.isCoverOpacity()?280:420)
  1792. .setBackgroundColor(Color.White)
  1793. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1794. .show()
  1795. }
  1796. }
  1797. //复制 到另个文件夹的对话框
  1798. showCopyDialog(isCurrent: boolean, item: VideoItem, index: number, id: string) {
  1799. Logger.info('onecoldv showCopyDialog')
  1800. let mList: Array<string> = []
  1801. let rPath = this.rootPath
  1802. if (isCurrent) {
  1803. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1804. rPath = this.currentPath
  1805. } else {
  1806. mList = Utility.getNameList(this.dirList);
  1807. rPath = this.rootPath
  1808. }
  1809. let dataBean = new BubbleBean()
  1810. dataBean.data = mList
  1811. dataBean.isCopy = true
  1812. dataBean.color = this.themeColor
  1813. dataBean.onItemClick = (i) => {
  1814. const newPath = rPath + '/' + mList[i] + '/' + item.fileName
  1815. Logger.info('newPath = ' + newPath)
  1816. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  1817. ToastUtil.showToast('复制成功')
  1818. this.cache.delete(rPath + '/' + mList[i]); // 删除目标路径缓存
  1819. this.getSortedFiles(this.currentPath)
  1820. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  1821. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  1822. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  1823. CommonConstants.TYPE_LOCAL, this.autoParseMusicName);
  1824. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  1825. this.table.insert(newItem, (id: number) => {
  1826. //加入数据库
  1827. });
  1828. }
  1829. }).catch((error: BusinessError) => {
  1830. console.error(error.message);
  1831. });
  1832. XPopup.dismissTop()
  1833. }
  1834. let popupPosition: PopupPosition = PopupPosition.BOTTOM
  1835. if (ArrayUtil.isNotEmpty(this.videoLocalList) && this.videoLocalList.length > 7) {
  1836. popupPosition = PopupPosition.TOP
  1837. }
  1838. if (index <= 3) {
  1839. popupPosition = PopupPosition.BOTTOM
  1840. }
  1841. let pup: XPopup
  1842. if (this.isDarkMode) {
  1843. pup = XPopup.Builder()
  1844. .setPopupPosition(popupPosition)
  1845. .atView(id)
  1846. .setMaxHeight('60%')
  1847. .setBackgroundColor(Color.Black)
  1848. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1849. .show();
  1850. } else {
  1851. pup = XPopup.Builder()
  1852. .setPopupPosition(popupPosition)
  1853. .atView(id)
  1854. .setMaxHeight('60%')
  1855. .setBackgroundColor(Color.White)
  1856. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1857. .show();
  1858. }
  1859. }
  1860. //重命名索引index的视频
  1861. doReName(index: string, newName: string, oldPath: string, newPath: string, info: VideoItem) {
  1862. FileUtil.rename(oldPath, newPath).then(async () => {
  1863. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1864. if (info.type === CommonConstants.TYPE_IS_DIR) {
  1865. //如果是文件夹先删除源数据,再添加新数据
  1866. this.table.deleteDataForParentPath(oldPath, (success: boolean, error?: string) => {
  1867. if (success) {
  1868. console.log(" onecold deleteDataForParentPath 文件夹重命名成功,数据库已同步");
  1869. } else {
  1870. console.error(" onecold deleteDataForParentPath 文件夹重命名数据库失败原因: " + error);
  1871. }
  1872. });
  1873. this.scanDirectory(newPath)
  1874. } else if (info.type === CommonConstants.TYPE_LOCAL) {
  1875. this.table.updateRename(newName, oldPath, newPath, (success: boolean, error?: string) => {
  1876. if (success) {
  1877. console.log(" onecold 重命名成功,数据库已同步");
  1878. } else {
  1879. console.error(" onecold 重命名数据库失败原因: " + error);
  1880. }
  1881. });
  1882. }
  1883. let mediaItem: VideoItem =
  1884. await Utility.uriGetMusicAssetsFromFile(this.context, newPath, CommonConstants.TYPE_LOCAL, this.autoParseMusicName);
  1885. this.videoLocalList[index] = mediaItem;
  1886. }
  1887. this.cache.delete(this.currentPath)
  1888. this.getSortedFiles(this.currentPath, true)
  1889. }).catch((error: BusinessError) => {
  1890. console.error(error.message);
  1891. });
  1892. }
  1893. build() {
  1894. Scroll() {
  1895. Column() {
  1896. if (!this.isShowCoverHeader()) {
  1897. Column() {
  1898. Line().width('100%').height('100%')
  1899. }
  1900. .height(this.topRectHeight)
  1901. .backgroundColor(this.isCustomizeBg ? Color.Transparent :
  1902. (this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor))
  1903. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  1904. TitleBar({ model: $titleBarModel })
  1905. .id('pup_positon_music')
  1906. }
  1907. Stack() {
  1908. Column() {
  1909. XComponent({
  1910. id: 'xcomponentId',
  1911. type: 'surface',
  1912. libraryname: 'ijkplayer_napi',
  1913. controller: this.xcomponentController
  1914. })
  1915. .onLoad((event?: object) => {
  1916. if (!!event) {
  1917. this.initDelayPlay(event);
  1918. }
  1919. })
  1920. .onKeyEvent((event?: KeyEvent) => {
  1921. // If the button type is pressed, the subsequent code will not be executed; the specific button logic will be executed upon release.
  1922. if (!event || event.type !== KeyType.Down) {
  1923. return;
  1924. }
  1925. //空格键 Space key controls pause/play
  1926. if (event.keyCode === KeyCode.KEYCODE_SPACE) {
  1927. console.info('onecold playOrPause 1999')
  1928. this.playOrPause()
  1929. }
  1930. // Right-click to fast forward
  1931. if (event.keyCode === KeyCode.KEYCODE_DPAD_RIGHT) {
  1932. this.sessionFastForwardCallback(15);
  1933. }
  1934. // Left-click to rewind
  1935. if (event.keyCode === KeyCode.KEYCODE_DPAD_LEFT) {
  1936. this.sessionRewindCallback(15);
  1937. }
  1938. })
  1939. .onDestroy(() => {
  1940. })
  1941. .width('100%')// .width(this.videoWidth)
  1942. .aspectRatio(this.videoAspectRatio)
  1943. }
  1944. .aspectRatio(this.videoAspectRatio)
  1945. .justifyContent(FlexAlign.Center)
  1946. .backgroundColor(Color.Transparent)
  1947. .visibility(Visibility.Hidden)
  1948. .height(CommonConstants.FULL_PERCENT)
  1949. .width(CommonConstants.FULL_PERCENT)
  1950. .bindSheet($$this.isABSheet, this.ABLoopSheet(), {
  1951. height:this.isLandscape?'80%': '43%',
  1952. dragBar: true,
  1953. showClose: true,
  1954. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  1955. blurStyle:BlurStyle.Thin,
  1956. backgroundColor:Color.Transparent,
  1957. title: { title: 'AB循环' }
  1958. })
  1959. Stack() {
  1960. Row() {
  1961. Blank()
  1962. .layoutWeight(1)
  1963. IndexerView(
  1964. {
  1965. indexArray: DEFAULT_INDEX,
  1966. selectedIndex: this.selectedIndex,
  1967. textSize: 12,
  1968. selectedColor: "#ff419ee5",
  1969. normalColor: "#ffa0a0a0",
  1970. floatSelectedTextColor: "#ffffff",
  1971. floatSelectedViewColor: "#ff419ee5",
  1972. onIndexChanged: (index) => {
  1973. this.listScroller.scrollToIndex(index)
  1974. }
  1975. })
  1976. .width(24)
  1977. .height("50%")
  1978. }.visibility(Visibility.None)
  1979. Column() {
  1980. if (!this.isShowCoverHeader()) {
  1981. this.tabTitle()
  1982. }
  1983. if(this.twoFingerType==4){
  1984. this.getWaterView()
  1985. }else{
  1986. if(this.isGridMusic){
  1987. this.getGridView()
  1988. }else {
  1989. this.getListView()
  1990. }
  1991. }
  1992. if (this.modeType == 0) {
  1993. Column() {
  1994. Button('同步数据', { type: ButtonType.Capsule, stateEffect: true })
  1995. .width(130)
  1996. .height(50)
  1997. .margin({ top: 100, bottom: 40 })
  1998. .backgroundColor(this.themeColor)
  1999. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2000. .onClick(() => {
  2001. this.asyncCurrentPathData()
  2002. })
  2003. }
  2004. .height(100)
  2005. .position({ top: 260 })
  2006. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  2007. .animation({ duration: 500 }),
  2008. TransitionEffect.scale({ x: 0, y: 0 })))
  2009. .justifyContent(FlexAlign.Center)
  2010. .opacity(this.isZero ? 1 : 0)
  2011. .visibility(this.isZero && !this.isFavMusic && !this.isHistory
  2012. && this.modeType === 0 ? Visibility.Visible : Visibility.None)
  2013. .animation({
  2014. duration: 500,
  2015. curve: 'ease-in-out' // 可选动画曲线
  2016. })
  2017. .width('100%')
  2018. }
  2019. }
  2020. .layoutWeight(1)
  2021. .height('100%')
  2022. }
  2023. .layoutWeight(1)
  2024. .height('100%')
  2025. Row() {
  2026. Button(this.isAllSelected ? '全不选' : '全选', { type: ButtonType.Circle, stateEffect: true })
  2027. .width(50)
  2028. .height(50)
  2029. .fontSize(13)
  2030. .margin({ top: 10, bottom: 10, right: 6 })
  2031. .backgroundColor(this.themeColor)
  2032. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  2033. .onClick(() => {
  2034. if (this.isAllSelected) {
  2035. // 全不选
  2036. this.selectedFiles = [];
  2037. } else {
  2038. // 全选
  2039. this.selectedFiles = [...this.getCurFileList()];
  2040. }
  2041. this.isAllSelected = !this.isAllSelected;
  2042. })
  2043. Button('内嵌标签', { type: ButtonType.Capsule, stateEffect: true })
  2044. .width(90)
  2045. .height(50)
  2046. .fontSize(13)
  2047. .margin({ top: 10, bottom: 10, right: 6 })
  2048. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  2049. .backgroundColor(this.themeColor)
  2050. .bindContentCover($$this.isOneKeyTags, this.TagsContentCoverBuilder(), {
  2051. transition: TransitionEffect.translate({ x: 500 }).animation({ curve: curves.springMotion(0.6, 0.8) })
  2052. })
  2053. .onClick(() => {
  2054. this.isOneKeyTags = !this.isOneKeyTags
  2055. })
  2056. Button('乱码修复', { type: ButtonType.Capsule, stateEffect: true })
  2057. .width(90)
  2058. .height(50)
  2059. .fontSize(13)
  2060. .margin({ top: 10, bottom: 10, right: 6 })
  2061. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  2062. .backgroundColor(this.themeColor)
  2063. .bindContentCover($$this.isFixMessy, this.FixMessyViewBuilder(), {
  2064. transition: TransitionEffect.translate({ x: 500 }).animation({ curve: curves.springMotion(0.6, 0.8) })
  2065. })
  2066. .onClick(() => {
  2067. this.isFixMessy = !this.isFixMessy
  2068. })
  2069. // Button('剪切', { type: ButtonType.Circle, stateEffect: true })
  2070. // .width('35%')
  2071. // .height(60)
  2072. // .id('music_cut')
  2073. // .margin({ top: 10, bottom: 10, right: 6 })
  2074. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  2075. // .backgroundColor(this.themeColor)
  2076. // .onClick(() => {
  2077. // this.showCutDialogForMultipleFiles(false, 'music_cut')
  2078. // })
  2079. //
  2080. // Button('移动', { type: ButtonType.Circle, stateEffect: true })
  2081. // .width('35%')
  2082. // .height(60)
  2083. // .id('music_cut_current')
  2084. // .visibility(this.isHasDir ? Visibility.Visible : Visibility.None)
  2085. // .margin({ top: 10, bottom: 10, right: 6 })
  2086. // .backgroundColor(this.themeColor)
  2087. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  2088. // .onClick(() => {
  2089. //
  2090. // this.showCutDialogForMultipleFiles(true, 'music_cut_current')
  2091. // })
  2092. // Button('复制', { type: ButtonType.Circle, stateEffect: true })
  2093. // .width('35%')
  2094. // .height(60)
  2095. // .id('music_copy_current')// .visibility(this.isHasDir?Visibility.None:Visibility.None)
  2096. // .margin({ top: 10, bottom: 10, right: 6 })
  2097. // .backgroundColor(this.themeColor)
  2098. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  2099. // .onClick(() => {
  2100. // this.showCopyDialogForMultipleFiles(false, 'music_copy_current')
  2101. // })
  2102. Button('删除', { type: ButtonType.Circle, stateEffect: true })
  2103. .width(50)
  2104. .height(50)
  2105. .fontSize(13)
  2106. .margin({ top: 10, bottom: 10, right: 6 })
  2107. .visibility(this.isFavMusic ? Visibility.None : Visibility.Visible)
  2108. .backgroundColor(this.themeColor)
  2109. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  2110. .onClick(() => {
  2111. this.showWarnIsDelete()
  2112. })
  2113. Button('取消', { type: ButtonType.Circle, stateEffect: true })
  2114. .width(50)
  2115. .height(50)
  2116. .fontSize(13)
  2117. .margin({ top: 10, bottom: 10, right: 6 })
  2118. .backgroundColor(this.themeColor)
  2119. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  2120. .onClick(() => {
  2121. this.selectedFiles = [];
  2122. this.isAllSelected = false
  2123. this.isMultiSelect = false
  2124. })
  2125. }
  2126. .width('100%')
  2127. .justifyContent(FlexAlign.Center)
  2128. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  2129. .opacity(this.isMultiSelect ? 1 : 0)
  2130. .animation({
  2131. duration: 666,
  2132. curve: 'ease-in-out' // 可选动画曲线
  2133. })
  2134. .position(this.isShowCoverHeader() ? { bottom: 78 }
  2135. : { bottom: this.isPhoneLan() ? 130 : 170 }) // 将 Row 固定在底部
  2136. }
  2137. .width('100%')
  2138. .height('100%')
  2139. .alignContent(Alignment.Top)
  2140. Column() {
  2141. this.PlayController()
  2142. }
  2143. .hitTestBehavior(HitTestMode.Transparent)
  2144. .position({ bottom: 0 }) // 将 Row 固定在底部
  2145. .opacity(this.barBottomOpacity)
  2146. }
  2147. .width('100%')
  2148. .height('100%')
  2149. .backgroundImage(this.isCustomizeBg ? this.customizeBgPath : $r('app.color.bottom_control_background'))
  2150. .backgroundImageSize(this.isCoverOpacity() ? { width: '100%' } : { height: '100%' })
  2151. .backgroundImagePosition(Alignment.Center)
  2152. .backdropBlur(this.blurValue)
  2153. .backgroundBrightness({ rate: this.isCustomizeBg ? 0.1 : 0, lightUpDegree: this.bgBrightness })
  2154. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
  2155. }
  2156. }
  2157. @Builder
  2158. TagsContentCoverBuilder() {
  2159. Scroll() {
  2160. Column() {
  2161. TagsContentCover(
  2162. {
  2163. selectedFiles:this.selectedFiles,
  2164. isShowDrawer:this.isOneKeyTags,
  2165. onTagsResult:(result: boolean)=>{
  2166. this.isMultiSelect = false
  2167. if(result){//如果嵌入成功,更新数据
  2168. this.doUpdateData()
  2169. }
  2170. }
  2171. }
  2172. )
  2173. }
  2174. }
  2175. .width('100%')
  2176. .height('100%')
  2177. }
  2178. @Builder
  2179. FixMessyViewBuilder() {
  2180. Scroll() {
  2181. Column() {
  2182. FixMessyView(
  2183. {
  2184. selectedFiles:this.selectedFiles,
  2185. isShowDrawer:this.isFixMessy,
  2186. onFixResult:(result: boolean)=>{
  2187. this.isMultiSelect = false
  2188. if(result){//如果嵌入成功,更新数据
  2189. this.doUpdateData()
  2190. }
  2191. }
  2192. }
  2193. )
  2194. }
  2195. }
  2196. .width('100%')
  2197. .height('100%')
  2198. }
  2199. asyncCurrentPathData() {
  2200. if (this.modeType == 0) {
  2201. workerInstance.postMessage({
  2202. code: 1,
  2203. data1: this.context,
  2204. data2: this.currentPath,
  2205. data3: this.lockPath,
  2206. data4: PreferencesUtil.getStringSync('COVER_API', ''),
  2207. data5: PreferencesUtil.getBooleanSync('autoParseMusicName', true),
  2208. });
  2209. }
  2210. }
  2211. // 处理文件选择的函数
  2212. handleFileSelection(item: VideoItem, checked: boolean) {
  2213. if (checked) {
  2214. if (!this.selectedFiles.some(x => x.filePath == item.filePath)) {
  2215. this.selectedFiles.push(item);
  2216. }
  2217. } else {
  2218. const index = this.selectedFiles.findIndex(x => x.filePath == item.filePath);
  2219. if (index > -1) {
  2220. this.selectedFiles.splice(index, 1);
  2221. }
  2222. }
  2223. }
  2224. private deleteComponentId: number = 0
  2225. //多选删除文件
  2226. showWarnIsDelete(){
  2227. this.getUIContext().getPromptAction().openCustomDialog({
  2228. builder: () => {
  2229. this.deleteComptentBuilder()
  2230. },
  2231. isModal:true,
  2232. showInSubWindow:false,
  2233. maskColor: Color.Transparent,
  2234. dialogTransition: // 设置弹窗内容显示的过渡效果
  2235. TransitionEffect.translate({ x: 0, y: 290, z: 0 })
  2236. .animation({ duration: 600, curve: Curve.Smooth }),
  2237. maskTransition: // 设置蒙层显示的过渡效果
  2238. TransitionEffect.opacity(0)
  2239. .animation({ duration: 600, curve: Curve.Smooth })
  2240. }).then((dialogId: number) => {
  2241. this.deleteComponentId = dialogId
  2242. })
  2243. .catch((error: BusinessError) => {
  2244. console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`)
  2245. })
  2246. }
  2247. @Builder
  2248. deleteComptentBuilder(){
  2249. DeleteComptent({
  2250. selectedFiles:this.selectedFiles,
  2251. onCancel:()=>{
  2252. this.isMultiSelect = false
  2253. this.getUIContext().getPromptAction().closeCustomDialog(this.deleteComponentId)
  2254. },
  2255. onDeleteResult:(result: boolean)=>{
  2256. this.isMultiSelect = false
  2257. this.getUIContext().getPromptAction().closeCustomDialog(this.deleteComponentId)
  2258. if(result){//如果删除成功,更新数据
  2259. this.selectedFiles = [];
  2260. this.isAllSelected = false
  2261. this.cache.delete(this.currentPath);
  2262. this.getSortedFiles(this.currentPath, true);
  2263. }
  2264. }
  2265. })
  2266. }
  2267. //多选移动文件
  2268. showCutDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  2269. Logger.info('onecold showCutDialogForMultipleFiles')
  2270. let mList: Array<string> = []
  2271. let rPath = this.rootPath
  2272. if (isCurrent) {
  2273. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  2274. rPath = this.currentPath
  2275. } else {
  2276. mList = Utility.getNameList(this.dirList);
  2277. rPath = this.rootPath
  2278. }
  2279. let dataBean = new BubbleBean();
  2280. dataBean.data = mList;
  2281. dataBean.color = this.themeColor
  2282. dataBean.onItemClick = (i) => {
  2283. const newDirPath = rPath + '/' + mList[i];
  2284. // Logger.info('newDirPath = ' + newDirPath)
  2285. this.selectedFiles.forEach((item) => {
  2286. const newPath = newDirPath + '/' + item.fileName;
  2287. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  2288. ToastUtil.showToast('移动成功');
  2289. this.table.deleteData(item, () => {
  2290. this.cache.delete(this.currentPath); // 删除原路径缓存
  2291. this.cache.delete(newDirPath); // 删除目标路径缓存
  2292. this.getSortedFiles(this.currentPath, true);
  2293. });
  2294. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2295. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2296. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2297. CommonConstants.TYPE_LOCAL, this.autoParseMusicName);
  2298. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2299. this.table.insert(newItem, (id: number) => {
  2300. //加入数据库
  2301. });
  2302. }
  2303. }).catch((error: Error) => {
  2304. console.error(error.message);
  2305. });
  2306. });
  2307. this.isMultiSelect = false
  2308. this.selectedFiles = [];
  2309. this.isAllSelected = false
  2310. XPopup.dismissTop();
  2311. };
  2312. let pup: XPopup
  2313. if (this.isDarkMode) {
  2314. pup = XPopup.Builder()
  2315. .setPopupPosition(PopupPosition.TOP)
  2316. .atView(viewId)
  2317. .setBackgroundColor(Color.Black)
  2318. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2319. .show();
  2320. } else {
  2321. pup = XPopup.Builder()
  2322. .setPopupPosition(PopupPosition.TOP)
  2323. .atView(viewId)
  2324. .setBackgroundColor(Color.White)
  2325. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2326. .show();
  2327. }
  2328. }
  2329. /**
  2330. * 加载所有歌单
  2331. */
  2332. async loadAllPlaylists() {
  2333. try {
  2334. this.allPlaylists = await this.playlistTable?.queryAllPlaylists()!
  2335. LogUtil.info('heanup Loaded playlists: ' + this.allPlaylists.length)
  2336. } catch (error) {
  2337. LogUtil.error('heaunp Failed to load playlists: ' + error.message)
  2338. }
  2339. }
  2340. /**
  2341. * 显示添加到歌单对话框
  2342. */
  2343. async showAddToPlaylistDialog(item: VideoItem) {
  2344. // 加载最新的歌单列表
  2345. await this.loadAllPlaylists()
  2346. showAddToPlaylistDialog(
  2347. item,
  2348. this.allPlaylists,
  2349. async (playlistId: string) => {
  2350. // 添加歌曲到歌单
  2351. const success = await this.playlistTable?.addSongToPlaylist(playlistId, item.filePath)
  2352. if (success) {
  2353. ToastUtil.showToast('已添加到歌单')
  2354. // 重新加载歌单列表
  2355. await this.loadAllPlaylists()
  2356. } else {
  2357. ToastUtil.showToast('歌曲已在该歌单中')
  2358. }
  2359. },
  2360. () => {
  2361. LogUtil.info('取消添加到歌单')
  2362. },
  2363. () => {
  2364. // 创建新歌单
  2365. showCreatePlaylistDialog(
  2366. async (name: string, description: string) => {
  2367. const success = await this.playlistTable?.createPlaylist(name, description)
  2368. if (success) {
  2369. ToastUtil.showToast('歌单创建成功')
  2370. // 重新加载歌单列表并打开添加对话框
  2371. await this.loadAllPlaylists()
  2372. await this.showAddToPlaylistDialog(item)
  2373. } else {
  2374. ToastUtil.showToast('歌单创建失败')
  2375. }
  2376. }
  2377. )
  2378. }
  2379. )
  2380. }
  2381. doFav(item: VideoItem) {
  2382. LogUtil.info('onecold doFav isFav=' + item.isFav)
  2383. let isFav = 0
  2384. if (Utility.getIsFav(this.favList, item)) {
  2385. isFav = 0
  2386. } else {
  2387. isFav = 1
  2388. }
  2389. this.table.updateIsFavByFilePath(item.filePath, isFav, async (result: boolean) => {
  2390. if (result) {
  2391. if (isFav === 1) {
  2392. ToastUtil.showToast('收藏成功');
  2393. } else {
  2394. ToastUtil.showToast('取消收藏成功');
  2395. }
  2396. this.deleteCache(this.currentPath)
  2397. this.getFavList(false)
  2398. if (this.modeType === 0 && !this.isFavMusic) {
  2399. LogUtil.info('onecold doFav currentPath =' + this.currentPath)
  2400. this.getSortedFiles(this.currentPath)
  2401. }
  2402. workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
  2403. workerInstance.postMessage({ code: 3, data: this.context });
  2404. workerInstance.postMessage({ code: 4, data: this.context });
  2405. }
  2406. })
  2407. }
  2408. //多选复制文件
  2409. showCopyDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  2410. console.log('onecold showCopyDialogForMultipleFiles');
  2411. let mList: Array<string> = []
  2412. let rPath = this.rootPath
  2413. if (isCurrent) {
  2414. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  2415. rPath = this.currentPath
  2416. } else {
  2417. mList = Utility.getNameList(this.dirList);
  2418. rPath = this.rootPath
  2419. }
  2420. let dataBean = new BubbleBean();
  2421. dataBean.data = mList;
  2422. dataBean.isCopy = true
  2423. dataBean.color = this.themeColor
  2424. dataBean.onItemClick = (i) => {
  2425. const newDirPath = rPath + '/' + mList[i];
  2426. // Logger.info('newDirPath = ' + newDirPath)
  2427. this.selectedFiles.forEach((item) => {
  2428. const newPath = newDirPath + '/' + item.fileName;
  2429. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  2430. ToastUtil.showToast('复制成功');
  2431. this.cache.delete(newDirPath); // 删除目标路径缓存
  2432. this.getSortedFiles(this.currentPath);
  2433. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2434. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2435. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2436. CommonConstants.TYPE_LOCAL, this.autoParseMusicName);
  2437. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2438. this.table.insert(newItem, (id: number) => {
  2439. //加入数据库
  2440. });
  2441. }
  2442. }).catch((error: Error) => {
  2443. console.error(error.message);
  2444. });
  2445. });
  2446. this.isMultiSelect = false
  2447. this.selectedFiles = [];
  2448. this.isAllSelected = false
  2449. XPopup.dismissTop();
  2450. };
  2451. let pup: XPopup
  2452. if (this.isDarkMode) {
  2453. pup = XPopup.Builder()
  2454. .setPopupPosition(PopupPosition.TOP)
  2455. .atView(viewId)
  2456. .setBackgroundColor(Color.Black)
  2457. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2458. .show();
  2459. } else {
  2460. pup = XPopup.Builder()
  2461. .setPopupPosition(PopupPosition.TOP)
  2462. .atView(viewId)
  2463. .setBackgroundColor(Color.White)
  2464. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2465. .show();
  2466. }
  2467. }
  2468. @Builder
  2469. private DirItem(item: VideoItem, index?: number) {
  2470. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2471. Row() {
  2472. Image(this.modeType !== 0 && StrUtil.isNotEmpty(item.pixelMapPath) ? item.pixelMapPath :
  2473. $r('app.media.music_group'))
  2474. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2475. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2476. .fillColor(this.themeColor)// .fontSize(33)
  2477. .alt($r('app.media.music_group'))
  2478. .borderRadius('100%')
  2479. .clip(true)
  2480. .margin({ left: 20, top: 8, bottom: 8 })
  2481. Column() {
  2482. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  2483. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2484. .maxLines(1)// .width('88%')
  2485. .textOverflow({ overflow: this.isLongNameRoLL?TextOverflow.MARQUEE:TextOverflow.Ellipsis })//超长滚动
  2486. .animation({
  2487. duration: 555,
  2488. curve: 'ease-in-out',
  2489. })
  2490. .transition({
  2491. type: TransitionType.Insert,
  2492. opacity: 0,
  2493. translate: { x: 160 }
  2494. })
  2495. .margin({ left: 10, right: 20 })
  2496. .fontColor($r('app.color.text_color'))
  2497. Row() {
  2498. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  2499. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2500. .padding({ top: 8 })
  2501. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2502. .fontColor($r('app.color.text_color'))
  2503. .margin({ left: 10 })
  2504. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  2505. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2506. .padding({ top: 8 })
  2507. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2508. .fontColor($r('app.color.text_color'))
  2509. .margin({ left: 10 })
  2510. Blank()
  2511. }
  2512. }
  2513. .height('100%')
  2514. .layoutWeight(1)
  2515. .justifyContent(FlexAlign.Center)
  2516. .alignItems(HorizontalAlign.Start)
  2517. Blank()
  2518. Image($r('app.media.arrow_right'))
  2519. .height(25)
  2520. .margin({ right: 10 })
  2521. .alignSelf(ItemAlign.Center)
  2522. .id(item.filePath)
  2523. }
  2524. }
  2525. .backgroundColor(Color.Transparent)
  2526. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2527. .width('100%')
  2528. .visibility(this.isShowDir(item.name) ? Visibility.Visible : Visibility.None)
  2529. .opacity(this.opacityItem) // 绑定透明度
  2530. }
  2531. isShowDir(dirName: string) {
  2532. this.isShowSimi = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, false)
  2533. this.isShowFAV = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_FAV, true)
  2534. this.isShowHistory = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HISTORY, true)
  2535. if (dirName === undefined) {
  2536. return true
  2537. }
  2538. if (dirName === LocalMusic.STR_LOCK_VIDEO) {
  2539. return this.isShowSimi
  2540. }
  2541. if (dirName === LocalMusic.STR_FAC_VIDEO) {
  2542. return this.isShowFAV
  2543. }
  2544. if (dirName === LocalMusic.STR_HISTORY_MUSIC) {
  2545. return this.isShowHistory
  2546. }
  2547. return true
  2548. }
  2549. @State opacityItem: number = 1; // 控制透明度的状态变量
  2550. @Builder
  2551. private MusicItem(item: VideoItem, index?: number) {
  2552. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2553. Row() {
  2554. Stack() {
  2555. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  2556. .fillColor(this.themeColor)
  2557. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2558. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2559. .alt($r('app.media.music_red'))
  2560. .borderRadius('100%')
  2561. .clip(true)
  2562. .draggable(false)
  2563. .interpolation(ImageInterpolation.High)// 用于重采样后的抗锯齿
  2564. .autoResize(true) // 重采样,可减少内存占用
  2565. .opacity(this.opacityItem)// 绑定透明度
  2566. .margin({ left: 20 })
  2567. .gesture(LongPressGesture()
  2568. .onAction(async () => {
  2569. //如果是专辑和艺术家的首页,不能长按
  2570. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2571. return
  2572. //如果是我的收藏 最近播放等也不能长按
  2573. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2574. item.name === LocalMusic.STR_HISTORY_MUSIC
  2575. )
  2576. return
  2577. this.longItemFilePath = item.filePath
  2578. this.tempLyricContent = await this.getLyricContent(item)
  2579. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2580. })
  2581. .onActionEnd((event: GestureEvent) => {
  2582. }))
  2583. .onClick(()=>{
  2584. this.doPlay(item,index)
  2585. this.isShowPlay = true
  2586. })
  2587. }
  2588. Column() {
  2589. Column() {
  2590. Text(this.isShowFileName?item.fileName :item.name)
  2591. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2592. .maxLines(1)
  2593. .textOverflow({ overflow: this.isLongNameRoLL?TextOverflow.MARQUEE:TextOverflow.Ellipsis })//超长滚动
  2594. .animation({
  2595. duration: 555,
  2596. curve: 'Linear',
  2597. })
  2598. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2599. $r('app.color.text_color'))
  2600. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2601. .padding({right:25})
  2602. .bindPopup(this.longItemFilePath === item.filePath, {
  2603. builder: this.MenuBuilder(item,index,item.filePath),
  2604. placement: Placement.Top,
  2605. // autoCancel: true,
  2606. mask: {color:'#33000000'},
  2607. // popupColor: Color.Yellow,
  2608. enableArrow: false,//是否显示箭头
  2609. showInSubWindow: false,
  2610. onStateChange: (e) => {
  2611. if (!e.isVisible) {
  2612. this.longItemFilePath = ''
  2613. this.tempLyricContent = ''
  2614. }
  2615. }
  2616. })
  2617. .gesture(LongPressGesture()
  2618. .onAction(async () => {
  2619. //如果是专辑和艺术家的首页,不能长按
  2620. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2621. return
  2622. //如果是我的收藏 最近播放等也不能长按
  2623. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2624. item.name === LocalMusic.STR_HISTORY_MUSIC
  2625. )
  2626. return
  2627. this.longItemFilePath = item.filePath
  2628. this.tempLyricContent = await this.getLyricContent(item)
  2629. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2630. })
  2631. .onActionEnd((event: GestureEvent) => {
  2632. })
  2633. )
  2634. Row() {
  2635. Column(){
  2636. Text(item.md5Str?.includes('Lossless')?
  2637. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  2638. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  2639. .padding({ top: 3,right:6,left:6,bottom:3 })
  2640. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2641. $r('app.color.text_color'))
  2642. .fontWeight(500)
  2643. .borderRadius(12)
  2644. .visibility(StrUtil.isEmpty(item.md5Str)?Visibility.None:Visibility.Visible)
  2645. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2646. .backgroundColor('#FFC107')
  2647. }
  2648. .padding({ top: 8 })
  2649. Text(StrUtil.isEmpty(item.artist) ? item.duration
  2650. :this.twoFingerType==2? item.artist +' ' + item.duration
  2651. : item.artist + ' ' + item?.album)
  2652. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2653. .padding({ top: 8 ,right:25})
  2654. .visibility(this.isShowFileName?Visibility.None:Visibility.Visible)
  2655. .maxLines(1)
  2656. .textOverflow({ overflow: this.isLongNameRoLL?TextOverflow.MARQUEE:TextOverflow.Ellipsis })//超长滚动
  2657. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2658. $r('app.color.text_color'))
  2659. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2660. Blank()
  2661. Text(this.isShowFileName?item.duration:item.size)
  2662. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2663. .padding({ top: 8 })
  2664. .maxLines(1)
  2665. .visibility(this.isShowFileName?Visibility.Visible:StrUtil.isEmpty(item.artist)
  2666. ? Visibility.Visible : Visibility.None)
  2667. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2668. $r('app.color.text_color'))
  2669. .margin({ left: 10 })
  2670. }
  2671. .visibility(this.twoFingerType==1?Visibility.None:Visibility.Visible)
  2672. .gesture(LongPressGesture()
  2673. .onAction(async () => {
  2674. //如果是专辑和艺术家的首页,不能长按
  2675. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2676. return
  2677. //如果是我的收藏 最近播放等也不能长按
  2678. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2679. item.name === LocalMusic.STR_HISTORY_MUSIC
  2680. )
  2681. return
  2682. this.longItemFilePath = item.filePath
  2683. this.tempLyricContent = await this.getLyricContent(item)
  2684. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2685. })
  2686. .onActionEnd((event: GestureEvent) => {
  2687. })
  2688. )
  2689. }
  2690. .height('100%')
  2691. .width('100%')
  2692. .justifyContent(FlexAlign.Center)
  2693. .alignItems(HorizontalAlign.Start)
  2694. }
  2695. .height('100%')
  2696. .margin({ left: 5 })
  2697. .layoutWeight(1)
  2698. Column() {
  2699. Checkbox({ name: 'checkbox' + index })
  2700. .select(this.selectedFiles.some(x => x.filePath === item.filePath))
  2701. .selectedColor(this.themeColor)
  2702. .shape(CheckBoxShape.CIRCLE)
  2703. .opacity(this.isMultiSelect ? 1 : 0)
  2704. .animation({
  2705. duration: 666,
  2706. curve: 'Smooth' // 可选动画曲线
  2707. })
  2708. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  2709. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  2710. .margin({ left: 20, top: 8, bottom: 8,right:18 })
  2711. .width(22)
  2712. .height(22)
  2713. ImageAnimator()
  2714. .images(this.imagesF)// 动画数组
  2715. .duration(1000)// 持续
  2716. .state(this.animationState)// 动画状态
  2717. .fillMode(FillMode.Forwards)
  2718. .width(18)
  2719. .margin({ right: 20, top: 8, bottom: 8 })
  2720. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  2721. Visibility.None)
  2722. .height(18)
  2723. .iterations(-1) // 播放次数
  2724. }
  2725. }
  2726. }
  2727. .backgroundColor(Color.Transparent)
  2728. .width('100%')
  2729. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2730. }
  2731. private readonly tabs: string[] = ['文件夹', '媒体库', '艺术家', '专辑']
  2732. @State tabOptions: SegmentButtonOptions = SegmentButtonOptions.tab({
  2733. buttons: [{ text: '文件夹' }, { text: '媒体库' },{ text: '艺术家' }],
  2734. direction: Direction.Ltr,
  2735. buttonPadding:{top:12,bottom:12},
  2736. backgroundColor: Color.Transparent,
  2737. fontSize:14,
  2738. selectedFontSize:15,
  2739. selectedFontColor:Color.White,
  2740. selectedBackgroundColor: this.themeColor,
  2741. localizedTextPadding: {
  2742. end: LengthMetrics.vp(20),
  2743. start: LengthMetrics.vp(20)
  2744. }
  2745. })
  2746. @State @Watch('capsuleSelectedIndexesChanged')tabSelectedIndexes: number[] = [0]
  2747. //当胶囊按钮的选择发生变化时调用此函数
  2748. capsuleSelectedIndexesChanged() {
  2749. this.modeType = this.tabSelectedIndexes[0]
  2750. }
  2751. @Builder
  2752. tabTitle() {
  2753. Column({ space: 2 }) {
  2754. SegmentButton({ options: this.tabOptions, selectedIndexes: $tabSelectedIndexes })
  2755. Line()
  2756. .width('100%')
  2757. .height(1)
  2758. .backgroundColor($r('app.color.index_background'))
  2759. .opacity(this.barOpacity)
  2760. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  2761. }
  2762. .width('100%')
  2763. .visibility(this.isShowTitleBar ? Visibility.Visible : Visibility.None)
  2764. }
  2765. // @Builder
  2766. // tabTitle() {
  2767. // Column() {
  2768. // // 使用 Stack 布局来实现绝对定位效果
  2769. // Stack() {
  2770. // // 背景动画容器
  2771. // Row() {
  2772. // ForEach(this.tabs, (i: string, index) => {
  2773. // Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2774. // Flex()
  2775. // .backgroundColor(this.isDarkMode ? $r('app.color.tab_item_bg') : this.themeColor)
  2776. // .borderRadius(20)
  2777. // .padding(10)
  2778. // .margin(6)
  2779. // .width('100%')
  2780. // .height('100%')
  2781. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2782. // .visibility(this.modeType === index ? Visibility.Visible : Visibility.None)
  2783. // .opacity(this.modeType === index ? 1 : 0)
  2784. // .animation({
  2785. // duration: 666,
  2786. // playMode: PlayMode.Normal,
  2787. // curve: 'ease-in-out'
  2788. // });
  2789. // }
  2790. // .layoutWeight(1)
  2791. // .margin({
  2792. // left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5,
  2793. // right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5, bottom: 1
  2794. // });
  2795. // });
  2796. // }
  2797. // .width('100%')
  2798. // .height(50);
  2799. //
  2800. // // 导航栏容器
  2801. // Row() {
  2802. // ForEach(this.tabs, (item: string, index) => {
  2803. // Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2804. // Text(item)
  2805. // .fontSize(16)
  2806. // .fontColor(this.modeType === index ? Color.White : $r('app.color.text_color'))
  2807. // .padding(15)
  2808. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2809. // .onClick(() => {
  2810. // this.modeType = index;
  2811. // // this.onModeChange();
  2812. // });
  2813. // }
  2814. // .layoutWeight(1)
  2815. // .stateStyles({
  2816. // pressed: { opacity: 0.6 } // 按压反馈
  2817. // });
  2818. // });
  2819. // }
  2820. // .width('100%')
  2821. // .height(this.topBarHeight)
  2822. // .opacity(this.barOpacity)
  2823. // .backgroundColor(Color.Transparent);
  2824. //
  2825. // }
  2826. // .width('100%')
  2827. // .height(this.topBarHeight)
  2828. // .opacity(this.barOpacity)
  2829. //
  2830. // Line()
  2831. // .width('100%')
  2832. // .height(1)
  2833. // .backgroundColor($r('app.color.index_background'))
  2834. // .opacity(this.barOpacity)
  2835. // .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  2836. // }
  2837. // .visibility(this.isShowTitleBar ? Visibility.Visible : Visibility.None)
  2838. // }
  2839. @State currentTitleName: string = '' //点击歌单,艺术家,专辑进去后的标题
  2840. @State currentTitleCover: string | ResourceStr = '' //点击歌单,艺术家,专辑进去后的封面
  2841. isShowCoverHeader() {
  2842. if (!this.isShowHeader) {
  2843. return false
  2844. }
  2845. if (this.modeType == 0) {
  2846. if (this.isHistory || this.isFavMusic) {
  2847. return true
  2848. }
  2849. if (this.currentPath != this.rootPath) {
  2850. return true
  2851. }
  2852. }
  2853. return (this.modeType == 2 || this.modeType == 3) && this.isCanBack
  2854. }
  2855. @Builder
  2856. coverHeader() {
  2857. if (this.isShowCoverHeader()) {
  2858. Column() {
  2859. Stack() {
  2860. // 居中标题
  2861. Text('')
  2862. .fontSize(18)
  2863. .fontColor(Color.White)
  2864. .align(Alignment.Center)
  2865. // 左右按钮
  2866. Row() {
  2867. Image($r('app.media.left_back_white'))
  2868. .width(28)
  2869. .height(28)
  2870. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2871. .margin({ left: 12, right: 8 })
  2872. .onClick(() => {
  2873. animateTo({ duration: 555 }, () => {
  2874. this.doSwipBack()
  2875. })
  2876. })
  2877. Blank().flexGrow(1)
  2878. if (this.modeType == 0 && !this.isHistory && !this.isFavMusic) {
  2879. Image($r('app.media.add'))
  2880. .width(25)
  2881. .height(25)
  2882. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2883. .margin({ left: 8, right: 15 })
  2884. .onClick(() => {
  2885. this.showAddDialog()
  2886. })
  2887. }
  2888. }
  2889. .height(48)
  2890. .width('100%')
  2891. .alignItems(VerticalAlign.Center)
  2892. }
  2893. .height(48)
  2894. .width('100%')
  2895. Row() {
  2896. Column() {
  2897. Image(this.currentTitleCover)
  2898. .height(100)
  2899. .width(100)
  2900. .alt(this.imageLabel)
  2901. .borderRadius(8)
  2902. .clickEffect({ level: ClickEffectLevel.HEAVY })
  2903. }
  2904. .alignItems(HorizontalAlign.Start)
  2905. .margin({ left: 30, top: 3, bottom: 15 })
  2906. Column() {
  2907. Column() {
  2908. Text(this.currentTitleName)
  2909. .fontSize(16)
  2910. .maxLines(1)
  2911. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  2912. .fontWeight(FontWeight.Bold)
  2913. .fontColor($r('app.color.text_color'))
  2914. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2915. if (this.modeType == 3 && ArrayUtil.isNotEmpty(this.videoLocalList)) {
  2916. Text(`艺术家:${this.videoLocalList[0].artist}`)
  2917. .fontSize(14)
  2918. .padding({ top: 8 })
  2919. .maxLines(1)
  2920. .fontWeight(FontWeight.Bold)
  2921. .fontColor($r('app.color.text_color'))
  2922. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2923. if(this.videoLocalList[0].genre){
  2924. Text(`风格:${this.videoLocalList[0].genre}`)
  2925. .fontSize(14)
  2926. .padding({ top: 8 })
  2927. .maxLines(1)
  2928. .visibility(StrUtil.isEmpty(this.videoLocalList[0].genre)||
  2929. this.videoLocalList[0].genre.includes(this.UNKONWN)
  2930. ?Visibility.None:Visibility.Visible)
  2931. .fontWeight(FontWeight.Bold)
  2932. .fontColor($r('app.color.text_color'))
  2933. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2934. }
  2935. if(this.videoLocalList[0].year){
  2936. Text(`发行时间:${this.videoLocalList[0].year}`)
  2937. .fontSize(14)
  2938. .padding({ top: 8 })
  2939. .maxLines(1)
  2940. .visibility(StrUtil.isEmpty(this.videoLocalList[0].year)||
  2941. this.videoLocalList[0].year.includes(this.UNKONWN)
  2942. ?Visibility.None:Visibility.Visible)
  2943. .fontWeight(FontWeight.Bold)
  2944. .fontColor($r('app.color.text_color'))
  2945. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2946. }
  2947. }
  2948. if(this.modeType != 3){
  2949. Row() {
  2950. Text(`共${this.videoLocalList.length}首歌`)
  2951. .fontSize(13)
  2952. .fontWeight(FontWeight.Bold)
  2953. .padding({ top: 8 })
  2954. .fontColor($r('app.color.text_color'))
  2955. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2956. Blank()
  2957. }
  2958. }
  2959. }
  2960. .height('100%')
  2961. .width('100%')
  2962. .justifyContent(FlexAlign.Center)
  2963. .alignItems(HorizontalAlign.Start)
  2964. }
  2965. .height('100%')
  2966. .layoutWeight(1)
  2967. .margin({ left: 20 })
  2968. }
  2969. this.listViewTitle()
  2970. }
  2971. .backgroundImage(this.getCoverTitleBg())
  2972. .height(250)
  2973. .width('100%')
  2974. .backgroundImageSize({ height: '100%', width: '100%' })
  2975. .backgroundBlurStyle(this.isCustomizeBg ? BlurStyle.NONE : BlurStyle.BACKGROUND_ULTRA_THICK)
  2976. .padding({ top: this.topRectHeight, bottom: this.bottomBarHeight + 48 })
  2977. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  2978. .justifyContent(FlexAlign.SpaceBetween)
  2979. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.7, y: 0.7 }).animation({ duration: 500 }),
  2980. TransitionEffect.scale({ x: 0, y: 0 })))
  2981. } else {
  2982. this.listViewTitle()
  2983. }
  2984. }
  2985. getCoverTitleBg(): ResourceStr | image.PixelMap {
  2986. if (this.isCustomizeBg) {
  2987. return ('rgba(255,255,255,0.2)')
  2988. }
  2989. if (this.isDarkMode) {
  2990. return $r('app.color.user_center_card_background')
  2991. }
  2992. return this.currentTitleCover
  2993. }
  2994. @Builder
  2995. listViewTitle() {
  2996. Column() {
  2997. Row({ space: 8 }) {
  2998. Row({ space: 8 }) {
  2999. Image($r("app.media.hm_playlist"))
  3000. .width(25)
  3001. .margin({ left: 8 })
  3002. .fillColor(this.themeColor)
  3003. Text(this.artistList.length ==100 ? `共找到${this.artistCount}位艺术家`
  3004. :`共找到${this.artistList.length}位艺术家`)
  3005. .fontColor($r('app.color.text_color'))
  3006. .fontSize(14)
  3007. .opacity(this.opacityItem)
  3008. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  3009. Text(this.albumList.length ==100 ? `共找到${this.albumCount+''}张专辑`
  3010. :`共找到${this.albumList.length}张专辑`)
  3011. .fontColor($r('app.color.text_color'))
  3012. .opacity(this.opacityItem)
  3013. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  3014. .fontSize(14)
  3015. }
  3016. .layoutWeight(1)
  3017. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  3018. Row() {
  3019. TextInput({
  3020. placeholder: this.modeType === 2 ? '输入艺术家名称...' : '输入专辑名称...',
  3021. text: this.searchText
  3022. })
  3023. .height(35)
  3024. .onChange((value: string) => {
  3025. this.onSearchInput(value);
  3026. })
  3027. .layoutWeight(1)
  3028. Text(`取消`)
  3029. .margin({ left: 10, right: 10 })
  3030. .fontColor($r('app.color.text_color'))
  3031. .fontSize(16)
  3032. .onClick(() => {
  3033. this.isSearchMode = false
  3034. this.searchText = ''
  3035. if (this.modeType === 2) {
  3036. this.updateListData(this.artistList)
  3037. } else {
  3038. this.updateListData(this.albumList)
  3039. }
  3040. })
  3041. }
  3042. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  3043. .animation({
  3044. duration: 666,
  3045. curve: 'ease-in-out' // 可选动画曲线
  3046. })
  3047. Blank()
  3048. Image($r("app.media.search"))
  3049. .width(25)
  3050. .visibility(this.modeType === 2 || this.modeType === 3 ? Visibility.Visible : Visibility.None)
  3051. .animation({
  3052. duration: 666,
  3053. curve: 'ease-in-out' // 可选动画曲线
  3054. })// .opacity(this.opacityItem)
  3055. .fillColor(this.themeColor)
  3056. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3057. .onClick(() => {
  3058. this.isSearchMode = true
  3059. })
  3060. Image($r("app.media.top_rank"))
  3061. .width(25)// .opacity(this.opacityItem)
  3062. .fillColor(this.themeColor)
  3063. .animation({
  3064. duration: 666,
  3065. curve: 'ease-in-out' // 可选动画曲线
  3066. })
  3067. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3068. .onClick(() => {
  3069. this.showRankDialog()
  3070. })
  3071. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  3072. .width(25)
  3073. .animation({
  3074. duration: 666,
  3075. curve: 'ease-in-out' // 可选动画曲线
  3076. })
  3077. .fillColor(this.themeColor)
  3078. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3079. .onClick(() => {
  3080. this.isGridMusic = !this.isGridMusic
  3081. })
  3082. }
  3083. .visibility(((this.modeType === 2 || this.modeType === 3) && !this.isCanBack) ? Visibility.Visible :
  3084. Visibility.None)
  3085. .width('100%')
  3086. .padding(10)
  3087. .height(50)
  3088. .border({
  3089. width: { bottom: 1 },
  3090. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  3091. })
  3092. Row({ space: 8 }) {
  3093. Row({ space: 8 }) {
  3094. Image($r("app.media.hm_play"))
  3095. .width(25)
  3096. .margin({ left: 8 })
  3097. .fillColor(this.themeColor)
  3098. Text(`播放全部`)
  3099. .fontColor($r('app.color.text_color'))
  3100. .fontSize(14)
  3101. .animation({
  3102. duration: 666,
  3103. curve: 'ease-in-out' // 可选动画曲线
  3104. })
  3105. if(Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length>0){
  3106. Text(this.modeType==1&&Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length==100?
  3107. `(${this.mediaKuCount}首)`
  3108. :`(${Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length}首)`)
  3109. .fontColor($r('app.color.text_color'))
  3110. .fontSize(14)
  3111. .opacity(this.opacityItem)
  3112. .animation({
  3113. duration: 666,
  3114. curve: 'ease-in-out' // 可选动画曲线
  3115. })
  3116. }
  3117. }
  3118. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3119. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  3120. .animation({
  3121. duration: 666,
  3122. curve: 'ease-in-out' // 可选动画曲线
  3123. })
  3124. // .backgroundColor(this.isClickedPLayAll ? $r('app.color.button_click') : Color.Transparent)
  3125. .onTouch((event: TouchEvent) => {
  3126. if (event.type === TouchType.Down) {
  3127. this.isClickedPLayAll = true;
  3128. } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
  3129. this.isClickedPLayAll = false;
  3130. }
  3131. })
  3132. .onClick(() => {
  3133. // ToastUtil.showToast('当前的手机的折叠状态 ='+DisplayUtil.getFoldStatus())
  3134. if (this.modeType === 0) {
  3135. const playList = this.getCurFileList();
  3136. const item = Utility.getPlayItem(playList, this.playType);
  3137. if (item) { // 显式检查undefined
  3138. this.doPlay(item);
  3139. }
  3140. } else {
  3141. const item = Utility.getPlayItem(this.mediaKuList, this.playType);
  3142. if (item) {
  3143. this.doPlay(item);
  3144. }
  3145. }
  3146. })
  3147. Row() {
  3148. TextInput({ placeholder: '输入名称...', text: this.searchText })
  3149. .height(35)
  3150. .onChange((value: string) => {
  3151. this.onSearchInput(value);
  3152. })
  3153. .layoutWeight(1)
  3154. Text(`取消`)
  3155. .margin({ left: 10, right: 10 })
  3156. .fontColor($r('app.color.text_color'))
  3157. .fontSize(16)
  3158. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3159. .onClick(() => {
  3160. this.isSearchMode = false
  3161. this.searchText = ''
  3162. if(this.modeType==0){
  3163. this.updateListData(this.videoLocalList)
  3164. } else if(this.modeType==1){
  3165. this.updateListData(this.mediaKuList)
  3166. } else if(this.modeType==2&&!this.isCanBack){
  3167. this.updateListData(this.artistList)
  3168. } else if(this.modeType==3&&!this.isCanBack){
  3169. this.updateListData(this.albumList)
  3170. }
  3171. })
  3172. }
  3173. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  3174. .animation({
  3175. duration: 666,
  3176. curve: 'ease-in-out' // 可选动画曲线
  3177. })
  3178. Blank()
  3179. Image($r("app.media.search"))
  3180. .width(25)// .visibility(this.modeType===1?Visibility.Visible:Visibility.None)
  3181. .animation({
  3182. duration: 666,
  3183. curve: 'ease-in-out' // 可选动画曲线
  3184. })// .opacity(this.opacityItem)
  3185. .fillColor(this.themeColor)
  3186. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3187. .onClick(() => {
  3188. this.isSearchMode = true
  3189. })
  3190. Image($r("app.media.refresh"))
  3191. .fillColor(this.themeColor)
  3192. .width(25)
  3193. .visibility(this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
  3194. .animation({
  3195. duration: 666,
  3196. curve: 'ease-in-out' // 可选动画曲线
  3197. })
  3198. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3199. .onClick(() => {
  3200. if (this.isFavMusic) {
  3201. this.getFavList(true)
  3202. } else {
  3203. if(this.modeType == 0){
  3204. this.asyncCurrentPathData()
  3205. }else if(this.modeType ==1){
  3206. workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
  3207. }
  3208. }
  3209. })
  3210. Image($r("app.media.top_rank"))
  3211. .width(25)
  3212. .visibility(this.isHistory || this.isSearchMode ? Visibility.None :
  3213. Visibility.Visible)// .opacity(this.opacityItem)
  3214. .animation({
  3215. duration: 666,
  3216. curve: 'ease-in-out' // 可选动画曲线
  3217. })
  3218. .fillColor(this.themeColor)
  3219. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3220. .onClick(() => {
  3221. this.showRankDialog()
  3222. })
  3223. Image(this.isMultiSelect ? $r("app.media.cancel_multi") : $r("app.media.top_flower"))
  3224. .width(24)
  3225. .visibility(this.isHistory || this.isSearchMode ? Visibility.None : Visibility.Visible)
  3226. .animation({
  3227. duration: 666,
  3228. curve: 'ease-in-out' // 可选动画曲线
  3229. })
  3230. .fillColor(this.themeColor)
  3231. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3232. .onClick(() => {
  3233. this.isMultiSelect = !this.isMultiSelect
  3234. })
  3235. SymbolGlyph($r('sys.symbol.trash'))
  3236. .fontColor([this.themeColor])
  3237. .fontSize(25)
  3238. .effectStrategy(1)
  3239. .visibility(this.isHistory ? Visibility.Visible : Visibility.None)
  3240. .animation({
  3241. duration: 666,
  3242. curve: 'ease-in-out' // 可选动画曲线
  3243. })
  3244. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3245. .onClick(() => {
  3246. this.clearVideoHistory() //清空播放记录
  3247. })
  3248. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  3249. .width(24)
  3250. .animation({
  3251. duration: 666,
  3252. curve: 'ease-in-out' // 可选动画曲线
  3253. })
  3254. .fillColor(this.themeColor)
  3255. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  3256. .bindPopup($$this.tipPopup, {
  3257. builder: this.popupBuilder,
  3258. placement: Placement.Bottom,
  3259. maskColor: 0x33000000,
  3260. enableArrow: true,
  3261. onStateChange: (e) => {
  3262. if (!e.isVisible) {
  3263. this.tipPopup = false;
  3264. }
  3265. }
  3266. })
  3267. .onClick(() => {
  3268. if(this.twoFingerType==4){
  3269. this.isGridMusic = false
  3270. this.twoFingerType=3
  3271. }else{
  3272. this.isGridMusic = !this.isGridMusic
  3273. }
  3274. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3275. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3276. })
  3277. }
  3278. .width('100%')
  3279. .padding(10)
  3280. .height(50)
  3281. .visibility(this.modeType === 0 || this.modeType === 1 || this.isCanBack ? Visibility.Visible : Visibility.None)
  3282. .border({
  3283. width: { bottom: 1 },
  3284. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  3285. })
  3286. }
  3287. .visibility(this.isShowAllBar ? Visibility.Visible : Visibility.None)
  3288. }
  3289. // 第二步:popup构造器定义弹框内容
  3290. @Builder popupBuilder() {
  3291. Column({ space: 2 }) {
  3292. Text('友情提示:双指缩放可以放大缩小列表')
  3293. .fontSize(12)
  3294. .fontWeight(FontWeight.Regular)
  3295. .fontColor($r('app.color.text_color'))
  3296. }
  3297. .justifyContent(FlexAlign.SpaceAround)
  3298. .width(220)
  3299. .height(55)
  3300. .padding(15)
  3301. }
  3302. //搜索功能的实现
  3303. @State searchText: string = ''; // 用户输入内容
  3304. @State filteredList: Array<VideoItem> = []; // 过滤后的结果
  3305. @State isSearchMode: boolean = false
  3306. // 实时搜索逻辑(带防抖)
  3307. private onSearchInput(value: string) {
  3308. this.searchText = value.trim();
  3309. let mSearchList: Array<VideoItem> = []
  3310. switch (this.modeType) {
  3311. case 0:
  3312. // mSearchList = this.videoLocalList
  3313. // break;
  3314. case 1:
  3315. mSearchList = this.mediaKuList
  3316. break;
  3317. case 2:
  3318. mSearchList = this.artistList
  3319. break;
  3320. case 3:
  3321. mSearchList = this.albumList
  3322. break;
  3323. }
  3324. // 新增条件判断:空输入时显示所有数据
  3325. if (this.searchText === '') {
  3326. this.filteredList = [...mSearchList]; // 创建新数组以触发状态更新
  3327. } else {
  3328. this.filteredList = mSearchList.filter((item: VideoItem) => {
  3329. //支持模糊匹配和艺术家 专辑匹配
  3330. const regex = new RegExp(this.searchText.toLowerCase().replace(/\s+/g, '.*'), 'i');
  3331. return regex.test(item.name.toLowerCase())||
  3332. regex.test(item.fileName?.toLowerCase() ?? "") ||
  3333. regex.test(item.artist?.toLowerCase() ?? "") ||
  3334. regex.test(item.album?.toLowerCase() ?? "")
  3335. });
  3336. }
  3337. this.updateListData(this.filteredList);
  3338. // this.isSearchMode = false; // 根据业务需求决定是否启用
  3339. }
  3340. @State dragItem: number = -1
  3341. @State scaleItem: number = -1
  3342. @State neighborItem: number = -1
  3343. @State neighborScale: number = -1
  3344. @State offsetY: number = 0
  3345. private dragRefOffset: number = 0
  3346. private ITEM_INTV: number = 78
  3347. scaleSelect(item: number): number {
  3348. if (this.scaleItem === item) {
  3349. return 1.05
  3350. } else if (this.neighborItem === item) {
  3351. return this.neighborScale
  3352. } else {
  3353. return 1
  3354. }
  3355. }
  3356. itemMove(index: number, newIndex: number): void {
  3357. if (newIndex < 0 || newIndex >= this.videoLocalList.length) {
  3358. return;
  3359. }
  3360. let tmp = this.videoLocalList.splice(index, 1);
  3361. this.videoLocalList.splice(newIndex, 0, tmp[0]);
  3362. this.dataSource.pushArrayData(this.videoLocalList)
  3363. }
  3364. //瀑布流布局 支持双指缩放
  3365. @State columns: number = 2;
  3366. @State waterFlowScale: number = 1;
  3367. @State imageScale: number = 1;
  3368. @State waterFlowOpacity: number = 1;
  3369. @State waterFlowSnapshot: image.PixelMap | undefined = undefined;
  3370. private columnChanged: boolean = false;
  3371. private oldColumn: number = this.columns;
  3372. private pinchTime: number = 0;
  3373. // 根据缩放阈值改变列数,触发WaterFlow重新布局
  3374. changeColumns(scale: number) {
  3375. if (scale > (this.columns / (this.columns - 0.5)) && this.columns > 1) {
  3376. this.columns--;
  3377. this.columnChanged = true;
  3378. } else if (scale < 1 && this.columns < 4) {
  3379. this.columns++;
  3380. this.columnChanged = true;
  3381. }
  3382. }
  3383. @Builder
  3384. getWaterView(){
  3385. Scroll(this.scroller) {
  3386. Column() {
  3387. if(this.isShowCoverHeader()){
  3388. this.coverHeader()
  3389. }else {
  3390. this.listViewTitle()
  3391. }
  3392. WaterFlow({
  3393. scroller:this.waterScroller,
  3394. layoutMode: WaterFlowLayoutMode.SLIDING_WINDOW
  3395. }) {
  3396. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3397. FlowItem() {
  3398. this.MusicWaterCardItem(item,index)
  3399. }
  3400. .width('100%')
  3401. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.9 })
  3402. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3403. {
  3404. preview: MenuPreviewMode.IMAGE,
  3405. previewAnimationOptions: { scale: [0.8, 1.0] },
  3406. })
  3407. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3408. {
  3409. preview: MenuPreviewMode.IMAGE,
  3410. previewAnimationOptions: { scale: [0.8, 1.0] },
  3411. })
  3412. .transition(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }))
  3413. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3414. TransitionEffect.scale({ x: 0, y: 0 })))
  3415. .gesture(
  3416. GestureGroup(GestureMode.Exclusive,
  3417. SwipeGesture({ direction: SwipeDirection.Horizontal })
  3418. .onAction((event: GestureEvent) => {
  3419. if (event) {
  3420. // this.sideBarController.openSideBar()
  3421. }
  3422. }),
  3423. TapGesture({ count: 1, fingers: 1 })
  3424. .onAction(async () => {
  3425. })
  3426. )
  3427. )
  3428. }, (item: VideoItem) => item.filePath)
  3429. }
  3430. // .columnsTemplate('repeat(auto-fit, 160)')
  3431. .id('waterflow') // 设置id用于截图
  3432. .columnsTemplate('1fr '.repeat(this.columns)) // 动态生成列模板,如:'1fr 1fr 1fr'表示3列等宽
  3433. .columnsGap(12) // 列间距
  3434. .rowsGap(16) // 行间距
  3435. .cachedCount(6)
  3436. .margin(
  3437. this.isHiCar()?{bottom:this.bottomBarHeight+90}:
  3438. {bottom:this.isShowCoverHeader()? this.topBarHeight+35:
  3439. this.isCoverOpacity()?this.topBarHeight+this.bottomBarHeight+78
  3440. :this.topBarHeight+this.bottomBarHeight+108})
  3441. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3442. .animation({ duration: 500, curve: Curve.Ease }))
  3443. .scrollBar(BarState.Off)
  3444. // .fadingEdge(true, { fadingEdgeLength: LengthMetrics.vp(38) })
  3445. // 效果:只有向上或者向下滑动到顶部时才会有弹簧回弹效果
  3446. .edgeEffect(EdgeEffect.Spring, { alwaysEnabled: true })
  3447. .width('100%')
  3448. .height('100%')
  3449. .padding(10)
  3450. .opacity(this.waterFlowOpacity)
  3451. .scale({
  3452. x: this.waterFlowScale,
  3453. y: this.waterFlowScale,
  3454. centerX: 0,
  3455. centerY: 0
  3456. })
  3457. .onAppear(() => {
  3458. this.scroller.scrollEdge(Edge.Top)
  3459. })
  3460. .nestedScroll({
  3461. scrollForward: NestedScrollMode.PARENT_FIRST,
  3462. scrollBackward: NestedScrollMode.SELF_FIRST
  3463. })
  3464. .priorityGesture(
  3465. PinchGesture()
  3466. .onActionStart((event: GestureEvent) => {
  3467. // 双指捏合手势识别成功时截图
  3468. this.pinchTime = event.timestamp;
  3469. this.columnChanged = false;
  3470. this.oldColumn = this.columns;
  3471. this.getUIContext().getComponentSnapshot().get('waterflow', (error: Error, pixmap: image.PixelMap) => {
  3472. if (error) {
  3473. console.info('error:' + JSON.stringify(error));
  3474. return;
  3475. }
  3476. this.waterFlowSnapshot = pixmap;
  3477. if ((this.oldColumn === 1 ) && event.scale > 1|| (this.oldColumn === 4 && event.scale < 1)) {
  3478. console.info("onecold onActionStart oldColumn:" + this.oldColumn)
  3479. if (this.oldColumn ===4) {
  3480. this.twoFingerType =3
  3481. this.isGridMusic = true
  3482. }else if (this.oldColumn ===1) {
  3483. this.twoFingerType =1
  3484. this.isGridMusic = false
  3485. }
  3486. return;
  3487. }
  3488. })
  3489. })
  3490. .onActionUpdate((event: GestureEvent) => {
  3491. // 手势更新:处理缩放逻辑和视觉效果
  3492. // 边界限制:防止超出列数范围时继续缩放
  3493. if ((this.oldColumn === 1 && event.scale > 1) || (this.oldColumn === 4 && event.scale < 1)) {
  3494. return;
  3495. }
  3496. // 节流处理:避免过于频繁的更新,提升性能
  3497. if (event.timestamp - this.pinchTime < 10000000) {
  3498. return;
  3499. }
  3500. this.pinchTime = event.timestamp;
  3501. this.waterFlowScale = event.scale;
  3502. this.imageScale = event.scale;
  3503. // 根据缩放比例设置WaterFlow透明度
  3504. this.waterFlowOpacity = (this.waterFlowScale > 1) ? (this.waterFlowScale - 1) : (1 - this.waterFlowScale);
  3505. this.waterFlowOpacity *= 3;
  3506. if (!this.columnChanged) {
  3507. this.changeColumns(event.scale);
  3508. }
  3509. // 列数改变后的缩放比例调整:避免出现空白区域
  3510. if (this.columnChanged) {
  3511. this.waterFlowScale = this.imageScale * this.columns / this.oldColumn;
  3512. // 限制缩放范围,确保视觉效果自然
  3513. if (event.scale < 1) {
  3514. this.waterFlowScale = this.waterFlowScale > 1 ? this.waterFlowScale : 1;
  3515. } else {
  3516. this.waterFlowScale = this.waterFlowScale < 1 ? this.waterFlowScale : 1;
  3517. }
  3518. }
  3519. })
  3520. .onActionEnd((event: GestureEvent) => {
  3521. // 手势结束:执行归位动画并保存状态
  3522. // 执行归位动画:平滑过渡到正常状态
  3523. this.getUIContext()?.animateTo({ duration: 300 }, () => {
  3524. this.waterFlowScale = 1;
  3525. this.waterFlowOpacity = 1;
  3526. })
  3527. // 持久化保存当前列数:下次启动时恢复
  3528. PreferencesUtil.putSync('lastColumns', this.columns);
  3529. })
  3530. )
  3531. //允许拖拽音乐和视频到List或Grid上自动导入视频
  3532. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3533. .onDrop((event?: DragEvent) => {
  3534. try {
  3535. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3536. if (dragData !== undefined) {
  3537. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3538. if (records.length > 0) {
  3539. for (let i = 0; i < records.length; i++) {
  3540. let types = records[i].getTypes();
  3541. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3542. const fileUriUds =
  3543. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3544. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3545. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3546. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3547. this.targetFile = fileUriUds.oriUri;
  3548. this.saveVideoDatas([this.targetFile])
  3549. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3550. }
  3551. }
  3552. }
  3553. } else {
  3554. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3555. }
  3556. } else {
  3557. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3558. }
  3559. } catch (error) {
  3560. const err = error as BusinessError;
  3561. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3562. }
  3563. })
  3564. }
  3565. }
  3566. .scrollBar(BarState.Off)
  3567. }
  3568. //瀑布流卡片布局
  3569. @Builder
  3570. private MusicWaterCardItem(item: VideoItem, index: number) {
  3571. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3572. Stack() {
  3573. Column() {
  3574. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3575. .backgroundImageSize(ImageSize.Auto)
  3576. .borderRadius({
  3577. topLeft: 12,
  3578. topRight : 12,
  3579. bottomLeft: 0,
  3580. bottomRight: 0
  3581. })
  3582. .draggable(false)// 禁止长按手势拖动
  3583. // .autoResize(true) // 重采样,可减少内存占用
  3584. // .interpolation(ImageInterpolation.High)// 用于重采样后的抗锯齿
  3585. .width('100%')
  3586. .height('auto')
  3587. .objectFit(ImageFit.Auto)
  3588. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3589. height: '99%' ,
  3590. dragBar: true,
  3591. onDisappear: () => {
  3592. this.longItemFilePath = '';
  3593. this.tempLyricContent = ''
  3594. },
  3595. showClose: true,
  3596. preferType: SheetType.CENTER ,
  3597. title: { title: '编辑标签' }
  3598. })
  3599. .draggable(false)
  3600. .opacity(this.opacityItem)// 绑定透明度
  3601. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3602. // .animation({ duration: 500, curve: Curve.Ease }))
  3603. .animation({
  3604. duration: 666,
  3605. curve: 'ease-in-out' // 可选动画曲线
  3606. })
  3607. .margin({
  3608. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3609. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3610. })
  3611. Column() {
  3612. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3613. .fontSize(this.columns == 4 ||this.columns==3? 12 : this.columns == 2 ? 15 : 18)
  3614. .maxLines(1)
  3615. .fontWeight(FontWeight.Bold)
  3616. .textOverflow({ overflow: this.isLongNameRoLL?TextOverflow.MARQUEE:TextOverflow.Ellipsis })//超长滚动
  3617. .animation({
  3618. duration: 555,
  3619. curve: 'Linear',
  3620. })
  3621. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3622. height: '95%',
  3623. dragBar: true,
  3624. showClose: true,
  3625. onDisappear: () => {
  3626. this.longItemFilePathDetail = '';
  3627. },
  3628. blurStyle:BlurStyle.Thin,
  3629. backgroundColor:Color.Transparent,
  3630. preferType: SheetType.CENTER ,
  3631. title: { title: '详情' }
  3632. })
  3633. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3634. $r('app.color.text_color'))
  3635. Column() {
  3636. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  3637. .fontSize(11)
  3638. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 14)
  3639. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3640. .fontColor($r('app.color.text_color'))
  3641. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  3642. .fontSize(11)
  3643. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 14)
  3644. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3645. .fontColor($r('app.color.text_color'))
  3646. Row(){
  3647. Column(){
  3648. Text(item.md5Str?.includes('Lossless')?
  3649. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  3650. .fontSize(this.columns == 4 ||this.columns==3? 8 : this.columns == 2 ? 9 : 11)
  3651. .padding({ top: 3,right:6,left:6,bottom:3 })
  3652. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3653. $r('app.color.text_color'))
  3654. .fontWeight(500)
  3655. .borderRadius(12)
  3656. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  3657. .backgroundColor('#FFC107')
  3658. .visibility(StrUtil.isEmpty(item.md5Str)||this.twoFingerType==1?Visibility.None:Visibility.Visible)
  3659. }
  3660. .margin({ top: 2 ,right:6})
  3661. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  3662. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  3663. Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  3664. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 13)
  3665. .maxLines(1)
  3666. .textOverflow({ overflow: this.isLongNameRoLL?TextOverflow.MARQUEE:TextOverflow.Ellipsis })//超长滚动
  3667. .margin({ top: 2})
  3668. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  3669. || item.type == CommonConstants.TYPE_IS_ALBUM
  3670. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3671. .fontWeight(FontWeight.Medium)
  3672. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3673. $r('app.color.text_color'))
  3674. }
  3675. }
  3676. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  3677. }
  3678. .height(this.columns == 4 ||this.columns==3? item.type==CommonConstants.TYPE_IS_DIR?30:40
  3679. : this.columns == 2 ? (item.type==CommonConstants.TYPE_IS_DIR?38:48) :
  3680. (item.type==CommonConstants.TYPE_IS_DIR?48:58))
  3681. .width('100%')
  3682. .justifyContent(FlexAlign.Center)
  3683. .margin({
  3684. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3685. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3686. })
  3687. }
  3688. .width('100%')
  3689. .borderRadius(12)
  3690. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  3691. .backgroundImageSize({ height: '100%', width: '100%' })
  3692. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  3693. .animation({ curve: Curve.Sharp, duration: 300 })
  3694. Checkbox({ name: 'checkbox' + index })
  3695. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  3696. .selectedColor(this.themeColor)
  3697. .shape(CheckBoxShape.CIRCLE)
  3698. .opacity(this.isMultiSelect ? 1 : 0)
  3699. .animation({
  3700. duration: 666,
  3701. curve: 'Smooth' // 可选动画曲线
  3702. })
  3703. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  3704. Visibility.None)
  3705. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  3706. .margin({ left: 20, top: 8, bottom: 8 })
  3707. .width(38)
  3708. .height(38)
  3709. }
  3710. }
  3711. .backgroundColor(Color.Transparent)
  3712. .width('100%')
  3713. .height('auto')
  3714. .padding({top:2})
  3715. .reuseId('card_item')
  3716. .onClick(() => {
  3717. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3718. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3719. this.handleFileSelection(item, !isChecked);
  3720. } else {
  3721. this.doPlay(item, index)
  3722. }
  3723. })
  3724. }
  3725. // Grid布局的开始
  3726. private dragRefOffSetX: number = 0;
  3727. private dragRefOffSetY: number = 0;
  3728. private FIX_VP_X: number = 180;
  3729. private FIX_VP_Y: number = 84;
  3730. isDraggable(index: number): boolean {
  3731. return index >= 0;
  3732. }
  3733. getRowEnd(item: number) {
  3734. if (item.toString() === '0') {
  3735. return 1;
  3736. } else {
  3737. return 0;
  3738. }
  3739. }
  3740. isInLeft(index: number) {
  3741. return index % 2 == 0;
  3742. }
  3743. down(index: number): void {
  3744. if ([this.videoLocalList.length - 1, this.videoLocalList.length - 2].includes(index)) {
  3745. return;
  3746. }
  3747. this.offsetY -= this.FIX_VP_Y;
  3748. this.dragRefOffSetY += this.FIX_VP_Y;
  3749. this.itemMove(index, index + 1);
  3750. }
  3751. up(index: number): void {
  3752. if (!this.isDraggable(index - 2)) {
  3753. return;
  3754. }
  3755. this.offsetY += this.FIX_VP_Y;
  3756. this.dragRefOffSetY -= this.FIX_VP_Y;
  3757. this.itemMove(index, index - 1);
  3758. }
  3759. left(index: number): void {
  3760. if (this.isInLeft(index)) {
  3761. return;
  3762. }
  3763. if (!this.isDraggable(index - 1)) {
  3764. return;
  3765. }
  3766. this.offsetX += this.FIX_VP_X;
  3767. this.dragRefOffSetX -= this.FIX_VP_X;
  3768. this.itemMove(index, index - 1)
  3769. }
  3770. right(index: number): void {
  3771. if (!this.isInLeft(index)) {
  3772. return;
  3773. }
  3774. if (!this.isDraggable(index + 1)) {
  3775. return;
  3776. }
  3777. this.offsetX -= this.FIX_VP_X;
  3778. this.dragRefOffSetX += this.FIX_VP_X;
  3779. this.itemMove(index, index + 1)
  3780. }
  3781. private scroller: Scroller = new Scroller();
  3782. private waterScroller: Scroller = new Scroller();
  3783. @State startIndex: number = 0
  3784. @State endIndex: number = 0
  3785. @State scaleValue: number = 1
  3786. @State pinchValue: number = 1
  3787. layoutOptionsForHeader: GridLayoutOptions = {
  3788. regularSize: [1, 1], // 只支持[1, 1]
  3789. irregularIndexes: [0], // 索引为0的GridItem占用一行
  3790. };
  3791. @Builder
  3792. getGridView() {
  3793. Grid(this.scroller, this.layoutOptionsForHeader) {
  3794. GridItem() {
  3795. if (this.isShowCoverHeader()) {
  3796. this.coverHeader()
  3797. } else {
  3798. this.listViewTitle()
  3799. }
  3800. }
  3801. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3802. GridItem() {
  3803. Stack({ alignContent: Alignment.Center }) {
  3804. this.MusicItemGrid(item, index)
  3805. }
  3806. }
  3807. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3808. {
  3809. preview: MenuPreviewMode.IMAGE,
  3810. previewAnimationOptions: { scale: [0.8, 1.0] },
  3811. })
  3812. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3813. {
  3814. preview: MenuPreviewMode.IMAGE,
  3815. previewAnimationOptions: { scale: [0.8, 1.0] },
  3816. })
  3817. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3818. TransitionEffect.scale({ x: 0, y: 0 })))
  3819. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3820. .scale({ x: this.scaleItem === index ? 1.02 : 1, y: this.scaleItem === index ? 1.02 : 1 })
  3821. .zIndex(this.dragItem === index ? 1 : 0)
  3822. .translate(this.dragItem === index ? { x: this.offsetX, y: this.offsetY } : { x: 0, y: 0 })
  3823. }, (item: VideoItem) => item.filePath)
  3824. }
  3825. .width(this.isShowHeader ? '100%' : '94%')
  3826. .height('100%')
  3827. .editMode(true)
  3828. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3829. .animation({ duration: 500, curve: Curve.Ease }))
  3830. .margin(
  3831. this.isHiCar()?{bottom:this.bottomBarHeight+98}:
  3832. {
  3833. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+30 : this.topBarHeight+90)
  3834. : (this.isShowCoverHeader() ? this.topBarHeight+45 : this.topBarHeight+128)
  3835. })
  3836. .reuseId('grid_item')
  3837. .layoutWeight(1)
  3838. .scrollBar(BarState.Off)
  3839. .supportAnimation(true)
  3840. .cachedCount(this.twoFingerType==1?5:this.twoFingerType==2?4:3)
  3841. .columnsTemplate(
  3842. this.twoFingerType == 3 ? 'repeat(auto-fit, 160)' :
  3843. this.twoFingerType == 2 ? 'repeat(auto-fit, 110)' : 'repeat(auto-fit, 80)'
  3844. )
  3845. .rowsGap(this.isShowDrawer ? 25 : (this.twoFingerType == 3 ? 10 : this.twoFingerType == 2 ? 5 : 1))
  3846. .visibility(this.isGridMusic ? Visibility.Visible : Visibility.None)
  3847. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3848. .gesture(PinchGesture({ fingers: 2 })
  3849. .onActionEnd((event: GestureEvent) => {
  3850. this.setGridTwoFingers()
  3851. })
  3852. .onActionUpdate(e => {
  3853. this.scaleValue = this.pinchValue * e.scale
  3854. })
  3855. .onActionStart(e => {
  3856. }))
  3857. .enableScrollInteraction(true)
  3858. .onScrollIndex((start: number, end: number) => {
  3859. this.startIndex = start
  3860. this.endIndex = end
  3861. })
  3862. .onScrollFrameBegin((offset: number) => {
  3863. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3864. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3865. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3866. if (this.isScrollHide) {
  3867. this.setBarHeightHide2(offset)
  3868. } else {
  3869. this.setBarHeightNormal()
  3870. }
  3871. } else {
  3872. this.setBarHeightHide(offset)
  3873. }
  3874. return { offsetRemain: offset };
  3875. })
  3876. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3877. .onDrop((event?: DragEvent) => {
  3878. try {
  3879. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3880. if (dragData !== undefined) {
  3881. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3882. if (records.length > 0) {
  3883. for (let i = 0; i < records.length; i++) {
  3884. let types = records[i].getTypes();
  3885. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3886. const fileUriUds =
  3887. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3888. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3889. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3890. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3891. this.targetFile = fileUriUds.oriUri;
  3892. this.saveVideoDatas([this.targetFile])
  3893. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3894. }
  3895. }
  3896. }
  3897. } else {
  3898. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3899. }
  3900. } else {
  3901. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3902. }
  3903. } catch (error) {
  3904. const err = error as BusinessError;
  3905. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3906. }
  3907. })
  3908. }
  3909. @State targetFile: string = '';
  3910. setGridTwoFingers() {
  3911. this.pinchValue = this.scaleValue;
  3912. Logger.info('this.pinchValue = ' + this.pinchValue);
  3913. if (this.pinchValue >= 1) {
  3914. this.twoFingerType++
  3915. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3916. if(this.twoFingerType >= 4){
  3917. this.twoFingerType = 4//切换成瀑布流
  3918. this.columns = 4
  3919. }
  3920. } else {
  3921. this.twoFingerType--
  3922. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3923. if (this.twoFingerType < 1) {
  3924. this.twoFingerType = 3
  3925. this.isGridMusic = false
  3926. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3927. }
  3928. }
  3929. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3930. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3931. this.pinchValue = 1;
  3932. this.scaleValue = 1;
  3933. }
  3934. @State longItemFilePath: string = ''
  3935. @State tempLyricContent: string = ''
  3936. @Builder
  3937. private MusicItemGrid(item: VideoItem, index: number) {
  3938. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3939. Stack() {
  3940. Column() {
  3941. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3942. .height(this.getGridHeight())
  3943. .width(this.getGridWight())
  3944. .draggable(false)
  3945. .interpolation(ImageInterpolation.High)// 用于重采样后的抗锯齿
  3946. .autoResize(true) // 重采样,可减少内存占用
  3947. .alt($r('app.media.ic_avatar2'))
  3948. .clip(true)
  3949. .borderRadius({
  3950. topLeft: 12,
  3951. topRight: 12,
  3952. bottomLeft: 0,
  3953. bottomRight: 0
  3954. })
  3955. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3956. height: '99%' ,
  3957. dragBar: true,
  3958. onDisappear: () => {
  3959. this.longItemFilePath = '';
  3960. this.tempLyricContent = ''
  3961. },
  3962. showClose: true,
  3963. preferType: SheetType.CENTER ,
  3964. title: { title: '编辑标签' }
  3965. })
  3966. .draggable(false)
  3967. .opacity(this.opacityItem)// 绑定透明度
  3968. .animation({
  3969. duration: 666,
  3970. curve: 'ease-in-out' // 可选动画曲线
  3971. })
  3972. .margin({
  3973. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3974. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3975. })
  3976. Column() {
  3977. Text(this.isShowFileName&&item.type!=CommonConstants.TYPE_IS_DIR?item.fileName :item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3978. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  3979. .maxLines(1)
  3980. .fontWeight(FontWeight.Bold)
  3981. .textOverflow({ overflow: this.isLongNameRoLL?TextOverflow.MARQUEE:TextOverflow.Ellipsis })//超长滚动
  3982. .animation({
  3983. duration: 555,
  3984. curve: 'Linear',
  3985. })
  3986. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3987. height: '95%',
  3988. dragBar: true,
  3989. showClose: true,
  3990. onDisappear: () => {
  3991. this.longItemFilePathDetail = '';
  3992. },
  3993. blurStyle:BlurStyle.Thin,
  3994. backgroundColor:Color.Transparent,
  3995. preferType: SheetType.CENTER ,
  3996. title: { title: '详情' }
  3997. })
  3998. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3999. $r('app.color.text_color'))
  4000. Column() {
  4001. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  4002. .fontSize(11)
  4003. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  4004. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  4005. .fontColor($r('app.color.text_color'))
  4006. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  4007. .fontSize(11)
  4008. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  4009. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  4010. .fontColor($r('app.color.text_color'))
  4011. Row(){
  4012. Column(){
  4013. Text(item.md5Str?.includes('Lossless')?
  4014. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  4015. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  4016. .padding({ top: 3,right:6,left:6,bottom:3 })
  4017. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  4018. $r('app.color.text_color'))
  4019. .fontWeight(500)
  4020. .borderRadius(12)
  4021. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  4022. .backgroundColor('#FFC107')
  4023. .visibility(StrUtil.isEmpty(item.md5Str)||this.twoFingerType==1?Visibility.None:Visibility.Visible)
  4024. }
  4025. .margin({ top: 2 ,right:6})
  4026. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  4027. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  4028. Text(this.isShowFileName?item.duration:StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  4029. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 13)
  4030. .maxLines(1)
  4031. .textOverflow({ overflow: this.isLongNameRoLL?TextOverflow.MARQUEE:TextOverflow.Ellipsis })//超长滚动
  4032. .margin({ top: 2})
  4033. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  4034. || item.type == CommonConstants.TYPE_IS_ALBUM
  4035. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  4036. .fontWeight(FontWeight.Medium)
  4037. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  4038. $r('app.color.text_color'))
  4039. }
  4040. }
  4041. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  4042. }
  4043. .height(this.twoFingerType == 3 ? 60 : this.twoFingerType == 2 ? 48 : 35)
  4044. .width(this.getGridWight())
  4045. .justifyContent(FlexAlign.Center)
  4046. .margin({
  4047. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  4048. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  4049. })
  4050. }
  4051. .width(this.getGridWight())
  4052. .borderRadius(12)
  4053. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  4054. .backgroundImageSize({ height: '100%', width: '100%' })
  4055. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  4056. .animation({ curve: Curve.Sharp, duration: 300 })
  4057. Checkbox({ name: 'checkbox' + index })
  4058. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  4059. .selectedColor(this.themeColor)
  4060. .shape(CheckBoxShape.CIRCLE)
  4061. .opacity(this.isMultiSelect ? 1 : 0)
  4062. .animation({
  4063. duration: 666,
  4064. curve: 'Smooth' // 可选动画曲线
  4065. })
  4066. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  4067. Visibility.None)
  4068. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  4069. .margin({ left: 20, top: 8, bottom: 8 })
  4070. .width(38)
  4071. .height(38)
  4072. }
  4073. }
  4074. .backgroundColor(Color.Transparent)
  4075. .width('100%')
  4076. .padding({ top: 15 })
  4077. .height(this.getGridAllHeight())
  4078. .onClick(() => {
  4079. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  4080. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  4081. this.handleFileSelection(item, !isChecked);
  4082. } else {
  4083. this.doPlay(item, index)
  4084. }
  4085. })
  4086. }
  4087. getGridAllHeight() {
  4088. let heightG = 222
  4089. switch (this.twoFingerType) {
  4090. case 1:
  4091. heightG = 143
  4092. break;
  4093. case 2:
  4094. heightG = 178
  4095. break;
  4096. case 3:
  4097. heightG = 222
  4098. break;
  4099. }
  4100. return heightG
  4101. }
  4102. getGridHeight() {
  4103. let heightG = 150
  4104. switch (this.twoFingerType) {
  4105. case 1:
  4106. heightG = 80
  4107. break;
  4108. case 2:
  4109. heightG = 110
  4110. break;
  4111. case 3:
  4112. heightG = 150
  4113. break;
  4114. }
  4115. return heightG
  4116. }
  4117. getGridWight() {
  4118. let wightG = 158
  4119. switch (this.twoFingerType) {
  4120. case 1:
  4121. wightG = 80
  4122. break;
  4123. case 2:
  4124. wightG = 110
  4125. break;
  4126. case 3:
  4127. wightG = 158
  4128. break;
  4129. }
  4130. return wightG
  4131. }
  4132. @State isShowDetail:boolean = false
  4133. @State longItemFilePathDetail:string =''
  4134. @Builder
  4135. MenuBuilder(item: VideoItem, index: number, filePath: string) {
  4136. if(
  4137. ((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  4138. ||(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  4139. item.name === LocalMusic.STR_HISTORY_MUSIC)
  4140. ){
  4141. //如果是专辑和艺术家的首页,不能长按
  4142. //如果是我的收藏 最近播放等也不能长按
  4143. }else{
  4144. Scroll() {
  4145. Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
  4146. Menu() {
  4147. MenuItem({
  4148. symbolStartIcon: new SymbolGlyphModifier(Utility.getIsFav(this.favList, item) ?
  4149. $r('sys.symbol.heart_fill') : $r('sys.symbol.heart')),
  4150. content: Utility.getIsFav(this.favList, item) ? '取消收藏' : '收藏'
  4151. })
  4152. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  4153. .onClick(() => {
  4154. if (item) {
  4155. this.doFav(item)
  4156. }
  4157. this.longItemFilePath = ''
  4158. })
  4159. MenuItem({
  4160. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.forward_end_fill')),
  4161. content: '下一首播放'
  4162. })
  4163. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  4164. .onClick(() => {
  4165. this.addToNextPlay(item);
  4166. this.longItemFilePath = ''
  4167. })
  4168. MenuItem({
  4169. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.music_note_list')),
  4170. content: '添加到歌单'
  4171. })
  4172. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  4173. .onClick(async () => {
  4174. this.longItemFilePath = ''
  4175. await this.showAddToPlaylistDialog(item)
  4176. })
  4177. MenuItem({
  4178. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
  4179. content: '编辑标签'
  4180. })
  4181. .bindSheet($$this.isShowEdit, this.editSheet(item), {
  4182. height: '99%',
  4183. dragBar: true,
  4184. showClose: true,
  4185. preferType: SheetType.CENTER ,
  4186. title: { title: '编辑标签' }
  4187. })
  4188. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  4189. .onClick(async() => {
  4190. this.setEditStrEmpty()
  4191. this.tempLyricContent = await this.getLyricContent(item);
  4192. if(this.isGridMusic||this.twoFingerType==4){
  4193. this.longItemFilePath = item.filePath
  4194. }else{
  4195. this.isShowEdit = !this.isShowEdit;
  4196. }
  4197. })
  4198. MenuItem({
  4199. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.checkmark_square_on_square')),
  4200. content: $r('app.string.select_all')
  4201. })
  4202. .onClick(() => {
  4203. this.isMultiSelect = !this.isMultiSelect
  4204. this.longItemFilePath = ''
  4205. this.selectedFiles.push(item)
  4206. })
  4207. MenuItem({
  4208. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.rename')),
  4209. content: $r('app.string.rename')
  4210. })
  4211. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  4212. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  4213. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  4214. .onClick(() => {
  4215. this.showReNameDialog(item, index + '', filePath)
  4216. this.longItemFilePath = ''
  4217. })
  4218. MenuItem({
  4219. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
  4220. content: $r('app.string.delete')
  4221. })
  4222. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  4223. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  4224. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  4225. .onClick(() => {
  4226. this.selectedFiles.push(item)
  4227. this.showWarnIsDelete()
  4228. this.longItemFilePath = ''
  4229. })
  4230. MenuItem({
  4231. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.info_circle')),
  4232. content: $r('app.string.detail')
  4233. })
  4234. .bindSheet($$this.isShowDetail, this.detailSheet(item), {
  4235. height:'95%',
  4236. dragBar: true,
  4237. showClose: true,
  4238. blurStyle:BlurStyle.Thin,
  4239. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  4240. backgroundColor:Color.Transparent,
  4241. title: { title: '详情信息' }
  4242. })
  4243. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  4244. .onClick(() => {
  4245. if(this.isGridMusic||this.twoFingerType==4){
  4246. this.longItemFilePathDetail = item.filePath
  4247. }else{
  4248. this.isShowDetail = !this.isShowDetail
  4249. }
  4250. })
  4251. MenuItem({
  4252. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.share')),
  4253. content: $r('app.string.share')
  4254. })
  4255. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  4256. .onClick(() => {
  4257. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  4258. this.longItemFilePath = ''
  4259. })
  4260. }
  4261. .font({ size: 15, weight: FontWeight.Normal })
  4262. }
  4263. .width(180)
  4264. }
  4265. .height('auto')
  4266. }
  4267. }
  4268. private listMaxScrollOffsetY: number = 0
  4269. @State selectedIndex: number = -1
  4270. setlistTwoFingers() {
  4271. this.pinchValue = this.scaleValue;
  4272. Logger.info('this.pinchValue = ' + this.pinchValue);
  4273. if (this.pinchValue >= 1) {
  4274. this.twoFingerType++
  4275. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  4276. if (this.twoFingerType > 3) {
  4277. this.twoFingerType = 1
  4278. this.isGridMusic = true
  4279. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  4280. }
  4281. } else {
  4282. this.twoFingerType--
  4283. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  4284. if (this.twoFingerType < 1) {
  4285. this.twoFingerType = 4
  4286. this.columns = 1
  4287. }
  4288. }
  4289. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  4290. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  4291. this.pinchValue = 1;
  4292. this.scaleValue = 1;
  4293. }
  4294. @Builder
  4295. getListView() {
  4296. List({ scroller: this.listScroller }) {
  4297. ListItemGroup({ header: this.coverHeader() }) {
  4298. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  4299. ListItem() {
  4300. Column() {
  4301. if (item.type === CommonConstants.TYPE_IS_DIR
  4302. || item.type === CommonConstants.TYPE_IS_ARTIST || item.type === CommonConstants.TYPE_IS_ALBUM) {
  4303. this.DirItem(item, index)
  4304. } else if (item.type === CommonConstants.TYPE_IS_CSJAD) { //如果是穿山甲广告
  4305. } else {
  4306. this.MusicItem(item, index)
  4307. }
  4308. }
  4309. .shadow(this.scaleItem === index ? {
  4310. radius: 70,
  4311. color: '#15000000',
  4312. offsetX: 0,
  4313. offsetY: 0
  4314. } :
  4315. {
  4316. radius: 0,
  4317. color: '#15000000',
  4318. offsetX: 0,
  4319. offsetY: 0
  4320. })
  4321. .animation({ curve: Curve.Sharp, duration: 300 })
  4322. }
  4323. // .transition(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }))
  4324. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  4325. .animation({ duration: 500 }),
  4326. TransitionEffect.scale({ x: 0, y: 0 })))
  4327. .clickEffect({ level: ClickEffectLevel.LIGHT })
  4328. .swipeAction((
  4329. (this.isSwipe&&this.modeType == 0 || this.modeType == 1 || ((this.modeType == 3 || this.modeType == 2) && this.isCanBack))
  4330. && item.type !== CommonConstants.TYPE_IS_CSJAD &&
  4331. !this.isHistory) ? { end: this.DeleteButton(item, index, item.filePath) } : {}) //左滑
  4332. .onClick(() => {
  4333. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  4334. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  4335. this.handleFileSelection(item, !isChecked);
  4336. } else {
  4337. this.doPlay(item, index)
  4338. }
  4339. })
  4340. //拖动List关键代码开始
  4341. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  4342. .zIndex(this.dragItem === index ? 1 : 0)
  4343. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  4344. .gesture(
  4345. GestureGroup(GestureMode.Sequence,
  4346. LongPressGesture({ repeat: true })
  4347. .onAction((event?: GestureEvent) => {
  4348. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  4349. this.scaleItem = index
  4350. })
  4351. })
  4352. .onActionEnd(() => {
  4353. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  4354. this.scaleItem = -1
  4355. })
  4356. }),
  4357. PanGesture({ fingers: 1, direction: null, distance: 0 })
  4358. .onActionStart(() => {
  4359. this.dragItem = index // 记录当前拖动项索引
  4360. this.dragRefOffset = 0 // 重置偏移基准
  4361. })
  4362. .onActionUpdate((event: GestureEvent) => {
  4363. this.offsetY = event.offsetY - this.dragRefOffset;
  4364. this.neighborItem = -1;
  4365. let indexA = this.videoLocalList.indexOf(item);
  4366. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  4367. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  4368. let value: number = 0;
  4369. if (this.offsetY < 0) {
  4370. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  4371. this.neighborItem = indexA - 1;
  4372. this.neighborScale = 1 - value / 20;
  4373. } else if (this.offsetY > 0) {
  4374. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  4375. this.neighborItem = indexA + 1;
  4376. this.neighborScale = 1 - value / 20;
  4377. }
  4378. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.videoLocalList.length) {
  4379. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4380. this.offsetY -= this.ITEM_INTV;
  4381. this.dragRefOffset += this.ITEM_INTV;
  4382. this.itemMove(indexA, indexA + 1);
  4383. });
  4384. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  4385. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4386. this.offsetY += this.ITEM_INTV;
  4387. this.dragRefOffset -= this.ITEM_INTV;
  4388. this.itemMove(indexA, indexA - 1);
  4389. });
  4390. }
  4391. let curListOffset = this.listScroller.currentOffset()
  4392. // 获取手指信息
  4393. let fingerInfo = event.fingerList[0]
  4394. let clickPercentY =
  4395. (fingerInfo.globalY - Number(this.listArea.globalPosition.y)) / Number(this.listArea.height)
  4396. if (clickPercentY > 0.8 && !this.listScroller.isAtEnd()) {
  4397. let scrollVelocity = clickPercentY > 0.9 ? 4 : 2
  4398. if (this.listMaxScrollOffsetY - curListOffset.yOffset > scrollVelocity + 5) {
  4399. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset += scrollVelocity })
  4400. }
  4401. } else if (clickPercentY < 0.2 && curListOffset.yOffset >= 0) {
  4402. let scrollVelocity = clickPercentY < 0.1 ? 4 : 2
  4403. if (curListOffset.yOffset > scrollVelocity + 5) {
  4404. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset -= scrollVelocity })
  4405. }
  4406. }
  4407. })
  4408. .onActionEnd((event: GestureEvent) => {
  4409. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4410. this.dragItem = -1
  4411. this.neighborItem = -1
  4412. })
  4413. animateTo({
  4414. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  4415. }, () => {
  4416. this.scaleItem = -1
  4417. })
  4418. })
  4419. )
  4420. .onCancel(() => {
  4421. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4422. this.dragItem = -1
  4423. this.neighborItem = -1
  4424. })
  4425. animateTo({
  4426. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  4427. }, () => {
  4428. this.scaleItem = -1
  4429. })
  4430. })
  4431. ) //拖动List关键代码结束
  4432. }, (item: VideoItem) => item.filePath)
  4433. }
  4434. }
  4435. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  4436. .gesture(PinchGesture({ fingers: 2 })
  4437. .onActionEnd((event: GestureEvent) => {
  4438. this.setlistTwoFingers()
  4439. })
  4440. .onActionUpdate(e => {
  4441. this.scaleValue = this.pinchValue * e.scale
  4442. })
  4443. .onActionStart(e => {
  4444. }))
  4445. // .divider({ strokeWidth: 1, color: this.isDarkMode? '#333333':'#ffe9f0f0' })
  4446. .margin(
  4447. this.isHiCar()&&(this.windowWidth>1800&&this.windowHeight>=1200)?{bottom:this.bottomBarHeight+98}:
  4448. {
  4449. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+25 : this.topBarHeight+80)
  4450. : (this.isShowCoverHeader() ? this.topBarHeight+35 : this.isHiCarSmall()?this.topBarHeight+90:this.topBarHeight+125)
  4451. })
  4452. .cachedCount(6)
  4453. .reuseId('list_item')
  4454. .borderRadius(20)
  4455. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  4456. TransitionEffect.scale({ x: 0, y: 0 })))
  4457. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  4458. // .animation({ duration: 500, curve: Curve.Ease }))
  4459. .layoutWeight(1)
  4460. .onScrollIndex((start) => {
  4461. this.selectedIndex = start
  4462. })
  4463. .visibility(this.isGridMusic ? Visibility.None : Visibility.Visible)
  4464. .lanes(
  4465. new BreakpointType<number>({
  4466. sm: 1,
  4467. md: 2,
  4468. lg: 2,
  4469. xl: 3,
  4470. xxl: 4
  4471. }).getValue(this.currentBreakpoint),
  4472. new BreakpointType<number>({
  4473. sm: 0,
  4474. md: 12,
  4475. lg: 12,
  4476. xl: 16,
  4477. xxl: 20
  4478. }).getValue(this.currentBreakpoint)
  4479. )
  4480. .onAreaChange((oldValue: Area, newValue: Area) => {
  4481. this.listArea = newValue
  4482. if (this.twoFingerType == 3) {
  4483. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_BIG) - 10
  4484. } else if (this.twoFingerType == 2) {
  4485. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT) - 10
  4486. } else if (this.twoFingerType == 1) {
  4487. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_SMALL) - 10
  4488. }
  4489. })
  4490. .onScrollFrameBegin((offset: number) => {
  4491. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  4492. // if (this.isPhoneLan()) {
  4493. // this.setBarHeightHide(offset)
  4494. // } else
  4495. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  4496. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  4497. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  4498. if (this.isScrollHide) {
  4499. this.setBarHeightHide2(offset)
  4500. } else {
  4501. this.setBarHeightNormal()
  4502. }
  4503. } else {
  4504. this.setBarHeightHide(offset)
  4505. }
  4506. return { offsetRemain: offset };
  4507. })
  4508. //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
  4509. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  4510. .onDrop((event?: DragEvent) => {
  4511. try {
  4512. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  4513. if (dragData !== undefined) {
  4514. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  4515. if (records.length > 0) {
  4516. for (let i = 0; i < records.length; i++) {
  4517. let types = records[i].getTypes();
  4518. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  4519. const fileUriUds =
  4520. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  4521. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  4522. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  4523. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  4524. this.targetFile = fileUriUds.oriUri;
  4525. this.saveVideoDatas([this.targetFile])
  4526. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  4527. }
  4528. }
  4529. }
  4530. } else {
  4531. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  4532. }
  4533. } else {
  4534. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  4535. }
  4536. } catch (error) {
  4537. const err = error as BusinessError;
  4538. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  4539. }
  4540. })
  4541. }
  4542. setBarHeightNormal() {
  4543. this.hideDone = false;
  4544. this.getUIContext().animateTo({
  4545. duration: 300
  4546. }, () => {
  4547. this.bottomBarHeight = 55 + 0;
  4548. this.topBarHeight = 50 + 0;
  4549. this.barOpacity = 1;
  4550. this.barBottomOpacity = 1
  4551. this.currentYOffset = 0;
  4552. this.isHiding = false;
  4553. });
  4554. }
  4555. setBarHeightHide(offset: number) {
  4556. if (offset > 0 && !this.hideDone) {
  4557. this.currentYOffset += offset;
  4558. if (this.currentYOffset <= 100) {
  4559. this.bottomBarHeight = this.bottomBarHeight * (1 - this.currentYOffset / 100);
  4560. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  4561. this.barOpacity = 1 - this.currentYOffset / 100;
  4562. this.barBottomOpacity = 1 - this.currentYOffset / 100;
  4563. } else {
  4564. this.topBarHeight = 0;
  4565. this.bottomBarHeight = 0;
  4566. this.barBottomOpacity = 0
  4567. this.barOpacity = 0;
  4568. this.hideDone = true;
  4569. }
  4570. this.isHiding = true;
  4571. }
  4572. if (offset < 0 && this.isHiding) {
  4573. this.hideDone = false;
  4574. this.getUIContext().animateTo({
  4575. duration: 300
  4576. }, () => {
  4577. this.bottomBarHeight = 55 + 0;
  4578. this.topBarHeight = 50 + 0;
  4579. this.barOpacity = 1;
  4580. this.barBottomOpacity = 1
  4581. this.currentYOffset = 0;
  4582. this.isHiding = false;
  4583. });
  4584. }
  4585. }
  4586. //这个方法没隐藏bottomBar,只隐藏topbar
  4587. setBarHeightHide2(offset: number) {
  4588. if (offset > 0 && !this.hideDone) {
  4589. this.currentYOffset += offset;
  4590. if (this.currentYOffset <= 100) {
  4591. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  4592. this.barOpacity = 1 - this.currentYOffset / 100;
  4593. } else {
  4594. this.topBarHeight = 0;
  4595. this.barOpacity = 0;
  4596. this.hideDone = true;
  4597. }
  4598. this.isHiding = true;
  4599. }
  4600. if (offset < 0 && this.isHiding) {
  4601. this.hideDone = false;
  4602. this.getUIContext().animateTo({
  4603. duration: 300
  4604. }, () => {
  4605. this.topBarHeight = 50 + 0;
  4606. this.barOpacity = 1;
  4607. this.currentYOffset = 0;
  4608. this.isHiding = false;
  4609. });
  4610. }
  4611. }
  4612. private async doPlay(item: VideoItem, index?: number, isFromSonPlayList?: boolean,isOpen?:boolean) {
  4613. Logger.info(`heanup doPlay被调用 - 歌曲: ${item.name}, 文件路径: ${item.filePath}, 索引: ${index}, 类型: ${item.type}, isFromSonPlayList: ${isFromSonPlayList}`)
  4614. switch (item.type) {
  4615. case CommonConstants.TYPE_IS_DIR:
  4616. // 进入歌单前安全保存当前滚动偏移量,支持列表和网格
  4617. let offsetB = 0
  4618. if(this.twoFingerType==4){
  4619. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4620. let cur = this.waterScroller.currentOffset()
  4621. if (cur && typeof cur.yOffset === 'number') {
  4622. offsetB = cur.yOffset
  4623. }
  4624. }
  4625. this.mScrollMap.set('lastWaterDirScrollOffset', offsetB)
  4626. }else
  4627. if (this.isGridMusic) {
  4628. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4629. let cur = this.scroller.currentOffset()
  4630. if (cur && typeof cur.yOffset === 'number') {
  4631. offsetB = cur.yOffset
  4632. }
  4633. }
  4634. this.mScrollMap.set('lastGridDirScrollOffset', offsetB)
  4635. } else {
  4636. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4637. let cur = this.listScroller.currentOffset()
  4638. if (cur && typeof cur.yOffset === 'number') {
  4639. offsetB = cur.yOffset
  4640. }
  4641. }
  4642. this.mScrollMap.set('lastListDirScrollOffset', offsetB)
  4643. }
  4644. if (item.name === LocalMusic.STR_LOCK_VIDEO) {
  4645. this.showVerifyDialog()
  4646. this.currentTitleName = '私密音频'
  4647. this.currentTitleCover = $r('app.media.ic_avatar5')
  4648. } else if (item.name === LocalMusic.STR_HISTORY_MUSIC) {
  4649. this.titleBarModel.setTitleName('最近播放')
  4650. this.currentTitleCover = $r('app.media.ic_avatar2')
  4651. this.currentTitleName = '最近播放'
  4652. //加载动画效果
  4653. this.updateListData(this.historyList, true)
  4654. // this.videoLocalList = this.historyList
  4655. if (ArrayUtil.isEmpty(this.historyList)) {
  4656. ToastUtil.showToast('最近播放记录空空如也')
  4657. } else {
  4658. this.currentTitleCover = Utility.getFirstCoverFromList(this.historyList)
  4659. }
  4660. this.isHistory = true
  4661. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4662. } else if (item.name === LocalMusic.STR_FAC_VIDEO) {
  4663. this.titleBarModel.setTitleName('我的收藏')
  4664. this.currentTitleName = '我的收藏'
  4665. this.currentTitleCover = $r('app.media.ic_avatar1')
  4666. //加载动画效果
  4667. this.updateListData(this.favList)
  4668. if (ArrayUtil.isEmpty(this.favList)) {
  4669. ToastUtil.showToast('无音乐收藏记录')
  4670. } else {
  4671. this.currentTitleCover = Utility.getFirstCoverFromList(this.favList)
  4672. }
  4673. this.isFavMusic = true
  4674. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4675. } else {
  4676. this.currentTitleName = item.name
  4677. this.currentPath = item.filePath
  4678. this.currentTitleCover = $r('app.media.ic_avatar5')
  4679. this.getSortedFiles(this.currentPath)
  4680. }
  4681. //进入歌单的时候的滚动位置在顶部
  4682. if(this.twoFingerType==4){
  4683. setTimeout(() => {
  4684. this.waterScroller.scrollEdge(Edge.Top)
  4685. this.scroller.scrollEdge(Edge.Top)
  4686. }, 380)
  4687. }else{
  4688. if (this.isGridMusic) {
  4689. this.scroller.scrollEdge(Edge.Top)
  4690. }else{
  4691. this.listScroller.scrollEdge(Edge.Top)
  4692. }
  4693. }
  4694. break;
  4695. case CommonConstants.TYPE_IS_ARTIST:
  4696. // 进入艺术家前安全保存当前滚动偏移量,支持列表和网格
  4697. let offsetA = 0
  4698. if(this.twoFingerType==4){
  4699. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4700. let cur = this.waterScroller.currentOffset()
  4701. if (cur && typeof cur.yOffset === 'number') {
  4702. offsetA = cur.yOffset
  4703. }
  4704. }
  4705. this.mScrollMap.set('lastWaterArtistScrollOffset', offsetA)
  4706. }else
  4707. if (this.isGridMusic) {
  4708. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4709. let cur = this.scroller.currentOffset()
  4710. if (cur && typeof cur.yOffset === 'number') {
  4711. offsetA = cur.yOffset
  4712. }
  4713. }
  4714. this.mScrollMap.set('lastGridArtistScrollOffset', offsetA)
  4715. } else {
  4716. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4717. let cur = this.listScroller.currentOffset()
  4718. if (cur && typeof cur.yOffset === 'number') {
  4719. offsetA = cur.yOffset
  4720. }
  4721. }
  4722. this.mScrollMap.set('lastListArtistScrollOffset', offsetA)
  4723. }
  4724. let mList = this.artistMap.get(item.name)
  4725. if (mList !== undefined && ArrayUtil.isNotEmpty(mList)) {
  4726. Utility.doSortListAscending(mList)
  4727. this.isCanBack = true
  4728. this.titleBarModel.setTitleName(item.name)
  4729. this.currentTitleName = '艺术家:' + item.name
  4730. if (item.pixelMapPath) {
  4731. this.currentTitleCover = item.pixelMapPath
  4732. }
  4733. this.updateListData(mList)
  4734. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4735. }
  4736. //进入歌单的时候的滚动位置在顶部
  4737. if(this.twoFingerType==4){
  4738. setTimeout(() => {
  4739. this.waterScroller.scrollEdge(Edge.Top)
  4740. this.scroller.scrollEdge(Edge.Top)
  4741. }, 380)
  4742. }else{
  4743. if (this.isGridMusic) {
  4744. this.scroller.scrollEdge(Edge.Top)
  4745. }
  4746. }
  4747. break;
  4748. case CommonConstants.TYPE_IS_ALBUM:
  4749. // 进入专辑前安全保存当前滚动偏移量,支持列表和网格
  4750. let offset = 0
  4751. if(this.twoFingerType==4){
  4752. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4753. let cur = this.waterScroller.currentOffset()
  4754. if (cur && typeof cur.yOffset === 'number') {
  4755. offset = cur.yOffset
  4756. }
  4757. }
  4758. this.mScrollMap.set('lastWaterAlBumScrollOffset', offset)
  4759. }else
  4760. if (this.isGridMusic) {
  4761. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4762. let cur = this.scroller.currentOffset()
  4763. if (cur && typeof cur.yOffset === 'number') {
  4764. offset = cur.yOffset
  4765. }
  4766. }
  4767. this.mScrollMap.set('lastGridAlBumScrollOffset', offset)
  4768. } else {
  4769. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4770. let cur = this.listScroller.currentOffset()
  4771. if (cur && typeof cur.yOffset === 'number') {
  4772. offset = cur.yOffset
  4773. }
  4774. }
  4775. this.mScrollMap.set('lastListAlBumScrollOffset', offset)
  4776. }
  4777. let albumList = this.albumMap.get(item.name)
  4778. if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
  4779. Utility.doSortListAscending(albumList)
  4780. this.isCanBack = true
  4781. this.titleBarModel.setTitleName(item.name)
  4782. this.currentTitleName = '专辑:' + item.name
  4783. if (item.pixelMapPath) {
  4784. this.currentTitleCover = item.pixelMapPath
  4785. }
  4786. this.updateListData(albumList)
  4787. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4788. this.mScrollMap.set(item.name, this.selectedIndex)
  4789. }
  4790. //进入歌单的时候的滚动位置在顶部
  4791. if(this.twoFingerType==4){
  4792. setTimeout(() => {
  4793. this.waterScroller.scrollEdge(Edge.Top)
  4794. this.scroller.scrollEdge(Edge.Top)
  4795. }, 380)
  4796. }else{
  4797. if (this.isGridMusic) {
  4798. this.scroller.scrollEdge(Edge.Top)
  4799. }
  4800. }
  4801. break;
  4802. case CommonConstants.TYPE_IS_CSJAD:
  4803. return
  4804. break;
  4805. case CommonConstants.TYPE_LOCAL:
  4806. if(item&&item.filePath.toLowerCase().endsWith('.cue')){
  4807. const cueinfo:CueInfo = await parseCueFile(item.filePath)
  4808. const cueTracks:CueTrack[] = cueinfo.tracks
  4809. console.log('onecold cue cueTracks =', JSON.stringify(cueTracks));
  4810. if(ArrayUtil.isNotEmpty(cueTracks)){
  4811. this.showCueDialog(cueTracks,cueinfo)
  4812. }
  4813. // this.showCueSheet = !this.showCueSheet
  4814. return
  4815. }
  4816. if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
  4817. this.stop();
  4818. }
  4819. if (isOpen) {
  4820. this.currentSong = item
  4821. if (index !== undefined) {
  4822. this.curIndex = index
  4823. }
  4824. this.songList = []
  4825. this.songList.push(item)
  4826. this.sonDataSource.pushArrayData(this.songList)
  4827. }else if(isFromSonPlayList){ //点击来自右下角的播放列表
  4828. this.currentSong = item
  4829. if (index !== undefined) {
  4830. this.curIndex = index
  4831. }
  4832. // 确保播放列表是完整的歌单歌曲列表(已在finishLoadingPlaylist中设置)
  4833. Logger.info(`heanup isFromSonPlayList分支 - 当前播放列表长度: ${this.songList.length}, 当前索引: ${this.curIndex}`)
  4834. }else {
  4835. let globalVideoList = Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL) as VideoItem[];
  4836. this.curIndex = Utility.getCurIndexFromGlobalList(globalVideoList, item.filePath)
  4837. this.songList = globalVideoList
  4838. this.sonDataSource.pushArrayData(this.songList)
  4839. this.currentSong = globalVideoList[this.curIndex]
  4840. }
  4841. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  4842. this.videoUrl = this.currentSong.filePath
  4843. this.name = this.currentSong.name
  4844. this.cover = this.currentSong.pixelMapPath
  4845. this.artist = this.currentSong.artist
  4846. LogUtil.info('this.currentSong.duration =' + this.currentSong.duration)
  4847. LogUtil.info('this.currentSongmimeType =' + this.currentSong.mimeType)
  4848. this.startPlayOrResumePlay()
  4849. break;
  4850. }
  4851. }
  4852. private cueComponentId: number = 0
  4853. //显示cue分轨列表对话框
  4854. showCueDialog(cueTracks:CueTrack[],cueinfo:CueInfo){
  4855. this.getUIContext().getPromptAction().openCustomDialog({
  4856. builder: () => {
  4857. this.cueComptentBuilder(cueTracks,cueinfo)
  4858. },
  4859. isModal:true,
  4860. showInSubWindow:false,
  4861. maskColor: Color.Transparent,
  4862. dialogTransition: // 设置弹窗内容显示的过渡效果
  4863. TransitionEffect.translate({ x: 0, y: 390, z: 0 })
  4864. .animation({ duration: 600, curve: Curve.Smooth }),
  4865. maskTransition: // 设置蒙层显示的过渡效果
  4866. TransitionEffect.opacity(0.5)
  4867. .animation({ duration: 600, curve: Curve.Smooth })
  4868. }).then((dialogId: number) => {
  4869. this.cueComponentId = dialogId
  4870. })
  4871. .catch((error: BusinessError) => {
  4872. console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`)
  4873. })
  4874. }
  4875. @Builder
  4876. cueComptentBuilder(cueTracks:CueTrack[]=[],cueinfo:CueInfo){
  4877. CueComptent({
  4878. title:cueinfo.title,
  4879. cueTracks:cueTracks,
  4880. isLongNameRoLL:this.isLongNameRoLL,
  4881. onCancel:()=>{
  4882. this.getUIContext().getPromptAction().closeCustomDialog(this.cueComponentId)
  4883. },
  4884. onDoItemClick:(item: CueTrack, index: number)=>{
  4885. //获取cueinfo对应的filePath
  4886. let globalVideoList = Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL) as VideoItem[];
  4887. this.curIndex = Utility.getCurIndexFromGlobalList(globalVideoList, cueinfo.filePath)
  4888. this.currentSong = Utility.getItemByFilePath(globalVideoList, cueinfo.filePath)
  4889. console.info('onecold cueinfo.filePath=', cueinfo.filePath)
  4890. console.info('onecold this.currentSong =', JSON.stringify(this.currentSong))
  4891. if (this.currentSong){
  4892. if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
  4893. this.stop();//播放之前先停止之前播放。
  4894. }
  4895. this.songList = globalVideoList
  4896. this.sonDataSource.pushArrayData(this.songList)
  4897. this.videoUrl = this.currentSong.filePath
  4898. this.name = item.title||this.currentSong.name
  4899. this.cover = this.currentSong.pixelMapPath
  4900. this.artist = item.performer||this.currentSong.artist
  4901. this.currentSong.name = this.name
  4902. this.currentSong.artist = this.artist
  4903. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  4904. this.startPlayOrResumePlay(item.startOffset)//从cue的某个位置开始播放
  4905. }
  4906. }
  4907. })
  4908. }
  4909. @Builder
  4910. PlayController() {
  4911. Column() {
  4912. Line().width('100%').height(1).backgroundColor($r('app.color.index_background'))
  4913. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4914. Row() {
  4915. if(this.isHiCar()){
  4916. this.playConRigth()
  4917. Column(){
  4918. this.centerName()
  4919. }.layoutWeight(1)
  4920. .onClick(()=>{
  4921. this.showPlayerView()
  4922. })
  4923. this.playConLeft(false)
  4924. }else{
  4925. this.playConLeft()
  4926. this.playConRigth()
  4927. }
  4928. }
  4929. .width('100%')
  4930. .height(this.bottomBarHeight)
  4931. .justifyContent(FlexAlign.Center)
  4932. .hitTestBehavior(HitTestMode.Transparent)
  4933. .backgroundColor(this.isCustomizeBg ? Color.Transparent : $r('app.color.bottom_control_background'))
  4934. .bindContentCover($$this.isShowPlay, this.MusicPlayBuilder(), {
  4935. // modalTransition: ModalTransition.DEFAULT,
  4936. transition: AnimationHelper.transitionInDown(666),
  4937. backgroundColor: 'rgba(0, 0, 0, 0.9)',
  4938. })
  4939. .padding({
  4940. left: 16,
  4941. right: 16
  4942. })
  4943. Line()
  4944. .width('100%')
  4945. .height(25)
  4946. .backgroundColor($r('app.color.bottom_control_background'))// .visibility(this.isPhoneLan()?Visibility.None:this.isCustomizeBg?Visibility.Hidden:Visibility.Visible)
  4947. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4948. }
  4949. .clickEffect({ level: ClickEffectLevel.HEAVY })
  4950. }
  4951. @State isFrontWhite: boolean = false
  4952. @Builder
  4953. centerName() {
  4954. Column() {
  4955. Text(this.currentSong?.name)
  4956. .fontSize(16)
  4957. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4958. .maxLines(1)
  4959. .fontColor($r('app.color.text_color'))
  4960. .fontWeight(500);
  4961. Row() {
  4962. Text(this.currentSong?.artist)
  4963. .margin({ top: 2 })
  4964. .fontSize(13)
  4965. .textAlign(TextAlign.Start)
  4966. .maxLines(1)
  4967. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4968. .fontColor($r('app.color.text_color'));
  4969. }
  4970. .visibility(this.currentSong?.artist? Visibility.Visible:Visibility.None)
  4971. }
  4972. .alignItems(HorizontalAlign.Center)
  4973. }
  4974. @Builder
  4975. playConLeft(isLeft: boolean = true) {
  4976. Row() {
  4977. RotatingCover({ songLabel: this.currentSong?.pixelMapPath });
  4978. Column() {
  4979. Text(this.currentSong?.name)
  4980. .fontSize(16)
  4981. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4982. .maxLines(1)
  4983. .fontColor($r('app.color.text_color'))
  4984. .fontWeight(500);
  4985. Row() {
  4986. Text(this.currentSong?.artist)
  4987. .margin({ top: 2 })
  4988. .fontSize(13)
  4989. .textAlign(TextAlign.Start)
  4990. .maxLines(1)
  4991. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4992. .fontColor($r('app.color.text_color'));
  4993. }
  4994. .visibility(this.currentSong?.artist? Visibility.Visible:Visibility.None)
  4995. }
  4996. .alignItems(isLeft?HorizontalAlign.Start:HorizontalAlign.End)
  4997. .margin({ right: isLeft?22:10 })
  4998. .visibility(isLeft? Visibility.Visible:Visibility.None)
  4999. }
  5000. .padding({ right: 18 })
  5001. .layoutWeight(isLeft?1:0)
  5002. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  5003. .onClick(() => {
  5004. this.showPlayerView()
  5005. })
  5006. }
  5007. //打开播放页
  5008. showPlayerView() {
  5009. if (ArrayUtil.isNotEmpty(this.songList)) {
  5010. this.isShowPlay = true;
  5011. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc';
  5012. this.initLyric(lyricPath);
  5013. this.startAutoHide();
  5014. } else {
  5015. ToastUtil.showToast('当前播放列表为空,请先导入音乐。');
  5016. }
  5017. }
  5018. @Builder
  5019. playConRigth() {
  5020. Row() {
  5021. Image($r('app.media.hm_previous'))
  5022. .height(28)
  5023. .width(28)
  5024. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  5025. .margin({ left: 8, right: 16 })
  5026. .fillColor(this.themeColor)
  5027. .displayPriority(2)
  5028. .onClick(() => {
  5029. if (ArrayUtil.isNotEmpty(this.songList)) {
  5030. this.playPrevious()
  5031. } else {
  5032. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  5033. }
  5034. })
  5035. //播放进度条
  5036. Stack() {
  5037. Progress({
  5038. value: Math.floor(this.progressValue),
  5039. type: ProgressType.Ring,
  5040. })
  5041. .color(this.themeColor)// 进度条前景色为灰色
  5042. .backgroundColor($r('app.color.index_background'))
  5043. .height(40)
  5044. .aspectRatio(CommonConstants.ASPECT_RATIO)
  5045. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
  5046. .height(38)
  5047. .width(38)
  5048. .displayPriority(3)
  5049. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  5050. .fillColor(this.themeColor)
  5051. .onClick(() => {
  5052. if (ArrayUtil.isNotEmpty(this.songList)) {
  5053. console.info('onecold playOrPause 4642')
  5054. this.playOrPause()
  5055. } else {
  5056. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  5057. }
  5058. })
  5059. }
  5060. Image($r('app.media.hm_next'))
  5061. .height(28)
  5062. .width(28)
  5063. .margin({
  5064. right: 16,
  5065. left: 16
  5066. })
  5067. .fillColor(this.themeColor)
  5068. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  5069. .displayPriority(2)
  5070. .onClick(() => {
  5071. if (ArrayUtil.isNotEmpty(this.songList)) {
  5072. this.playNext()
  5073. } else {
  5074. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  5075. }
  5076. })
  5077. Image($r('app.media.hm_playlist'))
  5078. .height(28)
  5079. .width(28)
  5080. .displayPriority(1)
  5081. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  5082. .fillColor(this.themeColor)
  5083. .bindSheet($$this.isShowSheet, this.PlayListSheet(), {
  5084. height: '95%',
  5085. dragBar: true,
  5086. showClose: true,
  5087. blurStyle: BlurStyle.Thin,
  5088. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  5089. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  5090. title: {
  5091. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  5092. + `(${this.songList.length}首)`
  5093. }
  5094. })
  5095. .onClick(() => {
  5096. if (ArrayUtil.isNotEmpty(this.songList)) {
  5097. this.isShowSheet = !this.isShowSheet;
  5098. this.isFrontWhite = false
  5099. LogUtil.info('onecold scrollToIndex = ' + this.curIndex)
  5100. this.scrollIndex()
  5101. } else {
  5102. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  5103. }
  5104. })
  5105. }
  5106. }
  5107. scrollIndex(){
  5108. if(this.curIndex>500)//条数太大的时候 滚动非常卡 导致闪退,先改为不滚
  5109. return
  5110. try {
  5111. setTimeout(() => {
  5112. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  5113. this.playListScroller.scrollToIndex(this.curIndex,true, ScrollAlign.CENTER)
  5114. })
  5115. }, 123)
  5116. }catch (error) {
  5117. console.error(`onecold scrollIndex出错: ${error}`);
  5118. }
  5119. }
  5120. //播放列表布局
  5121. @Builder
  5122. PlayListSheet() {
  5123. Column() {
  5124. this.PlayList()
  5125. }
  5126. .width('100%')
  5127. .height('100%')
  5128. }
  5129. @State titleStr: string = ''
  5130. @State ablumStr: string = ''
  5131. @State artistStr: string = ''
  5132. @State lyricConStr: string = ''
  5133. @State currentEditItem: string = ''
  5134. @State yearStr: string = ''
  5135. @State trackStr: string = ''
  5136. @State genreStr: string = ''
  5137. @State imagePathStr: string = ''
  5138. @State albumArtistStr: string = ''
  5139. @State composerStr: string = ''
  5140. @State lyricistStr: string = ''
  5141. @State commentStr: string = ''
  5142. @State discStr: string = ''
  5143. doUpdateData() {
  5144. setTimeout(() => {
  5145. if (this.modeType === 0) {
  5146. this.deleteCache(this.currentPath)
  5147. this.getSortedFiles(this.currentPath)
  5148. }
  5149. workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
  5150. workerInstance.postMessage({ code: 3, data: this.context });
  5151. workerInstance.postMessage({ code: 4, data: this.context });
  5152. }, 999)
  5153. }
  5154. //编辑信息
  5155. async doEdit(item: VideoItem) {
  5156. if (!item) {
  5157. return
  5158. }
  5159. if (StrUtil.isEmpty(this.titleStr)) {
  5160. ToastUtil.showToast('标题不能为空')
  5161. return
  5162. }
  5163. //用户更改了封面,那就内嵌下封面
  5164. if(StrUtil.isNotEmpty(this.imagePathStr)){
  5165. const resultCover:boolean = await changeMusicCover(this.context,
  5166. item.filePath,this.imagePathStr,true);
  5167. this.imagePathStr = ''
  5168. if(resultCover){
  5169. ToastUtil.showToast('内嵌封面成功')
  5170. }
  5171. }
  5172. const metadata:FFMpegTags = {
  5173. title: this.titleStr,
  5174. artist: this.artistStr,
  5175. album: this.ablumStr,
  5176. TYER:this.yearStr,
  5177. genre:this.genreStr,
  5178. track:this.trackStr,
  5179. album_artist:this.albumArtistStr,
  5180. TPE2:this.albumArtistStr,//ID3v2 中通常没有专门的 "专辑艺术家" 字段,但有些软件会使用 TPE2 来表示专辑艺
  5181. COMPOSER:this.composerStr,
  5182. lyricist:this.lyricistStr,
  5183. TEXT:this.lyricistStr,//ID3v2 使用 TEXT 字段来表示作词者
  5184. comment:this.commentStr,
  5185. disc:this.discStr,
  5186. };
  5187. //内嵌下标签的值,设置overwrite为true会直接修改原文件
  5188. const result:boolean = await repairAudioMetadata(
  5189. item.filePath,
  5190. this.lyricConStr,
  5191. metadata,
  5192. true
  5193. );
  5194. if (result) {
  5195. this.table.updateMediaInfo(item.filePath, this.titleStr, this.artistStr, this.ablumStr,this.lyricConStr,
  5196. this.yearStr,this.genreStr,this.trackStr,this.albumArtistStr,this.composerStr, this.lyricistStr,this.commentStr,this.discStr,
  5197. (success: boolean, error?: string) => {
  5198. // this.isShowEdit = false
  5199. if (success) {
  5200. console.log(" onecold 编辑信息成功,数据库已同步");
  5201. ToastUtil.showToast('内嵌音乐标签成功')
  5202. this.isShowMoreView = false
  5203. this.name = this.titleStr
  5204. if (item.filePath == this.currentSong?.filePath) {
  5205. this.currentSong.name = this.titleStr
  5206. this.artist = this.artistStr
  5207. this.currentSong.artist = this.artistStr
  5208. this.currentSong.album = this.ablumStr
  5209. this.currentSong.year = this.yearStr
  5210. this.currentSong.genre = this.genreStr
  5211. this.currentSong.track = this.trackStr
  5212. this.currentSong.lyricContent = this.lyricConStr
  5213. this.initLyric(item.filePath)
  5214. this.currentSong.ALBUMARTIST = this.albumArtistStr
  5215. this.currentSong.COMPOSER = this.composerStr
  5216. this.currentSong.LYRICIST = this.lyricistStr
  5217. this.currentSong.COMMENT = this.commentStr
  5218. }
  5219. this.doUpdateData()
  5220. } else {
  5221. // ToastUtil.showToast('保存失败' + error?.toString())
  5222. console.error(" onecold 编辑信息数据库失败原因: " + error);
  5223. }
  5224. });
  5225. console.log(' onecold 元数据标签更新成功,');
  5226. } else {
  5227. ToastUtil.showToast('内嵌音乐标签失败')
  5228. console.log('onecold 内嵌音乐标签失败');
  5229. }
  5230. this.longItemFilePath = ''
  5231. this.tempLyricContent = ''
  5232. this.isShowEdit = false
  5233. }
  5234. updateLyricToDB() {
  5235. }
  5236. @Builder
  5237. editSheet(item: VideoItem) {
  5238. Scroll() {
  5239. Column() {
  5240. this.editDetail(item)
  5241. }
  5242. }
  5243. .width('100%')
  5244. .height('100%')
  5245. }
  5246. @Builder
  5247. editDetail(item: VideoItem) {
  5248. Column() {
  5249. if (item) {
  5250. Row() {
  5251. Stack() {
  5252. Image(StrUtil.isNotEmpty(this.imagePathStr)?this.imagePathStr.startsWith('http')?
  5253. this.imagePathStr:fileUri.getUriFromPath(this.imagePathStr):
  5254. StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.add_image2') :
  5255. item.pixelMapPath)
  5256. .fillColor(this.themeColor)
  5257. .height(88)
  5258. .width(88)
  5259. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
  5260. .borderRadius(12)
  5261. .clip(true)
  5262. .opacity(this.opacityItem)// 绑定透明度
  5263. .margin({ left: 25 })
  5264. }
  5265. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
  5266. .onClick(async () => {
  5267. const imagePath:string | undefined = await this.goSelectImage(item);
  5268. if (imagePath) {
  5269. //用户更改过图片
  5270. this.imagePathStr = imagePath
  5271. }
  5272. })
  5273. .width('28%')
  5274. Row() {
  5275. Column() {
  5276. Text(item.name)
  5277. .fontSize(17)
  5278. .maxLines(1)
  5279. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  5280. .animation({
  5281. duration: 555,
  5282. curve: 'Linear',
  5283. })
  5284. .fontColor(this.themeColor)
  5285. .margin({ left: 8 })
  5286. Row() {
  5287. Text(item.artist)
  5288. .fontSize(14)
  5289. .maxLines(1)
  5290. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  5291. .padding({ top: 8 })
  5292. .fontColor(this.themeColor)
  5293. .margin({ left: 8 })
  5294. }
  5295. }
  5296. .height('100%')
  5297. .width(100)
  5298. .layoutWeight(1)
  5299. .justifyContent(FlexAlign.Center)
  5300. .alignItems(HorizontalAlign.Start)
  5301. Column() {
  5302. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5303. Row(){
  5304. SymbolGlyph($r('sys.symbol.picture'))
  5305. .fontSize(18)
  5306. .fontColor([Color.White])
  5307. Text('获取封面')
  5308. .margin({ left: 4 })
  5309. .fontSize(11)
  5310. .fontColor(Color.White)
  5311. .fontWeight(480)
  5312. .textAlign(TextAlign.Center)
  5313. }
  5314. .justifyContent(FlexAlign.Center)
  5315. }
  5316. .height(38)
  5317. .width(100)
  5318. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5319. .backgroundColor(this.themeColor)
  5320. .stateEffect(true)
  5321. .margin({ right: 35 })
  5322. .onClick(async () => {
  5323. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  5324. this.showTipsDialog();
  5325. return; // Return empty string when no API is configured
  5326. }
  5327. const imagePath:string | undefined = await this.doSearchCover(item);
  5328. console.info('onecold imagePath = '+imagePath)
  5329. if (StrUtil.isNotEmpty(imagePath)) {
  5330. //用户更改过图片
  5331. this.imagePathStr = imagePath
  5332. ToastUtil.showToast('获取封面成功')
  5333. }else{
  5334. ToastUtil.showToast('获取封面失败,请重试')
  5335. }
  5336. })
  5337. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5338. Row(){
  5339. SymbolGlyph($r('sys.symbol.input_mode'))
  5340. .fontSize(18)
  5341. .fontColor([Color.White])
  5342. Text('获取歌词')
  5343. .margin({ left: 4 })
  5344. .fontSize(11)
  5345. .fontColor(Color.White)
  5346. .fontWeight(480)
  5347. .textAlign(TextAlign.Center)
  5348. }
  5349. .justifyContent(FlexAlign.Center)
  5350. }
  5351. .height(38)
  5352. .width(100)
  5353. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5354. .backgroundColor(this.themeColor)
  5355. .stateEffect(true)
  5356. .margin({ top: 9, right: 35 })
  5357. .onClick(async () => {
  5358. //判断有没有设置api
  5359. let apiUrl = PreferencesUtil.getStringSync('LRC_API', '')
  5360. if (StrUtil.isEmpty(apiUrl)) {
  5361. this.isLyricSetting = false
  5362. this.showTipsDialog()
  5363. return
  5364. }
  5365. let artist = item.artist
  5366. let title = item.name
  5367. if(!artist)
  5368. artist = ''
  5369. if(!title)
  5370. title = ''
  5371. let res: string | undefined = await getApiLyric(apiUrl,title, artist, false);
  5372. if (res && StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  5373. this.lyricConStr = res;
  5374. ToastUtil.showToast('获取歌词成功')
  5375. }else{
  5376. ToastUtil.showToast('获取歌词失败,请重试')
  5377. }
  5378. })
  5379. }
  5380. .justifyContent(FlexAlign.Start)
  5381. }
  5382. .height('100%')
  5383. .justifyContent(FlexAlign.Start)
  5384. .layoutWeight(1)
  5385. }
  5386. .width('100%')
  5387. .height(98)
  5388. Row() {
  5389. Text('标题:')
  5390. .fontSize(14)
  5391. .fontColor($r('app.color.text_color'))
  5392. .margin({ left: 22 })
  5393. TextInput({ text: item.name })
  5394. .height(40)
  5395. .maxLines(1)
  5396. .fontSize(14)
  5397. .layoutWeight(1)
  5398. .fontColor($r('app.color.text_color'))
  5399. .margin({ right: 20, left: 10 })
  5400. .onChange((val: string) => {
  5401. this.titleStr = val
  5402. })
  5403. }
  5404. .width('100%')
  5405. .margin({ top: 10, bottom: 10 })
  5406. .justifyContent(FlexAlign.Start)
  5407. Row() {
  5408. Text('艺术家:')
  5409. .fontSize(14)
  5410. .fontColor($r('app.color.text_color'))
  5411. .margin({ left: 22 })
  5412. TextInput({ text: item.artist })
  5413. .height(40)
  5414. .maxLines(1)
  5415. .fontSize(14)
  5416. .layoutWeight(1)
  5417. .fontColor($r('app.color.text_color'))
  5418. .margin({ right: 20, left: 10 })
  5419. .onChange((val: string) => {
  5420. this.artistStr = val
  5421. })
  5422. }
  5423. .width('100%')
  5424. .margin({ top: 10, bottom: 10 })
  5425. .justifyContent(FlexAlign.Start)
  5426. Row() {
  5427. Text('专辑名:')
  5428. .fontSize(14)
  5429. .fontColor($r('app.color.text_color'))
  5430. .margin({ left: 22 })
  5431. TextInput({ text: item.album })
  5432. .height(40)
  5433. .maxLines(1)
  5434. .fontSize(14)
  5435. .layoutWeight(1)
  5436. .fontColor($r('app.color.text_color'))
  5437. .margin({ right: 20, left: 10 })
  5438. .onChange((val: string) => {
  5439. this.ablumStr = val
  5440. })
  5441. }
  5442. .width('100%')
  5443. .margin({ top: 10, bottom: 10 })
  5444. .justifyContent(FlexAlign.Start)
  5445. Row() {
  5446. Column(){
  5447. Column(){
  5448. Text('歌词:')
  5449. .fontSize(14)
  5450. .fontColor($r('app.color.text_color'))
  5451. .margin({ top:9,left: 22 })
  5452. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5453. SymbolGlyph($r('sys.symbol.trash_fill'))
  5454. .fontSize(25)
  5455. .alignSelf(ItemAlign.Center)
  5456. .margin({ left: 22,top:25})
  5457. }
  5458. .backgroundColor(Color.Transparent)
  5459. .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
  5460. Visibility.None:Visibility.Visible)
  5461. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5462. .onClick(()=>{
  5463. this.lyricConStr = ''
  5464. this.lyricContent = ''
  5465. this.tempLyricContent = ''
  5466. })
  5467. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5468. SymbolGlyph($r('sys.symbol.plus'))
  5469. .fontSize(25)
  5470. .alignSelf(ItemAlign.Center)
  5471. .margin({ left: 22,top:25})
  5472. }
  5473. .backgroundColor(Color.Transparent)
  5474. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5475. .onClick( ()=>{
  5476. this.callFilePickerSelectFileForLyric()
  5477. })
  5478. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5479. SymbolGlyph($r('sys.symbol.traditional_square'))
  5480. .fontSize(25)
  5481. .alignSelf(ItemAlign.Center)
  5482. .margin({ left: 22,top:25})
  5483. }
  5484. .backgroundColor(Color.Transparent)
  5485. .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
  5486. Visibility.None:Visibility.Visible)
  5487. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5488. .onClick( ()=>{
  5489. let lyricC = StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr: this.tempLyricContent
  5490. this.lyricConStr = getTransverterText(lyricC,1)//1是简体转繁体 ,2是繁体转简体
  5491. })
  5492. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5493. Image($r('app.media.jianti'))
  5494. .height(25)
  5495. .fillColor($r('app.color.text_color'))
  5496. .alignSelf(ItemAlign.Center)
  5497. .margin({ left: 22,top:25})
  5498. }
  5499. .backgroundColor(Color.Transparent)
  5500. .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
  5501. Visibility.None:Visibility.Visible)
  5502. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5503. .onClick( ()=>{
  5504. let lyricC = StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr: this.tempLyricContent
  5505. this.lyricConStr = getTransverterText(lyricC,2)//1是简体转繁体 ,2是繁体转简体
  5506. })
  5507. }
  5508. .layoutWeight(1)
  5509. }
  5510. TextArea({ text: StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr:
  5511. this.tempLyricContent })
  5512. .type(TextAreaType.NORMAL)
  5513. .height(StrUtil.isEmpty(this.lyricConStr)&&StrUtil.isEmpty(this.tempLyricContent)?100:'auto')
  5514. .fontSize(14)
  5515. .layoutWeight(1)
  5516. .fontColor($r('app.color.text_color'))
  5517. .margin({ right: 20, left: 10 })
  5518. .onChange((val: string) => {
  5519. this.lyricConStr = val
  5520. })
  5521. }
  5522. .width('100%')
  5523. .height(StrUtil.isEmpty(this.lyricConStr)&&StrUtil.isEmpty(this.tempLyricContent)?120:'auto')
  5524. .margin({ top: 10, bottom: 10 })
  5525. .justifyContent(FlexAlign.Start)
  5526. Row() {
  5527. Text('年份:')
  5528. .fontSize(14)
  5529. .fontColor($r('app.color.text_color'))
  5530. .margin({ left: 22 })
  5531. TextInput({ text: item.year })
  5532. .height(40)
  5533. .maxLines(1)
  5534. .fontSize(14)
  5535. .type(InputType.Number)
  5536. .layoutWeight(1)
  5537. .fontColor($r('app.color.text_color'))
  5538. .margin({ right: 20, left: 10 })
  5539. .onChange((val: string) => {
  5540. this.yearStr = val
  5541. })
  5542. }
  5543. .width('100%')
  5544. .margin({ top: 10, bottom: 10 })
  5545. .justifyContent(FlexAlign.Start)
  5546. Row() {
  5547. Text('音轨号:')
  5548. .fontSize(14)
  5549. .fontColor($r('app.color.text_color'))
  5550. .margin({ left: 22 })
  5551. TextInput({ text:item.track=='未知'?'': item.track })
  5552. .height(40)
  5553. .maxLines(1)
  5554. .fontSize(14)
  5555. .type(InputType.Number)
  5556. .layoutWeight(1)
  5557. .fontColor($r('app.color.text_color'))
  5558. .margin({ right: 20, left: 10 })
  5559. .onChange((val: string) => {
  5560. this.trackStr = val
  5561. })
  5562. }
  5563. .width('100%')
  5564. .margin({ top: 10, bottom: 10 })
  5565. .justifyContent(FlexAlign.Start)
  5566. Row() {
  5567. Text('碟号:')
  5568. .fontSize(14)
  5569. .fontColor($r('app.color.text_color'))
  5570. .margin({ left: 22 })
  5571. TextInput({ text:item.disc })
  5572. .height(40)
  5573. .maxLines(1)
  5574. .fontSize(14)
  5575. .type(InputType.Number)
  5576. .layoutWeight(1)
  5577. .fontColor($r('app.color.text_color'))
  5578. .margin({ right: 20, left: 10 })
  5579. .onChange((val: string) => {
  5580. this.discStr = val
  5581. })
  5582. }
  5583. .width('100%')
  5584. .margin({ top: 10, bottom: 10 })
  5585. .justifyContent(FlexAlign.Start)
  5586. Row() {
  5587. Text('风格:')
  5588. .fontSize(14)
  5589. .fontColor($r('app.color.text_color'))
  5590. .margin({ left: 22 })
  5591. TextInput({ text: item.genre })
  5592. .height(40)
  5593. .maxLines(1)
  5594. .fontSize(14)
  5595. .layoutWeight(1)
  5596. .fontColor($r('app.color.text_color'))
  5597. .margin({ right: 20, left: 10 })
  5598. .onChange((val: string) => {
  5599. this.genreStr = val
  5600. })
  5601. }
  5602. .width('100%')
  5603. .margin({ top: 10, bottom: 10 })
  5604. .justifyContent(FlexAlign.Start)
  5605. Row() {
  5606. Text('专辑艺术家:')
  5607. .fontSize(14)
  5608. .fontColor($r('app.color.text_color'))
  5609. .margin({ left: 22 })
  5610. TextInput({ text: item.ALBUMARTIST })
  5611. .height(40)
  5612. .maxLines(1)
  5613. .fontSize(14)
  5614. .layoutWeight(1)
  5615. .fontColor($r('app.color.text_color'))
  5616. .margin({ right: 20, left: 10 })
  5617. .onChange((val: string) => {
  5618. this.albumArtistStr = val
  5619. })
  5620. }
  5621. .width('100%')
  5622. .margin({ top: 10, bottom: 10 })
  5623. .justifyContent(FlexAlign.Start)
  5624. Row() {
  5625. Text('作曲:')
  5626. .fontSize(14)
  5627. .fontColor($r('app.color.text_color'))
  5628. .margin({ left: 22 })
  5629. TextInput({ text: item.COMPOSER })
  5630. .height(40)
  5631. .maxLines(1)
  5632. .fontSize(14)
  5633. .layoutWeight(1)
  5634. .fontColor($r('app.color.text_color'))
  5635. .margin({ right: 20, left: 10 })
  5636. .onChange((val: string) => {
  5637. this.composerStr = val
  5638. })
  5639. }
  5640. .width('100%')
  5641. .margin({ top: 10, bottom: 10 })
  5642. .justifyContent(FlexAlign.Start)
  5643. Row() {
  5644. Text('作词:')
  5645. .fontSize(14)
  5646. .fontColor($r('app.color.text_color'))
  5647. .margin({ left: 22 })
  5648. TextInput({ text: item.LYRICIST })
  5649. .height(40)
  5650. .maxLines(1)
  5651. .fontSize(14)
  5652. .layoutWeight(1)
  5653. .fontColor($r('app.color.text_color'))
  5654. .margin({ right: 20, left: 10 })
  5655. .onChange((val: string) => {
  5656. this.lyricistStr = val
  5657. })
  5658. }
  5659. .width('100%')
  5660. .margin({ top: 10, bottom: 10 })
  5661. .justifyContent(FlexAlign.Start)
  5662. Row() {
  5663. Text('注释:')
  5664. .fontSize(14)
  5665. .fontColor($r('app.color.text_color'))
  5666. .margin({ left: 22 })
  5667. TextInput({ text: item.COMMENT })
  5668. .height(40)
  5669. .maxLines(1)
  5670. .fontSize(14)
  5671. .layoutWeight(1)
  5672. .fontColor($r('app.color.text_color'))
  5673. .margin({ right: 20, left: 10 })
  5674. .onChange((val: string) => {
  5675. this.commentStr = val
  5676. })
  5677. }
  5678. .width('100%')
  5679. .margin({ top: 10, bottom: 10 })
  5680. .justifyContent(FlexAlign.Start)
  5681. Row() {
  5682. Button('保存')
  5683. .fontColor(Color.White)
  5684. .layoutWeight(1)
  5685. .height(50)
  5686. .width(100)
  5687. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5688. .backgroundColor(this.themeColor)
  5689. .stateEffect(true)
  5690. .margin({ right: 20, bottom: 20 })
  5691. .onClick(async () => {
  5692. this.doEdit(item)
  5693. })
  5694. Button('取消')
  5695. .fontColor(Color.White)
  5696. .layoutWeight(1)
  5697. .height(50)
  5698. .width(100)
  5699. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5700. .backgroundColor(this.themeColor)
  5701. .stateEffect(true)
  5702. .margin({ left: 20, bottom: 20 })
  5703. .onClick(async () => {
  5704. if(this.isGridMusic){
  5705. this.longItemFilePath =''
  5706. }else{
  5707. this.isShowEdit = false
  5708. }
  5709. this.setEditStrEmpty()
  5710. if(this.isShowPlay){
  5711. this.isShowEdit = false
  5712. }
  5713. })
  5714. }
  5715. .margin({
  5716. left: 38,
  5717. right: 38,
  5718. top: 10,
  5719. bottom: 10
  5720. })
  5721. .width(250)
  5722. .height(60)
  5723. }
  5724. }
  5725. .margin({ bottom: 20 })
  5726. }
  5727. setEditStrEmpty(){
  5728. this.imagePathStr = ''
  5729. this.lyricConStr = ''
  5730. this.artistStr = ''
  5731. this.titleStr = ''
  5732. this.ablumStr = ''
  5733. this.genreStr = ''
  5734. this.yearStr = ''
  5735. this.trackStr = ''
  5736. this.albumArtistStr = ''
  5737. this.composerStr = ''
  5738. this.lyricistStr = ''
  5739. this.commentStr = ''
  5740. this.discStr = ''
  5741. }
  5742. @Builder
  5743. detailSheet(item:VideoItem) {
  5744. Scroll() {
  5745. Column() {
  5746. this.songDetail(item)
  5747. }
  5748. }
  5749. .width('100%')
  5750. .height('100%')
  5751. }
  5752. @Builder
  5753. songDetail(currentItem:VideoItem) {
  5754. Column() {
  5755. if (currentItem) {
  5756. Row() {
  5757. Stack() {
  5758. Image(StrUtil.isEmpty(currentItem.pixelMapPath) ? $r('app.media.music_red') :
  5759. currentItem.pixelMapPath)
  5760. .fillColor(this.themeColor)
  5761. .height(80)
  5762. .width(80)
  5763. .borderRadius(10)
  5764. .opacity(this.opacityItem)// 绑定透明度
  5765. .margin({ left: 22 })
  5766. }
  5767. Column() {
  5768. Column() {
  5769. Text(currentItem.name)
  5770. .fontSize(16)
  5771. .maxLines(1)
  5772. .animation({
  5773. duration: 555,
  5774. curve: 'Linear',
  5775. })
  5776. .fontColor($r('app.color.text_color'))
  5777. .margin({ left: 15 })
  5778. }
  5779. .height('100%')
  5780. .width('100%')
  5781. .justifyContent(FlexAlign.Center)
  5782. .alignItems(HorizontalAlign.Start)
  5783. }
  5784. .height('100%')
  5785. }
  5786. .width('100%')
  5787. .height(90)
  5788. .justifyContent(FlexAlign.SpaceBetween)
  5789. Row() {
  5790. Text('艺术家:')
  5791. .fontSize(14)
  5792. .fontColor($r('app.color.text_color'))
  5793. .margin({ left: 22 })
  5794. Text(currentItem?.artist ? currentItem.artist : '未知歌手')
  5795. .fontSize(14)
  5796. .fontColor($r('app.color.text_color'))
  5797. .margin({ left: 10 })
  5798. .layoutWeight(1)
  5799. }
  5800. .width('100%')
  5801. .margin({ top: 10, bottom: 10 })
  5802. .justifyContent(FlexAlign.Start)
  5803. Row() {
  5804. Text('专辑名:')
  5805. .fontSize(14)
  5806. .fontColor($r('app.color.text_color'))
  5807. .margin({ left: 22 })
  5808. Text(currentItem?.album ?currentItem.album : '未知专辑')
  5809. .fontSize(14)
  5810. .margin({ left: 10 })
  5811. .fontColor($r('app.color.text_color'))
  5812. .layoutWeight(1)
  5813. }
  5814. .width('100%')
  5815. .margin({ top: 10, bottom: 10 })
  5816. .justifyContent(FlexAlign.Start)
  5817. Row() {
  5818. Text('时长:')
  5819. .fontSize(14)
  5820. .fontColor($r('app.color.text_color'))
  5821. .margin({ left: 22 })
  5822. Text(StrUtil.isEmpty(currentItem.duration)?
  5823. (this.isShowDetailMore?this.totalTime:'未知'):currentItem.duration)
  5824. .fontSize(14)
  5825. .margin({ left: 10 })
  5826. .fontColor($r('app.color.text_color'))
  5827. .layoutWeight(1)
  5828. }
  5829. .width('100%')
  5830. .margin({ top: 10, bottom: 10 })
  5831. .justifyContent(FlexAlign.Start)
  5832. Row() {
  5833. Text('采样率:')
  5834. .fontSize(14)
  5835. .fontColor($r('app.color.text_color'))
  5836. .margin({ left: 22 })
  5837. Text(Utility.convertToKHz(currentItem.sampleRate))
  5838. .fontSize(14)
  5839. .margin({ left: 10 })
  5840. .fontColor($r('app.color.text_color'))
  5841. .layoutWeight(1)
  5842. }
  5843. .width('100%')
  5844. .margin({ top: 10, bottom: 10 })
  5845. .justifyContent(FlexAlign.Start)
  5846. Row() {
  5847. Text('比特率:')
  5848. .fontSize(14)
  5849. .fontColor($r('app.color.text_color'))
  5850. .margin({ left: 22 })
  5851. Text(currentItem.bit_rate)
  5852. .fontSize(14)
  5853. .margin({ left: 10 })
  5854. .fontColor($r('app.color.text_color'))
  5855. .layoutWeight(1)
  5856. }
  5857. .width('100%')
  5858. .margin({ top: 10, bottom: 10 })
  5859. .justifyContent(FlexAlign.Start)
  5860. Row() {
  5861. Text('位深:')
  5862. .fontSize(14)
  5863. .fontColor($r('app.color.text_color'))
  5864. .margin({ left: 22 })
  5865. Text(`${currentItem.bits_per_raw_sample} bits`)
  5866. .fontSize(14)
  5867. .margin({ left: 10 })
  5868. .fontColor($r('app.color.text_color'))
  5869. .layoutWeight(1)
  5870. }
  5871. .width('100%')
  5872. .margin({ top: 10, bottom: 10 })
  5873. .justifyContent(FlexAlign.Start)
  5874. Row() {
  5875. Text('声道:')
  5876. .fontSize(14)
  5877. .fontColor($r('app.color.text_color'))
  5878. .margin({ left: 22 })
  5879. Text(`${currentItem.channels}`)
  5880. .fontSize(14)
  5881. .margin({ left: 10 })
  5882. .fontColor($r('app.color.text_color'))
  5883. .layoutWeight(1)
  5884. }
  5885. .width('100%')
  5886. .margin({ top: 10, bottom: 10 })
  5887. .justifyContent(FlexAlign.Start)
  5888. Row() {
  5889. Text('声道布局:')
  5890. .fontSize(14)
  5891. .fontColor($r('app.color.text_color'))
  5892. .margin({ left: 22 })
  5893. Text(`${currentItem.channel_layout}`)
  5894. .fontSize(14)
  5895. .margin({ left: 10 })
  5896. .fontColor($r('app.color.text_color'))
  5897. .layoutWeight(1)
  5898. }
  5899. .width('100%')
  5900. .margin({ top: 10, bottom: 10 })
  5901. .justifyContent(FlexAlign.Start)
  5902. Row() {
  5903. Text('起始播放点:')
  5904. .fontSize(14)
  5905. .fontColor($r('app.color.text_color'))
  5906. .margin({ left: 22 })
  5907. Text(`${currentItem.start_time}`)
  5908. .fontSize(14)
  5909. .margin({ left: 10 })
  5910. .fontColor($r('app.color.text_color'))
  5911. .layoutWeight(1)
  5912. }
  5913. .width('100%')
  5914. .margin({ top: 10, bottom: 10 })
  5915. .justifyContent(FlexAlign.Start)
  5916. Row() {
  5917. Text('风格:')
  5918. .fontSize(14)
  5919. .fontColor($r('app.color.text_color'))
  5920. .margin({ left: 22 })
  5921. Text(currentItem.genre)
  5922. .fontSize(14)
  5923. .margin({ left: 10 })
  5924. .fontColor($r('app.color.text_color'))
  5925. .layoutWeight(1)
  5926. }
  5927. .width('100%')
  5928. .margin({ top: 10, bottom: 10 })
  5929. .justifyContent(FlexAlign.Start)
  5930. Row() {
  5931. Text('发行时间:')
  5932. .fontSize(14)
  5933. .fontColor($r('app.color.text_color'))
  5934. .margin({ left: 22 })
  5935. Text(currentItem.year)
  5936. .fontSize(14)
  5937. .margin({ left: 10 })
  5938. .fontColor($r('app.color.text_color'))
  5939. .layoutWeight(1)
  5940. }
  5941. .width('100%')
  5942. .margin({ top: 10, bottom: 10 })
  5943. .justifyContent(FlexAlign.Start)
  5944. Row() {
  5945. Text('质量评分:')
  5946. .fontSize(14)
  5947. .fontColor($r('app.color.text_color'))
  5948. .margin({ left: 22 })
  5949. Text(currentItem.probe_score+"")
  5950. .fontSize(14)
  5951. .margin({ left: 10 })
  5952. .fontColor($r('app.color.text_color'))
  5953. .layoutWeight(1)
  5954. }
  5955. .width('100%')
  5956. .margin({ top: 10, bottom: 10 })
  5957. .justifyContent(FlexAlign.Start)
  5958. Row() {
  5959. Text('音轨号:')
  5960. .fontSize(14)
  5961. .fontColor($r('app.color.text_color'))
  5962. .margin({ left: 22 })
  5963. Text(currentItem.track)
  5964. .fontSize(14)
  5965. .margin({ left: 10 })
  5966. .fontColor($r('app.color.text_color'))
  5967. .layoutWeight(1)
  5968. }
  5969. .width('100%')
  5970. .margin({ top: 10, bottom: 10 })
  5971. .justifyContent(FlexAlign.Start)
  5972. Row() {
  5973. Text('碟号:')
  5974. .fontSize(14)
  5975. .fontColor($r('app.color.text_color'))
  5976. .margin({ left: 22 })
  5977. Text(currentItem.disc)
  5978. .fontSize(14)
  5979. .margin({ left: 10 })
  5980. .fontColor($r('app.color.text_color'))
  5981. .layoutWeight(1)
  5982. }
  5983. .width('100%')
  5984. .margin({ top: 10, bottom: 10 })
  5985. .justifyContent(FlexAlign.Start)
  5986. Row() {
  5987. Text('专辑艺术家:')
  5988. .fontSize(14)
  5989. .fontColor($r('app.color.text_color'))
  5990. .margin({ left: 22 })
  5991. Text(currentItem.ALBUMARTIST)
  5992. .fontSize(14)
  5993. .margin({ left: 10 })
  5994. .fontColor($r('app.color.text_color'))
  5995. .layoutWeight(1)
  5996. }
  5997. .width('100%')
  5998. .margin({ top: 10, bottom: 10 })
  5999. .justifyContent(FlexAlign.Start)
  6000. Row() {
  6001. Text('作曲家:')
  6002. .fontSize(14)
  6003. .fontColor($r('app.color.text_color'))
  6004. .margin({ left: 22 })
  6005. Text(currentItem.COMPOSER)
  6006. .fontSize(14)
  6007. .margin({ left: 10 })
  6008. .fontColor($r('app.color.text_color'))
  6009. .layoutWeight(1)
  6010. }
  6011. .width('100%')
  6012. .margin({ top: 10, bottom: 10 })
  6013. .justifyContent(FlexAlign.Start)
  6014. Row() {
  6015. Text('作词家:')
  6016. .fontSize(14)
  6017. .fontColor($r('app.color.text_color'))
  6018. .margin({ left: 22 })
  6019. Text(currentItem.LYRICIST)
  6020. .fontSize(14)
  6021. .margin({ left: 10 })
  6022. .fontColor($r('app.color.text_color'))
  6023. .layoutWeight(1)
  6024. }
  6025. .width('100%')
  6026. .margin({ top: 10, bottom: 10 })
  6027. .justifyContent(FlexAlign.Start)
  6028. Row() {
  6029. Text('注释:')
  6030. .fontSize(14)
  6031. .fontColor($r('app.color.text_color'))
  6032. .margin({ left: 22 })
  6033. Text(currentItem.COMMENT)
  6034. .fontSize(14)
  6035. .margin({ left: 10 })
  6036. .fontColor($r('app.color.text_color'))
  6037. .layoutWeight(1)
  6038. }
  6039. .width('100%')
  6040. .margin({ top: 10, bottom: 10 })
  6041. .justifyContent(FlexAlign.Start)
  6042. Row() {
  6043. Text('格式:')
  6044. .fontSize(14)
  6045. .fontColor($r('app.color.text_color'))
  6046. .margin({ left: 22 })
  6047. Text(Utility.formatMimeType(currentItem.mimeType))
  6048. .fontSize(14)
  6049. .margin({ left: 10 })
  6050. .fontColor($r('app.color.text_color'))
  6051. .layoutWeight(1)
  6052. }
  6053. .width('100%')
  6054. .margin({ top: 10, bottom: 10 })
  6055. .justifyContent(FlexAlign.Start)
  6056. Row() {
  6057. Text('播放次数:')
  6058. .fontSize(14)
  6059. .fontColor($r('app.color.text_color'))
  6060. .margin({ left: 22 })
  6061. Text(currentItem.playCount?.toString())
  6062. .fontSize(14)
  6063. .margin({ left: 10 })
  6064. .fontColor($r('app.color.text_color'))
  6065. .layoutWeight(1)
  6066. }
  6067. .width('100%')
  6068. .margin({ top: 10, bottom: 10 })
  6069. .justifyContent(FlexAlign.Start)
  6070. Row() {
  6071. Text('流数量:')
  6072. .fontSize(14)
  6073. .fontColor($r('app.color.text_color'))
  6074. .margin({ left: 22 })
  6075. Text(currentItem.nb_streams?.toString())
  6076. .fontSize(14)
  6077. .margin({ left: 10 })
  6078. .fontColor($r('app.color.text_color'))
  6079. .layoutWeight(1)
  6080. }
  6081. .width('100%')
  6082. .margin({ top: 10, bottom: 10 })
  6083. .justifyContent(FlexAlign.Start)
  6084. Row() {
  6085. Text('文件大小:')
  6086. .fontSize(14)
  6087. .fontColor($r('app.color.text_color'))
  6088. .margin({ left: 22 })
  6089. Text(currentItem.size)
  6090. .fontSize(14)
  6091. .margin({ left: 10 })
  6092. .fontColor($r('app.color.text_color'))
  6093. .layoutWeight(1)
  6094. }
  6095. .width('100%')
  6096. .margin({ top: 10, bottom: 10 })
  6097. .justifyContent(FlexAlign.Start)
  6098. Row() {
  6099. Text('文件名:')
  6100. .fontSize(14)
  6101. .fontColor($r('app.color.text_color'))
  6102. .margin({ left: 22 })
  6103. Text(currentItem.fileName)
  6104. .fontSize(14)
  6105. .margin({ left: 10 })
  6106. .fontColor($r('app.color.text_color'))
  6107. .layoutWeight(1)
  6108. }
  6109. .width('100%')
  6110. .margin({ top: 10, bottom: 10 })
  6111. .justifyContent(FlexAlign.Start)
  6112. Row() {
  6113. Text('修改时间:')
  6114. .fontSize(14)
  6115. .fontColor($r('app.color.text_color'))
  6116. .margin({ left: 22 })
  6117. Text(currentItem.cTime)
  6118. .fontSize(14)
  6119. .margin({ left: 10 })
  6120. .fontColor($r('app.color.text_color'))
  6121. .layoutWeight(1)
  6122. }
  6123. .width('100%')
  6124. .margin({ top: 10, bottom: 10 })
  6125. .justifyContent(FlexAlign.Start)
  6126. Row() {
  6127. Text('存放目录:')
  6128. .fontSize(14)
  6129. .fontColor($r('app.color.text_color'))
  6130. .margin({ left: 22 })
  6131. Text(currentItem.filePath)
  6132. .fontSize(12)
  6133. .margin({ left: 10 })
  6134. .fontColor($r('app.color.text_color'))
  6135. .layoutWeight(1)
  6136. }
  6137. .margin({ top: 10, bottom: 10 })
  6138. .width('100%')
  6139. .justifyContent(FlexAlign.Start)
  6140. Row() {
  6141. Text('内嵌歌词:')
  6142. .fontSize(14)
  6143. .fontColor($r('app.color.text_color'))
  6144. .margin({ left: 22 })
  6145. Text(currentItem.lyricContent)
  6146. .fontSize(12)
  6147. .copyOption(CopyOptions.InApp)
  6148. .margin({ left: 10 })
  6149. .fontColor($r('app.color.text_color'))
  6150. .layoutWeight(1)
  6151. }
  6152. .margin({ top: 10, bottom: 10 })
  6153. .width('100%')
  6154. .justifyContent(FlexAlign.Start)
  6155. }
  6156. }
  6157. .margin({ bottom: 20 })
  6158. }
  6159. //定时关闭布局
  6160. @Builder
  6161. TimeCloseSheet() {
  6162. Scroll() {
  6163. Column() {
  6164. this.TimeClose()
  6165. }
  6166. }
  6167. .width('100%')
  6168. .height('100%')
  6169. }
  6170. //倒计时关闭音乐,退出App功能实现。
  6171. @State selectedMinutes: number = 0 // 0表示未开启
  6172. @State remainingSeconds: number = 0
  6173. // 预设时间选项
  6174. private presetTimes: number[] = [0, 5, 15, 30, 45, 60, -1]
  6175. private formatTime(seconds: number): string {
  6176. const mins = Math.floor(seconds / 60)
  6177. const secs = seconds % 60
  6178. return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
  6179. }
  6180. // 开始倒计时
  6181. private handleTimeSelect(minutes: number) {
  6182. if (minutes === this.selectedMinutes) {
  6183. this.stopCountdown();
  6184. this.selectedMinutes = 0;
  6185. return;
  6186. }
  6187. this.selectedMinutes = minutes;
  6188. this.remainingSeconds = minutes * 60;
  6189. this.startCountdown(); // 新增调用
  6190. }
  6191. @Builder
  6192. TimeClose() {
  6193. Column() {
  6194. // 倒计时显示区域
  6195. Text(this.selectedMinutes > 0 ?
  6196. `剩余时间:${this.formatTime(this.remainingSeconds)}` :
  6197. "定时关闭未开启")
  6198. .fontSize(17)
  6199. .fontColor($r('app.color.text_color'))
  6200. .margin({ top: 2, bottom: 8 });
  6201. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  6202. ForEach(this.presetTimes, (minutes: number, index: number) => {
  6203. // 单行时间选项容器
  6204. Row() {
  6205. // 文字描述区域
  6206. Text(this.getDisplayText(minutes))
  6207. .fontSize(15)
  6208. .fontColor(minutes === this.selectedMinutes ? this.themeColor :
  6209. $r('app.color.text_color'))// 选中态颜色变化
  6210. .textAlign(TextAlign.Start)
  6211. .layoutWeight(1); // 占据剩余空间
  6212. // 复选框样式的选择器
  6213. Row() {
  6214. if (minutes === this.selectedMinutes) {
  6215. // 选中状态 - 带勾号的圆形复选框
  6216. Row() {
  6217. // 使用系统内置的勾号图标
  6218. Image($r('sys.media.ohos_ic_public_ok'))
  6219. .width(14)
  6220. .height(14)
  6221. .fillColor(Color.White)
  6222. }
  6223. .width(24)
  6224. .height(24)
  6225. .borderRadius(12)
  6226. .backgroundColor(this.themeColor)
  6227. .justifyContent(FlexAlign.Center)
  6228. .alignItems(VerticalAlign.Center)
  6229. } else {
  6230. // 未选中状态的圆形边框
  6231. Row()
  6232. .width(24)
  6233. .height(24)
  6234. .borderRadius(12)
  6235. .border({
  6236. width: 2,
  6237. color: $r('app.color.text_color'),
  6238. style: BorderStyle.Solid
  6239. })
  6240. .backgroundColor(Color.Transparent)
  6241. }
  6242. }
  6243. .width(24)
  6244. .height(24)
  6245. .margin({ left: 20 })
  6246. .justifyContent(FlexAlign.Center)
  6247. .alignItems(VerticalAlign.Center)
  6248. }
  6249. .width('100%')
  6250. .padding({
  6251. top: 18,
  6252. bottom: 18,
  6253. left: 18,
  6254. right: 18
  6255. })
  6256. .backgroundColor(minutes === this.selectedMinutes ? $r('app.color.timeColor_bg') :
  6257. $r('app.color.bottom_control_background')) // 选中背景高亮
  6258. .borderRadius(12)
  6259. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6260. .margin({ bottom: 18 })
  6261. .onClick(() => this.handleSelect(minutes)); // 点击整行触发选择
  6262. });
  6263. }
  6264. .width('100%')
  6265. .padding(16)
  6266. }
  6267. }
  6268. // 获取显示文本
  6269. private getDisplayText(minutes: number): string {
  6270. if (minutes === -1) {
  6271. return Utility.resourceToString(getContext(this), $r('app.string.customize'));
  6272. }
  6273. return minutes === 0 ? Utility.resourceToString(getContext(this), $r('app.string.close')) :
  6274. `${minutes}` + Utility.resourceToString(getContext(this), $r('app.string.minute_after'));
  6275. }
  6276. // 处理选择事件
  6277. private handleSelect(minutes: number): void {
  6278. if (minutes === -1) { // 自定义
  6279. // 弹出自定义时间对话框
  6280. DialogHelper.showTextInputDialog({
  6281. title: '自定义时间',
  6282. maskColor: Color.Transparent,
  6283. inputType: InputType.Number,
  6284. text: '',
  6285. onChange: (text) => {
  6286. console.error("onChange: " + text);
  6287. },
  6288. onAction: (action, dialogId, content) => {
  6289. if (action == DialogAction.TWO) {
  6290. const customMinutes = Number(content);
  6291. if (customMinutes > 0) {
  6292. this.handleTimeSelect(customMinutes); // 设置自定义时间
  6293. ToastUtil.showToast("设置成功," + customMinutes + "分钟后定时关闭");
  6294. }
  6295. }
  6296. }
  6297. });
  6298. } else {
  6299. this.handleTimeSelect(minutes); // 统一调用选择处理方法
  6300. }
  6301. }
  6302. // 添加定时器引用
  6303. private timerId: number = -1;
  6304. // 启动/重置倒计时
  6305. private startCountdown() {
  6306. // 清除旧定时器
  6307. if (this.timerId !== -1) {
  6308. clearInterval(this.timerId);
  6309. }
  6310. // 创建新定时器
  6311. if (this.selectedMinutes > 0) {
  6312. this.timerId = setInterval(() => {
  6313. if (this.remainingSeconds === 15) {
  6314. this.showConfirmationDialog();
  6315. }
  6316. if (this.remainingSeconds > 0) {
  6317. this.remainingSeconds -= 1;
  6318. } else {
  6319. this.stopCountdown();
  6320. this.handleTimeout();
  6321. }
  6322. }, 1000);
  6323. }
  6324. }
  6325. // 15倒计时后再次提示显示确认是否关闭App对话框
  6326. private showConfirmationDialog() {
  6327. DialogHelper.showAlertDialog({
  6328. backgroundColor: $r('app.color.btn_green'),
  6329. title: '确认关闭',
  6330. maskColor: Color.Transparent,
  6331. content: "马上到达定时关闭时间,您是否确定要退出应用?",
  6332. borderStyle: BorderStyle.Dashed,
  6333. primaryButton: '暂不关闭',
  6334. secondaryButton: '确定',
  6335. onAction: (action) => {
  6336. if (action == DialogAction.ONE) { //暂不关闭,取消定时
  6337. this.stopCountdown();
  6338. this.selectedMinutes = 0
  6339. } else if (action == DialogAction.TWO) {
  6340. }
  6341. }
  6342. })
  6343. }
  6344. // 停止倒计时
  6345. private stopCountdown() {
  6346. if (this.timerId !== -1) {
  6347. clearInterval(this.timerId);
  6348. this.timerId = -1;
  6349. }
  6350. }
  6351. // 超时处理
  6352. private handleTimeout() {
  6353. // 执行播放器关闭逻辑
  6354. this.selectedMinutes = 0;
  6355. ToastUtil.showToast(" 定时关闭已完成");
  6356. this.stop(); // 假设存在的播放器实例
  6357. //退出APP
  6358. const mContext = getContext(this) as common.UIAbilityContext
  6359. mContext.terminateSelf();
  6360. AvSessionController.getInstance(true).unregisterSessionListener()
  6361. }
  6362. //倒计时关闭音乐,退出App功能实现结束。
  6363. //播放列表的拖动List 重新排序
  6364. @State sonDataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.songList)
  6365. //左滑操作 移动文件 重命名 删除等操作
  6366. @Builder
  6367. sonButton(item: VideoItem, index: number, filePath: string) {
  6368. Row() {
  6369. //加入下一首播放
  6370. Button() {
  6371. Image($r('app.media.next_to_play'))
  6372. .fillColor(Color.White)
  6373. .width(20)
  6374. }
  6375. .width(40)
  6376. .height(40)
  6377. .type(ButtonType.Circle)
  6378. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  6379. .backgroundColor(this.themeColor)
  6380. .margin(5)
  6381. .onClick(() => {
  6382. this.addToNextPlay(item);
  6383. })
  6384. Button() {
  6385. Image($r('app.media.close'))
  6386. .fillColor(Color.White)
  6387. .width(20)
  6388. }
  6389. .width(40)
  6390. .height(40)
  6391. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  6392. .type(ButtonType.Circle)
  6393. .backgroundColor(this.themeColor)
  6394. .margin(5)
  6395. .onClick(() => {
  6396. this.songList.splice(Number(index), 1)
  6397. this.sonDataSource.pushArrayData(this.songList)
  6398. })
  6399. Button() {
  6400. Image($r('app.media.share2'))
  6401. .fillColor(Color.White)
  6402. .width(20)
  6403. }
  6404. .width(40)
  6405. .height(40)
  6406. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  6407. .type(ButtonType.Circle)
  6408. .backgroundColor(this.themeColor)
  6409. .margin(5)
  6410. .onClick(() => {
  6411. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  6412. })
  6413. }
  6414. }
  6415. itemMoveSon(index: number, newIndex: number): void {
  6416. if (newIndex < 0 || newIndex >= this.songList.length) {
  6417. return;
  6418. }
  6419. let tmp = this.songList.splice(index, 1);
  6420. this.songList.splice(newIndex, 0, tmp[0]);
  6421. this.sonDataSource.pushArrayData(this.songList)
  6422. this.curIndex = Utility.getIndexFromList(this.songList, this.videoUrl)
  6423. }
  6424. @Builder
  6425. PlayList() {
  6426. List({ scroller: this.playListScroller }) {
  6427. LazyForEach(this.sonDataSource, (item: VideoItem, index: number) => {
  6428. ListItem() {
  6429. this.MusicItemSon(item, index)
  6430. }
  6431. .swipeAction({ end: this.sonButton(item, index, item.filePath) }) //左滑
  6432. .animation({
  6433. duration: 666,
  6434. curve: 'ease-in-out' // 可选动画曲线
  6435. })
  6436. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 600 }),
  6437. TransitionEffect.scale({ x: 0, y: 0 })))
  6438. .clickEffect({ level: ClickEffectLevel.MIDDLE })
  6439. //拖动List关键代码开始
  6440. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  6441. .zIndex(this.dragItem === index ? 1 : 0)
  6442. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  6443. .gesture(
  6444. GestureGroup(GestureMode.Sequence,
  6445. LongPressGesture({ repeat: true })
  6446. .onAction((event?: GestureEvent) => {
  6447. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  6448. this.scaleItem = index
  6449. })
  6450. })
  6451. .onActionEnd(() => {
  6452. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  6453. this.scaleItem = -1
  6454. })
  6455. }),
  6456. PanGesture({ fingers: 1, direction: null, distance: 0 })
  6457. .onActionStart(() => {
  6458. this.dragItem = index // 记录当前拖动项索引
  6459. this.dragRefOffset = 0 // 重置偏移基准
  6460. })
  6461. .onActionUpdate((event: GestureEvent) => {
  6462. this.offsetY = event.offsetY - this.dragRefOffset;
  6463. this.neighborItem = -1;
  6464. let indexA = this.songList.indexOf(item);
  6465. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  6466. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  6467. let value: number = 0;
  6468. if (this.offsetY < 0) {
  6469. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  6470. this.neighborItem = indexA - 1;
  6471. this.neighborScale = 1 - value / 20;
  6472. } else if (this.offsetY > 0) {
  6473. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  6474. this.neighborItem = indexA + 1;
  6475. this.neighborScale = 1 - value / 20;
  6476. }
  6477. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.songList.length) {
  6478. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6479. this.offsetY -= this.ITEM_INTV;
  6480. this.dragRefOffset += this.ITEM_INTV;
  6481. this.itemMoveSon(indexA, indexA + 1);
  6482. });
  6483. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  6484. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6485. this.offsetY += this.ITEM_INTV;
  6486. this.dragRefOffset -= this.ITEM_INTV;
  6487. this.itemMoveSon(indexA, indexA - 1);
  6488. });
  6489. }
  6490. })
  6491. .onActionEnd((event: GestureEvent) => {
  6492. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6493. this.dragItem = -1
  6494. this.neighborItem = -1
  6495. })
  6496. animateTo({
  6497. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  6498. }, () => {
  6499. this.scaleItem = -1
  6500. })
  6501. })
  6502. )
  6503. .onCancel(() => {
  6504. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6505. this.dragItem = -1
  6506. this.neighborItem = -1
  6507. })
  6508. animateTo({
  6509. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  6510. }, () => {
  6511. this.scaleItem = -1
  6512. })
  6513. })
  6514. ) //拖动List关键代码结束
  6515. .onClick(() => {
  6516. this.doPlay(item, index, true)
  6517. })
  6518. }, (item: VideoItem) => item.filePath)
  6519. }
  6520. .width('100%')
  6521. .height('100%')
  6522. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  6523. // .animation({ duration: 500, curve: Curve.Ease }))
  6524. .cachedCount(10)
  6525. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  6526. .gesture(PinchGesture({ fingers: 2 })
  6527. .onActionEnd((event: GestureEvent) => {
  6528. this.setSonListTwoFingers()
  6529. })
  6530. .onActionUpdate(e => {
  6531. this.scaleValue = this.pinchValue * e.scale
  6532. })
  6533. .onActionStart(e => {
  6534. }))
  6535. .padding({
  6536. bottom: 0
  6537. })
  6538. }
  6539. setSonListTwoFingers() {
  6540. this.pinchValue = this.scaleValue;
  6541. Logger.info('this.pinchValue = ' + this.pinchValue);
  6542. if (this.pinchValue >= 1) {
  6543. this.sonTwoFingerType++
  6544. Logger.info('this.twoFingerType1 = ' + this.sonTwoFingerType);
  6545. if (this.sonTwoFingerType > 3) {
  6546. this.sonTwoFingerType = 1
  6547. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  6548. }
  6549. } else {
  6550. this.sonTwoFingerType--
  6551. Logger.info('this.twoFingerType2 = ' + this.sonTwoFingerType);
  6552. if (this.sonTwoFingerType < 1) {
  6553. this.sonTwoFingerType = 1
  6554. }
  6555. }
  6556. PreferencesUtil.put('sonTwoFingerType', this.sonTwoFingerType)
  6557. this.pinchValue = 1;
  6558. this.scaleValue = 1;
  6559. }
  6560. @State sonTwoFingerType:number = 3
  6561. @Builder
  6562. private MusicItemSon(item: VideoItem, index?: number) {
  6563. Button({ type: ButtonType.Normal, stateEffect: true }) {
  6564. Row() {
  6565. Stack() {
  6566. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  6567. .height(this.sonTwoFingerType == 3||this.sonTwoFingerType==4 ? 55 : this.sonTwoFingerType == 2 ? 48 : 40)
  6568. .width(this.sonTwoFingerType == 3||this.sonTwoFingerType==4 ? 55 : this.sonTwoFingerType == 2 ? 48 : 40)
  6569. .alt($r('app.media.music_red'))
  6570. .fillColor(this.themeColor)
  6571. .borderRadius('100%')
  6572. .clip(true)
  6573. .interpolation(ImageInterpolation.High)// 用于重采样后的抗锯齿
  6574. .draggable(false)// 禁止长按手势拖动
  6575. .autoResize(true) // 重采样,可减少内存占用
  6576. .margin({ left: 20 })
  6577. }
  6578. .width('15%')
  6579. Column() {
  6580. Column() {
  6581. Text(this.isShowFileName?item.fileName :item.name)
  6582. .fontSize(this.sonTwoFingerType == 1 ? 12 : this.sonTwoFingerType == 2 ? 15 : 18)
  6583. .fontColor(this.curIndex === index ? this.themeColor :
  6584. this.isFrontWhite ? Color.White : $r('app.color.text_color'))
  6585. .maxLines(1)
  6586. .margin({ left: this.sonTwoFingerType == 3 ? 18 : 10 })
  6587. Row() {
  6588. Column(){
  6589. Text(item.md5Str?.includes('Lossless')?
  6590. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  6591. .fontSize(this.sonTwoFingerType == 1 ? 8 : this.sonTwoFingerType == 2 ? 9 : 11)
  6592. .padding({ top: 3,right:6,left:6,bottom:3 })
  6593. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  6594. $r('app.color.text_color'))
  6595. .fontWeight(500)
  6596. .borderRadius(12)
  6597. .margin({ left: this.sonTwoFingerType == 3 ? 12 : 10 })
  6598. .backgroundColor('#FFC107')
  6599. }
  6600. .padding({ top: 8 })
  6601. Text(StrUtil.isEmpty(item.artist) ? item.duration :
  6602. this.sonTwoFingerType<=2?" "+item?.duration:
  6603. item.artist + ' ' + item?.album)
  6604. .fontSize(this.sonTwoFingerType == 1 ? 11 : this.sonTwoFingerType == 2 ? 12 : 14)
  6605. .padding({ top: 8 })
  6606. .maxLines(1)
  6607. .fontColor(this.curIndex === index ? this.themeColor :
  6608. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  6609. .margin({ left: this.sonTwoFingerType == 3 ? 5 : 3 })
  6610. Blank()
  6611. Text(item.size)
  6612. .fontSize(this.sonTwoFingerType == 1 ? 11 : this.sonTwoFingerType == 2 ? 12 : 14)
  6613. .padding({ top: 8 })
  6614. .maxLines(1)
  6615. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  6616. .fontColor(this.curIndex === index ? $r('app.color.title_bar_bg_text') :
  6617. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  6618. .margin({ left: 10 })
  6619. }
  6620. }
  6621. .height('100%')
  6622. .width('100%')
  6623. .justifyContent(FlexAlign.Center)
  6624. .alignItems(HorizontalAlign.Start)
  6625. }
  6626. .height('100%')
  6627. .width('65%')
  6628. Column() {
  6629. ImageAnimator()
  6630. .images(this.imagesF)// 动画数组
  6631. .duration(1000)// 持续
  6632. .state(this.animationState)// 动画状态
  6633. .fillMode(FillMode.Forwards)
  6634. .width(18)
  6635. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  6636. Visibility.None)
  6637. .height(18)
  6638. .iterations(-1) // 播放次数
  6639. }
  6640. .width('20%')
  6641. }
  6642. }
  6643. .backgroundColor(Color.Transparent)
  6644. .width('100%')
  6645. .reuseId('son_item')
  6646. .height(this.sonTwoFingerType == 3 ? ITEM_HEIGHT_BIG : this.sonTwoFingerType == 2 ? ITEM_HEIGHT+10 : ITEM_HEIGHT_SMALL+10)
  6647. .shadow(this.scaleItem === index ? {
  6648. radius: 70,
  6649. color: '#15000000',
  6650. offsetX: 0,
  6651. offsetY: 0
  6652. } :
  6653. {
  6654. radius: 0,
  6655. color: '#15000000',
  6656. offsetX: 0,
  6657. offsetY: 0
  6658. })
  6659. .animation({ curve: Curve.Sharp, duration: 300 })
  6660. }
  6661. @Builder
  6662. MusicPlayBuilder() {
  6663. Column() {
  6664. this.IjkMusicPlayerView()
  6665. }
  6666. .height('100%')
  6667. .width('100%')
  6668. .onDisAppear(() => {
  6669. this.translateY = 0;
  6670. })
  6671. .translate({ y: this.translateY })
  6672. .gesture(
  6673. PanGesture(this.panOption)
  6674. .onActionUpdate((event?: GestureEvent) => {
  6675. if (event) {
  6676. // 只允许向下滑动,向上滑动时限制为0
  6677. this.translateY = Math.max(0, event.offsetY);
  6678. }
  6679. })
  6680. .onActionEnd((event?: GestureEvent) => {
  6681. // 使用更低的阈值和滑动速度判断
  6682. const minDistance = 100; // 最小滑动距离 100vp
  6683. const minVelocity = 500; // 最小滑动速度
  6684. // 获取滑动速度(如果可用)
  6685. const velocity = event?.velocityY || 0;
  6686. // 判断是否应该关闭:距离足够 或者 速度足够快
  6687. const shouldClose = this.translateY > minDistance || velocity > minVelocity;
  6688. if (shouldClose) {
  6689. // 添加关闭动画
  6690. this.getUIContext().animateTo({
  6691. duration: 300,
  6692. curve: Curve.Smooth
  6693. }, () => {
  6694. this.isShowPlay = false;
  6695. this.translateY = 0;
  6696. })
  6697. } else {
  6698. // 回弹动画
  6699. this.getUIContext().animateTo({
  6700. duration: 300,
  6701. curve: Curve.Smooth
  6702. }, () => {
  6703. this.translateY = 0;
  6704. })
  6705. }
  6706. })
  6707. )
  6708. }
  6709. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD; //一多界面适配
  6710. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  6711. HeightBreakpoint.HEIGHT_LG;
  6712. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  6713. @State topBarHeight: number = 50
  6714. @State barOpacity: number = 1
  6715. @State barBottomOpacity: number = 1
  6716. private hideDone: boolean = false;
  6717. @State currentYOffset: number = 0;
  6718. @State bottomBarHeight: number = 60;
  6719. private isHiding: boolean = false;
  6720. //是否是Pura X外屏,或者小屏幕
  6721. isPuraWP() {
  6722. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  6723. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  6724. }
  6725. //是否是Pura X外屏,或者小屏幕,手机横屏
  6726. /**
  6727. * 是否是Pura X外屏,或者小屏幕,手机横屏
  6728. * @returns
  6729. */
  6730. isCoverOpacity() {
  6731. if (this.isPuraWP()) {
  6732. return true
  6733. }
  6734. if (this.isPhoneLan()) {
  6735. return true
  6736. }
  6737. if (deviceInfo.marketName.includes('Pura X')
  6738. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  6739. return true
  6740. }
  6741. return false
  6742. }
  6743. //是不是手机横屏
  6744. isPhoneLan() {
  6745. // LogUtil.info('twocold this.currentHeightBreakpoint = '+this.currentHeightBreakpoint)
  6746. // LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
  6747. LogUtil.info('hicar isPhoneLan width= ' + this.windowWidth);
  6748. LogUtil.info('hicar isPhoneLan height= ' + this.windowHeight);
  6749. LogUtil.info(`twocold hicarWindow size: ${this.windowWidth}x${this.windowHeight}, this.isHiCarStatus: ${this.isHiCarStatus}`);
  6750. LogUtil.info(`twocold hicar Window size: ${this.windowWidth}x${this.windowHeight}, isHiCarSmall: ${this.isHiCarSmall()}`);
  6751. if (this.isHiCarKuanBianPing()) {
  6752. return true
  6753. }
  6754. if (this.isHiCar()) {
  6755. return false
  6756. }
  6757. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  6758. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_SM
  6759. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_MD&&this.isLandscape) { //如果是手机横屏,返回true
  6760. return true
  6761. }
  6762. return false
  6763. }
  6764. //是不是1920x720的hicar的屏幕分辨率
  6765. isHiCarKuanBianPing(){
  6766. if(!this.isHiCar()){
  6767. return false
  6768. }
  6769. const hiCarAspectRatios: HiCarAspectRatio[] = [
  6770. { ratio: 1920 / 720, name: "1920x720" },
  6771. ];
  6772. const currentRatio: number = this.windowWidth / this.windowHeight;
  6773. const RATIO_TOLERANCE: number = 0.22; // 宽高比容差
  6774. LogUtil.info('twocold isHiCarKuanBianPing currentRatio = ' + currentRatio)
  6775. for (const hiCarRatio of hiCarAspectRatios) {
  6776. LogUtil.info('twocold isHiCarKuanBianPing hiCarRatio= ' + hiCarRatio.ratio)
  6777. LogUtil.info('twocold isHiCarKuanBianPing Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  6778. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  6779. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  6780. //宽扁平的尺寸设置列表展示
  6781. this.twoFingerType ==3
  6782. this.isGridMusic = false
  6783. return true;
  6784. }
  6785. }
  6786. return false;
  6787. }
  6788. //是不是hicar的屏幕分辨率
  6789. isHiCarSmall() {
  6790. if(!this.isHiCar()){
  6791. return false
  6792. }
  6793. if(this.windowWidth>1800&&this.windowHeight>=1200)//大屏幕可以Grid
  6794. {
  6795. this.columns = 6
  6796. return false
  6797. }
  6798. const hiCarAspectRatios: HiCarAspectRatio[] = [
  6799. { ratio: 800 / 480, name: "800x480" },
  6800. { ratio: 1280 / 720, name: "1280x720" },
  6801. { ratio: 1920 / 1080, name: "1920x1080" },
  6802. ];
  6803. const currentRatio: number = this.windowWidth / this.windowHeight;
  6804. const RATIO_TOLERANCE: number = 0.22; // 宽高比容差
  6805. LogUtil.info('twocold isHiCarSmall currentRatio = ' + currentRatio)
  6806. for (const hiCarRatio of hiCarAspectRatios) {
  6807. LogUtil.info('twocold isHiCarSmall hiCarRatio= ' + hiCarRatio.ratio)
  6808. LogUtil.info('twocold isHiCarSmall Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  6809. LogUtil.info('twocold isHiCarSmall isHiCarStatus= ' + this.isHiCarStatus);
  6810. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  6811. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  6812. //宽扁平的尺寸设置列表展示
  6813. return true;
  6814. }
  6815. }
  6816. return false;
  6817. }
  6818. isHiCar() {
  6819. return this.isHiCarStatus&&this.curDisplayIsHiCar;
  6820. }
  6821. //是不是正常的手机竖屏
  6822. isPhonePortrait() {
  6823. // LogUtil.info('twocold this.currentHeightBreakpoint = ' + this.currentHeightBreakpoint)
  6824. // LogUtil.info('twocold this.currentWidthBreakpoint = ' + this.currentWidthBreakpoint)
  6825. // LogUtil.info('Heanup 当前设备类型:' + DeviceUtil.getDeviceType())
  6826. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  6827. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG
  6828. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_SM) { //如果是手机横屏,返回false
  6829. return true
  6830. }
  6831. return false
  6832. }
  6833. @State showSpeedDialog: boolean = false
  6834. @State longPressSpeed: number = 3 //长按默认倍数
  6835. @Builder
  6836. SpeedDialog() {
  6837. Stack() {
  6838. Column() {
  6839. Text('已切换至' + this.longPressSpeed + '倍速播放')
  6840. .fontColor(Color.White)
  6841. .visibility(Visibility.Hidden)
  6842. }
  6843. .backgroundColor(Color.Black)
  6844. .borderRadius(20)
  6845. .padding({
  6846. top: 10,
  6847. right: 20,
  6848. left: 15,
  6849. bottom: 20
  6850. })
  6851. .opacity(0.6)
  6852. Text('已切换至' + this.longPressSpeed + '倍速播放')
  6853. .fontColor(Color.White)
  6854. }
  6855. .transition(TransitionEffect.OPACITY.animation({ duration: 500, curve: Curve.Ease }))
  6856. .zIndex(5)
  6857. .margin({ top: 80 })
  6858. }
  6859. @Builder
  6860. IjkMusicPlayerView() {
  6861. Column() {
  6862. Column() {
  6863. Column() {
  6864. //播放标题
  6865. Column() {
  6866. this.PlayTitle()
  6867. }
  6868. .position({ x: 0, y: this.isCoverOpacity() ? 15 : 40 })
  6869. .width('100%')
  6870. .margin({ top: 0 })
  6871. .height(PlayConstants.HEIGHT)
  6872. .visibility(DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1 ?
  6873. Visibility.Visible : this.isShowPlayPageBack ? Visibility.Visible : Visibility.None)
  6874. if (this.showSpeedDialog) {
  6875. this.SpeedDialog()
  6876. }
  6877. Stack() {
  6878. //手势拖动快进
  6879. Column()
  6880. .width(CommonConstants.FULL_PERCENT)
  6881. .height('100%')
  6882. .gesture(
  6883. GestureGroup(GestureMode.Parallel,
  6884. // 长按屏幕倍数播放
  6885. LongPressGesture({ repeat: true })
  6886. .onAction(() => {
  6887. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6888. this.showSpeedDialog = true;
  6889. this.mIjkMediaPlayer.setSpeed(this.longPressSpeed + 'f');
  6890. }
  6891. })
  6892. .onActionEnd(() => {
  6893. this.showSpeedDialog = false;
  6894. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  6895. }),
  6896. //双击屏幕暂停或者播放
  6897. TapGesture({ count: 2 })
  6898. .onAction((event: GestureEvent) => {
  6899. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6900. ToastUtil.showToast('已暂停')
  6901. }
  6902. console.info('onecold playOrPause 6693')
  6903. this.playOrPause()
  6904. })
  6905. )
  6906. )
  6907. }
  6908. .height('65%')
  6909. Swiper() {
  6910. this.CoverInfo()
  6911. this.PlayerLyrics()
  6912. }
  6913. .onChange((index: number) => {
  6914. this.currentSwiperIndex = index
  6915. })
  6916. .indicator(false)
  6917. // .indicator(this.currentBreakpoint === BreakpointTypeEnum.SM ?
  6918. // new DotIndicator()
  6919. // .top(this.isCoverOpacity()?0:10)
  6920. //
  6921. // .selectedColor($r('app.color.select_swiper'))
  6922. // .color($r('app.color.slider_track')):false
  6923. // )
  6924. .displayCount(new BreakpointType({
  6925. sm: 1,
  6926. md: 2,
  6927. lg: 2,
  6928. xl: 2,
  6929. xxl: 2
  6930. }).getValue(this.currentBreakpoint))
  6931. .clip(false)
  6932. .loop(false)
  6933. .autoPlay(false)
  6934. // .interval(8000)
  6935. .position({ x: 0, y: this.isCoverOpacity() ? 30 : 40 })
  6936. .height('100%')
  6937. .hitTestBehavior(HitTestMode.Transparent)
  6938. Image($r('app.media.icon_replay'))
  6939. .objectFit(ImageFit.Auto)
  6940. .width('120px')
  6941. .height('120px')
  6942. .position({ x: '45.1%', y: '47.5%' })// .visibility(this.replayVisible)
  6943. .border({ width: 0 })
  6944. .visibility(Visibility.None)
  6945. .borderStyle(BorderStyle.Dashed)// .hitTestBehavior(HitTestMode.Transparent)
  6946. .onClick(() => {
  6947. console.info('onecold startPlayOrResumePlay 6744')
  6948. this.startPlayOrResumePlay();
  6949. })
  6950. }
  6951. .width(CommonConstants.FULL_PERCENT)
  6952. .height(CommonConstants.FULL_PERCENT)
  6953. .justifyContent(FlexAlign.End)
  6954. }
  6955. .justifyContent(FlexAlign.End)
  6956. .margin({ bottom: 8 })
  6957. }
  6958. .backgroundImage(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  6959. // .backgroundImage(this.isPuraWP() && this.currentSwiperIndex === 0 ?
  6960. // (StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover) : this.imageLabelBg)
  6961. .backgroundImageSize(this.isPuraWP() ? { width: '100%' } : { height: '150%', width: '100%' })
  6962. // .backgroundImagePosition(Alignment.Center)
  6963. .animation({
  6964. duration: 666,
  6965. curve: 'ease-in-out' // 可选动画曲线
  6966. })
  6967. .backgroundBlurStyle(this.isPuraWP() && this.currentSwiperIndex === 0 ? BlurStyle.NONE :
  6968. BlurStyle.BACKGROUND_ULTRA_THICK)
  6969. .hitTestBehavior(HitTestMode.Transparent)
  6970. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  6971. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  6972. .backgroundBrightness({ rate: this.isPuraWP() ? 0.1 : 0, lightUpDegree: -0.1 })
  6973. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
  6974. .onClick(() => {
  6975. // this.startAutoHide()
  6976. if(this.isHiCar())
  6977. return
  6978. if(this.is_auto_hide_progress){
  6979. this.is_auto_hide_progress = false
  6980. }
  6981. this.startAutoHide()
  6982. })
  6983. }
  6984. @State progressValue: number = 0;
  6985. @State currentTime: string = "00:00";
  6986. @State totalTime: string = "00:00";
  6987. @State loadingVisible: Visibility = Visibility.None;
  6988. @State replayVisible: Visibility = Visibility.None;
  6989. @State slideEnable: boolean = false;
  6990. @State aspRatio: number = 0.5;
  6991. @State mContext: object | undefined = undefined;
  6992. // private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
  6993. @State mFirst: boolean = true;
  6994. @State mDestroyPage: boolean = false;
  6995. @State playSpeed: number = 1;
  6996. @State oldSeconds: number = 0;
  6997. @State isSeekTo: boolean = false;
  6998. @State isCurrentTime: boolean = false;
  6999. @State videoWidth: string = '100%';
  7000. @State videoHeight: string = '100%';
  7001. @State initAspectRatio: number = 1;
  7002. @State videoAspectRatio: number = this.initAspectRatio;
  7003. private videoUrl: string = '';
  7004. private last: number = 0;
  7005. @State videoParentAspectRatio: number = this.initAspectRatio;
  7006. private mIjkMediaPlayer = IjkMediaPlayer.getInstance();
  7007. @State CONTROL_PlayStatus: number = PlayStatus.INIT;
  7008. @State PROGRESS_MAX_VALUE: number = 100;
  7009. @State updateProgressTimer: number = 0;
  7010. @State isHide: boolean = false; //是否因此播放器的按钮,默认是进入横屏模式隐藏,点击视频的时候显示
  7011. @State name: string = '';
  7012. // @State loop: boolean = false;
  7013. @State playType: number = 0; //0:连续播放 1:单片重复播放 2:正常播放 3:随机播放
  7014. @State multiple: string = '1.0X';
  7015. xcomponentController: XComponentController = new XComponentController()
  7016. private panOptionBright: PanGestureOptions =
  7017. new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down });
  7018. private panOptionVolume: PanGestureOptions =
  7019. new PanGestureOptions({ direction: PanDirection.Vertical | PanDirection.Up | PanDirection.Down });
  7020. private panOptionSeekTo: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Horizontal });
  7021. //手势的音量控制和亮度控制
  7022. private positionX: number = PlayConstants.POSITION_X;
  7023. private positionY: number = PlayConstants.POSITION_Y;
  7024. private windowClass: window.Window = globalThis.windowClass
  7025. @State volume: number = 0.5;
  7026. @State volumeSmall: boolean = false
  7027. @State autoParseMusicName: boolean = true
  7028. @State isShowFileName: boolean = false
  7029. @State isLongNameRoLL: boolean = true//长歌名滚动
  7030. @State volumeShow: boolean = PlayConstants.VOLUME_SHOW;
  7031. @State bright: number = PlayConstants.BRIGHT;
  7032. @State brightShow: boolean = PlayConstants.BRIGHT_SHOW;
  7033. @State seekToShow: boolean = PlayConstants.BRIGHT_SHOW;
  7034. @State screenWidth: number = 0
  7035. @State screenHeight: number = 0
  7036. @State statusBarHeight: number = 0
  7037. @State isYesFull: boolean = false
  7038. private seekValue: number = 0
  7039. @State isVideoLock: boolean = false; // Whether the video playback is locked
  7040. eventHub = getContext().eventHub;
  7041. //投播组件
  7042. private avSessionController: AvSessionController = AvSessionController.getInstance(false);
  7043. private castController: avSession.AVCastController | undefined = undefined;
  7044. @State isCastPlaying: boolean = false;
  7045. @State currentTime2: number = 0;
  7046. @State currentStringTime: string = '00:00';
  7047. @State duration: number = 0;
  7048. @State isReady: boolean = false;
  7049. @State durationTime: number = 0;
  7050. @State durationStringTime: string = '00:00';
  7051. @StorageLink('isPlaying') @Watch('animationRoFun') isPlaying: boolean = false;
  7052. // @State isPlaying: boolean = false;
  7053. private castSeek: boolean = false;
  7054. private castItem: avSession.AVQueueItem | undefined = undefined;
  7055. // @State isBgPlayOpen:boolean = true //是否启用后台播放
  7056. @State imageLabel: PixelMap | Resource = CommonConstants.musicBgList[0];
  7057. @State imageLabelBg: PixelMap | Resource = CommonConstants.musicBgList[0];
  7058. @State rotateAngle2: number = -9
  7059. @StorageLink('imageColor') imageColor: string = 'rgba(0, 0, 2, 1.00)';
  7060. @State cover: string | undefined = '';
  7061. @State artist: string | undefined = ''
  7062. // 1.初始化controller
  7063. private lyricController: LyricController = new LyricController()
  7064. private lyricControllerXF: LyricController = new LyricController() //悬浮歌词控制器
  7065. private lyricControllerSingle: LyricController = new LyricController() //播放页单行歌词控制器
  7066. private parser = new LyricParser()
  7067. @State randomColor: string = 'rgb(0,0,0)'
  7068. @State randomShakenX: number = 0
  7069. @State randomShakenY: number = 0
  7070. @State lyricTextSize: number = 24
  7071. @State lyricContent: string = ''
  7072. @State isDebug: boolean = false
  7073. @State isHightLightCenter: boolean = true
  7074. /**
  7075. * 初始化歌词加载与展示逻辑
  7076. * @param lyricPath 歌词文件路径(支持普通.lrc和加密.lrcc)
  7077. * @param isOnLineAndToast 是否弹出Toast提示(可选)获取在线歌词为true
  7078. * @param isApi2 是否使用API2获取歌词(可选)
  7079. *
  7080. * 主要流程:
  7081. * 1. 设置歌词显示样式(字号、颜色、行距、对齐、动画等)。
  7082. * 2. 优先尝试本地读取歌词文件(支持加密和普通两种后缀)。
  7083. * 3. 若本地无歌词且满足条件(调试模式或会员且安装时间超过2天),则联网获取歌词。
  7084. * 4. 获取到歌词后,解析并设置到lyricController,并保存到本地。
  7085. * 5. 本地有歌词时,读取文件内容(自动检测编码,支持解密),解析后设置到lyricController。
  7086. * 6. 解析失败或读取失败时,清空歌词显示。
  7087. *
  7088. * 注意事项:
  7089. * - 仅会员且安装时间超过2天才可联网获取歌词(调试模式isDebug=true时跳过限制)。
  7090. * - 支持加密歌词文件(.lrcc),自动检测并解密。
  7091. * - 歌词内容解析后通过lyricController驱动UI渲染。
  7092. */
  7093. async initLyric(lyricPath: string, isOnLineAndToast?: boolean, isApi2?: boolean, isLocal?: boolean) {
  7094. if (StrUtil.isEmpty(lyricPath)) {
  7095. return
  7096. }
  7097. this.initPipLyricSetting()
  7098. this.lyricControllerSingle
  7099. .setTextSize(15)
  7100. .setCacheSize(4)
  7101. .setTextColor("#FFFFFF")
  7102. .setHighlightColor("#FFFFFF")
  7103. .setHighlightScale(1.2)
  7104. .setEmptyHint("")
  7105. .setAlignMode('center')
  7106. .setAnimationDuration(500)
  7107. .setSingleLine(true)
  7108. this.lyricContent = ''
  7109. this.lyricController
  7110. .setTextSize(this.currentLyricSize)
  7111. .setCacheSize(4)
  7112. .setTextColor("#DDDDDD")
  7113. .setHighlightColor("#FFFFFF")
  7114. .setEmptyHint("")
  7115. .setAnimationDuration(1000)
  7116. this.currentLyricAlignMode = PreferencesUtil.getNumberSync('LyricAlignMode', 1)
  7117. this.blurDegree = PreferencesUtil.getNumberSync('setBlurDegree', 3)
  7118. this.setBlurDegree(this.blurDegree, false)
  7119. this.setLyricAlignMode(this.currentLyricAlignMode, false)
  7120. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSize', 18), false)
  7121. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSize', 1.23), false)
  7122. this.lyricController.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpace', 10))
  7123. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColor', '#FFFFFF'), false)
  7124. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColor', '#FFFFFF'), false)
  7125. this.isHightLightCenter = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, true)
  7126. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  7127. this.lyricTextWeight = PreferencesUtil.getNumberSync('lyricTextWeight', 400)
  7128. this.lyricController.setTextWeight(this.lyricTextWeight)
  7129. this.showSingleLyric = false
  7130. this.timeOffset = 0
  7131. this.lyricController.setLyric(null)
  7132. this.lyricControllerSingle.setLyric(null)
  7133. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc'
  7134. console.log("onecold lyricPath =" + lyricPath)
  7135. let neiqianLrc = ''
  7136. let lyContent = this.currentSong?.lyricContent
  7137. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  7138. neiqianLrc = lyContent
  7139. }
  7140. if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast&&!isLocal&&!isLocal) {
  7141. console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
  7142. //赋值给this.lyricContent,播控中心才可以显示歌词
  7143. this.lyricContent = neiqianLrc
  7144. // 将文件内容按行分割成字符串数组
  7145. let lines = neiqianLrc.split('\n').map(line => line.trim());
  7146. // 3.解析歌词
  7147. let lyric = this.parser.parse(lines);
  7148. // 4.设置歌词
  7149. this.lyricController.setLyric(lyric);
  7150. this.lyricControllerXF.setLyric(lyric)
  7151. this.lyricControllerSingle.setLyric(lyric)
  7152. return
  7153. }
  7154. if (isOnLineAndToast || ((!FileUtil.accessSync(lyricPath) && !FileUtil.accessSync(jiaMilyricPath))
  7155. && !Utility.isVideoByExtension(this.videoUrl))) {
  7156. if (this.currentSong !== undefined) {
  7157. // ToastUtil.showShort('正在为你搜索在线歌词!')
  7158. //判断是不是赞助会员,是会员的话才开启歌词功能
  7159. // if (!this.isDebug) {
  7160. // if (!Utility.isNoble()) {
  7161. // LogUtil.debug("onecold 不是赞助会员")
  7162. // return
  7163. // }
  7164. // if(!Utility.isPassInstallTime(33)){
  7165. // LogUtil.debug("onecold not pass time")
  7166. // // LogUtil.debug("onecold 用户安装app没超过12天" )
  7167. // return
  7168. // }
  7169. // }
  7170. let artist = this.currentSong?.artist
  7171. if (artist === undefined) {
  7172. artist = ''
  7173. }
  7174. if (isApi2 === undefined) {
  7175. isApi2 = false
  7176. }
  7177. NetAxiosUtil.getLyric(this.name, artist, isApi2).then((res) => {
  7178. // LogUtil.debug("onecold res =" + res)
  7179. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  7180. if (StrUtil.isNotEmpty(res)) {
  7181. this.lyricContent = res
  7182. let lines = res.split('\n').map(line => line.trim());
  7183. // 3.解析歌词
  7184. let lyric = this.parser.parse(lines);
  7185. // 4.设置歌词
  7186. this.lyricController.setLyric(lyric);
  7187. this.lyricControllerXF.setLyric(lyric)
  7188. this.lyricControllerSingle.setLyric(lyric)
  7189. this.showSingleLyric = true
  7190. // 4.保存歌词文件lyric到本地
  7191. //2025年8月28日歌词不再加密下载
  7192. this.saveDataToFile(res, lyricPath, false)
  7193. } else {
  7194. this.lyricController.setLyric(null)
  7195. this.lyricControllerXF.setLyric(null)
  7196. this.lyricControllerSingle.setLyric(null)
  7197. if (isOnLineAndToast) {
  7198. ToastUtil.showShort('未获取到歌词!')
  7199. }
  7200. }
  7201. } else {
  7202. this.lyricController.setLyric(null)
  7203. this.lyricControllerXF.setLyric(null)
  7204. this.lyricControllerSingle.setLyric(null)
  7205. if (isOnLineAndToast) {
  7206. ToastUtil.showShort('未获取到歌词!')
  7207. }
  7208. }
  7209. })
  7210. } else {
  7211. this.lyricController.setLyric(null)
  7212. this.lyricControllerXF.setLyric(null)
  7213. this.lyricControllerSingle.setLyric(null)
  7214. if (isOnLineAndToast) {
  7215. ToastUtil.showShort('未获取到歌词!')
  7216. }
  7217. }
  7218. return
  7219. }
  7220. try {
  7221. let isJiaMi = false;
  7222. let realLyricPath = lyricPath
  7223. if (FileUtil.accessSync(jiaMilyricPath)) {
  7224. isJiaMi = true
  7225. realLyricPath = jiaMilyricPath
  7226. console.info("onecold 找到加密本地歌词 ");
  7227. } else {
  7228. isJiaMi = false
  7229. realLyricPath = lyricPath
  7230. console.info("onecold 找到本地歌词 ");
  7231. }
  7232. // 3.读取文件内容并指定编码为 UTF-8
  7233. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  7234. const stat = await fileIo.stat(file.fd);
  7235. const arrayBuffer = new ArrayBuffer(stat.size);
  7236. fs.read(file.fd, arrayBuffer)
  7237. .then((readLen: number) => {
  7238. console.info("read file data succeed");
  7239. // let buf = buffer.from(arrayBuffer, 0, readLen);
  7240. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  7241. // 检查 buf 是否为空
  7242. if (buf.length === 0) {
  7243. throw new Error("Buffer is empty after reading the file");
  7244. }
  7245. try {
  7246. // 检测文件编码
  7247. // let detectedEncoding = chardet.detect(buf);
  7248. // console.info("onecoldT Detected encoding: " + detectedEncoding);
  7249. let detectedEncoding = this.detect(arrayBuffer)
  7250. console.info("onecoldT Detected encoding: " + detectedEncoding);
  7251. // 使用检测到的编码解码,解决中文乱码问题
  7252. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  7253. console.info("onecoldT Detected textDecoder: " + textDecoder);
  7254. let fileContent = textDecoder.decode(buf);
  7255. console.info(`onecoldT The content of file1: ${fileContent}`);
  7256. //解密
  7257. if (isJiaMi) {
  7258. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent))
  7259. }
  7260. console.info(`onecold The content of file2: ${fileContent}`);
  7261. this.lyricContent = fileContent
  7262. if(isLocal){//编辑标签选择本地歌词需要赋值给this.lyricConStr
  7263. this.lyricConStr = fileContent
  7264. }
  7265. // 将文件内容按行分割成字符串数组
  7266. let lines = fileContent.split('\n').map(line => line.trim());
  7267. console.info(`onecold The content of file: ${fileContent}`);
  7268. // 3.解析歌词
  7269. let lyric = this.parser.parse(lines);
  7270. // 4.设置歌词
  7271. this.lyricController.setLyric(lyric);
  7272. this.lyricControllerXF.setLyric(lyric)
  7273. this.lyricControllerSingle.setLyric(lyric)
  7274. this.showSingleLyric = true
  7275. console.info(`The content of file: ${fileContent}`);
  7276. } catch (chardetError) {
  7277. console.error("chardet.detect failed with error: " + chardetError.message);
  7278. this.lyricController.setLyric(null);
  7279. this.lyricControllerXF.setLyric(null)
  7280. this.lyricControllerSingle.setLyric(null)
  7281. }
  7282. })
  7283. .catch((err: BusinessError) => {
  7284. this.lyricController.setLyric(null)
  7285. this.lyricControllerXF.setLyric(null)
  7286. this.lyricControllerSingle.setLyric(null)
  7287. console.error("read file data failed with error message: " + err.message + ", error code: " + err.code);
  7288. })
  7289. .catch((err: Error) => {
  7290. this.lyricController.setLyric(null)
  7291. this.lyricControllerXF.setLyric(null)
  7292. this.lyricControllerSingle.setLyric(null)
  7293. console.error("read file 2 data failed with error message: " + err.message);
  7294. })
  7295. .finally(() => {
  7296. fs.closeSync(file);
  7297. });
  7298. } catch (error) {
  7299. this.lyricController.setLyric(null)
  7300. this.lyricControllerSingle.setLyric(null)
  7301. this.lyricControllerXF.setLyric(null)
  7302. Logger.error(TAG, 'init Lyric failed with err: ' + JSON.stringify(error));
  7303. }
  7304. }
  7305. detect(data: ArrayBuffer): string {
  7306. //创建检测对象
  7307. let detector: UniversalDetector = new UniversalDetector();
  7308. // 传入检测数据并实时判断编码格式
  7309. detector.handleData(data, 0, data.byteLength);
  7310. // 标记检测数据 读取结束
  7311. detector.dataEnd();
  7312. // 获取检测结果
  7313. let detected: string = detector.getDetectedCharset();
  7314. // 释放资源
  7315. detector.reset();
  7316. return detected;
  7317. }
  7318. //初始化悬浮歌词的自定义设置
  7319. initPipLyricSetting() {
  7320. this.lyricControllerXF
  7321. .setTextSize(this.currentLyricSize)
  7322. .setCacheSize(4)
  7323. .setTextColor("#DDDDDD")
  7324. .setHighlightColor("#FFFFFF")// .setLineSpace(18)
  7325. .setEmptyHint("")
  7326. .setAnimationDuration(1000)
  7327. this.currentLyricAlignModePip = PreferencesUtil.getNumberSync('LyricAlignModePip', 0)
  7328. this.blurDegreePip = PreferencesUtil.getNumberSync('setBlurDegreePip', 3)
  7329. this.setBlurDegree(this.blurDegreePip, true)
  7330. this.setLyricAlignMode(this.currentLyricAlignModePip, true)
  7331. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSizePip', 18), true)
  7332. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSizePip', 1.23), true)
  7333. this.lyricControllerXF.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpacePip', 10))
  7334. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColorPip', '#FFFFFF'), true)
  7335. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColorPip', '#FFFFFF'), true)
  7336. this.lyricControllerXF.setHightLightCenter(true)
  7337. this.lyricTextWeightPip = PreferencesUtil.getNumberSync('lyricTextWeightPip', 400)
  7338. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  7339. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  7340. this.pipBgIndex = PreferencesUtil.getNumberSync('pipBgIndex', 0)
  7341. if (this.pipBgIndex === 0) {
  7342. if (this.cover) {
  7343. this.pipBg = this.cover
  7344. } else {
  7345. this.pipBg = this.imageColor
  7346. }
  7347. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  7348. }
  7349. }
  7350. //根据item返回歌词内容
  7351. async getLyricContent(item: VideoItem): Promise<string> {
  7352. let neiqianLrc = ''
  7353. let lyContent = item?.lyricContent
  7354. if(lyContent&&StrUtil.isNotEmpty(lyContent)){
  7355. neiqianLrc = lyContent
  7356. return neiqianLrc
  7357. }
  7358. try {
  7359. //取数据库里面的歌词lyContent
  7360. const lyricContent = await this.table.getLyricContentByFilePath(item.filePath);
  7361. if (lyricContent&&StrUtil.isNotEmpty(lyricContent)) {
  7362. console.log("onecold Lyrics:", lyricContent);
  7363. neiqianLrc = lyricContent
  7364. return neiqianLrc
  7365. }
  7366. } catch (error) {
  7367. console.error("Error fetching lyrics:", error);
  7368. }
  7369. try {
  7370. let filePath = item.filePath;
  7371. let lyricPath = filePath.substring(0, filePath.lastIndexOf('.')) + '.lrc';
  7372. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc';
  7373. let isJiaMi = false;
  7374. let realLyricPath = lyricPath;
  7375. if (FileUtil.accessSync(jiaMilyricPath)) {
  7376. isJiaMi = true;
  7377. realLyricPath = jiaMilyricPath;
  7378. console.info("onecold 找到加密本地歌词");
  7379. } else {
  7380. console.info("onecold 找到本地歌词");
  7381. }
  7382. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  7383. const stat = await fileIo.stat(file.fd);
  7384. const arrayBuffer = new ArrayBuffer(stat.size);
  7385. const readLen = await fs.read(file.fd, arrayBuffer);
  7386. console.info("read file data succeed");
  7387. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  7388. if (buf.length === 0) {
  7389. throw new Error("Buffer is empty after reading the file");
  7390. }
  7391. // let detectedEncoding = chardet.detect(buf);
  7392. let detectedEncoding = this.detect(arrayBuffer)
  7393. console.info("Detected encoding: " + detectedEncoding);
  7394. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  7395. let fileContent = textDecoder.decode(buf);
  7396. console.info(`onecold The content of file1: ${fileContent}`);
  7397. if (isJiaMi) {
  7398. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent));
  7399. }
  7400. console.info(`onecold The content of file2: ${fileContent}`);
  7401. fs.closeSync(file);
  7402. return fileContent;
  7403. } catch (error) {
  7404. console.error('init Lyric failed with err: ' + JSON.stringify(error));
  7405. return '';
  7406. }
  7407. }
  7408. async saveDataToFile(content: string, filePath: string, isJiaMi?: boolean) {
  7409. if (StrUtil.isEmpty(filePath)) {
  7410. return
  7411. }
  7412. try {
  7413. //将content进行加密
  7414. // let jiaMilyricPath = filePath.substring(0,filePath.lastIndexOf('.'))+'.lrcc'
  7415. let lyricContent = ''
  7416. if (isJiaMi) {
  7417. lyricContent = Base64Util.encodeToStrSync(StrUtil.strToUint8Array(content))
  7418. } else {
  7419. lyricContent = content
  7420. }
  7421. const file = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  7422. // 清空文件内容
  7423. await fileIo.truncate(file.fd, 0);
  7424. await fileIo.write(file.fd, lyricContent);
  7425. await fileIo.close(file);
  7426. console.log('onecold lyric file Data saved successfully.');
  7427. } catch (error) {
  7428. console.error('onecold lyric file Failed to save data:', error);
  7429. }
  7430. }
  7431. /**
  7432. * Get largest proportion color of an image.
  7433. */
  7434. getImageColor() {
  7435. if (!this.context) {
  7436. return;
  7437. }
  7438. let bg = Utility.getMusisBg()
  7439. this.imageLabel = bg
  7440. ColorConversion.setSysBarLightBackground(true);
  7441. this.context.resourceManager.getMediaContent(bg)
  7442. .then((value: Uint8Array) => {
  7443. let buffer = value.buffer as ArrayBuffer;
  7444. image.createImageSource(buffer).createPixelMap().then((pixelMap) => {
  7445. effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
  7446. if (error) {
  7447. Logger.error('Failed to create color picker.');
  7448. } else {
  7449. let color = colorPicker.getLargestProportionColor();
  7450. let colorArr = ColorConversion.dealColor(color.red, color.green, color.blue);
  7451. this.imageColor = `rgba(${colorArr[0]}, ${colorArr[1]}, ${colorArr[2]}, 1)`;
  7452. }
  7453. })
  7454. let headFilter = effectKit.createEffect(pixelMap);
  7455. if (headFilter !== null) {
  7456. headFilter.blur(15);
  7457. headFilter.getEffectPixelMap().then((value) => {
  7458. this.imageLabelBg = value;
  7459. })
  7460. }
  7461. })
  7462. .catch((error: BusinessError) => {
  7463. Logger.error(`${error.code} + ${error.message}`)
  7464. })
  7465. })
  7466. .catch((error: BusinessError) => {
  7467. Logger.error(`${error.code} + ${error.message}`)
  7468. })
  7469. }
  7470. setImageColor(cover: string) {
  7471. if (!this.context) {
  7472. return;
  7473. }
  7474. if (cover === undefined) {
  7475. return;
  7476. }
  7477. imagePathToPixelMap(cover).then((value) => {
  7478. let headFilter = effectKit.createEffect(value);
  7479. if (headFilter !== null) {
  7480. headFilter.blur(15);
  7481. headFilter.getEffectPixelMap().then((value) => {
  7482. this.imageLabelBg = value;
  7483. })
  7484. }
  7485. }).catch((error: BusinessError) => {
  7486. Logger.error(`${error.code} + ${error.message}`)
  7487. })
  7488. }
  7489. setImageColor2(cover: string) {
  7490. if (!this.context) {
  7491. return;
  7492. }
  7493. if (cover === undefined) {
  7494. return;
  7495. }
  7496. LogUtils.getInstance().LOGI("setImageColor2--> cover ==" + cover);
  7497. ImageUtils.getImageDealData(getContext(this), cover, this.videoUrl).then((data) => {
  7498. this.imageColor = data.imageColor;
  7499. if (data.blurPixelMap) {
  7500. this.imageLabelBg = data.blurPixelMap;
  7501. }
  7502. })
  7503. }
  7504. // 定义开始旋转的方法
  7505. // 定时器用于一百毫秒执行一次旋转角度
  7506. @State timer: number = 0
  7507. @State rotateAngle: number = 0
  7508. //封面旋转动画
  7509. animationRoFun() {
  7510. if (this.isPlaying && !this.isCoverRectangle) {
  7511. this.timer = setInterval(() => {
  7512. this.rotateAngle += 1
  7513. }, 100)
  7514. this.startRotation()
  7515. } else {
  7516. clearInterval(this.timer)
  7517. this.stopRotation()
  7518. }
  7519. }
  7520. // 定义开始旋转的方法
  7521. startRotation() {
  7522. if (this.isPlaying) {
  7523. animateTo({
  7524. duration: 777,
  7525. iterations: 1,
  7526. curve: Curve.Linear
  7527. }, () => {
  7528. this.rotateAngle2 = -9
  7529. })
  7530. }
  7531. }
  7532. // 回调,暂停和播放按钮回调,下一首和上一首
  7533. playChange() {
  7534. // if(this.isCoverRectangle){
  7535. // return
  7536. // }
  7537. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  7538. this.setIsPlaying(true)
  7539. this.animationState = AnimationStatus.Running
  7540. } else {
  7541. this.setIsPlaying(false)
  7542. this.animationState = AnimationStatus.Paused
  7543. }
  7544. }
  7545. // 定义停止旋转的方法
  7546. stopRotation() {
  7547. if (this.isCoverRectangle) {
  7548. this.rotateAngle = 0
  7549. } else {
  7550. //唱针以左上角为点选择逆时针40度
  7551. animateTo({
  7552. duration: 1000,
  7553. curve: Curve.Linear,
  7554. iterations: 1,
  7555. }, () => {
  7556. this.rotateAngle2 = -45;
  7557. });
  7558. }
  7559. }
  7560. @Builder
  7561. private LyricsTopItem() {
  7562. Row() {
  7563. Stack() {
  7564. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  7565. .height(55)
  7566. .width(55)
  7567. .alt(this.imageLabel)
  7568. .borderRadius(8)
  7569. .clickEffect({ level: ClickEffectLevel.HEAVY })
  7570. .margin({ left: this.currentLyricAlignMode === 0 ? 28 : -15 })
  7571. }
  7572. .width('18%')
  7573. Column() {
  7574. Column() {
  7575. Text(this.name)
  7576. .fontSize(16)
  7577. .maxLines(1)
  7578. .fontWeight(FontWeight.Bolder)
  7579. .fontColor(this.currentLyricColor)
  7580. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  7581. Row() {
  7582. Text(this.currentSong?.artist !== undefined ? this.currentSong?.artist : '')
  7583. .fontSize(13)
  7584. .fontWeight(FontWeight.Bold)
  7585. .padding({ top: 8 })
  7586. .fontColor(this.currentLyricColor)
  7587. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  7588. Blank()
  7589. }
  7590. }
  7591. .height('100%')
  7592. .width('100%')
  7593. .justifyContent(FlexAlign.Center)
  7594. .alignItems(HorizontalAlign.Start)
  7595. }
  7596. .height('100%')
  7597. .width('65%')
  7598. Column() {
  7599. Image($r('app.media.lyric'))
  7600. .width(28)
  7601. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7602. .margin({ right: 30 })
  7603. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7604. .onClick(() => {
  7605. this.isLyricSetting = !this.isLyricSetting;
  7606. })
  7607. .bindSheet($$this.isLyricSetting, this.lyricSettingSheet(false), {
  7608. height: '95%',
  7609. dragBar: true,
  7610. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7611. showClose: true,
  7612. blurStyle: BlurStyle.Thin,
  7613. backgroundColor: Color.Transparent,
  7614. // title: { title: $r('app.string.lyric_setting') }
  7615. })
  7616. }
  7617. .width('18%')
  7618. }
  7619. .width('82%')
  7620. .height(58)
  7621. .justifyContent(FlexAlign.SpaceBetween)
  7622. }
  7623. //歌词显示
  7624. @Builder
  7625. PlayerLyrics() {
  7626. Column() {
  7627. Column() {
  7628. this.LyricsTopItem()
  7629. }
  7630. .height(this.isPuraWP() ? 15 : 58)
  7631. .visibility(this.currentBreakpoint !== BreakpointTypeEnum.SM ?
  7632. Visibility.None : Visibility.Visible)
  7633. .margin({ left: 6, top: this.isPuraWP() ? 5 : 38 })
  7634. .width("100%")
  7635. Column() {
  7636. LyricView2({
  7637. controller: this.lyricController,
  7638. enableSeek: true,
  7639. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  7640. seekLineColor: "#80ffffff", // 滑动定位线颜色
  7641. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  7642. onSeekAction: (position: number) => { // 滑动歌词触发seek定位回调
  7643. if (!this.isPlaying) {
  7644. console.info('onecold startPlayOrResumePlay 7527')
  7645. this.startPlayOrResumePlay()
  7646. }
  7647. else {
  7648. this.isSeekTo = true;
  7649. this.mDestroyPage = false;
  7650. this.showLoadIng();
  7651. this.seekTo(position + "");
  7652. this.isSeekTo = false;
  7653. }
  7654. return true
  7655. }
  7656. })
  7657. .width("100%")
  7658. .layoutWeight(1)
  7659. .margin({ left: this.currentLyricAlignMode === 0 ? 0 : 50, top: 2, bottom: this.isPhoneLan()||this.isHiCarKuanBianPing() ? 40 : 10 })
  7660. if (this.isPhoneLan()) {
  7661. Column() {
  7662. this.playProgressView()
  7663. // this.playCenterView()
  7664. }
  7665. .margin({ bottom: 30, right: this.currentLyricAlignMode == 0 ? 0 : 30 })
  7666. }
  7667. }
  7668. .position({
  7669. top: this.currentBreakpoint !== BreakpointTypeEnum.SM ? (this.isPhoneLan() ? 0 : 45) :
  7670. (this.isPuraWP() ? 58 : 99)
  7671. })
  7672. .justifyContent(FlexAlign.Center)
  7673. .height(this.isCoverOpacity() ? this.isPhoneLan()?'95%':'90%' : '82%')
  7674. }
  7675. }
  7676. @Builder
  7677. SingleLyricView() {
  7678. Column() {
  7679. Column() {
  7680. LyricView2({
  7681. controller: this.lyricControllerSingle,
  7682. enableSeek: false,
  7683. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  7684. seekLineColor: "#80ffffff", // 滑动定位线颜色
  7685. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  7686. })
  7687. }
  7688. .height(66)
  7689. .margin({ bottom: 20 })
  7690. }
  7691. }
  7692. //播放器的底部控制中心,上一首,暂停,下一首,播放进度条等
  7693. @Builder
  7694. BottomControl() {
  7695. Column() {
  7696. this.TopPlayProgressView()
  7697. //播放 暂停,下一首,上一首
  7698. this.playCenterView()
  7699. //播放进度条
  7700. this.BottomView()
  7701. }
  7702. .position({ bottom: this.isHiCarSmall()?50:(this.isCoverOpacity() ? 55 : 70) }) // 将 固定在底部
  7703. }
  7704. //播放控制上一首 下一首 暂停和播放
  7705. @Builder
  7706. playCenterView(){
  7707. Row() {
  7708. Row({ space: 20 }) {
  7709. Button({type:ButtonType.Circle,stateEffect:true}){
  7710. //更多功能
  7711. Image($r('app.media.menu'))
  7712. .width(24)
  7713. .clickEffect({level:ClickEffectLevel.MIDDLE})
  7714. .bindSheet($$this.isShowMoreView, this.PlayMoreSheet(), {
  7715. height: this.isCoverOpacity() ? '95%' : '93%',
  7716. preferType: this.currentBreakpoint!==BreakpointTypeEnum.SM?SheetType.CENTER:SheetType.BOTTOM,
  7717. dragBar: true,
  7718. showClose: true,
  7719. blurStyle: BlurStyle.Thin,
  7720. backgroundColor: Color.Transparent,
  7721. })
  7722. }
  7723. .margin({ left: 5 })
  7724. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7725. .backgroundColor(Color.Transparent)
  7726. .onClick(() => {
  7727. this.isShowMoreView = !this.isShowMoreView;
  7728. })
  7729. Button({type:ButtonType.Circle,stateEffect:true}){
  7730. Image($r('app.media.ic_previous'))
  7731. .width(33)
  7732. .clickEffect({level:ClickEffectLevel.HEAVY})
  7733. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7734. }
  7735. .onClick(async () => {
  7736. this.playPrevious()
  7737. })
  7738. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7739. .backgroundColor(Color.Transparent)
  7740. .margin({ left: 5 })
  7741. }
  7742. Button({type:ButtonType.Circle,stateEffect:true}){
  7743. Column() {
  7744. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ?
  7745. (this.isCircleBtn?$r('app.media.hm_pause'):$r('app.media.ic_public_play'))
  7746. : (this.isCircleBtn?$r('app.media.hm_play2'):$r('app.media.ic_public_pause')))
  7747. .width(this.isPhoneLan()?45:55)
  7748. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7749. .fillColor(Color.White)
  7750. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7751. .onClick(async () => {
  7752. console.info('onecold playOrPause 7651')
  7753. this.playOrPause()
  7754. })
  7755. }
  7756. }
  7757. .backgroundColor(Color.Transparent)
  7758. .layoutWeight(1)
  7759. // .margin({ left: 38, right: 38 })
  7760. Row({ space: 20 }) {
  7761. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7762. Image($r('app.media.ic_next'))
  7763. .width(33)
  7764. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7765. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7766. .onClick(() => {
  7767. this.playNext();
  7768. })
  7769. }
  7770. .backgroundColor(Color.Transparent)
  7771. .margin({ right: 5 })
  7772. .width(33)
  7773. if(this.isPhoneLan()){
  7774. this.fullButton()
  7775. }else{
  7776. Button({type:ButtonType.Circle,stateEffect:true}){
  7777. //添加或取消收藏
  7778. SymbolGlyph(Utility.getIsFav(this.favList,this.currentSong)?
  7779. $r('sys.symbol.heart_fill'):$r('sys.symbol.heart'))
  7780. .fontSize(23)
  7781. .fontColor([Color.White])
  7782. .alignSelf(ItemAlign.Center)
  7783. // .width(24)
  7784. .clickEffect({level:ClickEffectLevel.MIDDLE})
  7785. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7786. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7787. .onClick(async () => {
  7788. if(this.currentSong){
  7789. this.doFav(this.currentSong)
  7790. }
  7791. })
  7792. }
  7793. .backgroundColor(Color.Transparent)
  7794. .width(24)
  7795. }
  7796. }
  7797. // .margin({ left: 5 })
  7798. }
  7799. .width('95%')
  7800. .margin({ bottom:this.isCoverOpacity()?0:20 })
  7801. .justifyContent(FlexAlign.SpaceEvenly)
  7802. }
  7803. @Builder
  7804. TopPlayProgressView(){
  7805. Row() {
  7806. Column(){
  7807. Row(){
  7808. Stack(){
  7809. SymbolGlyph($r('sys.symbol.arrow_counterclockwise'))
  7810. .fontColor([Color.White])
  7811. .fontSize(21)
  7812. .effectStrategy(1)
  7813. Text(this.fastForwardSeconds)
  7814. .fontColor(Color.White)
  7815. .fontSize(10)
  7816. .fontWeight(FontWeight.Bold)
  7817. }
  7818. .margin({left:12,bottom:6})
  7819. .visibility(this.isShowBackFast?Visibility.Visible:Visibility.None)
  7820. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  7821. .onClick(()=>{
  7822. this.backForward()
  7823. })
  7824. Slider({
  7825. value: this.progressValue,
  7826. min: 0,
  7827. max: this.PROGRESS_MAX_VALUE,
  7828. step: 1,
  7829. style: SliderStyle.InSet
  7830. })
  7831. .height(20)
  7832. .blockColor('rgba(255,255,255,1)')
  7833. .trackColor('rgba(255,255,255,0.3)')
  7834. .selectedColor(Color.White)
  7835. .trackThickness(4)
  7836. .layoutWeight(1)
  7837. .showSteps(false)
  7838. .showTips(true)
  7839. .alignSelf(ItemAlign.Center)
  7840. .enabled(this.slideEnable)
  7841. .onChange((value: number, mode: SliderChangeMode) => {
  7842. // if (mode == 2) {
  7843. this.isSeekTo = true;
  7844. this.mDestroyPage = false;
  7845. this.showLoadIng();
  7846. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  7847. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  7848. this.seekTo(seekValue + "");
  7849. // this.setProgress()
  7850. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  7851. this.isSeekTo = false;
  7852. // }
  7853. })
  7854. Stack(){
  7855. SymbolGlyph($r('sys.symbol.arrow_clockwise'))
  7856. .fontColor([Color.White])
  7857. .fontSize(21)
  7858. .effectStrategy(1)
  7859. Text(this.fastForwardSeconds)
  7860. .fontColor(Color.White)
  7861. .fontSize(10)
  7862. .fontWeight(FontWeight.Bold)
  7863. }
  7864. .margin({right:10,bottom:6})
  7865. .visibility(this.isShowBackFast?Visibility.Visible:Visibility.None)
  7866. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  7867. .onClick(()=>{
  7868. this.fastForward()
  7869. })
  7870. }
  7871. .padding({ right: 7,left:22 })
  7872. Row(){
  7873. Text(this.currentTime)
  7874. .fontSize(10)
  7875. .fontColor(Color.White)
  7876. Blank()
  7877. .layoutWeight(1)
  7878. Text(this.totalTime)
  7879. .fontSize(10)
  7880. .fontColor(Color.White)
  7881. }
  7882. .justifyContent(FlexAlign.Start)
  7883. .padding({ right: 18,left:36 })
  7884. }
  7885. }
  7886. //x5的竖屏模式需要99%
  7887. .width(this.isLandscape?'80%':'93%')
  7888. .justifyContent(FlexAlign.Center)
  7889. .margin({bottom:6})
  7890. .animation({
  7891. duration: 666,
  7892. curve: 'ease-in-out' // 可选动画曲线
  7893. })
  7894. }
  7895. //播放进度条
  7896. @Builder
  7897. BottomView(){
  7898. Row() {
  7899. Button({type:ButtonType.Circle,stateEffect:true}){
  7900. Column() {
  7901. if (this.playType === 0) {
  7902. Image($r('app.media.loop'))
  7903. .width(27)
  7904. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7905. } else if (this.playType === 1) {
  7906. Image($r('app.media.single'))
  7907. .width(27)
  7908. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7909. } else if (this.playType === 2) {
  7910. Image($r('app.media.normal_play'))
  7911. .width(27)
  7912. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7913. } else if (this.playType === 3) {
  7914. Image($r('app.media.random'))
  7915. .width(27)
  7916. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7917. }
  7918. }
  7919. }
  7920. .layoutWeight(1)
  7921. .margin({ left: 5 })
  7922. .backgroundColor(Color.Transparent)
  7923. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7924. .onClick(async () => {
  7925. this.setLoopMode()
  7926. })
  7927. this.fullButton()
  7928. Button({type:ButtonType.Circle,stateEffect:true}){
  7929. Column() {
  7930. Image($r('app.media.lyric'))
  7931. .width(26)
  7932. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7933. }
  7934. }
  7935. .layoutWeight(1)
  7936. .backgroundColor(Color.Transparent)
  7937. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7938. .onClick(async () => {
  7939. this.isLyricSetting = !this.isLyricSetting;
  7940. })
  7941. //播放列表
  7942. Button({type:ButtonType.Circle,stateEffect:true}){
  7943. Image($r('app.media.hm_playlist'))
  7944. .width(24)
  7945. .fillColor(Color.White)
  7946. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7947. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  7948. height: '95%',
  7949. dragBar: true,
  7950. showClose: true,
  7951. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7952. blurStyle: BlurStyle.Thin,
  7953. backgroundColor: this.isPlayListBgGrass?Color.Transparent:$r('app.color.silvery'),
  7954. title: {
  7955. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  7956. + `(${this.songList.length}首)`
  7957. }
  7958. })
  7959. }
  7960. .layoutWeight(1)
  7961. .backgroundColor(Color.Transparent)
  7962. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7963. .onClick(() => {
  7964. this.isShowSheetView = !this.isShowSheetView;
  7965. if(this.isPlayListBgGrass){
  7966. this.isFrontWhite = true
  7967. }else{
  7968. this.isFrontWhite = false
  7969. }
  7970. this.scrollIndex()
  7971. })
  7972. }
  7973. .width(this.isLandscape?'88%':'95%')
  7974. .justifyContent(FlexAlign.SpaceAround)
  7975. .height(30)
  7976. .margin({top:3})
  7977. .animation({
  7978. duration: 666,
  7979. curve: 'ease-in-out' // 可选动画曲线
  7980. })
  7981. }
  7982. @Builder
  7983. fullButton(){
  7984. Button({type:ButtonType.Circle,stateEffect:true}){
  7985. Column() {
  7986. Image($r('app.media.full_4'))
  7987. .width(25)
  7988. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7989. }
  7990. }
  7991. .layoutWeight(1)
  7992. .backgroundColor(Color.Transparent)
  7993. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7994. .onClick(async () => {
  7995. if (this.isLandscape) {
  7996. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  7997. } else {
  7998. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  7999. }
  8000. })
  8001. }
  8002. //旧版本播放进度条
  8003. @Builder
  8004. playProgressView() {
  8005. Row() {
  8006. Button({ type: ButtonType.Circle, stateEffect: true }) {
  8007. Column() {
  8008. if (this.playType === 0) {
  8009. Image($r('app.media.loop'))
  8010. .width($r('app.float.control_image_width'))
  8011. .aspectRatio(CommonConstants.ASPECT_RATIO)
  8012. } else if (this.playType === 1) {
  8013. Image($r('app.media.single'))
  8014. .width($r('app.float.control_image_width'))
  8015. .aspectRatio(CommonConstants.ASPECT_RATIO)
  8016. } else if (this.playType === 2) {
  8017. Image($r('app.media.normal_play'))
  8018. .width($r('app.float.control_image_width'))
  8019. .aspectRatio(CommonConstants.ASPECT_RATIO)
  8020. } else if (this.playType === 3) {
  8021. Image($r('app.media.random'))
  8022. .width($r('app.float.control_image_width'))
  8023. .aspectRatio(CommonConstants.ASPECT_RATIO)
  8024. }
  8025. }
  8026. }
  8027. .visibility(this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  8028. .animation({
  8029. duration: 666,
  8030. curve: 'ease-in-out' // 可选动画曲线
  8031. })
  8032. .backgroundColor(Color.Transparent)
  8033. .margin({ right: 10 })
  8034. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8035. .onClick(async () => {
  8036. this.setLoopMode()
  8037. })
  8038. Text(this.currentTime)
  8039. .fontSize($r('app.float.slider_font_size'))
  8040. .fontColor(Color.White)
  8041. .margin(3)
  8042. Slider({
  8043. value: this.progressValue,
  8044. min: 0,
  8045. max: this.PROGRESS_MAX_VALUE,
  8046. step: 1,
  8047. style: SliderStyle.OutSet
  8048. })
  8049. .width('600px')
  8050. .blockColor('rgba(255,255,255,1)')
  8051. .trackColor('rgba(255,255,255,0.3)')
  8052. .selectedColor(Color.White)
  8053. .trackThickness(PlayConstants.PROGRESS_TRACK_THICKNESS)
  8054. .layoutWeight(1)
  8055. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  8056. .showSteps(false)
  8057. .showTips(true)
  8058. .enabled(this.slideEnable)
  8059. .onChange((value: number, mode: SliderChangeMode) => {
  8060. // if (mode == 2) {
  8061. this.isSeekTo = true;
  8062. this.mDestroyPage = false;
  8063. this.showLoadIng();
  8064. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  8065. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  8066. this.seekTo(seekValue + "");
  8067. // this.setProgress()
  8068. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  8069. this.isSeekTo = false;
  8070. // }
  8071. })
  8072. Text(this.totalTime)
  8073. .fontSize($r('app.float.slider_font_size'))
  8074. .fontColor(Color.White)
  8075. .margin(3)
  8076. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  8077. //播放列表
  8078. Button({ type: ButtonType.Circle, stateEffect: true }) {
  8079. Image($r('app.media.hm_playlist'))
  8080. .width($r('app.float.control_image_width'))
  8081. .fillColor(Color.White)
  8082. .aspectRatio(CommonConstants.ASPECT_RATIO)
  8083. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  8084. height: '95%',
  8085. dragBar: true,
  8086. showClose: true,
  8087. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8088. blurStyle: BlurStyle.Thin,
  8089. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  8090. title: {
  8091. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  8092. + `(${this.songList.length}首)`
  8093. }
  8094. })
  8095. }
  8096. .visibility( this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  8097. .animation({
  8098. duration: 666,
  8099. curve: 'ease-in-out' // 可选动画曲线
  8100. })
  8101. .backgroundColor(Color.Transparent)
  8102. .margin({ right: 20, left: 10 })
  8103. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8104. .onClick(() => {
  8105. this.isShowSheetView = !this.isShowSheetView;
  8106. if (this.isPlayListBgGrass) {
  8107. this.isFrontWhite = true
  8108. } else {
  8109. this.isFrontWhite = false
  8110. }
  8111. this.scrollIndex()
  8112. })
  8113. }
  8114. //x5的竖屏模式需要99%
  8115. .width(this.isPhonePortrait() ? '93.4%'
  8116. : this.currentHeightBreakpoint == 1 && this.currentWidthBreakpoint == 2 ? '99%' : '82%')
  8117. .height(this.isPhoneLan() ? 25 : 33)
  8118. .animation({
  8119. duration: 666,
  8120. curve: 'ease-in-out' // 可选动画曲线
  8121. })
  8122. }
  8123. isBigScreen() {
  8124. if (this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_LG) {
  8125. return true
  8126. }
  8127. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  8128. && this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  8129. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG) {
  8130. return false
  8131. } else {
  8132. return true
  8133. }
  8134. return false
  8135. }
  8136. @State is_auto_hide_progress: boolean = false //手机横屏自动隐藏播放进退条,点击屏幕可以显示,倒计时4秒后又自动隐藏
  8137. @State isCoverRectangle: boolean = false
  8138. @State isCoverTop: boolean = true
  8139. // 添加控制缩放的状态变量
  8140. @State scaleValueImage: number = 1
  8141. @Builder
  8142. CoverInfo() {
  8143. Column() {
  8144. //如果是方形,判断是不是封面在顶部,如果不是顶部,显示musicNameInfo, 如果是圆形显示musicNameInfo
  8145. if (this.isCoverRectangle) {
  8146. if (!this.isCoverTop) {
  8147. this.musicNameInfo(false)
  8148. }
  8149. } else {
  8150. this.musicNameInfo(false)
  8151. }
  8152. Stack() {
  8153. // 唱片旋转效果
  8154. Image($r('app.media.ic_music_disc'))
  8155. .width(245)
  8156. .height(245)
  8157. .margin({ right: 20, left: 20 ,top:this.isCoverRectangle||this.isLandscape?0:43})
  8158. .aspectRatio(1)
  8159. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  8160. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  8161. .borderRadius('100%')
  8162. .align(Alignment.Center)
  8163. .clip(true)// .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
  8164. .rotate({
  8165. angle: this.rotateAngle,
  8166. centerX: "50%",
  8167. centerY: "50%",
  8168. })
  8169. .animation({
  8170. duration: 100,
  8171. curve: Curve.Linear
  8172. })
  8173. .shadow({
  8174. radius: 30,
  8175. color: this.randomColor
  8176. })
  8177. Column() {
  8178. if (this.isCoverTop && !this.isCoverOpacity() && this.isCoverRectangle) {
  8179. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  8180. .height(this.isHiCar()?(px2vp(this.windowHeight)*0.46):'auto')
  8181. .width(this.isHiCar()?'auto':this.isBigScreen() ? '72%' : this.isCoverTopBig ? '100%' : '88%')
  8182. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  8183. .alt(this.imageLabel)
  8184. .margin({ right: 8, left: 8, top: 8 })
  8185. .aspectRatio(1)
  8186. .opacity(this.opacityValueImage)
  8187. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  8188. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  8189. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  8190. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  8191. .align(Alignment.Center)//
  8192. .clip(true)
  8193. .rotate({
  8194. x: 0,
  8195. y: 0,
  8196. z: 1,
  8197. angle: this.rotateAngle
  8198. })
  8199. .onClick(() => {
  8200. this.getImageColor()
  8201. })
  8202. this.musicNameInfo(false)
  8203. } else {
  8204. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  8205. .height(this.isHiCarSmall()?(this.isHiCarKuanBianPing()?140:px2vp(this.windowHeight)*0.38):
  8206. (this.isCoverOpacity() ? (px2vp(this.windowHeight)*0.62) : this.isCoverRectangle ? 320 : 162))
  8207. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  8208. .alt(this.imageLabel)
  8209. .margin({ right: 20, left: 20,top:this.isCoverRectangle||this.isLandscape?0:43 })
  8210. .aspectRatio(1)
  8211. .opacity(this.opacityValueImage)
  8212. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  8213. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  8214. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  8215. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  8216. .align(Alignment.Center)//
  8217. .clip(true)
  8218. .rotate({
  8219. x: 0,
  8220. y: 0,
  8221. z: 1,
  8222. angle: this.rotateAngle
  8223. })
  8224. .onClick(() => {
  8225. this.getImageColor()
  8226. })
  8227. if (this.isPhoneLan()) {
  8228. Text(this.name)
  8229. .fontSize(18)
  8230. .fontWeight(FontWeight.Bold)
  8231. .margin({ top: 13 })
  8232. .textOverflow({ overflow: TextOverflow.Ellipsis })
  8233. .maxLines(1)
  8234. .width('99%')
  8235. .textAlign(TextAlign.Center)
  8236. .fontColor(Color.White)
  8237. }
  8238. }
  8239. }
  8240. // 唱针以左上角为点选择逆时针40度
  8241. Image($r('app.media.ic_music_cover_hand'))
  8242. .height(130)
  8243. .margin({ bottom: 220, top: 0 })
  8244. .align(Alignment.Top)
  8245. .rotate({ angle: this.rotateAngle2, centerX: 0, centerY: 0 })
  8246. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  8247. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  8248. Column({ space: 8 }) {
  8249. Text(this.name)
  8250. .fontSize(this.isPuraWP() ? 24 : (this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22))
  8251. .fontWeight(FontWeight.Bold)
  8252. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  8253. .maxLines(1)
  8254. .width('48%')
  8255. .textAlign(TextAlign.Center)
  8256. .fontColor(Color.White)
  8257. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  8258. Text(this.artist)
  8259. .fontSize(this.isPuraWP() ? 18 : (this.isCoverOpacity() ? 12 : 15))
  8260. .fontColor(Color.White)
  8261. .fontWeight(FontWeight.Bold)
  8262. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  8263. }
  8264. .justifyContent(FlexAlign.Start)
  8265. .zIndex(1)
  8266. .visibility(this.isCoverOpacity() ? Visibility.Visible : Visibility.None)
  8267. }
  8268. .margin({
  8269. bottom: this.isCoverOpacity() || this.isCoverRectangle ?
  8270. (this.isPhonePortrait() && this.isShowSingleLineLyric ? 20 : 55) : 0,
  8271. top: this.isCoverOpacity() ? 0 : 20
  8272. })
  8273. if (this.isPhonePortrait() && this.isShowSingleLineLyric) {
  8274. this.SingleLyricView()
  8275. }
  8276. if (this.isPhoneLan()) {
  8277. Column() {
  8278. this.playCenterView()
  8279. // this.playProgressView()
  8280. }
  8281. .position({ left: 28, bottom: 38 })
  8282. } else {
  8283. this.BottomControl()
  8284. }
  8285. }
  8286. .width(CommonConstants.FULL_PERCENT)
  8287. .clip(true)
  8288. }
  8289. @Builder
  8290. private musicNameInfo(isHidden: boolean) {
  8291. Column({ space: 8 }) {
  8292. Text(this.name)
  8293. .fontSize(this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22)
  8294. .fontWeight(FontWeight.Bold)
  8295. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  8296. .maxLines(1)
  8297. .width('99%')
  8298. .textAlign(TextAlign.Center)
  8299. .fontColor(Color.White)
  8300. Text(this.artist + ' ' + this.currentSong?.album)
  8301. .fontSize(this.isCoverOpacity() ? 12 : 15)
  8302. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  8303. .fontColor(Color.White)
  8304. .textAlign(TextAlign.Center)
  8305. .visibility(StrUtil.isEmpty(this.artist)?Visibility.None:Visibility.Visible)
  8306. .width('99%')
  8307. .maxLines(1)
  8308. }
  8309. .margin({ top: this.isCoverOpacity() ? 20 : isHidden ? 40 : 20 })
  8310. .zIndex(1)
  8311. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  8312. .visibility(this.isCoverOpacity() || isHidden ? Visibility.None : Visibility.Visible)
  8313. }
  8314. @Builder
  8315. private PlayTitle() {
  8316. Row() {
  8317. Row() {
  8318. Image($r('app.media.ic_back_down'))
  8319. .width($r('app.float.title_image_size'))// .aspectRatio(CommonConstants.ASPECT_RATIO)
  8320. .hitTestBehavior(HitTestMode.Transparent)
  8321. Text(this.name + ' ' + this.artist)
  8322. .fontColor(Color.White)
  8323. .fontSize($r('app.float.title_font_size'))
  8324. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  8325. .maxLines(1)
  8326. .visibility(Visibility.None)
  8327. .margin({ left: 2, right: 30 })
  8328. }
  8329. .layoutWeight(1)
  8330. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8331. .visibility(this.isHide ? Visibility.Hidden : Visibility.Visible)
  8332. .onClick(() => {
  8333. this.isShowPlay = false;
  8334. })
  8335. Column() {
  8336. AVCastPicker({
  8337. normalColor: Color.White,
  8338. onStateChange: this.onStateVastChange
  8339. })
  8340. .width(24)
  8341. .height(24)
  8342. }
  8343. .visibility(this.isHide ? Visibility.Hidden : Visibility.None)
  8344. }
  8345. .width(PlayConstants.ROW_WIDTH)
  8346. }
  8347. @Builder
  8348. lyricSettingSheet(isPip: boolean) {
  8349. Scroll() {
  8350. this.lyricSetting(isPip)
  8351. }
  8352. .width('100%')
  8353. .height('100%')
  8354. }
  8355. @Builder
  8356. lyricSetting(isPip: boolean) {
  8357. Column() {
  8358. // 时间调节模块
  8359. if (!isPip) {
  8360. this.BuildTimeControls()
  8361. }
  8362. // 字号控制模块
  8363. this.BuildFontControls(isPip)
  8364. }
  8365. }
  8366. // 歌词时间偏移状态
  8367. @State timeOffset: number = 0.0
  8368. @State currentLyricColor: string = '#FFFFFF'
  8369. @State currentLyricColorPip: string = '#FFFFFF'
  8370. @State currentHighLightLyricColor: string = '#FF4081'
  8371. @State currentHighLightLyricColorPip: string = '#FF4081'
  8372. // 歌词字号状态
  8373. @State currentLyricSize: number = 20
  8374. @State currentLyricSizePip: number = 20
  8375. // 高亮歌词放大倍数
  8376. @State currentHightLyricSize: number = 1.2
  8377. @State currentHightLyricSizePip: number = 1.2
  8378. @State currentLyricLineSpace: number = 10
  8379. @State currentLyricLineSpacePip: number = 10
  8380. @State currentLyricAlignMode: number = 1
  8381. @State currentLyricAlignModePip: number = 1
  8382. @State blurDegree: number = 2
  8383. @State blurDegreePip: number = 2
  8384. @State isShowSelectColor: boolean = false
  8385. @State isShowHLSelectColor: boolean = false
  8386. @State isShowPipBgSelectColor: boolean = false
  8387. @State pipLyWidth: number = 330
  8388. @State pipLyHeight: number = 120
  8389. // 构建颜色选择器
  8390. @Builder
  8391. SelectColor(isHighColor: boolean, isPip: boolean, isBGPip?: boolean) {
  8392. Row({ space: 10 }) {
  8393. HSBColorPicker({
  8394. color: '#FFFFFF',
  8395. radius: 8,
  8396. layout: HSBColorPickerLayout.COLUMN,
  8397. predefine: ['#8b27f4', '#73f9fc', '#fffe55', '#f5cee3', '#eb4827', '#e93bf4', '#3e68f4', '#c5e6d3', '#e4e4e4',
  8398. '#fa7105'],
  8399. onChange: (value: string) => isHighColor ? this.changeLyricHightLightColor(value, isPip) :
  8400. this.changeLyricColor(value, isPip, isBGPip)
  8401. })
  8402. .height(250)
  8403. .layoutWeight(1)
  8404. .padding(25)
  8405. }
  8406. .width('66%')
  8407. }
  8408. @State isOpenPip: boolean = false
  8409. @State pipBgIndex: number = 0
  8410. // 构建字号控制器
  8411. @Builder
  8412. BuildFontControls(isPip: boolean) {
  8413. Column() {
  8414. if (isPip) {
  8415. Column() {
  8416. Row() {
  8417. Text('悬浮歌词')
  8418. .margin({ left: 18 })
  8419. .fontSize(15)
  8420. .fontColor(Color.White)
  8421. .fontWeight(480)
  8422. .layoutWeight(1)
  8423. Toggle({ type: ToggleType.Switch, isOn: this.isOpenPip })
  8424. .selectedColor(this.themeColor)
  8425. .switchPointColor(Color.White)
  8426. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8427. .margin({ right: 18 })
  8428. .onChange((checked: boolean) => {
  8429. this.isOpenPip = checked;
  8430. if (this.isOpenPip) {
  8431. this.startPip()
  8432. } else {
  8433. this.stopPip()
  8434. }
  8435. PreferencesUtil.put('isOpenPip', this.isOpenPip)
  8436. })
  8437. .width(50)
  8438. .height(30);
  8439. }
  8440. .height(55)
  8441. }
  8442. .backgroundColor(Color.Transparent)
  8443. .borderRadius(15)
  8444. .margin({
  8445. left: 30,
  8446. right: 30,
  8447. top: 0,
  8448. bottom: 20
  8449. })
  8450. .padding(0)
  8451. .border({
  8452. color: Color.White,
  8453. width: 1.8
  8454. })
  8455. }else{
  8456. Column() {
  8457. Row() {
  8458. Text('单行歌词')
  8459. .margin({ left: 18 })
  8460. .fontSize(15)
  8461. .fontColor(Color.White)
  8462. .fontWeight(480)
  8463. .layoutWeight(1)
  8464. Toggle({ type: ToggleType.Switch, isOn: this.isShowSingleLineLyric })
  8465. .selectedColor(this.themeColor)
  8466. .switchPointColor(Color.White)
  8467. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8468. .margin({ right: 18 })
  8469. .onChange((checked: boolean) => {
  8470. this.isShowSingleLineLyric = checked;
  8471. PreferencesUtil.put(SettingPage.IS_SHOW_SLLYRIC, this.isShowSingleLineLyric)
  8472. })
  8473. .width(50)
  8474. .height(30);
  8475. }
  8476. .height(55)
  8477. }
  8478. .backgroundColor(Color.Transparent)
  8479. .borderRadius(15)
  8480. .margin({
  8481. left: 30,
  8482. right: 30,
  8483. top: 10,
  8484. bottom: 10
  8485. })
  8486. .padding(0)
  8487. .border({
  8488. color: Color.White,
  8489. width: 1.8
  8490. })
  8491. }
  8492. Row() {
  8493. Text(`歌词居中:`)
  8494. .fontSize(14)
  8495. .fontColor(Color.White)
  8496. .margin({ left: 2 })
  8497. Row() {
  8498. ForEach(['居中', '居左'], (size: string, index: number) => {
  8499. Button(size)
  8500. .width(60)
  8501. .height(28)
  8502. .fontSize(12)
  8503. .fontColor('#FFFFFF')
  8504. .backgroundColor((!isPip && this.currentLyricAlignMode === index) ||
  8505. (isPip && this.currentLyricAlignModePip === index) ? this.themeColor : Color.Transparent)
  8506. .border({
  8507. color: (!isPip && this.currentLyricAlignMode === index) ||
  8508. (isPip && this.currentLyricAlignModePip === index) ?
  8509. '#007DFF' : '#DDDDDD',
  8510. width: 1.8
  8511. })
  8512. .onClick(() => {
  8513. this.setLyricAlignMode(index, isPip)
  8514. })
  8515. .margin({ left: 10, right: 8 })
  8516. })
  8517. }
  8518. .width('76%')
  8519. Blank()
  8520. }
  8521. .margin({
  8522. top: 10,
  8523. bottom: 10,
  8524. right: 20,
  8525. left: 20
  8526. })
  8527. if (isPip) {
  8528. Row() {
  8529. Text(`悬浮背景:`)
  8530. .fontSize(14)
  8531. .fontColor(Color.White)
  8532. Select([
  8533. { value: CommonConstants.PIP_LYRIC_BG[0] },
  8534. { value: CommonConstants.PIP_LYRIC_BG[1] }])
  8535. .font({ size: 13, weight: FontWeight.Medium })
  8536. .fontColor(Color.White)
  8537. .margin({ left: 10 })
  8538. .selected(this.pipBgIndex)
  8539. .value(CommonConstants.PIP_LYRIC_BG[this.pipBgIndex])
  8540. .onSelect(async (_index: number, text?: string | undefined) => {
  8541. this.pipBgIndex = _index
  8542. PreferencesUtil.put('pipBgIndex', this.pipBgIndex)
  8543. if (this.pipBgIndex === 0) {
  8544. if (this.cover) {
  8545. this.pipBg = this.cover
  8546. } else {
  8547. this.pipBg = this.imageColor
  8548. }
  8549. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  8550. } else {
  8551. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  8552. }
  8553. })
  8554. Column() {
  8555. }
  8556. .backgroundColor(this.pipBg)
  8557. .margin({ left: 10, right: 10 })
  8558. .borderRadius(20)
  8559. .height(28)
  8560. .width(28)
  8561. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8562. Row() {
  8563. SymbolGlyph($r('sys.symbol.paintbrush'))
  8564. .fontColor([Color.White])
  8565. .effectStrategy(1)
  8566. Text(`选择颜色`)
  8567. .fontSize(13)
  8568. .margin({ left: 10 })
  8569. .fontColor(Color.White)
  8570. }
  8571. }
  8572. .visibility(this.pipBgIndex === 1 ? Visibility.Visible : Visibility.None)
  8573. .backgroundColor(Color.Transparent)
  8574. .border({
  8575. color: '#FFFFFF',
  8576. radius: 20,
  8577. width: 1.8
  8578. })
  8579. .height(36)
  8580. .width(110)
  8581. .onClick(() => {
  8582. this.isShowPipBgSelectColor = !this.isShowPipBgSelectColor
  8583. })
  8584. .bindPopup(this.isShowPipBgSelectColor, {
  8585. builder: this.SelectColor(false, isPip, true),
  8586. placement: Placement.Top,
  8587. mask: { color: '#33000000' },
  8588. enableArrow: false, //是否显示箭头
  8589. showInSubWindow: false,
  8590. onStateChange: (e) => {
  8591. if (!e.isVisible) {
  8592. this.isShowPipBgSelectColor = false
  8593. }
  8594. }
  8595. })
  8596. }
  8597. .width('76%')
  8598. .margin({ bottom: 5, right: 45, left: 20 })
  8599. }
  8600. if (!isPip) {
  8601. Row() {
  8602. Text(`高亮居中:`)
  8603. .fontSize(14)
  8604. .fontColor(Color.White)
  8605. Column() {
  8606. Toggle({ type: ToggleType.Switch, isOn: this.isHightLightCenter })
  8607. .selectedColor(this.themeColor)
  8608. .switchPointColor(Color.White)
  8609. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8610. .onChange((checked: boolean) => {
  8611. this.isHightLightCenter = checked;
  8612. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isHightLightCenter)
  8613. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  8614. })
  8615. .width(50)
  8616. .height(30)
  8617. .alignSelf(ItemAlign.Start)
  8618. .margin({ left: 12 })
  8619. Blank()
  8620. }
  8621. .width('76%')
  8622. }
  8623. .margin({
  8624. left: 20,
  8625. right: 15,
  8626. top: 10,
  8627. bottom: 10
  8628. })
  8629. }
  8630. Row() {
  8631. Text(`歌词颜色:`)
  8632. .fontSize(14)
  8633. .fontColor(Color.White)
  8634. Text(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  8635. .fontSize(15)
  8636. .fontColor(Color.White)
  8637. .margin({ left: 12, right: 12 })
  8638. Column() {
  8639. }
  8640. .backgroundColor(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  8641. .margin({ right: 12 })
  8642. .borderRadius(20)
  8643. .height(28)
  8644. .width(28)
  8645. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8646. Row() {
  8647. SymbolGlyph($r('sys.symbol.paintbrush'))
  8648. .fontColor([Color.White])
  8649. .effectStrategy(1)
  8650. Text(`选择颜色`)
  8651. .fontSize(13)
  8652. .margin({ left: 10 })
  8653. .fontColor(Color.White)
  8654. }
  8655. }
  8656. .backgroundColor(Color.Transparent)
  8657. .border({
  8658. color: '#FFFFFF',
  8659. radius: 20,
  8660. width: 1.8
  8661. })
  8662. .height(36)
  8663. .width(110)
  8664. .onClick(() => {
  8665. this.isShowSelectColor = !this.isShowSelectColor
  8666. })
  8667. .bindPopup(this.isShowSelectColor, {
  8668. builder: this.SelectColor(false, isPip),
  8669. placement: Placement.Top,
  8670. mask: { color: '#33000000' },
  8671. enableArrow: false, //是否显示箭头
  8672. showInSubWindow: false,
  8673. onStateChange: (e) => {
  8674. if (!e.isVisible) {
  8675. this.isShowSelectColor = false
  8676. }
  8677. }
  8678. })
  8679. }
  8680. .width('76%')
  8681. .margin({
  8682. top: 10,
  8683. bottom: 10,
  8684. right: 45,
  8685. left: 20
  8686. })
  8687. Row() {
  8688. Text(`高亮颜色:`)
  8689. .fontSize(14)
  8690. .fontColor(Color.White)
  8691. Text(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  8692. .fontSize(15)
  8693. .fontColor(Color.White)
  8694. .margin({ left: 12, right: 12 })
  8695. Column() {
  8696. }
  8697. .backgroundColor(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  8698. .margin({ right: 12 })
  8699. .borderRadius(20)
  8700. .height(28)
  8701. .width(28)
  8702. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8703. Row() {
  8704. SymbolGlyph($r('sys.symbol.paintbrush'))
  8705. .fontColor([Color.White])
  8706. .effectStrategy(1)
  8707. Text(`选择颜色`)
  8708. .fontSize(13)
  8709. .margin({ left: 10 })
  8710. .fontColor(Color.White)
  8711. }
  8712. }
  8713. .backgroundColor(Color.Transparent)
  8714. .border({
  8715. color: '#FFFFFF',
  8716. radius: 20,
  8717. width: 1.8
  8718. })
  8719. .height(36)
  8720. .width(110)
  8721. .onClick(() => {
  8722. this.isShowHLSelectColor = !this.isShowHLSelectColor
  8723. })
  8724. .bindPopup(this.isShowHLSelectColor, {
  8725. builder: this.SelectColor(true, isPip),
  8726. placement: Placement.Top,
  8727. mask: { color: '#33000000' },
  8728. enableArrow: false, //是否显示箭头
  8729. showInSubWindow: false,
  8730. onStateChange: (e) => {
  8731. if (!e.isVisible) {
  8732. this.isShowHLSelectColor = false
  8733. }
  8734. }
  8735. })
  8736. }
  8737. .width('76%')
  8738. .margin({
  8739. top: 10,
  8740. bottom: 10,
  8741. right: 45,
  8742. left: 20
  8743. })
  8744. if (isPip) {
  8745. Row() {
  8746. Text(`显示宽度:`)
  8747. .fontSize(14)
  8748. .fontColor(Color.White)
  8749. Slider({
  8750. value: this.pipLyWidth,
  8751. min: 10,
  8752. max: 800,
  8753. step: 1,
  8754. style: SliderStyle.OutSet
  8755. })
  8756. .blockColor(this.themeColor)
  8757. .trackColor($r('app.color.speed_text_color'))
  8758. .selectedColor(Color.White)
  8759. .trackThickness(6)
  8760. .onChange((value: number) => {
  8761. this.pipLyWidth = value
  8762. if (this.pipController) {
  8763. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8764. PreferencesUtil.putSync('pipLyWidth', this.pipLyWidth)
  8765. }
  8766. })
  8767. .width('76%')
  8768. }
  8769. .margin({
  8770. left: 20,
  8771. right: 15,
  8772. top: 5,
  8773. bottom: 5
  8774. })
  8775. Row() {
  8776. Text(`显示高度:`)
  8777. .fontSize(14)
  8778. .fontColor(Color.White)
  8779. Slider({
  8780. value: this.pipLyHeight,
  8781. min: 10,
  8782. max: 1000,
  8783. step: 1,
  8784. style: SliderStyle.OutSet
  8785. })
  8786. .blockColor(this.themeColor)
  8787. .trackColor($r('app.color.speed_text_color'))
  8788. .selectedColor(Color.White)
  8789. .trackThickness(6)
  8790. .onChange((value: number) => {
  8791. this.pipLyHeight = value
  8792. if (this.pipController) {
  8793. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8794. PreferencesUtil.putSync('pipLyHeight', this.pipLyHeight)
  8795. }
  8796. })
  8797. .width('76%')
  8798. }
  8799. .margin({
  8800. left: 20,
  8801. right: 15,
  8802. top: 5,
  8803. bottom: 5
  8804. })
  8805. }
  8806. Row() {
  8807. Text(`歌词字号:`)
  8808. .fontSize(14)
  8809. .fontColor(Color.White)
  8810. Slider({
  8811. value: isPip ? this.currentLyricSizePip : this.currentLyricSize,
  8812. min: 12,
  8813. max: 30,
  8814. step: 0.1,
  8815. style: SliderStyle.OutSet
  8816. })
  8817. .blockColor(this.themeColor)
  8818. .trackColor($r('app.color.speed_text_color'))
  8819. .selectedColor(Color.White)
  8820. .trackThickness(6)
  8821. .onChange((value: number) => {
  8822. this.setLyricTextSize(value, isPip)
  8823. })
  8824. .width('76%')
  8825. }
  8826. .margin({
  8827. left: 20,
  8828. right: 15,
  8829. top: 5,
  8830. bottom: 5
  8831. })
  8832. Row() {
  8833. Text(`高亮倍数:`)
  8834. .fontSize(14)
  8835. .fontColor(Color.White)
  8836. Slider({
  8837. value: isPip ? this.currentHightLyricSizePip : this.currentHightLyricSize,
  8838. min: 1,
  8839. max: 2,
  8840. step: 0.1,
  8841. style: SliderStyle.OutSet
  8842. })
  8843. .blockColor(this.themeColor)
  8844. .trackColor($r('app.color.speed_text_color'))
  8845. .selectedColor(Color.White)
  8846. .trackThickness(6)
  8847. .onChange((value: number) => {
  8848. this.setHighLyricTextSize(value, isPip)
  8849. })
  8850. .width('76%')
  8851. }
  8852. .margin({
  8853. left: 20,
  8854. right: 15,
  8855. top: 5,
  8856. bottom: 5
  8857. })
  8858. Row() {
  8859. Text(`歌词间隙:`)
  8860. .fontSize(14)
  8861. .fontColor(Color.White)
  8862. Slider({
  8863. value: isPip ? this.currentLyricLineSpacePip : this.currentLyricLineSpace,
  8864. min: 0,
  8865. max: 100,
  8866. step: 1,
  8867. style: SliderStyle.OutSet
  8868. })
  8869. .blockColor(this.themeColor)
  8870. .trackColor($r('app.color.speed_text_color'))
  8871. .selectedColor(Color.White)
  8872. .trackThickness(6)
  8873. .onChange((value: number) => {
  8874. this.setLyricLineSpace(value, isPip)
  8875. })
  8876. .width('76%')
  8877. }
  8878. .margin({
  8879. left: 20,
  8880. right: 15,
  8881. top: 5,
  8882. bottom: 5
  8883. })
  8884. //取值间隔为100,默认为400,取值越大,字体越粗
  8885. Row() {
  8886. Text(`歌词字重:`)
  8887. .fontSize(14)
  8888. .fontColor(Color.White)
  8889. Slider({
  8890. value: isPip ? this.lyricTextWeightPip : this.lyricTextWeight,
  8891. min: 100,
  8892. max: 900,
  8893. step: 100,
  8894. style: SliderStyle.OutSet
  8895. })
  8896. .blockColor(this.themeColor)
  8897. .trackColor($r('app.color.speed_text_color'))
  8898. .selectedColor(Color.White)
  8899. .trackThickness(6)
  8900. .onChange((value: number) => {
  8901. if (isPip) {
  8902. this.lyricTextWeightPip = value
  8903. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  8904. PreferencesUtil.putSync('lyricTextWeightPip', this.lyricTextWeightPip)
  8905. } else {
  8906. this.lyricTextWeight = value
  8907. this.lyricController.setTextWeight(this.lyricTextWeight)
  8908. PreferencesUtil.putSync('lyricTextWeight', this.lyricTextWeight)
  8909. }
  8910. })
  8911. .width('76%')
  8912. }
  8913. .margin({
  8914. left: 20,
  8915. right: 15,
  8916. top: 5,
  8917. bottom: 5
  8918. })
  8919. if (!isPip) {
  8920. Row() {
  8921. Text(`歌词模糊:`)
  8922. .fontSize(14)
  8923. .fontColor(Color.White)
  8924. Slider({
  8925. value: isPip ? this.blurDegreePip : this.blurDegree,
  8926. min: 0,
  8927. max: 5,
  8928. step: 0.1,
  8929. style: SliderStyle.OutSet
  8930. })
  8931. .blockColor(this.themeColor)
  8932. .trackColor($r('app.color.speed_text_color'))
  8933. .selectedColor(Color.White)
  8934. .trackThickness(6)
  8935. .onChange((value: number) => {
  8936. this.setBlurDegree(value, isPip)
  8937. })
  8938. .width('76%')
  8939. }
  8940. .margin({
  8941. left: 20,
  8942. right: 15,
  8943. top: 5,
  8944. bottom: 15
  8945. })
  8946. }
  8947. Row() {
  8948. this.pushLyricButton($r('app.media.cut_current'), 0, '本地歌词')
  8949. this.pushLyricButton($r('app.media.white_search'), 1, '获取歌词')
  8950. // this.pushLyricButton($r('app.media.white_search'), 1, '繁体转简体')
  8951. }
  8952. .justifyContent(FlexAlign.Center)
  8953. .margin({ top: 3, bottom: 10 })
  8954. }
  8955. }
  8956. private setBlurDegree(index: number, isPip: boolean) {
  8957. if (isPip) {
  8958. this.blurDegreePip = index
  8959. this.lyricControllerXF.setBlurDegree(this.blurDegreePip)
  8960. PreferencesUtil.putSync('setBlurDegreePip', this.blurDegreePip)
  8961. } else {
  8962. this.blurDegree = index
  8963. this.lyricController.setBlurDegree(this.blurDegree)
  8964. PreferencesUtil.putSync('setBlurDegree', this.blurDegree)
  8965. }
  8966. }
  8967. private setLyricAlignMode(index: number, isPip: boolean) {
  8968. if (isPip) {
  8969. this.currentLyricAlignModePip = index
  8970. if (this.currentLyricAlignModePip === 1) {
  8971. this.lyricControllerXF.setAlignMode("left")
  8972. } else {
  8973. this.lyricControllerXF.setAlignMode("center")
  8974. }
  8975. PreferencesUtil.putSync('LyricAlignModePip', this.currentLyricAlignModePip)
  8976. } else {
  8977. this.currentLyricAlignMode = index
  8978. if (this.currentLyricAlignMode === 1) {
  8979. this.lyricController.setAlignMode("left")
  8980. } else {
  8981. this.lyricController.setAlignMode("center")
  8982. }
  8983. PreferencesUtil.putSync('LyricAlignMode', this.currentLyricAlignMode)
  8984. }
  8985. }
  8986. private setLyricTextSize(index: number, isPip: boolean) {
  8987. if (isPip) {
  8988. this.currentLyricSizePip = index
  8989. this.lyricControllerXF.setTextSize(this.currentLyricSizePip)
  8990. PreferencesUtil.putSync('LyricTextSizePip', this.currentLyricSizePip)
  8991. } else {
  8992. this.currentLyricSize = index
  8993. this.lyricController.setTextSize(this.currentLyricSize)
  8994. PreferencesUtil.putSync('LyricTextSize', this.currentLyricSize)
  8995. }
  8996. }
  8997. private setHighLyricTextSize(scale: number, isPip: boolean) {
  8998. if (isPip) {
  8999. this.currentHightLyricSizePip = scale
  9000. this.lyricControllerXF
  9001. .setHighlightScale(this.currentHightLyricSizePip)
  9002. PreferencesUtil.putSync('HighLyricTextSizePip', scale)
  9003. } else {
  9004. this.currentHightLyricSize = scale
  9005. this.lyricController
  9006. .setHighlightScale(this.currentHightLyricSize)
  9007. PreferencesUtil.putSync('HighLyricTextSize', scale)
  9008. }
  9009. }
  9010. private setLyricLineSpace(index: number, isPip: boolean) {
  9011. if (isPip) {
  9012. this.currentLyricLineSpacePip = index
  9013. this.lyricControllerXF.setLineSpace(this.currentLyricLineSpacePip)
  9014. PreferencesUtil.putSync('LyricLineSpacePip', this.currentLyricLineSpacePip)
  9015. } else {
  9016. this.currentLyricLineSpace = index
  9017. this.lyricController.setLineSpace(this.currentLyricLineSpace)
  9018. PreferencesUtil.putSync('LyricLineSpace', this.currentLyricLineSpace)
  9019. }
  9020. }
  9021. private changeLyricColor(color: string, isPip: boolean, isBG?: boolean) {
  9022. LogUtil.info('onecold isBG = ' + isBG)
  9023. if (isBG) { //如果是设置悬浮背景
  9024. this.pipBg = color
  9025. PreferencesUtil.putSync('BGColorPip', this.pipBg)
  9026. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  9027. return
  9028. }
  9029. if (isPip) {
  9030. this.currentLyricColorPip = color
  9031. this.lyricControllerXF
  9032. .setTextColor(this.currentLyricColorPip)
  9033. PreferencesUtil.putSync('LyricColorPip', this.currentLyricColorPip)
  9034. } else {
  9035. this.currentLyricColor = color
  9036. this.lyricController
  9037. .setTextColor(this.currentLyricColor)
  9038. PreferencesUtil.putSync('LyricColor', this.currentLyricColor)
  9039. }
  9040. }
  9041. private changeLyricHightLightColor(color: string, isPip: boolean) {
  9042. if (isPip) {
  9043. this.currentHighLightLyricColorPip = color
  9044. this.lyricControllerXF
  9045. .setHighlightColor(this.currentHighLightLyricColorPip)
  9046. PreferencesUtil.putSync('LyricHighLightColorPip', this.currentHighLightLyricColorPip)
  9047. } else {
  9048. this.currentHighLightLyricColor = color
  9049. this.lyricController
  9050. .setHighlightColor(this.currentHighLightLyricColor)
  9051. PreferencesUtil.putSync('LyricHighLightColor', this.currentHighLightLyricColor)
  9052. }
  9053. }
  9054. // 构建时间控制器
  9055. @Builder
  9056. BuildTimeControls() {
  9057. Column() {
  9058. // 时间显示
  9059. Text(this.getTimeText())
  9060. .fontSize(18)
  9061. .fontColor(Color.White)
  9062. .margin({ bottom: 10 })
  9063. Row() {
  9064. this.PrecisionTimeButton($r('app.media.ic_previous'), -0.5, ' -0.5s ')
  9065. this.PrecisionTimeButton($r('app.media.loop'), 0, '重置')
  9066. this.PrecisionTimeButton($r('app.media.ic_next'), 0.5, ' +0.5s ')
  9067. }
  9068. .justifyContent(FlexAlign.Center)
  9069. }
  9070. .margin({ top: 12, bottom: 8 })
  9071. }
  9072. // 精度按钮组件
  9073. @Builder
  9074. PrecisionTimeButton(icon: Resource, step: number, label: string) {
  9075. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  9076. Column() {
  9077. Image(icon)
  9078. .width(28)
  9079. .margin({ bottom: 5 })
  9080. .opacity(this.isButtonDisabled(step) ? 0.5 : 1)
  9081. Text(label)
  9082. .fontSize(12)
  9083. .fontColor('#FFFFFF')
  9084. }
  9085. }
  9086. .backgroundColor(Color.Transparent)
  9087. .enabled(!this.isButtonDisabled(step))
  9088. .onClick(() => this.handlePrecisionAdjust(step))
  9089. .padding(5)
  9090. .width(66)
  9091. .height(66)
  9092. .margin({ left: 18, right: 18 })
  9093. .border({
  9094. color: '#FFFFFF',
  9095. width: 1.8
  9096. })
  9097. }
  9098. private handlePrecisionAdjust(step: number) {
  9099. if (step === 0) {
  9100. this.timeOffset = 0
  9101. return
  9102. }
  9103. // 精度处理:保留1位小数
  9104. const newOffset = Number((this.timeOffset + step).toFixed(5))
  9105. // 边界保护(±15.0秒)
  9106. if (newOffset < -30.0 || newOffset > 30.0) {
  9107. // this.triggerEdgeFeedback(newOffset) // 触发边界反馈
  9108. return
  9109. }
  9110. // 状态更新
  9111. this.timeOffset = newOffset
  9112. }
  9113. // 按钮禁用逻辑
  9114. private isButtonDisabled(step: number): boolean {
  9115. const futureOffset = this.timeOffset + step
  9116. return (futureOffset < -30.0) || (futureOffset > 30.0)
  9117. }
  9118. // 时间显示文本升级
  9119. private getTimeText(): string {
  9120. const absValue = Math.abs(this.timeOffset)
  9121. return this.timeOffset === 0
  9122. ? '歌词时间已重置'
  9123. : `歌词已${this.timeOffset < 0 ? '延后' : '提前'} ${absValue.toFixed(1)} 秒`
  9124. }
  9125. // 导入 本地歌词 搜索歌词
  9126. @Builder
  9127. pushLyricButton(icon: Resource, step: number, label: string) {
  9128. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  9129. Row() {
  9130. Image(icon)
  9131. .width(14)
  9132. .margin({ left: 13 })
  9133. Text(label)
  9134. .fontSize(12)
  9135. .margin({ left: 6 })
  9136. .fontColor('#FFFFFF')
  9137. }
  9138. }
  9139. .onClick(() => {
  9140. switch (step) {
  9141. case 0:
  9142. this.callFilePickerSelectFileForLyric()
  9143. break;
  9144. case 1:
  9145. //判断有没有设置api
  9146. if (PreferencesUtil.getStringSync('LRC_API', '') === '') {
  9147. this.isLyricSetting = false
  9148. this.showTipsDialog()
  9149. return
  9150. }
  9151. if (StrUtil.isNotEmpty(this.videoUrl)) {
  9152. ToastUtil.showToast('正在获取')
  9153. this.isLyricSetting = false
  9154. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  9155. this.initLyric(lyricPath, true);
  9156. }
  9157. break;
  9158. }
  9159. })
  9160. .padding(5)
  9161. .width(110)
  9162. .backgroundColor(Color.Transparent)
  9163. .height(40)
  9164. .margin({ left: 6, right: 6 })
  9165. .border({
  9166. color: '#FFFFFF',
  9167. radius: 20,
  9168. width: 1.8
  9169. })
  9170. }
  9171. showVipDialog() {
  9172. DialogHelper.showCustomContentDialog({
  9173. dialogId: 'vip',
  9174. title: "友情提示",
  9175. autoCancel: false, //点击遮障层时,不关闭弹窗
  9176. backCancel: true, //点击返回键,不关闭弹窗
  9177. contentBuilder: () => {
  9178. this.customVipBuilder("该功能需开通会员,非常感谢您的支持!")
  9179. },
  9180. buttons: [],
  9181. })
  9182. }
  9183. //去赞助的自定义内容
  9184. @Builder
  9185. customVipBuilder(content: string) {
  9186. Column() {
  9187. Text(content)
  9188. .fontColor(Color.Gray)
  9189. .fontSize(16)
  9190. .alignSelf(ItemAlign.Start)
  9191. .margin({ bottom: 15 })
  9192. .fontSize(16)
  9193. Row() {
  9194. Button('取消')
  9195. .fontColor(Color.White)
  9196. .backgroundColor(this.themeColor)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  9197. .height(50)
  9198. .layoutWeight(1)
  9199. .stateEffect(true)
  9200. .margin({ right: 6 })
  9201. .onClick(() => {
  9202. DialogHelper.closeDialog('vip'); //关闭弹框
  9203. })
  9204. Button('开通')
  9205. .fontColor(Color.White)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  9206. .layoutWeight(1)
  9207. .height(50)
  9208. .backgroundColor(this.themeColor)
  9209. .stateEffect(true)
  9210. .margin({ left: 6 })
  9211. .onClick(() => {
  9212. DialogHelper.closeDialog('vip'); //关闭弹框
  9213. this.isShowPlay = false
  9214. this.mType = 1 //跳转到用户中心
  9215. // router.pushUrl({
  9216. // url: 'pages/VipPage'
  9217. // }, router.RouterMode.Single);
  9218. })
  9219. }
  9220. }
  9221. .width("100%")
  9222. .padding(10)
  9223. }
  9224. showTipsDialog() {
  9225. DialogHelper.showCustomContentDialog({
  9226. dialogId: 'tips',
  9227. title: "友情提示",
  9228. autoCancel: false, //点击遮障层时,不关闭弹窗
  9229. backCancel: true, //点击返回键,不关闭弹窗
  9230. contentBuilder: () => {
  9231. this.customTipsBuilder("请到设置界面配置API服务器地址!")
  9232. },
  9233. buttons: [],
  9234. })
  9235. }
  9236. @Builder
  9237. customTipsBuilder(content: string) {
  9238. Column() {
  9239. Text(content)
  9240. .fontColor(Color.Gray)
  9241. .fontSize(16)
  9242. .alignSelf(ItemAlign.Start)
  9243. .margin({ bottom: 15 })
  9244. .fontSize(16)
  9245. Row() {
  9246. Button('取消')
  9247. .fontColor(Color.White)
  9248. .backgroundColor(this.themeColor)
  9249. .height(50)
  9250. .layoutWeight(1)
  9251. .stateEffect(true)
  9252. .margin({ right: 6 })
  9253. .onClick(() => {
  9254. DialogHelper.closeDialog('tips'); //关闭弹框
  9255. })
  9256. Button('跳转')
  9257. .fontColor(Color.White)//
  9258. .layoutWeight(1)
  9259. .height(50)
  9260. .backgroundColor(this.themeColor)
  9261. .stateEffect(true)
  9262. .margin({ left: 6 })
  9263. .onClick(() => {
  9264. DialogHelper.closeDialog('tips'); //关闭弹框
  9265. this.isShowEdit = false
  9266. this.longItemFilePath = ''
  9267. // if(this.isGridMusic&&!this.isShowPlay){
  9268. // this.longItemFilePath== ''
  9269. // }else{
  9270. // this.isShowEdit = false
  9271. // }
  9272. this.isShowMoreView = false;
  9273. this.isShowPlay = false
  9274. this.mType = 4
  9275. // router.pushUrl({
  9276. // url: 'pages/SettingPage'
  9277. // }, router.RouterMode.Single);
  9278. })
  9279. }
  9280. }
  9281. .width("100%")
  9282. .padding(10)
  9283. }
  9284. @Builder
  9285. PlayMoreSheet() {
  9286. Column() {
  9287. this.MoreList()
  9288. }
  9289. .width('100%')
  9290. .height('100%')
  9291. }
  9292. @Builder
  9293. MoreList() {
  9294. Scroll() {
  9295. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  9296. ForEach(this.moreItems, (more: MoreItem, index: number) => {
  9297. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  9298. Row() {
  9299. if (more.id === 3&&this.currentSong) {
  9300. Image(more.image)
  9301. .width(24)
  9302. .height(24)
  9303. .margin({ left: 10, right: 10 })
  9304. Text(more.title)
  9305. .fontSize(16)
  9306. .fontColor(Color.White)
  9307. .bindSheet($$this.isShowDetailMore, this.detailSheet(this.currentSong), {
  9308. height: this.isCoverOpacity() ? '95%' : '95%',
  9309. dragBar: true,
  9310. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  9311. showClose: true,
  9312. blurStyle: BlurStyle.Thin,
  9313. backgroundColor: Color.Transparent,
  9314. title: { title: '歌曲信息' }
  9315. })
  9316. } else if (more.id === 15 && this.currentSong) { //编辑标签
  9317. Image(more.image)
  9318. .width(24)
  9319. .height(24)
  9320. .margin({ left: 10, right: 10 })
  9321. Text(more.title)
  9322. .fontSize(16)
  9323. .fontColor(Color.White)
  9324. .bindSheet($$this.isShowEdit, this.editSheet(this.currentSong), {
  9325. height: '99%',
  9326. dragBar: true,
  9327. showClose: true,
  9328. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  9329. // blurStyle:BlurStyle.Thin,
  9330. // backgroundColor:Color.Transparent,
  9331. title: { title: '编辑标签' }
  9332. })
  9333. } else if (more.id === 5) { //定时关闭
  9334. Image(more.image)
  9335. .width(24)
  9336. .height(24)
  9337. .margin({ left: 10, right: 10 })
  9338. Text(more.title)
  9339. .fontSize(16)
  9340. .fontColor(Color.White)
  9341. .onClick(() => {
  9342. this.doMore(more.id)
  9343. })
  9344. .bindSheet($$this.isShowTimeCloseMore, this.TimeCloseSheet(), {
  9345. height: this.isCoverOpacity() ? '95%' : '95%',
  9346. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  9347. dragBar: true,
  9348. showClose: true,
  9349. title: { title: $r('app.string.time_close') }
  9350. })
  9351. } else if (more.id === 2) { //歌词设置
  9352. Image(more.image)
  9353. .width(24)
  9354. .height(24)
  9355. .margin({ left: 10, right: 10 })
  9356. Text(more.title)
  9357. .fontSize(16)
  9358. .fontColor(Color.White)
  9359. } else if (more.id === 16) { //悬浮歌词设置
  9360. Image(more.image)
  9361. .width(24)
  9362. .height(24)
  9363. .margin({ left: 10, right: 10 })
  9364. Text(more.title)
  9365. .fontSize(16)
  9366. .fontColor(Color.White)
  9367. .bindSheet($$this.showPipLyric, this.lyricSettingSheet(true), {
  9368. height: this.isCoverOpacity() ? '95%' : '95%',
  9369. dragBar: true,
  9370. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  9371. showClose: true,
  9372. blurStyle: BlurStyle.Thin,
  9373. backgroundColor: Color.Transparent,
  9374. title: { title: '悬浮歌词' }
  9375. })
  9376. } else if (more.id === 11) {
  9377. Image(more.image)
  9378. .width(24)
  9379. .height(24)
  9380. .margin({ left: 10, right: 10 })
  9381. Text(more.title)
  9382. .fontSize(16)
  9383. .fontColor(Color.White)
  9384. .bindSheet($$this.isJumpSetting, this.JumpTopEndSheet(), {
  9385. height: this.isCoverOpacity() ? '95%' : '60%',
  9386. dragBar: true,
  9387. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  9388. showClose: true,
  9389. blurStyle: BlurStyle.Thin,
  9390. backgroundColor: Color.Transparent,
  9391. title: { title: '跳过头尾' }
  9392. })
  9393. } else if (more.id === 12) { //投播
  9394. AVCastPicker({
  9395. customPicker: (): void => this.TPImageBuilder(more),
  9396. onStateChange: (state) => {
  9397. if (state == AVCastPickerState.STATE_APPEARING) {
  9398. console.log(' The picker starts showing.');
  9399. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  9400. console.log(' The picker finishes presenting.');
  9401. }
  9402. },
  9403. pickerStyle: AVCastPickerStyle.STYLE_PANEL,
  9404. sessionType: 'video'
  9405. })
  9406. .id('AVCastPicker')
  9407. } else {
  9408. Image(more.image)
  9409. .width(24)
  9410. .height(24)
  9411. .margin({ left: 10, right: 10 })
  9412. .onClick(() => {
  9413. this.doMore(more.id)
  9414. })
  9415. Text(more.id == 17 ? (this.isLandscape ? '竖屏模式' : '横屏模式') : more.title)
  9416. .fontSize(16)
  9417. .fontColor(Color.White)
  9418. .onClick(() => {
  9419. this.doMore(more.id)
  9420. })
  9421. Select([//倍速
  9422. { value: '0.25x' },
  9423. { value: '0.5x' },
  9424. { value: '0.75x' },
  9425. { value: '1x' },
  9426. { value: '1.25x' },
  9427. { value: '1.5x' },
  9428. { value: '1.75x' },
  9429. { value: '2x' },
  9430. { value: '3x' }])
  9431. .font({ size: 16, weight: FontWeight.Medium })
  9432. .fontColor($r('sys.color.white'))
  9433. .margin({ left: 25 })
  9434. .visibility(more.id === 1 ? Visibility.Visible : Visibility.None)
  9435. .selected(CommonConstants.video_speed_list.indexOf(this.playSpeed))
  9436. .value(Utility.optimizedFormat(this.playSpeed))
  9437. .onSelect(async (_index: number, text?: string | undefined) => {
  9438. let speed = parseFloat(text?.replace('x', '') || '1');
  9439. if (!CommonConstants.video_speed_list.includes(speed)) {
  9440. speed = 1;
  9441. }
  9442. this.playSpeed = speed
  9443. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  9444. })
  9445. Slider({
  9446. value: this.volume,
  9447. min: 0,
  9448. max: 1,
  9449. step: 0.1,
  9450. style: SliderStyle.OutSet
  9451. })
  9452. .margin({ left: 18, right: 8 })
  9453. .blockColor(this.themeColor)
  9454. .trackColor($r('app.color.speed_text_color'))
  9455. .selectedColor(Color.White)
  9456. .trackThickness(9)
  9457. .visibility(more.id === 9 ? Visibility.Visible : Visibility.None)
  9458. .onChange((value: number) => {
  9459. this.volume = value;
  9460. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  9461. PreferencesUtil.putSync('DefalutVolume',this.volume)
  9462. })
  9463. .layoutWeight(1)
  9464. Blank()
  9465. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  9466. .selectedColor(this.themeColor)
  9467. .switchPointColor(Color.White)
  9468. .margin({ right: 15 })
  9469. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  9470. .visibility(more.id == 6 ? Visibility.Visible : Visibility.None)
  9471. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  9472. if (more.id == 6) {
  9473. this.isMusicMemoryPlay = checked;
  9474. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  9475. if (this.isMusicMemoryPlay) {
  9476. ToastUtil.showToast('记忆播放已开启')
  9477. } else {
  9478. ToastUtil.showToast('记忆播放已关闭')
  9479. }
  9480. }
  9481. })
  9482. .width(48)
  9483. .height(24);
  9484. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  9485. .selectedColor(this.themeColor)
  9486. .switchPointColor(Color.White)
  9487. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  9488. .margin({ right: 15 })
  9489. .visibility(more.id == 7 ? Visibility.Visible : Visibility.None)
  9490. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  9491. if (more.id == 7) {
  9492. this.isMusicBGCover = checked;
  9493. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  9494. if (this.isMusicBGCover) {
  9495. ToastUtil.showToast('播放背景随音乐封面已开启')
  9496. } else {
  9497. ToastUtil.showToast('播放背景随音乐封面已关闭')
  9498. }
  9499. }
  9500. })
  9501. .width(48)
  9502. .height(24);
  9503. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  9504. .selectedColor(this.themeColor)
  9505. .switchPointColor(Color.White)
  9506. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  9507. .margin({ right: 15 })
  9508. .visibility(more.id == 8 ? Visibility.Visible : Visibility.None)
  9509. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  9510. if (more.id == 8) {
  9511. this.isSavePlayMode = checked;
  9512. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  9513. if (this.isSavePlayMode) {
  9514. ToastUtil.showToast('保存播放模式已开启')
  9515. } else {
  9516. ToastUtil.showToast('保存播放模式已关闭')
  9517. }
  9518. }
  9519. })
  9520. .width(48)
  9521. .height(24);
  9522. Toggle({ type: ToggleType.Switch, isOn: this.isCoverRectangle })
  9523. .selectedColor(this.themeColor)
  9524. .switchPointColor(Color.White)
  9525. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  9526. .margin({ right: 15 })
  9527. .visibility(more.id == 13 ? Visibility.Visible : Visibility.None)
  9528. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  9529. if (more.id == 13) {
  9530. this.isCoverRectangle = checked;
  9531. PreferencesUtil.put(SettingPage.IS_COVER_RECTANGLE, this.isCoverRectangle)
  9532. if (this.isCoverRectangle) {
  9533. ToastUtil.showToast('封面方形已开启')
  9534. this.animationRoFun()
  9535. } else {
  9536. ToastUtil.showToast('封面圆形已开启')
  9537. this.animationRoFun()
  9538. }
  9539. }
  9540. })
  9541. .width(48)
  9542. .height(24);
  9543. }
  9544. }
  9545. .width('100%')
  9546. .height(45)
  9547. .padding(15)
  9548. .backgroundColor(Color.Transparent)
  9549. .borderRadius(12)
  9550. .margin({ bottom: 6 })
  9551. }
  9552. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.9 })
  9553. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  9554. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  9555. .backgroundColor(Color.Transparent)
  9556. .onClick(() => {
  9557. this.doMore(more.id)
  9558. })
  9559. });
  9560. }
  9561. .width('100%')
  9562. .padding(16)
  9563. }.margin({ bottom: 18 })
  9564. }
  9565. @Builder
  9566. TPImageBuilder(more: MoreItem): void {
  9567. Row() {
  9568. Image($r('app.media.tuoping'))
  9569. .width(22)
  9570. .height(22)
  9571. .margin({ left: 10, right: 10 })
  9572. Text(more.title)
  9573. .fontSize(16)
  9574. .fontColor(Color.White)
  9575. }
  9576. .width('100%')
  9577. .layoutWeight(1)
  9578. .alignItems(VerticalAlign.Center)
  9579. .justifyContent(FlexAlign.Start)
  9580. }
  9581. private moreItems: MoreItem[] = [
  9582. { id: 1, image: $r('app.media.speed'), title: '倍速' },
  9583. { id: 2, image: $r('app.media.lyric'), title: '歌词' },
  9584. { id: 17, image: $r('app.media.full_4'), title: '横屏模式' },
  9585. { id: 16, image: $r('app.media.hua_zhong_hua'), title: '悬浮歌词' },
  9586. { id: 14, image: $r('app.media.cover_online'), title: '获取封面' },
  9587. { id: 15, image: $r('app.media.rename2'), title: '编辑标签' },
  9588. { id: 5, image: $r('app.media.time_close'), title: '定时关闭' },
  9589. { id: 10, image: $r('app.media.ring_tone'), title: '设为铃声' },
  9590. { id: 11, image: $r('app.media.time_close'), title: '跳过头尾' },
  9591. { id:20,image: $r("app.media.a_b"), title: 'AB循环' },
  9592. { id: 12, image: $r('app.media.toubo'), title: '投播' },
  9593. { id: 3, image: $r('app.media.hua_zhong_hua'), title: '详情' },
  9594. { id: 4, image: $r('app.media.share2'), title: '分享' },
  9595. { id: 9, image: $r('app.media.volume_white'), title: '调整音量' },
  9596. // { id: 6, image: $r('app.media.memory'), title: '记忆播放' },
  9597. { id: 13, image: $r('app.media.rectangle'), title: '封面方形' },
  9598. { id: 8, image: $r('app.media.cut_current'), title: '保存播放模式' },
  9599. { id: 7, image: $r('app.media.playlist2'), title: '播放背景随音乐封面' },
  9600. ];
  9601. @State isShowMoreView: boolean = false;
  9602. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  9603. @State isShowTimeCloseMore: boolean = false
  9604. @State isShowDetailMore: boolean = false
  9605. @State isMusicBGCover: boolean = true
  9606. @State isSavePlayMode: boolean = true
  9607. @State isLyricSetting: boolean = false
  9608. @State isJumpSetting: boolean = false
  9609. @State isShowEdit: boolean = false
  9610. @State showPipLyric: boolean = false
  9611. async setRingTone() {
  9612. if (StrUtil.isEmpty(this.videoUrl) || StrUtil.isEmpty(this.name)) {
  9613. return
  9614. }
  9615. // 确定后的逻辑
  9616. let ringtoneTypeList: Array<ringtone.RingtoneType> = ringtone.getSupportedRingtoneTypes();
  9617. LogUtil.info('onecold getSupportedRingtoneTypes : ' + JSON.stringify(ringtoneTypeList));
  9618. let dataTypeList: Array<uniformTypeDescriptor.UniformDataType> =
  9619. ringtone.getSupportedDataTypes(ringtone.RingtoneType.NOTIFICATION);
  9620. LogUtil.info('onecold getSupportedDataTypes: ' + JSON.stringify(dataTypeList));
  9621. //let fileName: string = audioPath.substring(audioPath.lastIndexOf('/') + 1, audioPath.lastIndexOf('.'));
  9622. await ringtone.startRingtoneSetting(getContext(this) as common.UIAbilityContext
  9623. , this.videoUrl, this.name).then(res => {
  9624. LogUtil.info('onecold setFlag :' + res);
  9625. });
  9626. }
  9627. doMore(moreId: number) {
  9628. switch (moreId) {
  9629. case 2: //歌词
  9630. this.isLyricSetting = !this.isLyricSetting;
  9631. this.isShowMoreView = false
  9632. break;
  9633. case 3: //详情
  9634. this.isShowDetailMore = !this.isShowDetailMore;
  9635. break;
  9636. case 4: //分享
  9637. if (this.currentSong !== undefined) {
  9638. Utility.doShareMusic(this.currentSong, getContext(this) as common.UIAbilityContext)
  9639. }
  9640. this.isShowMoreView = false
  9641. break;
  9642. case 5: //定时关闭
  9643. this.isShowTimeCloseMore = !this.isShowTimeCloseMore;
  9644. break;
  9645. case 10: //设为铃声
  9646. this.setRingTone()
  9647. this.isShowMoreView = false
  9648. break;
  9649. case 11: //跳过头尾
  9650. this.isJumpSetting = !this.isJumpSetting;
  9651. break;
  9652. case 13: //倍速
  9653. break;
  9654. case 14: //搜索封面
  9655. if (this.currentSong !== undefined) {
  9656. this.doSearchCover(this.currentSong)
  9657. }
  9658. this.isShowMoreView = false
  9659. break;
  9660. case 15: //编辑标签
  9661. this.setEditStrEmpty()
  9662. this.tempLyricContent = this.lyricContent
  9663. this.isShowEdit = !this.isShowEdit;
  9664. break;
  9665. case 16: //悬浮歌词
  9666. this.showPipLyric = !this.showPipLyric;
  9667. break;
  9668. case 17: //横屏模式
  9669. if (this.isLandscape) {
  9670. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  9671. } else {
  9672. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  9673. }
  9674. this.isShowMoreView = false
  9675. break;
  9676. case 20://AB循环
  9677. this.isOpenAB = !this.isOpenAB;
  9678. this.isABSheet = false
  9679. break;
  9680. }
  9681. }
  9682. //AB循环
  9683. @State isOpenAB:boolean = false
  9684. @State jumpATime:number = 0
  9685. @State jumpBTime:number = 0
  9686. @State isABSheet:boolean = false
  9687. @Builder
  9688. ABLoopSheet() {
  9689. ABLoopComptent({
  9690. jumpATime:this.jumpATime,
  9691. jumpBTime:this.jumpBTime,
  9692. onClickAItem: async ()=>{
  9693. if(this.mIjkMediaPlayer){
  9694. this.jumpATime = await this.mIjkMediaPlayer.getCurrentPosition()
  9695. }
  9696. },
  9697. onClickBItem: async ()=>{
  9698. if(this.mIjkMediaPlayer){
  9699. this.jumpBTime = await this.mIjkMediaPlayer.getCurrentPosition()
  9700. if(this.jumpBTime<=this.jumpATime){
  9701. ToastUtil.showToast('设置B点时间不能小于A点时间')
  9702. this.jumpBTime = 0
  9703. }
  9704. }
  9705. },
  9706. onCancleButtonClick: async ()=>{
  9707. this.isOpenAB = false
  9708. this.isABSheet = false
  9709. },
  9710. onStartButtonClick: async ()=>{
  9711. this.isABSheet = false
  9712. this.startABLoop()
  9713. },
  9714. })
  9715. }
  9716. //开始AB循环
  9717. startABLoop(){
  9718. if(this.mIjkMediaPlayer){
  9719. this.seekTo(this.jumpATime+'')
  9720. this.isOpenAB = true
  9721. }
  9722. }
  9723. /**
  9724. * 切换横竖屏
  9725. *
  9726. */
  9727. setOrientation(orientation: number) {
  9728. this.windowClass.setPreferredOrientation(orientation).then(() => {
  9729. Logger.info('setWindowOrientation: ' + orientation + ' Succeeded.');
  9730. }).catch((err: BusinessError) => {
  9731. Logger.info('setWindowOrientation: ' + orientation + ' Failed. Cause: ' + JSON.stringify(err));
  9732. });
  9733. }
  9734. /**
  9735. * 画中画功能(悬浮歌词功能)
  9736. *
  9737. */
  9738. private nodeController: TextNodeController = new TextNodeController('#000000', this.lyricControllerXF);
  9739. pipController?: PiPWindow.PiPController;
  9740. navigationId: string = '';
  9741. @State curState: string = '';
  9742. @State curError: ResourceStr = '';
  9743. @State pipBg: string = '#E8E8E8'
  9744. @State buttonAction: string = '';
  9745. //开启画中画功能
  9746. async startPip() {
  9747. this.nodeController = new TextNodeController(this.pipBg, this.lyricControllerXF);
  9748. if (!this.pipController) {
  9749. await this.createPipController();
  9750. }
  9751. if (!this.pipController) {
  9752. Logger.info(`[${TAG}] pipController create error`);
  9753. return;
  9754. }
  9755. await this.pipController.startPiP();
  9756. }
  9757. async stopPip() {
  9758. if (!this.pipController) {
  9759. Logger.info(`[${TAG}] pipController is not exist`);
  9760. return;
  9761. }
  9762. this.isOpenPip = false
  9763. await this.pipController.stopPiP();
  9764. }
  9765. async createPipController() {
  9766. this.pipController = await PiPWindow.create({
  9767. context: getContext(this),
  9768. componentController: this.xcomponentController,
  9769. navigationId: this.navigationId,
  9770. templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY,
  9771. controlGroups: [PiPWindow.VideoPlayControlGroup.VIDEO_PREVIOUS_NEXT],
  9772. customUIController: this.nodeController,
  9773. });
  9774. this.pipLyWidth = PreferencesUtil.getNumberSync('pipLyWidth', 330)
  9775. this.pipLyHeight = PreferencesUtil.getNumberSync('pipLyHeight', 120)
  9776. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  9777. this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => {
  9778. this.onStateChange(state, reason);
  9779. });
  9780. this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => {
  9781. this.onActionEvent(event, status);
  9782. });
  9783. }
  9784. destroyPipController() {
  9785. if (!this.pipController) {
  9786. return;
  9787. }
  9788. this.pipController.off('stateChange');
  9789. this.pipController.off('controlPanelActionEvent');
  9790. this.pipController = undefined;
  9791. }
  9792. onStateChange(state: PiPWindow.PiPState, reason: string) {
  9793. switch (state) {
  9794. case PiPWindow.PiPState.ABOUT_TO_START:
  9795. this.curState = 'ABOUT_TO_START';
  9796. this.curError = $r('app.string.current_error_hint');
  9797. break;
  9798. case PiPWindow.PiPState.STARTED:
  9799. this.curState = 'STARTED';
  9800. this.curError = $r('app.string.current_error_hint');
  9801. break;
  9802. case PiPWindow.PiPState.ABOUT_TO_STOP:
  9803. this.curState = 'ABOUT_TO_STOP';
  9804. this.curError = $r('app.string.current_error_hint');
  9805. break;
  9806. case PiPWindow.PiPState.STOPPED:
  9807. this.curState = 'STOPPED';
  9808. this.curError = $r('app.string.current_error_hint');
  9809. this.stopPip()
  9810. this.destroyPipController()
  9811. break;
  9812. case PiPWindow.PiPState.ABOUT_TO_RESTORE:
  9813. this.curState = 'ABOUT_TO_RESTORE';
  9814. this.curError = $r('app.string.current_error_hint');
  9815. break;
  9816. case PiPWindow.PiPState.ERROR:
  9817. this.curState = 'ERROR';
  9818. this.curError = reason;
  9819. break;
  9820. default:
  9821. break;
  9822. }
  9823. Logger.info(`[${TAG}] onecold onStateChange: ${this.curState}, reason: ${reason}`);
  9824. }
  9825. onActionEvent(event: PiPWindow.PiPActionEventType, status: number | undefined) {
  9826. LogUtil.info('onecold onActionEvent = ' + event + ' status=' + status)
  9827. switch (event) {
  9828. case 'playbackStateChanged':
  9829. if (status === 0) {
  9830. this.pause();
  9831. } else {
  9832. console.info('onecold startPlayOrResumePlay 9869')
  9833. this.startPlayOrResumePlay();
  9834. }
  9835. break;
  9836. case 'nextVideo':
  9837. // 切换到下一个视频
  9838. this.playNext()
  9839. break;
  9840. case 'previousVideo':
  9841. // 切换到上一个视频
  9842. this.playPrevious()
  9843. break;
  9844. case 'previousVideo':
  9845. // 切换到上一个视频
  9846. this.playPrevious()
  9847. break;
  9848. default:
  9849. }
  9850. this.buttonAction = event + `-status:${status}`;
  9851. Logger.info(`[${TAG}] onActionEvent: ${this.buttonAction} status:${status}}`);
  9852. }
  9853. /**
  9854. * 画中画功能(悬浮歌词功能)结束
  9855. *
  9856. */
  9857. async doSearchCover(item: VideoItem): Promise<string> {
  9858. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  9859. this.isShowMoreView = false;
  9860. this.showTipsDialog();
  9861. return ''; // Return empty string when no API is configured
  9862. }
  9863. if (!item) {
  9864. return ''; // Return empty string if item is undefined
  9865. }
  9866. const artist = item?.artist || ''; // Use empty string if artist is missing
  9867. return this.searchCover(item, item.name, artist); // Await is not needed here as we return the promise directly
  9868. }
  9869. /**
  9870. *api搜索封面
  9871. *item,根据title和artist
  9872. */
  9873. searchCover(item: VideoItem, title: string, artist: string): Promise<string> {
  9874. return NetAxiosUtil.getLyricCover(title, artist, PreferencesUtil.getStringSync('COVER_API', '')).then(async (res) => {
  9875. LogUtil.debug("onecold res =" + res);
  9876. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  9877. if (item.filePath == this.currentSong?.filePath) {
  9878. this.cover = res;
  9879. if (this.currentSong) {
  9880. this.currentSong.pixelMapPath = res;
  9881. }
  9882. }
  9883. // Update pixel map path but always return res regardless of success
  9884. this.table.updatePixelMapPath(item.filePath, res, (success: boolean, error?: string) => {
  9885. if (success) {
  9886. this.doUpdateData();
  9887. console.log("onecold 更新音乐封面成功,数据库已同步");
  9888. } else {
  9889. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  9890. }
  9891. // Note: We don't resolve/reject here because we already returned res
  9892. });
  9893. LogUtil.debug("onecold this.cover =" + this.cover);
  9894. }
  9895. return res; // Always return res regardless of updatePixelMapPath result
  9896. });
  9897. }
  9898. @State jumpTopTime: number = 0
  9899. @State jumpEndTime: number = 0
  9900. @State isOpenJump: boolean = false
  9901. @Builder
  9902. JumpTopEndSheet() {
  9903. Scroll() {
  9904. Column() {
  9905. Column() {
  9906. Text('仅对本播放列表有效')
  9907. .fontSize(16)
  9908. .fontColor($r('app.color.text_color'))
  9909. // 跳过头尾
  9910. Column() {
  9911. Row() {
  9912. Text('跳过片头:')
  9913. .fontSize(16)
  9914. .fontColor($r('app.color.text_color'))
  9915. Text(this.jumpTopTime + 's')
  9916. .fontSize(16)
  9917. .fontColor($r('app.color.text_color'))
  9918. }
  9919. .margin({ bottom: 5 })
  9920. Row() {
  9921. Slider({
  9922. value: this.jumpTopTime,
  9923. min: 0,
  9924. max: 120,
  9925. step: 1,
  9926. style: SliderStyle.OutSet
  9927. })
  9928. .blockColor(this.themeColor)
  9929. .trackColor($r('app.color.speed_text_color'))
  9930. .selectedColor(Color.White)
  9931. .trackThickness(8)
  9932. .onChange((value: number) => {
  9933. this.jumpTopTime = value;
  9934. })
  9935. .width('85%')
  9936. }
  9937. .alignItems(VerticalAlign.Top)
  9938. }
  9939. .margin({ top: 10, bottom: 10 })
  9940. // 跳过头尾
  9941. Column() {
  9942. Row() {
  9943. Text('跳过片尾:')
  9944. .fontSize(16)
  9945. .fontColor($r('app.color.text_color'))
  9946. Text(this.jumpEndTime + 's')
  9947. .fontSize(16)
  9948. .fontColor($r('app.color.text_color'))
  9949. }
  9950. .margin({ bottom: 5 })
  9951. Row() {
  9952. Slider({
  9953. value: this.jumpEndTime,
  9954. min: 0,
  9955. max: 120,
  9956. step: 1,
  9957. style: SliderStyle.OutSet
  9958. })
  9959. .blockColor(this.themeColor)
  9960. .trackColor($r('app.color.speed_text_color'))
  9961. .selectedColor(Color.White)
  9962. .trackThickness(8)
  9963. .onChange((value: number) => {
  9964. this.jumpEndTime = value;
  9965. })
  9966. .width('85%')
  9967. }
  9968. .alignItems(VerticalAlign.Top)
  9969. }
  9970. .margin({ top: 10, bottom: 10 })
  9971. Row() {
  9972. Button('保存设置')
  9973. .fontColor(Color.White)
  9974. .layoutWeight(1)
  9975. .height(40)
  9976. .width(80)
  9977. .backgroundColor(this.themeColor)
  9978. .stateEffect(true)
  9979. .margin({ left: 0, bottom: 20 })
  9980. .onClick(async () => {
  9981. if (!Utility.isNoble()) {
  9982. this.isJumpSetting = false
  9983. this.isShowMoreView = false
  9984. this.showVipDialog()
  9985. return
  9986. }
  9987. if (this.currentSong === undefined) {
  9988. return
  9989. }
  9990. if (this.modeType === 0) {
  9991. let parentPath = FileUtil.getParentPath(this.videoUrl)
  9992. PreferencesUtil.putSync(parentPath + 'isOpenJump', true)
  9993. PreferencesUtil.putSync(parentPath + 'jumpEndTime', this.jumpEndTime)
  9994. PreferencesUtil.putSync(parentPath + 'jumpTopTime', this.jumpTopTime)
  9995. } else if (this.modeType === 1) { //媒体库
  9996. PreferencesUtil.putSync(1 + 'isOpenJump', true)
  9997. PreferencesUtil.putSync(1 + 'jumpEndTime', this.jumpEndTime)
  9998. PreferencesUtil.putSync(1 + 'jumpTopTime', this.jumpTopTime)
  9999. } else if (this.modeType === 2) { //艺术家
  10000. if (this.currentSong?.artist) {
  10001. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'isOpenJump', true)
  10002. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpEndTime', this.jumpEndTime)
  10003. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpTopTime', this.jumpTopTime)
  10004. }
  10005. } else if (this.modeType === 3) { //专辑
  10006. if (this.currentSong?.album) {
  10007. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'isOpenJump', true)
  10008. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpEndTime', this.jumpEndTime)
  10009. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpTopTime', this.jumpTopTime)
  10010. }
  10011. }
  10012. ToastUtil.showShort("保存成功")
  10013. this.isJumpSetting = false
  10014. })
  10015. }
  10016. .margin({
  10017. left: 38,
  10018. right: 38,
  10019. top: 10,
  10020. bottom: 10
  10021. })
  10022. .width(120)
  10023. .height(50)
  10024. }
  10025. }
  10026. }
  10027. .width('100%')
  10028. .height('100%')
  10029. }
  10030. // 应用可以通过onStateChange接口监听组件显示/消失状态,当组件显示时建议不要销毁AVCastPicker的显示;当组件消失时,再根据业务隐藏AVCastPicker。
  10031. private onStateVastChange(state: AVCastPickerState) {
  10032. if (state == AVCastPickerState.STATE_APPEARING) {
  10033. console.log('The picker starts showing.');
  10034. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  10035. console.log('The picker finishes presenting.');
  10036. }
  10037. }
  10038. private showSelectLyric() {
  10039. DialogHelper.showActionSheetDialog({
  10040. title: '温馨提醒:\n1.歌词文件名必须和目标歌曲文件名相同\n2.歌词文件和目标歌曲要同个歌单路径。',
  10041. // sheets: ["本地歌词", "搜索歌词"],
  10042. sheets: [
  10043. { value: "本地歌词", fontColor: $r('app.color.text_color') },
  10044. { value: "搜索歌词", fontColor: $r('app.color.text_color') },
  10045. ],
  10046. maskColor: Color.Transparent,
  10047. backgroundColor: $r('app.color.bg_card'),
  10048. transition: AnimationHelper.transitionInDown(666),
  10049. onAction: (index) => {
  10050. switch (index) {
  10051. case 0:
  10052. this.callFilePickerSelectFileForLyric()
  10053. break;
  10054. case 1:
  10055. if (StrUtil.isNotEmpty(this.videoUrl)) {
  10056. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  10057. this.initLyric(lyricPath);
  10058. }
  10059. break;
  10060. }
  10061. }
  10062. })
  10063. }
  10064. // 拉起picker选择文件管理器
  10065. async callFilePickerSelectFileForLyric(): Promise<void> {
  10066. try {
  10067. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  10068. DocumentSelectOptions.maxSelectNumber = 1
  10069. DocumentSelectOptions.fileSuffixFilters = CommonConstants.LYRIC_FORMAT
  10070. let documentPicker = new picker.DocumentViewPicker();
  10071. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  10072. Logger.info(TAG,
  10073. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  10074. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  10075. this.saveVideoDatasLyric(DocumentSelectResult)
  10076. }
  10077. }).catch((err: BusinessError) => {
  10078. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  10079. });
  10080. } catch (err) {
  10081. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  10082. }
  10083. }
  10084. async saveVideoDatasLyric(uris: string[]) {
  10085. if (ArrayUtil.isEmpty(uris)) {
  10086. return
  10087. }
  10088. let newUris: string[] = [];
  10089. for (let i = 0; i < uris.length; i++) {
  10090. let filePath = getContext(this).filesDir + '/' + Utility.getMediaNameByUri(uris[i])
  10091. Logger.info(TAG, 'filePath uri: ' + filePath);
  10092. newUris.push(filePath)
  10093. let file = fileIo.openSync(uris[i], fileIo.OpenMode.READ_ONLY)
  10094. let file2 = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  10095. fileIo.copyFileSync(file.fd, file2.fd)
  10096. fileIo.closeSync(file);
  10097. fileIo.closeSync(file2);
  10098. this.initLyric(filePath,false,false,true)
  10099. }
  10100. }
  10101. private initDelayPlay(context: object) {
  10102. this.mContext = context;
  10103. }
  10104. startPipLyric() {
  10105. if (this.pipController) {
  10106. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  10107. PiPWindow.PiPControlStatus.PLAY);
  10108. }
  10109. this.isOpenPip = PreferencesUtil.getBooleanSync('isOpenPip', false)
  10110. if (this.isOpenPip) {
  10111. this.startPip()
  10112. } else {
  10113. this.stopPip()
  10114. }
  10115. }
  10116. //startOffset 从cue分轨时间开始播
  10117. private startPlayOrResumePlay(startOffset?:number) {
  10118. //针对dsf文件高采样率sampleRate>441000,统一转wav播放
  10119. const sampleRate = this.currentSong?.sampleRate||0
  10120. if(this.videoUrl.toLowerCase().endsWith('.dsf')&&sampleRate>=441000){
  10121. console.info('onecold 采样率 ='+sampleRate)
  10122. let newDsfPath = this.context.filesDir + '/'+FileUtil.getFileName(this.videoUrl)+'.wav'
  10123. console.info('onecold newDsfPath ='+newDsfPath)
  10124. if(!FileUtil.accessSync(newDsfPath)){
  10125. const task = new taskpool.Task(convertDsfToWav,this.videoUrl,newDsfPath);
  10126. taskpool.execute(task, taskpool.Priority.HIGH).then((data)=>{
  10127. this.videoUrl = newDsfPath
  10128. this.startPlay(startOffset)
  10129. }).catch((e:object)=>{
  10130. console.info("task1 catch e: " + e);
  10131. })
  10132. }else{
  10133. this.videoUrl = newDsfPath
  10134. this.startPlay(startOffset)
  10135. }
  10136. }else{
  10137. this.startPlay(startOffset)
  10138. }
  10139. }
  10140. startPlay(startOffset?:number) {
  10141. this.startPipLyric()
  10142. this.mDestroyPage = false;
  10143. this.animationState = AnimationStatus.Running
  10144. LogUtils.getInstance().LOGI("onecold startPlayOrResumePlay start this.CONTROL_PlayStatus:" + this.CONTROL_PlayStatus)
  10145. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  10146. this.stopProgressTask();
  10147. this.startProgressTask();
  10148. this.play(this.videoUrl.toString(),startOffset);
  10149. }
  10150. if (this.CONTROL_PlayStatus == PlayStatus.PAUSE) {
  10151. this.mIjkMediaPlayer.start();
  10152. this.setProgress()
  10153. this.CONTROL_PlayStatus = PlayStatus.PLAY
  10154. }
  10155. this.setIsPlaying(true)
  10156. this.updateSessionPlayState(true)
  10157. this.watchStatus();
  10158. this.updateLastPlayTimeStr(this.videoUrl)
  10159. }
  10160. updateLastPlayTimeStr(filePath: string) {
  10161. let lastPlayTime = DateUtil.getTodayStr('yyyy-MM-dd HH:mm:ss')
  10162. this.table.updateLastPlayedStrByFilePath(filePath, lastPlayTime, (success: boolean, error?: string) => {
  10163. if (success) {
  10164. this.getHistoryList(false)
  10165. console.log(" onecold 更新最近播放时间成功,数据库已同步");
  10166. } else {
  10167. console.error(" onecold 更新最近播放时间数据库失败原因: " + error);
  10168. }
  10169. });
  10170. }
  10171. private completionNum(num: number): string | number {
  10172. if (num < 10) {
  10173. return '0' + num;
  10174. } else {
  10175. return num;
  10176. }
  10177. }
  10178. private stringForTime(timeMs: number): string {
  10179. let totalSeconds: number | string = (timeMs / 1000);
  10180. let newSeconds: number | string = totalSeconds % 60;
  10181. let minutes: number | string = (totalSeconds / 60) % 60;
  10182. let hours: number | string = totalSeconds / 3600;
  10183. //LogUtils.getInstance().LOGI("stringForTime hours:" + hours + ",minutes:" + minutes + ",seconds:" + newSeconds);
  10184. hours = this.completionNum(Math.floor(Math.floor(hours * 100) / 100));
  10185. minutes = this.completionNum(Math.floor(Math.floor(minutes * 100) / 100));
  10186. newSeconds = Math.floor(Math.floor(newSeconds * 100) / 100)
  10187. if (this.isCurrentTime) {
  10188. if (this.oldSeconds < newSeconds || newSeconds === 0 || this.isSeekTo) {
  10189. this.oldSeconds = newSeconds
  10190. } else {
  10191. newSeconds = this.oldSeconds
  10192. }
  10193. }
  10194. newSeconds = this.completionNum(newSeconds);
  10195. if (hours > 0) {
  10196. return hours + ":" + minutes + ":" + newSeconds;
  10197. } else {
  10198. return minutes + ":" + newSeconds;
  10199. }
  10200. }
  10201. private setProgress() {
  10202. let position = this.mIjkMediaPlayer.getCurrentPosition();
  10203. let duration = this.mIjkMediaPlayer.getDuration();
  10204. let pos = 0;
  10205. if (duration > 0) {
  10206. this.slideEnable = true;
  10207. let curPercent = position / duration;
  10208. pos = curPercent * 100;
  10209. if (pos > this.PROGRESS_MAX_VALUE) {
  10210. this.progressValue = this.PROGRESS_MAX_VALUE
  10211. } else {
  10212. this.progressValue = pos;
  10213. }
  10214. }
  10215. // LogUtils.getInstance()
  10216. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  10217. this.totalTime = this.stringForTime(duration);
  10218. if (position > duration) {
  10219. position = duration;
  10220. }
  10221. this.isCurrentTime = true;
  10222. this.lyricController.updatePosition(position + this.timeOffset * 1000)
  10223. this.lyricControllerXF.updatePosition(position + this.timeOffset * 1000)
  10224. this.lyricControllerSingle.updatePosition(position + this.timeOffset * 1000)
  10225. this.currentTime = this.stringForTime(position);
  10226. this.isCurrentTime = false
  10227. if (this.mIjkMediaPlayer.isPlaying()) {
  10228. this.randomColor =
  10229. `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
  10230. //如果是开启AB循环
  10231. if(this.isOpenAB){
  10232. if(position >=this.jumpBTime){
  10233. this.seekTo(this.jumpATime+'')
  10234. return
  10235. }
  10236. }
  10237. // 判断是否播放到结束时间
  10238. if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
  10239. if (position >= duration - this.jumpEndTime * 1000) {
  10240. if(this.playType == 1){//跳过尾部如果是单曲循环就选择单曲循环
  10241. this.CONTROL_PlayStatus = PlayStatus.INIT
  10242. this.startPlayOrResumePlay();
  10243. }else if (this.playType == 2) { //2:正常播放,单曲播完
  10244. this.showRePlay();
  10245. this.currentTime = this.stringForTime(this.mIjkMediaPlayer.getDuration());
  10246. this.progressValue = this.PROGRESS_MAX_VALUE;
  10247. this.slideEnable = false;
  10248. this.stop();
  10249. // ToastUtil.showToast('开始重新播放')
  10250. }else{
  10251. this.playNext()
  10252. }
  10253. }
  10254. }
  10255. } else {
  10256. this.randomColor = 'rbg(0,0,0)'
  10257. }
  10258. }
  10259. private startProgressTask() {
  10260. let that = this;
  10261. this.updateProgressTimer = setInterval(() => {
  10262. //LogUtils.getInstance().LOGI("startProgressTask");
  10263. if (!that.mDestroyPage) {
  10264. that.setProgress();
  10265. }
  10266. }, 300);
  10267. }
  10268. private stopProgressTask() {
  10269. LogUtils.getInstance().LOGI("stopProgressTask");
  10270. clearInterval(this.updateProgressTimer);
  10271. }
  10272. private showLoadIng() {
  10273. this.loadingVisible = Visibility.Visible;
  10274. this.replayVisible = Visibility.None;
  10275. }
  10276. private hideLoadIng() {
  10277. this.loadingVisible = Visibility.None;
  10278. this.replayVisible = Visibility.None;
  10279. }
  10280. private showRePlay() {
  10281. this.loadingVisible = Visibility.None;
  10282. this.replayVisible = Visibility.Visible;
  10283. }
  10284. private async play(url: string,startOffset?:number) {
  10285. let that = this;
  10286. that.showLoadIng();
  10287. this.isOpenAB = false
  10288. //设置XComponent回调的context
  10289. if (!!this.mContext) {
  10290. this.mIjkMediaPlayer.setContext(this.mContext, 'xcomponentId');
  10291. }
  10292. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  10293. this.mIjkMediaPlayer.reset();
  10294. }
  10295. this.CONTROL_PlayStatus = PlayStatus.PLAY;
  10296. //设置debug模式
  10297. this.mIjkMediaPlayer.setDebug(false);
  10298. //初始化配置
  10299. this.mIjkMediaPlayer.native_setup();
  10300. // 初始化配置后需要重新设置音频流音量,否则音量为默认值1.0 针对dsf格式设置最大值1.0
  10301. if(this.volumeSmall){
  10302. if(this.videoUrl.toLowerCase().endsWith('.dsf')){
  10303. this.mIjkMediaPlayer.setVolume('1', '1');
  10304. }else{
  10305. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  10306. }
  10307. }else{
  10308. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  10309. }
  10310. //设置视频源
  10311. this.mIjkMediaPlayer.setDataSource(url);
  10312. //设置视频源http请求头
  10313. let headers = new Map([
  10314. ["user_agent", "Mozilla/5.0 BiliDroid/7.30.0 (bbcallen@gmail.com)"],
  10315. ["referer", "https://www.bilibili.com"]
  10316. ]);
  10317. this.mIjkMediaPlayer.setDataSourceHeader(headers);
  10318. // if(PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN,false)){
  10319. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", "1"); // 启用硬件解码,会导致无法顺序播放
  10320. // }
  10321. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  10322. //使用精确寻帧 例如,拖动播放后,会寻找最近的关键帧进行播放,很有可能关键帧的位置不是拖动后的位置,而是较前的位置.可以设置这个参数来解决问题
  10323. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", "1");
  10324. const fileSize = await this.getFileSize(this.videoUrl);
  10325. let bufferSize = 1 * 1024 ; // 默认缓冲区大小为1MB
  10326. if (fileSize > 3 * 1024 * 1024 * 1024) { // 文件大于3GB
  10327. bufferSize = 25 * 1024 * 1024; // 设置缓冲区大小为25MB
  10328. }
  10329. // 使用软件解码(通常比硬件解码更节省内存)
  10330. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", '0');
  10331. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", '0');
  10332. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", '1024');
  10333. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", '500000');
  10334. //预读数据的缓冲区大小.修复大文件播放前几秒挂掉的bug,太大了会导致倍数播放失效
  10335. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", bufferSize + '');
  10336. //停止预读的最小帧数
  10337. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100");
  10338. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", '1'); ////重连模式,如果中途服务器断开了连接,让它重新连接
  10339. // 设置其他缓冲相关选项
  10340. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100"); // 设置最小缓冲帧数
  10341. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-frames", "1000"); // 设置最大缓冲
  10342. //启动预加载
  10343. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", "1");
  10344. // 设置无缓冲,这是播放器的缓冲区,有数据就播放
  10345. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", "0");
  10346. //跳帧处理,放CPU处理较慢时,进行跳帧处理,保证播放流程,画面和声音同步
  10347. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", "5");
  10348. // 最大缓冲cache是3s, 有时候网络波动,会突然在短时间内收到好几秒的数据
  10349. // 因此需要播放器丢包,才不会累积延时
  10350. // 这个和第三个参数packet-buffering无关。
  10351. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max_cached_duration", "3000");
  10352. // 无限制收流
  10353. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1");
  10354. this.mIjkMediaPlayer.setOptionLong(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1")
  10355. // 屏幕常亮
  10356. this.mIjkMediaPlayer.setScreenOnWhilePlaying(true);
  10357. // 设置超时
  10358. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", "10000000");
  10359. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "connect_timeout", "10000000");
  10360. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "addrinfo_timeout", "10000000");
  10361. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_timeout", "10000000");
  10362. // 变速播放
  10363. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", "1");
  10364. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  10365. let Speed = this.mIjkMediaPlayer.getSpeed()
  10366. LogUtils.getInstance().LOGI('getSpeed--' + Speed)
  10367. //是否开启循环播放
  10368. // this.mIjkMediaPlayer.setLoopCount(this.loop);
  10369. let mOnVideoSizeChangedListener: OnVideoSizeChangedListener = {
  10370. onVideoSizeChanged: (width: number, height: number, sar_num: number, sar_den: number) => {
  10371. if (height === 0) {
  10372. return;
  10373. }
  10374. const va = width / height;
  10375. const vpa = that.videoParentAspectRatio;
  10376. if (vpa > va) {
  10377. that.videoWidth = (width / (height * vpa)) * 100 + '%';
  10378. } else {
  10379. that.videoWidth = '100%';
  10380. }
  10381. if (width && height) {
  10382. that.videoAspectRatio = width / height;
  10383. }
  10384. LogUtils.getInstance()
  10385. .LOGI("setOnVideoSizeChangedListener-->go:" + width + "," + height + "," + sar_num + "," + sar_den);
  10386. that.hideLoadIng();
  10387. }
  10388. }
  10389. this.mIjkMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
  10390. let mOnPreparedListener: OnPreparedListener = {
  10391. onPrepared: async () => {
  10392. LogUtils.getInstance().LOGI("setOnPreparedListener-->go");
  10393. try {
  10394. // this.cover = this.songList[this.curIndex].pixelMapPath
  10395. // this.artist = this.songList[this.curIndex].artist
  10396. // this.videoUrl = this.songList[this.curIndex].filePath
  10397. let isBgCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  10398. if (isBgCover && this.cover !== undefined && StrUtil.isNotEmpty(this.cover)) {
  10399. this.setImageColor2(this.cover)
  10400. } else {
  10401. this.getImageColor();
  10402. }
  10403. //保存碰一碰分享的当前的歌曲
  10404. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  10405. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  10406. await this.initLyric(lyricPath);
  10407. setTimeout(() => {
  10408. this.avSessionController.initAvSession(false);
  10409. this.avSessionController.setAVMetadataMusic(this.songList[this.curIndex], this.duration, this.lyricContent);
  10410. this.setAvSessionListener();
  10411. this.updateSessionPlayState(true)
  10412. this.setCurrentPlayMode()
  10413. }, 500)
  10414. if(startOffset&&startOffset>0){//cue分轨播放
  10415. this.seekTo(startOffset + "");
  10416. this.saveLastPlayList()
  10417. return
  10418. }
  10419. //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  10420. let timeoutPlay = 0
  10421. if (StrUtil.isNotEmpty(this.videoUrl) &&
  10422. (this.videoUrl.toLowerCase().endsWith('.rmvb') || this.videoUrl.toLowerCase().endsWith('.flac'))) {
  10423. timeoutPlay = 1000
  10424. }
  10425. //跳过片头片尾关键代码,以下是跳过片头的关键代码
  10426. if (this.modeType === 0) { //文件夹
  10427. let parentPath = FileUtil.getParentPath(this.videoUrl)
  10428. this.jumpTopTime = PreferencesUtil.getNumberSync(parentPath + 'jumpTopTime')
  10429. this.jumpEndTime = PreferencesUtil.getNumberSync(parentPath + 'jumpEndTime')
  10430. this.isOpenJump = PreferencesUtil.getBooleanSync(parentPath + 'isOpenJump', false)
  10431. } else if (this.modeType === 1) { //媒体库
  10432. this.jumpTopTime = PreferencesUtil.getNumberSync(1 + 'jumpTopTime')
  10433. this.jumpEndTime = PreferencesUtil.getNumberSync(1 + 'jumpEndTime')
  10434. this.isOpenJump = PreferencesUtil.getBooleanSync(1 + 'isOpenJump', false)
  10435. } else if (this.modeType === 2) { //艺术家
  10436. if (this.currentSong?.artist) {
  10437. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpTopTime')
  10438. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpEndTime')
  10439. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.artist + 2 + 'isOpenJump', false)
  10440. }
  10441. } else if (this.modeType === 3) { //专辑
  10442. if (this.currentSong?.album) {
  10443. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpTopTime')
  10444. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpEndTime')
  10445. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.album + 3 + 'isOpenJump', false)
  10446. }
  10447. }
  10448. this.duration = this.mIjkMediaPlayer.getDuration()
  10449. if (this.isOpenJump) { //用户是否设置跳过片头片尾
  10450. if (this.mIjkMediaPlayer != null) {
  10451. let jumpTopTimeMs = this.jumpTopTime*1000;
  10452. if (jumpTopTimeMs <= this.duration) {
  10453. // 调用 seekTo 方法,跳到指定时间
  10454. if(PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY,true)){
  10455. console.log('onecold jumpTopTime = '+jumpTopTimeMs);
  10456. const position:number = PreferencesUtil.getNumberSync(this.videoUrl, 0);
  10457. console.log('onecold position = '+position);
  10458. if (position > jumpTopTimeMs) {
  10459. jumpTopTimeMs = position
  10460. }
  10461. }
  10462. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  10463. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  10464. this.seekTo(this.jumpTopTime * 1000 + ""); // 跳到开头
  10465. }
  10466. }, timeoutPlay)
  10467. } else {
  10468. // 提示用户无法跳过
  10469. ToastUtil.showToast('跳过时间超过视频时长');
  10470. }
  10471. }
  10472. } else {
  10473. this.jumpTopTime = 0
  10474. this.jumpEndTime = 0
  10475. console.error('onecold 最后一首: isFirstStartPlay = ' + this.isFirstStartPlay);
  10476. console.error('onecold 最后一首: isMemoryLastPlay = ' + this.isMemoryLastPlay);
  10477. console.error('onecold 最后一首: PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false) = ' +
  10478. PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false));
  10479. //记忆播放(每一首都会记忆播放)
  10480. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  10481. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  10482. if (PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)) {
  10483. this.restorePlaybackPosition() //读取播放记忆功能
  10484. } else if (this.isMemoryLastPlay && this.isFirstStartPlay) {
  10485. console.error('onecold 最后一首:读取播放记忆功能 = ' + this.isFirstStartPlay);
  10486. this.restorePlaybackPosition() //读取播放记忆功能
  10487. }
  10488. this.isFirstStartPlay = false
  10489. }, timeoutPlay)
  10490. } else {
  10491. this.isFirstStartPlay = false
  10492. }
  10493. }
  10494. this.saveLastPlayList()
  10495. } catch (error) {
  10496. let err: BusinessError = error as BusinessError;
  10497. console.error('onecold failed with err: ' + JSON.stringify(err));
  10498. }
  10499. }
  10500. }
  10501. this.mIjkMediaPlayer.setOnPreparedListener(mOnPreparedListener);
  10502. let mOnTimedTextListener: OnTimedTextListener = {
  10503. onTimedText: () => {
  10504. }
  10505. }
  10506. this.mIjkMediaPlayer.setOnTimedTextListener(mOnTimedTextListener)
  10507. let mOnCompletionListener: OnCompletionListener = {
  10508. onCompletion: () => {
  10509. LogUtils.getInstance().LOGI("OnCompletionListener-->go")
  10510. if (this.playType == 0) { //0:连续播放 1:单片重复播放 2:正常播放
  10511. this.playNext()
  10512. } else if (this.playType == 1) { //1:单片重复播放
  10513. this.CONTROL_PlayStatus = PlayStatus.INIT
  10514. console.info('onecold startPlayOrResumePlay 10592')
  10515. that.startPlayOrResumePlay();
  10516. } else if (this.playType == 2) { //2:正常播放,单曲播完
  10517. that.showRePlay();
  10518. that.currentTime = that.stringForTime(this.mIjkMediaPlayer.getDuration());
  10519. that.progressValue = this.PROGRESS_MAX_VALUE;
  10520. that.slideEnable = false;
  10521. that.stop();
  10522. // ToastUtil.showToast('开始重新播放')
  10523. } else if (this.playType == 3) { //3:随机播放
  10524. this.randomPlay()
  10525. }
  10526. }
  10527. }
  10528. this.mIjkMediaPlayer.setOnCompletionListener(mOnCompletionListener);
  10529. let mOnBufferingUpdateListener: OnBufferingUpdateListener = {
  10530. onBufferingUpdate: (percent: number) => {
  10531. LogUtils.getInstance().LOGI("OnBufferingUpdateListener-->go:" + percent);
  10532. let MediaInfo = this.mIjkMediaPlayer.getMediaInfo()
  10533. LogUtils.getInstance().LOGI('getMediaInfo---' + MediaInfo);
  10534. let VideoWidth = this.mIjkMediaPlayer.getVideoWidth()
  10535. LogUtils.getInstance().LOGI('getVideoWidth---' + VideoWidth);
  10536. let VideoHeight = this.mIjkMediaPlayer.getVideoHeight()
  10537. LogUtils.getInstance().LOGI('getVideoHeight---' + VideoHeight);
  10538. let VideoSarNum = this.mIjkMediaPlayer.getVideoSarNum()
  10539. LogUtils.getInstance().LOGI('getVideoSarNum---' + VideoSarNum);
  10540. let VideoSarDen = this.mIjkMediaPlayer.getVideoSarDen()
  10541. LogUtils.getInstance().LOGI('getVideoSarDen---' + VideoSarDen);
  10542. let AudioSessionId = this.mIjkMediaPlayer.getAudioSessionId()
  10543. LogUtils.getInstance().LOGI('getAudioSessionId---' + AudioSessionId);
  10544. let Looping = this.mIjkMediaPlayer.isLooping()
  10545. LogUtils.getInstance().LOGI('isLooping---' + Looping);
  10546. }
  10547. }
  10548. this.mIjkMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
  10549. let mOnSeekCompleteListener: OnSeekCompleteListener = {
  10550. onSeekComplete: () => {
  10551. LogUtils.getInstance().LOGI("OnSeekCompleteListener-->go");
  10552. console.info('onecold startPlayOrResumePlay 10643')
  10553. that.startPlayOrResumePlay();
  10554. }
  10555. }
  10556. this.mIjkMediaPlayer.setOnSeekCompleteListener(mOnSeekCompleteListener);
  10557. let mOnInfoListener: OnInfoListener = {
  10558. onInfo: (what: number, extra: number) => {
  10559. LogUtils.getInstance().LOGI("OnInfoListener-->go:" + what + "===" + extra);
  10560. that.hideLoadIng();
  10561. }
  10562. }
  10563. this.mIjkMediaPlayer.setOnInfoListener(mOnInfoListener);
  10564. let mOnErrorListener: OnErrorListener = {
  10565. onError: (what: number, extra: number) => {
  10566. this.stopProgressTask();
  10567. LogUtils.getInstance().LOGI("OnErrorListener-->go:" + what + "===" + extra + " this.videoUrl=" + this.videoUrl)
  10568. that.hideLoadIng();
  10569. if (StrUtil.isNotEmpty(this.videoUrl) && !FileUtil.accessSync(this.videoUrl)) {
  10570. ToastUtil.showToast(Utility.resourceToString(getContext(), $r('app.string.file_not_exist')))
  10571. } else {
  10572. ToastUtil.showToast(getContext()
  10573. .resourceManager
  10574. .getStringByNameSync("Honey_the_video_is_playing_errant_The_system_is_wandering"))
  10575. }
  10576. }
  10577. }
  10578. this.mIjkMediaPlayer.setOnErrorListener(mOnErrorListener);
  10579. this.mIjkMediaPlayer.setMessageListener();
  10580. this.mIjkMediaPlayer.prepareAsync();
  10581. this.mIjkMediaPlayer.start();
  10582. }
  10583. //保存最后播放的那首歌和已经对应的播放列表
  10584. saveLastPlayList() {
  10585. PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
  10586. PreferencesUtil.putSync('LastMusicList', this.songList)
  10587. }
  10588. // 清空播放记录
  10589. clearVideoHistory() {
  10590. this.table.clearPlayHistory((success: boolean, error?: string) => {
  10591. if (success) {
  10592. this.historyList = [];
  10593. this.updateListData(this.historyList)
  10594. // PreferencesUtil.putSync(LocalMusic.HISTORY_MUSIC, this.historyList)
  10595. ToastUtil.showToast('清空播放记录成功')
  10596. } else {
  10597. console.error(" onecold 清空播放记录数据库失败原因: " + error);
  10598. }
  10599. });
  10600. }
  10601. public async setAvSessionListener() {
  10602. if (!this.avSessionController) {
  10603. return;
  10604. }
  10605. this.avSessionController.getAvSession()?.on('play', this.sessionPlayCallback);
  10606. this.avSessionController.getAvSession()?.on('pause', this.sessionPauseCallback);
  10607. this.avSessionController.getAvSession()?.on('stop', this.sessionStopCallback);
  10608. this.avSessionController.getAvSession()?.on('playNext', this.sessionPlayNextCallback);
  10609. this.avSessionController.getAvSession()?.on('playPrevious', this.sessionPlayPreviousCallback);
  10610. this.avSessionController.getAvSession()?.on('fastForward', this.sessionFastForwardCallback);
  10611. this.avSessionController.getAvSession()?.on('rewind', this.sessionRewindCallback);
  10612. this.avSessionController.getAvSession()?.on('seek', this.sessionSeekCallback);
  10613. this.avSessionController.getAvSession()?.on('setLoopMode', this.sessionSetLoopModeCallback);
  10614. this.avSessionController.getAvSession()?.on('toggleFavorite', this.sessionToggleFavoriteCallback);
  10615. this.avSessionController.getAvSession()?.on('outputDeviceChange', this.sessionOutputDeviceChange)
  10616. }
  10617. setLoopMode() {
  10618. let itype = this.playType + 1
  10619. if (itype >= 4) {
  10620. this.playType = 0
  10621. ToastUtil.showToast('连续播放')
  10622. } else if (itype === 1) {
  10623. this.playType = 1
  10624. ToastUtil.showToast('单曲循环')
  10625. } else if (itype === 2) {
  10626. this.playType = 2
  10627. ToastUtil.showToast('单曲播完')
  10628. } else if (itype === 3) {
  10629. this.playType = 3
  10630. ToastUtil.showToast('随机播放')
  10631. } else if (itype === 0) {
  10632. this.playType = 0
  10633. ToastUtil.showToast('连续播放')
  10634. }
  10635. PreferencesUtil.putSync('musicPlayType', this.playType)
  10636. this.setCurrentPlayMode()
  10637. }
  10638. private sessionSetLoopModeCallback = (mode: number) => {
  10639. if (this.mIjkMediaPlayer != null) {
  10640. ToastUtil.showToast('当前播放模式:' + mode)
  10641. Logger.info('onecold 当前播放模式= ' + mode)
  10642. let hmPlayMode = mode + 1
  10643. if (hmPlayMode >= 4) {
  10644. hmPlayMode = 0
  10645. }
  10646. if (hmPlayMode === 1) {
  10647. this.playType = 1
  10648. ToastUtil.showToast('单曲循环')
  10649. } else if (hmPlayMode === 0) {
  10650. this.playType = 2
  10651. ToastUtil.showToast('单曲播完')
  10652. } else if (hmPlayMode === 3) {
  10653. this.playType = 3
  10654. ToastUtil.showToast('随机播放')
  10655. } else if (hmPlayMode === 2) {
  10656. this.playType = 0
  10657. ToastUtil.showToast('连续播放')
  10658. }
  10659. PreferencesUtil.putSync('musicPlayType', this.playType)
  10660. // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
  10661. let playBackState: avSession.AVPlaybackState = {
  10662. loopMode: hmPlayMode,
  10663. };
  10664. this.avSessionController.getAvSession()?.setAVPlaybackState(playBackState).then(() => {
  10665. console.info(`set setLoopMode AVPlaybackState successfully`);
  10666. }).catch((err: BusinessError) => {
  10667. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  10668. });
  10669. }
  10670. }
  10671. setCurrentPlayMode() {
  10672. if (!this.avSessionController) {
  10673. return;
  10674. }
  10675. let mLoopMode = 0
  10676. switch (this.playType) {
  10677. case 0:
  10678. mLoopMode = avSession.LoopMode.LOOP_MODE_LIST //连续播放
  10679. break;
  10680. case 1:
  10681. mLoopMode = avSession.LoopMode.LOOP_MODE_SINGLE //单曲
  10682. break;
  10683. case 2:
  10684. mLoopMode = avSession.LoopMode.LOOP_MODE_SEQUENCE //正常播放
  10685. break;
  10686. case 3:
  10687. mLoopMode = avSession.LoopMode.LOOP_MODE_SHUFFLE //随机播放
  10688. break;
  10689. }
  10690. // 应用启动时/内部切换循环模式,需要把应用内的当前的循环模式设置给AVSession。
  10691. let playBState: avSession.AVPlaybackState = {
  10692. loopMode: mLoopMode,
  10693. isFavorite: Utility.getIsFav(this.favList, this.currentSong),
  10694. };
  10695. this.avSessionController.getAvSession()?.setAVPlaybackState(playBState).then(() => {
  10696. console.info(`set setLoopMode AVPlaybackState successfully`);
  10697. }).catch((err: BusinessError) => {
  10698. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  10699. });
  10700. }
  10701. private sessionToggleFavoriteCallback = (assetId: string) => {
  10702. if (this.mIjkMediaPlayer != null && this.currentSong) {
  10703. console.info(`on toggleFavorite `);
  10704. // 应用收到收藏命令,进行收藏处理。
  10705. this.isFac = Utility.getIsFav(this.favList, this.currentSong)
  10706. this.doFav(this.currentSong)
  10707. // 应用内完成或者取消收藏,把新的收藏状态设置给AVSession。
  10708. let playbackState: avSession.AVPlaybackState = {
  10709. isFavorite: !this.isFac,
  10710. };
  10711. this.avSessionController.getAvSession()?.setAVPlaybackState(playbackState).then(() => {
  10712. console.info(`SetAVPlaybackState successfully`);
  10713. }).catch((err: BusinessError) => {
  10714. console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  10715. });
  10716. }
  10717. }
  10718. private sessionOutputDeviceChange = async (connectState: avSession.ConnectionState,
  10719. device: avSession.OutputDeviceInfo) => {
  10720. let currentDevice: avSession.DeviceInfo = device?.devices?.[0];
  10721. if (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  10722. connectState === avSession.ConnectionState.STATE_CONNECTED) {
  10723. await this.startCasting();
  10724. } else if ((currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  10725. connectState === avSession.ConnectionState.STATE_DISCONNECTED) ||
  10726. (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_LOCAL &&
  10727. connectState === avSession.ConnectionState.STATE_CONNECTED)) {
  10728. if (device) {
  10729. this.endCasting();
  10730. }
  10731. }
  10732. };
  10733. private async startCasting() {
  10734. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  10735. this.setPlaybackStateChangeListener();
  10736. this.pause();
  10737. this.initQueueItem();
  10738. this.prepare();
  10739. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  10740. refToIsCasting?.set(true);
  10741. this.castSeek = true;
  10742. this.isCastPlaying = true;
  10743. }
  10744. async changeCasting() {
  10745. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  10746. this.initQueueItem();
  10747. this.prepare();
  10748. this.setPlaybackStateChangeListener();
  10749. this.isCastPlaying = true;
  10750. this.castSeek = true;
  10751. }
  10752. public endCasting() {
  10753. this.avSessionController.getAvSession()?.stopCasting();
  10754. this.stopCast();
  10755. this.isCastPlaying = false;
  10756. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  10757. refToIsCasting?.set(false);
  10758. this.pause();
  10759. this.setIsPlaying(false);
  10760. // if (this.curIndex === this.curSource.index) {
  10761. // this.play
  10762. // this.seek(this.currentTime * 1000);
  10763. // this.setIsPlaying(true);
  10764. // } else {
  10765. // this.pauseVideo();
  10766. // this.setIsPlaying(false);
  10767. // }
  10768. }
  10769. public setIsPlaying(isPlayer: boolean) {
  10770. this.isPlaying = isPlayer;
  10771. // 发送播放状态变化事件给歌单详情页面
  10772. try {
  10773. const eventPlaybackStatus: emitter.InnerEvent = { eventId: EventConstants.EVENT_PLAYBACK_STATUS }
  10774. const currentFilePath = this.currentSong?.filePath || ''
  10775. const eventData: emitter.EventData = {
  10776. data: {
  10777. isPlaying: this.isPlaying,
  10778. curIndex: this.curIndex,
  10779. currentFilePath: currentFilePath
  10780. }
  10781. };
  10782. emitter.emit(eventPlaybackStatus, eventData)
  10783. Logger.info(`heanup 发送播放状态变化事件: isPlaying=${this.isPlaying}, curIndex=${this.curIndex}, currentFilePath=${currentFilePath}`)
  10784. } catch (error) {
  10785. Logger.error('heanup 发送播放状态变化事件失败: ' + error)
  10786. }
  10787. }
  10788. private setPlaybackStateChangeListener(): void {
  10789. this.castController?.on('playbackStateChange', 'all', this.playbackStateChangeListener);
  10790. this.castController?.on('endOfStream', this.reloadCasting);
  10791. this.castController?.on('playNext', this.playNextCallback);
  10792. this.castController?.on('playPrevious', this.playPreviousCallback);
  10793. }
  10794. private updateSessionPlayState(isPlay: boolean): void {
  10795. // if(!this.isBgPlayOpen)
  10796. // return
  10797. Logger.info(TAG, `updateIsPlay isPlay: ${isPlay}`);
  10798. this.setAVSessionPlayState({
  10799. state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
  10800. position: {
  10801. elapsedTime: this.mIjkMediaPlayer.getCurrentPosition(),
  10802. updateTime: new Date().getTime()
  10803. }
  10804. });
  10805. }
  10806. private setAVSessionPlayState(playbackState: avSession.AVPlaybackState): void {
  10807. this.avSessionController.setAvSessionPlayState(playbackState)
  10808. }
  10809. private positionChange(position: number) {
  10810. this.currentTime2 = position / 1000;
  10811. this.currentStringTime = secondToTime(Math.floor(position / 1000));
  10812. }
  10813. private playDurationChange(duration: number) {
  10814. this.duration = duration;
  10815. this.durationTime = Math.floor(this.duration / 1000);
  10816. this.durationStringTime = secondToTime((this.durationTime));
  10817. }
  10818. private playbackStateChangeListener = (playbackState: avSession.AVPlaybackState) => {
  10819. const duration = playbackState?.extras?.duration;
  10820. if (typeof duration === 'number') {
  10821. this.playDurationChange(duration as number);
  10822. }
  10823. if (typeof playbackState?.position?.elapsedTime !== 'undefined') {
  10824. this.positionChange(playbackState?.position?.elapsedTime);
  10825. }
  10826. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PAUSE ||
  10827. playbackState.state === CommonConstants2.PLAYBACK_STATE_STOP ||
  10828. playbackState.state === CommonConstants2.PLAYBACK_STATE_PREPARE ||
  10829. playbackState.state === CommonConstants2.PLAYBACK_STATE_INITIAL) {
  10830. this.isCastPlaying = false;
  10831. }
  10832. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PLAY) {
  10833. this.isCastPlaying = true;
  10834. }
  10835. };
  10836. private reloadCasting = async () => {
  10837. let item = this.songList[this.curIndex];
  10838. let uri = fileUri.getUriFromPath(item.filePath);
  10839. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  10840. // description.startPosition = 0;
  10841. this.castItem = {
  10842. itemId: this.curIndex,
  10843. description: {
  10844. assetId: item.filePath,
  10845. title: item.name,
  10846. artist: '',
  10847. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  10848. // mediaUri: item.filePath,
  10849. fdSrc: {
  10850. fd: file.fd
  10851. },
  10852. // 该字段大写,音频'AUDIO',视频'VIDEO'
  10853. mediaType: 'VIDEO',
  10854. mediaSize: item.videoSize,
  10855. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  10856. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  10857. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  10858. duration: this.duration,
  10859. // albumCoverUri: 'https://www.example.jpeg',
  10860. // albumTitle: '《ExampleAlbum》',
  10861. appName: this.appName,
  10862. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  10863. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  10864. }
  10865. };
  10866. this.prepare();
  10867. this.isCastPlaying = true;
  10868. };
  10869. public playNextCallback = (): void => {
  10870. this.playNext()
  10871. };
  10872. public playPreviousCallback = (): void => {
  10873. this.playPrevious()
  10874. };
  10875. async prepare() {
  10876. await this.castController?.prepare(this.castItem);
  10877. await this.castController?.start(this.castItem);
  10878. }
  10879. public initQueueItem() {
  10880. let item = this.songList[this.curIndex];
  10881. let time = this.currentTime;
  10882. let uri = fileUri.getUriFromPath(item.filePath);
  10883. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  10884. this.castItem = {
  10885. itemId: this.curIndex,
  10886. description: {
  10887. assetId: item.filePath,
  10888. title: item.name,
  10889. artist: '',
  10890. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  10891. fdSrc: {
  10892. fd: file.fd
  10893. },
  10894. // 该字段大写,音频'AUDIO',视频'VIDEO'
  10895. mediaType: 'AUDIO',
  10896. mediaSize: item.videoSize,
  10897. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  10898. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  10899. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  10900. duration: this.duration,
  10901. // albumCoverUri: 'https://www.example.jpeg',
  10902. // albumTitle: '《ExampleAlbum》',
  10903. appName: this.appName,
  10904. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  10905. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  10906. }
  10907. };
  10908. }
  10909. async stopCast() {
  10910. try {
  10911. this.castController?.off('playbackStateChange');
  10912. this.castController?.off('endOfStream');
  10913. this.castController?.off('playNext');
  10914. this.castController?.off('playPrevious');
  10915. this.castController?.off('error');
  10916. } catch (error) {
  10917. hilog.info(0x0000, TAG, `Failed to setAVCastController. code: ${error.code}, message: ${error.message}`);
  10918. }
  10919. }
  10920. private sessionPlayCallback = (): void => {
  10921. console.info('onecold playOrPause 11050')
  10922. this.playOrPause()
  10923. };
  10924. private sessionPauseCallback = (): void => {
  10925. console.info('onecold playOrPause 11054')
  10926. this.pause()
  10927. };
  10928. private playOrPause() {
  10929. if (!this.debounce()) {
  10930. return;
  10931. }
  10932. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  10933. this.pause();
  10934. } else {
  10935. console.info('onecold startPlayOrResumePlay 11064')
  10936. this.startPlayOrResumePlay();
  10937. this.playChange()
  10938. }
  10939. }
  10940. private sessionPlayNextCallback = (): void => {
  10941. this.playNext()
  10942. };
  10943. private sessionPlayPreviousCallback = (): void => {
  10944. this.playPrevious()
  10945. };
  10946. private sessionStopCallback = (): void => {
  10947. this.stop()
  10948. };
  10949. private sessionFastForwardCallback = (time?: number) => {
  10950. if (!time) {
  10951. return;
  10952. }
  10953. if (this.mIjkMediaPlayer != null) {
  10954. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  10955. let seeTime = curPosition + time * 1000;
  10956. // 限制 seekValue 在合法范围内
  10957. if (seeTime < 0) {
  10958. seeTime = 0;
  10959. } else if (seeTime > this.duration) {
  10960. seeTime = this.duration;
  10961. }
  10962. Logger.info('onecold seeTime= ' + seeTime)
  10963. this.setSeekToActionProgress(seeTime)
  10964. this.seekTo(seeTime + "")
  10965. }
  10966. };
  10967. /**
  10968. * Gesture method onActionUpdate.
  10969. *
  10970. * @param event Gesture event.手势拖动设置快进和后退
  10971. */
  10972. private setSeekToActionProgress(position: number) {
  10973. // let position = this.mIjkMediaPlayer.getCurrentPosition();
  10974. let duration = this.mIjkMediaPlayer.getDuration();
  10975. let pos = 0;
  10976. if (duration > 0) {
  10977. this.slideEnable = true;
  10978. let curPercent = position / duration;
  10979. pos = curPercent * 100;
  10980. if (pos > this.PROGRESS_MAX_VALUE) {
  10981. this.progressValue = this.PROGRESS_MAX_VALUE
  10982. } else {
  10983. this.progressValue = pos;
  10984. }
  10985. }
  10986. // LogUtils.getInstance()
  10987. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  10988. this.totalTime = this.stringForTime(duration);
  10989. if (position > duration) {
  10990. position = duration;
  10991. }
  10992. this.isCurrentTime = true;
  10993. this.currentTime = this.stringForTime(position);
  10994. this.isCurrentTime = false
  10995. }
  10996. private sessionRewindCallback = (time?: number) => {
  10997. if (!time) {
  10998. return;
  10999. }
  11000. if (this.mIjkMediaPlayer != null) {
  11001. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  11002. let seeTime = curPosition - time * 1000;
  11003. // 限制 seekValue 在合法范围内
  11004. if (seeTime < 0) {
  11005. seeTime = 0;
  11006. } else if (seeTime > this.duration) {
  11007. seeTime = this.duration;
  11008. }
  11009. Logger.info('onecold seeTime= ' + seeTime)
  11010. this.setSeekToActionProgress(seeTime)
  11011. this.seekTo(seeTime + "")
  11012. }
  11013. };
  11014. private sessionSeekCallback = (seekTime: number) => {
  11015. if (this.mIjkMediaPlayer != null) {
  11016. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  11017. this.seekTo(seekTime + "")
  11018. }
  11019. };
  11020. private async getFileSize(filePath: string): Promise<number> {
  11021. try {
  11022. const stat = await fs.stat(filePath);
  11023. return stat.size;
  11024. } catch (err) {
  11025. console.error('Failed to get file size: ' + err.message);
  11026. return 0;
  11027. }
  11028. }
  11029. private pause() {
  11030. if (this.mIjkMediaPlayer.isPlaying()) {
  11031. this.savePlaybackPosition();
  11032. this.mIjkMediaPlayer.pause();
  11033. this.setProgress();
  11034. this.mDestroyPage = true;
  11035. this.CONTROL_PlayStatus = PlayStatus.PAUSE;
  11036. this.updateSessionPlayState(false)
  11037. this.playChange()
  11038. if (this.pipController) {
  11039. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  11040. PiPWindow.PiPControlStatus.PAUSE);
  11041. }
  11042. }
  11043. }
  11044. private stop() {
  11045. this.savePlaybackPosition();
  11046. this.CONTROL_PlayStatus = PlayStatus.INIT;
  11047. this.mIjkMediaPlayer.stop();
  11048. this.mIjkMediaPlayer.release();
  11049. this.stopProgressTask();
  11050. this.updateSessionPlayState(false)
  11051. this.playChange()
  11052. this.watchStatus();
  11053. }
  11054. //保持记忆播放功能
  11055. private savePlaybackPosition() {
  11056. if (this.mIjkMediaPlayer != null) {
  11057. const position = this.mIjkMediaPlayer.getCurrentPosition();
  11058. // ToastUtil.showToast('保存记忆播放 = ' + position)
  11059. const duration = this.mIjkMediaPlayer.getDuration();
  11060. const threshold = 5000; // 阈值,单位为毫秒(这里设为5秒)
  11061. // 如果播放位置接近视频末尾,则保存 position 为 0
  11062. const playbackPosition = (duration - position < threshold) ? 0 : position;
  11063. PreferencesUtil.putSync(this.videoUrl, playbackPosition);
  11064. }
  11065. }
  11066. //获取记忆播放功能
  11067. private restorePlaybackPosition() {
  11068. const position: number = PreferencesUtil.getNumberSync(this.videoUrl, 0);
  11069. // ToastUtil.showToast('position = ' + position)
  11070. if (this.mIjkMediaPlayer != null && position > 0) {
  11071. // ToastUtil.showToast('seekTo = ' + position)
  11072. this.seekTo(position + "");
  11073. }
  11074. }
  11075. private seekTo(value: string) {
  11076. if (StrUtil.isNotEmpty(this.videoUrl) && this.videoUrl.toLowerCase().endsWith('.wma')) {
  11077. ToastUtil.showToast('wma格式不支持拖动快进。')
  11078. return
  11079. }
  11080. this.isSeekTo = true
  11081. this.mIjkMediaPlayer.seekTo(value);
  11082. console.info('onecold startPlayOrResumePlay 11227')
  11083. // this.startPlayOrResumePlay()
  11084. // 在这里恢复计时器状态
  11085. this.setProgress()
  11086. this.isSeekTo = false
  11087. }
  11088. // 添加到下一首播放
  11089. private addToNextPlay(song: VideoItem) {
  11090. if (!this.debounce()) {
  11091. return;
  11092. }
  11093. if (this.currentSong) {
  11094. if (this.currentSong === song) {
  11095. ToastUtil.showToast('当前已经在播放这首歌了!')
  11096. return
  11097. }
  11098. }
  11099. // 如果未开始播放或队列为空
  11100. if (this.curIndex === -1 || this.songList.length === 0) {
  11101. this.songList = [song];
  11102. this.curIndex = 0;
  11103. this.doPlay(song)
  11104. return;
  11105. }
  11106. // 插入到当前索引+1的位置
  11107. const insertPos = this.curIndex + 1;
  11108. this.songList.splice(insertPos, 0, song);
  11109. this.songList = [...this.songList]; // 触发状态更新
  11110. this.sonDataSource.pushArrayData(this.songList)
  11111. ToastUtil.showToast('已添加至下一首播放')
  11112. }
  11113. //后退10s,可再设置设置默认几秒
  11114. backForward() {
  11115. if(this.mIjkMediaPlayer){
  11116. let pos = this.mIjkMediaPlayer.getCurrentPosition();
  11117. let value = pos - Number(this.fastForwardSeconds) * 1000;
  11118. this.seekTo(value+"");
  11119. }
  11120. }
  11121. //快进10s,可再设置设置默认几秒
  11122. fastForward() {
  11123. if(this.mIjkMediaPlayer){
  11124. let pos = this.mIjkMediaPlayer.getCurrentPosition();
  11125. let value = pos + Number(this.fastForwardSeconds) * 1000;
  11126. this.seekTo(value+"");
  11127. }
  11128. }
  11129. //下一个
  11130. private playNext() {
  11131. if (!this.debounce()) {
  11132. return;
  11133. }
  11134. if (this.playType == 3) { //3:随机播放
  11135. this.randomPlay()
  11136. return;
  11137. }
  11138. if (ArrayUtil.isNotEmpty(this.songList)) {
  11139. if (this.curIndex == this.songList.length - 1) {
  11140. this.curIndex = 0;
  11141. } else {
  11142. this.curIndex++;
  11143. }
  11144. this.CONTROL_PlayStatus = PlayStatus.INIT;
  11145. this.stop();
  11146. this.currentSong = this.songList[this.curIndex]
  11147. this.videoUrl = this.songList[this.curIndex].filePath;
  11148. this.artist = this.songList[this.curIndex].artist
  11149. this.name = this.songList[this.curIndex].name
  11150. //this.cover = this.songList[this.curIndex].pixelMapPath
  11151. this.changeImageAnimation()
  11152. }
  11153. }
  11154. changeImageAnimation() {
  11155. if(this.openSkipSongAnimate){
  11156. // 第一步:淡出动画
  11157. this.getUIContext()?.animateTo({
  11158. duration: 500,
  11159. curve: Curve.EaseOut,
  11160. }, () => {
  11161. this.opacityValueImage = 0.1;
  11162. if(this.isCoverRectangle){
  11163. this.scaleValueImage = 0.88
  11164. }
  11165. });
  11166. // 第二步:切换图片后淡入
  11167. setTimeout(() => {
  11168. this.cover = this.songList[this.curIndex].pixelMapPath
  11169. this.getUIContext()?.animateTo({
  11170. duration: 500,
  11171. curve: Curve.EaseIn,
  11172. }, () => {
  11173. this.opacityValueImage = 1;
  11174. this.scaleValueImage = 1 // 图标恢复到原始大小
  11175. this.startPlayOrResumePlay()
  11176. });
  11177. }, 500);
  11178. }else{
  11179. this.cover = this.songList[this.curIndex].pixelMapPath
  11180. this.startPlayOrResumePlay()
  11181. }
  11182. }
  11183. // 存储已播放的歌曲索引
  11184. private playedIndices: Set<number> = new Set();
  11185. //随机播放
  11186. private randomPlay() {
  11187. // if (!this.debounce()) {
  11188. // return;
  11189. // }
  11190. if (ArrayUtil.isNotEmpty(this.songList)) {
  11191. if (this.songList.length > 3) {
  11192. // 如果所有歌曲都播放过一次,清空已播放索引集合
  11193. if (this.playedIndices.size === this.songList.length) {
  11194. this.playedIndices.clear();
  11195. }
  11196. // 随机选择一个未播放的歌曲索引
  11197. let newIndex: number;
  11198. // 添加超时机制防止无限循环
  11199. let attempt = 0;
  11200. const maxAttempts = 100; // 根据需求调整
  11201. do {
  11202. newIndex = RandomUtil.getRandomNumber(0, this.songList.length - 1);
  11203. attempt++;
  11204. } while (this.playedIndices.has(newIndex) && attempt < maxAttempts);
  11205. if (attempt >= maxAttempts) {
  11206. // 处理无法找到新索引的情况(如随机选择或按顺序播放)
  11207. newIndex = Math.floor(Math.random() * this.songList.length);
  11208. }
  11209. this.curIndex = newIndex;
  11210. this.playedIndices.add(newIndex);
  11211. } else {
  11212. // 当歌曲数量小于或等于3时,直接播放下一首
  11213. if (this.curIndex == this.songList.length - 1) {
  11214. this.curIndex = 0;
  11215. } else {
  11216. this.curIndex++;
  11217. }
  11218. }
  11219. this.CONTROL_PlayStatus = PlayStatus.INIT;
  11220. this.stop();
  11221. this.currentSong = this.songList[this.curIndex];
  11222. this.videoUrl = this.songList[this.curIndex].filePath;
  11223. this.name = this.songList[this.curIndex].name;
  11224. this.artist = this.songList[this.curIndex].artist
  11225. // this.cover = this.songList[this.curIndex].pixelMapPath
  11226. this.changeImageAnimation()
  11227. }
  11228. }
  11229. private playIndex(index: number) {
  11230. if (!this.debounce()) {
  11231. return;
  11232. }
  11233. if (ArrayUtil.isNotEmpty(this.songList)) {
  11234. this.CONTROL_PlayStatus = PlayStatus.INIT;
  11235. this.stop();
  11236. this.currentSong = this.songList[this.curIndex]
  11237. this.videoUrl = this.songList[index].filePath;
  11238. this.name = this.songList[index].name
  11239. this.artist = this.songList[this.curIndex].artist
  11240. this.curIndex = index;
  11241. this.changeImageAnimation()
  11242. }
  11243. }
  11244. //上一个
  11245. private playPrevious() {
  11246. if (!this.debounce()) {
  11247. return;
  11248. }
  11249. if (this.playType == 3) { //3:随机播放的上一首应该应该播放历史记录的第二首
  11250. this.randomModePlayFromHistory()
  11251. return;
  11252. }
  11253. if (this.curIndex == 0) {
  11254. this.curIndex = this.songList.length - 1;
  11255. } else {
  11256. this.curIndex--;
  11257. }
  11258. this.CONTROL_PlayStatus = PlayStatus.INIT;
  11259. this.stop();
  11260. this.currentSong = this.songList[this.curIndex]
  11261. this.videoUrl = this.songList[this.curIndex].filePath;
  11262. this.name = this.songList[this.curIndex].name
  11263. this.artist = this.songList[this.curIndex].artist
  11264. this.changeImageAnimation()
  11265. }
  11266. //随机播放模式下点击上一首: 上一首应该应该播放历史记录的第二首
  11267. private randomModePlayFromHistory() {
  11268. if (this.historyList.length >= 2) {
  11269. // 播放历史记录的第二首
  11270. const prevSong = this.historyList[1];
  11271. this.curIndex = this.songList.findIndex(song => song.filePath === prevSong.filePath);
  11272. this.CONTROL_PlayStatus = PlayStatus.INIT;
  11273. this.stop();
  11274. this.currentSong = prevSong;
  11275. this.videoUrl = prevSong.filePath;
  11276. this.cover = prevSong.pixelMapPath
  11277. this.artist = prevSong.artist
  11278. this.name = prevSong.name;
  11279. console.info('onecold startPlayOrResumePlay 11434')
  11280. this.startPlayOrResumePlay();
  11281. } else {
  11282. // 如果历史记录不足两首,可根据需求处理,这里简单按普通逻辑处理
  11283. if (this.curIndex === 0) {
  11284. this.curIndex = this.songList.length - 1;
  11285. } else {
  11286. this.curIndex--;
  11287. }
  11288. this.CONTROL_PlayStatus = PlayStatus.INIT;
  11289. this.stop();
  11290. this.currentSong = this.songList[this.curIndex];
  11291. this.videoUrl = this.songList[this.curIndex].filePath;
  11292. this.artist = this.songList[this.curIndex].artist
  11293. this.name = this.songList[this.curIndex].name;
  11294. this.changeImageAnimation()
  11295. }
  11296. }
  11297. debounce() {
  11298. const delay = 600;
  11299. let cur = new Date().getTime();
  11300. if (cur - this.last > delay) {
  11301. this.last = cur;
  11302. return true;
  11303. }
  11304. return false;
  11305. }
  11306. /**
  11307. * Sets whether the screen is a constant based on the playback status.
  11308. */
  11309. watchStatus() {
  11310. // let windowClass = GlobalContext.getContext().getObject('windowClass') as window.Window;
  11311. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  11312. this.windowClass.setWindowKeepScreenOn(true);
  11313. } else {
  11314. this.windowClass.setWindowKeepScreenOn(false);
  11315. }
  11316. }
  11317. /**
  11318. * Volume gesture method onActionStart.
  11319. *
  11320. * @param event Gesture event.
  11321. */
  11322. private customDialogComponentIdMM: number = 0
  11323. @Builder
  11324. customDialogComponentMM() {
  11325. Column() {
  11326. Row() {
  11327. Blank()
  11328. Text('验证密码')
  11329. .fontSize(22)
  11330. .fontColor($r('app.color.pri_bg'))
  11331. .margin({ top: 18 })
  11332. Blank()
  11333. Image($r('app.media.close'))
  11334. .fillColor(Color.White)
  11335. .margin({ top: 18, right: 18 })
  11336. .width(20)
  11337. .onClick(() => {
  11338. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  11339. })
  11340. }
  11341. .width('100%') // 使Row占据整个宽度
  11342. .justifyContent(FlexAlign.SpaceBetween); // 在Row中创建空间
  11343. Verify({
  11344. onVerifyCompleted: this.handleVerifyCompleted.bind(this)
  11345. });
  11346. }.height('60%')
  11347. .backgroundColor($r('app.color.index_background'))
  11348. .justifyContent(FlexAlign.SpaceBetween)
  11349. }
  11350. private handleVerifyCompleted(isSuccess: boolean) {
  11351. if (isSuccess) {
  11352. console.log('验证成功');
  11353. // 在这里处理验证成功后的逻辑
  11354. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  11355. this.currentPath = this.lockPath
  11356. this.getSortedFiles(this.currentPath)
  11357. } else {
  11358. // console.log('验证失败');
  11359. ToastUtil.showToast('验证失败')
  11360. }
  11361. }
  11362. private showVerifyDialog() {
  11363. promptAction.openCustomDialog({
  11364. transition: TransitionEffect.asymmetric(
  11365. TransitionEffect.OPACITY.animation({ duration: 888 }).combine(
  11366. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  11367. ,
  11368. TransitionEffect.OPACITY.animation({ delay: 888, duration: 888 }).combine(
  11369. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  11370. ),
  11371. builder: () => {
  11372. this.customDialogComponentMM()
  11373. },
  11374. isModal: true,
  11375. autoCancel: true,
  11376. maskColor: Color.Transparent,
  11377. alignment: DialogAlignment.Bottom,
  11378. onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
  11379. console.info("reason" + JSON.stringify(dismissDialogAction.reason))
  11380. console.log("dialog onWillDismiss")
  11381. if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
  11382. dismissDialogAction.dismiss()
  11383. }
  11384. if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
  11385. dismissDialogAction.dismiss()
  11386. }
  11387. }
  11388. }).then((dialogId: number) => {
  11389. this.customDialogComponentIdMM = dialogId
  11390. })
  11391. }
  11392. //左滑操作 移动文件 重命名 删除等操作
  11393. @Builder
  11394. DeleteButton(item: VideoItem, index: number, filePath: string) {
  11395. Row() {
  11396. //加入收藏
  11397. Button() {
  11398. Image(Utility.getIsFav(this.favList, item) ? $r('app.media.add_fac_light2') : $r('app.media.add_fac'))
  11399. .fillColor(Color.White)
  11400. .width(20)
  11401. }
  11402. .width(40)
  11403. .height(40)
  11404. .type(ButtonType.Circle)
  11405. .backgroundColor(this.themeColor)
  11406. .margin(5)
  11407. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  11408. .onClick(() => {
  11409. if (item) {
  11410. this.doFav(item)
  11411. }
  11412. })
  11413. //加入下一首播放
  11414. Button() {
  11415. Image($r('app.media.next_to_play'))
  11416. .fillColor(Color.White)
  11417. .width(20)
  11418. }
  11419. .width(40)
  11420. .height(40)
  11421. .type(ButtonType.Circle)
  11422. .backgroundColor(this.themeColor)
  11423. .margin(5)
  11424. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  11425. .onClick(() => {
  11426. this.addToNextPlay(item);
  11427. })
  11428. //复制文件
  11429. Button() {
  11430. Image($r('app.media.copy'))
  11431. .fillColor(Color.White)
  11432. .width(20)
  11433. }
  11434. .width(40)
  11435. .height(40)
  11436. .type(ButtonType.Circle)
  11437. .backgroundColor(this.themeColor)
  11438. .margin(5)
  11439. .id(filePath + 'copy')
  11440. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  11441. .onClick(() => {
  11442. this.showCopyDialog(false, item, index, filePath + 'copy');
  11443. })
  11444. //移动文件
  11445. Button() {
  11446. Image($r('app.media.cut'))
  11447. .fillColor(Color.White)
  11448. .width(20)
  11449. }
  11450. .width(40)
  11451. .height(40)
  11452. .type(ButtonType.Circle)
  11453. .backgroundColor(this.themeColor)
  11454. .margin(5)
  11455. .id(filePath)
  11456. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  11457. .onClick(() => {
  11458. this.showCutDialog(false, item, index, filePath);
  11459. })
  11460. Button() {
  11461. Image($r('app.media.cut_current'))
  11462. .fillColor(Color.White)
  11463. .width(20)
  11464. }
  11465. .width(40)
  11466. .height(40)
  11467. .type(ButtonType.Circle)
  11468. .backgroundColor(this.themeColor)
  11469. .margin(5)
  11470. .id(filePath + 'current')
  11471. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None :
  11472. (this.isHasDir ? Visibility.Visible : Visibility.None))
  11473. .onClick(() => {
  11474. this.showCutDialog(true, item, index, filePath + 'current');
  11475. })
  11476. //重命名
  11477. Button() {
  11478. Image($r('app.media.rename2'))
  11479. .fillColor(Color.White)
  11480. .width(20)
  11481. }
  11482. .width(40)
  11483. .height(40)
  11484. .type(ButtonType.Circle)
  11485. .backgroundColor(this.themeColor)
  11486. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  11487. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  11488. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  11489. .margin(5)
  11490. .onClick(() => {
  11491. this.showReNameDialog(item, index + '', filePath)
  11492. })
  11493. Button() {
  11494. Image($r('app.media.delete2'))
  11495. .fillColor(Color.White)
  11496. .width(20)
  11497. }
  11498. .width(40)
  11499. .height(40)
  11500. .type(ButtonType.Circle)
  11501. .backgroundColor(this.themeColor)
  11502. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  11503. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  11504. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  11505. .margin(5)
  11506. .onClick(() => {
  11507. this.selectedFiles.push(item)
  11508. this.showWarnIsDelete()
  11509. // this.showWarnIsDeleteFile(item, index + '', filePath)
  11510. })
  11511. Button() {
  11512. Image($r('app.media.share2'))
  11513. .fillColor(Color.White)
  11514. .width(20)
  11515. }
  11516. .width(40)
  11517. .height(40)
  11518. .type(ButtonType.Circle)
  11519. .backgroundColor(this.themeColor)
  11520. .margin(5)
  11521. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  11522. .onClick(() => {
  11523. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  11524. })
  11525. }
  11526. }
  11527. /**
  11528. * 穿山甲banner广告
  11529. */
  11530. // private declare bannerAd: CSJNativeExpressAd;
  11531. // @State private status: string = "未加载"
  11532. // @State private isShowAd: boolean = false
  11533. // private declare mAdSlot: AdSlot;
  11534. // private mBiddingAdm = '' //服务端bidding才需要设置
  11535. // private expressLoadAdListener: NativeExpressAdListener = {
  11536. // /**
  11537. // * 加载失败的回调
  11538. // *
  11539. // * @param code
  11540. // * @param message
  11541. // */
  11542. // onError: (code: number, message: string) => {
  11543. // console.error("加载广告失败,code=" + code + ",message=" + message);
  11544. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  11545. // },
  11546. //
  11547. // /**
  11548. // * 广告加载成功的回调,接入方可以在这个回调中进行渲染
  11549. // *
  11550. // * @param ads 返回的广告列表
  11551. // */
  11552. //
  11553. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  11554. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  11555. // if (ads && ads.length > 0) {
  11556. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  11557. // ad.setExpressInteractionListener({
  11558. // /**
  11559. // *广告的点击回调
  11560. // * @param type 广告的交互类型
  11561. // */
  11562. // onAdClicked: (type: number) => {
  11563. // console.log("BannerExpressAdPage==onAdClicked......");
  11564. // },
  11565. //
  11566. // /**
  11567. // * 广告的展示回调 每个广告仅回调一次
  11568. // * @param type 广告的交互类型
  11569. // */
  11570. // onAdShow: (type: number) => {
  11571. // console.log("BannerExpressAdPage==onAdShow......");
  11572. // },
  11573. //
  11574. // /**
  11575. // * 模板渲染失败
  11576. // */
  11577. // onRenderFail: (code: number, msg: string) => {
  11578. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  11579. // },
  11580. //
  11581. // /**
  11582. // * 模板渲染成功
  11583. // * @param width 返回view的宽 单位 vp
  11584. // * @param height 返回view的高 单位 vp
  11585. // */
  11586. // onRenderSuccess: (width: number, height: number) => {
  11587. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  11588. // this.bannerAd = ad;
  11589. // this.status = "广告加载完成待展示";
  11590. //
  11591. // this.showBannerAd()
  11592. // }
  11593. // })
  11594. // //渲染广告
  11595. // ad.setSlideIntervalTime(30 * 1000); //设置轮播时间长
  11596. // this.setDislikeCallback(ad); //设置dislike
  11597. // ad.render(this.getUIContext())
  11598. // this.status = "广告加载中...";
  11599. // });
  11600. // }
  11601. // }
  11602. // }
  11603. //
  11604. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  11605. // ad.setDislikeCallback({
  11606. // /**
  11607. // * dislike show
  11608. // */
  11609. // onShow: () => {
  11610. // console.log("BannerExpressAdPage==dislike......show");
  11611. // },
  11612. //
  11613. // /**
  11614. // * @param position 选择的位置
  11615. // * @param value 选择的内容
  11616. // * @param enforceRemove 是否强制关闭广告
  11617. // */
  11618. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  11619. // this.isShowAd = false;
  11620. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value +
  11621. // ",enforce=" + enforceRemove);
  11622. // },
  11623. //
  11624. // /**
  11625. // * 点击取消
  11626. // */
  11627. // onCancel: () => {
  11628. // console.log("BannerExpressAdPage==dislike......onCancel");
  11629. // }
  11630. //
  11631. // })
  11632. // }
  11633. /**
  11634. * 加载Banner广告
  11635. */
  11636. loadBannerAd(rit: string) {
  11637. // if (Utility.isNoble()) {
  11638. // return
  11639. // }
  11640. // if (!Utility.isPassInstallTime(2)) {
  11641. // return
  11642. // }
  11643. // this.isShowAd = false;
  11644. // let adCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
  11645. // this.mAdSlot = new AdSlotBuilder()
  11646. // .setCodeId(rit)
  11647. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  11648. // .setAdCount(1)
  11649. // .setBidAdm(this.mBiddingAdm)
  11650. // .build()
  11651. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  11652. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  11653. // this.status = "广告加载中..."
  11654. }
  11655. /**
  11656. * 展示Banner广告
  11657. */
  11658. // showBannerAd() {
  11659. // if (!this.bannerAd) {
  11660. // return
  11661. // }
  11662. // this.isShowAd = true
  11663. // this.status = "已展示"
  11664. // }
  11665. /**
  11666. * 穿山甲广告代码结束
  11667. */
  11668. /**
  11669. * 处理歌单播放请求
  11670. */
  11671. private handlePlaylistPlayRequest(playlistId: string, playlistName: string, songFilePaths: string[], startIndex: number) {
  11672. try {
  11673. Logger.info(`heanup 处理歌单播放请求: ${playlistName}, 歌曲数量: ${songFilePaths.length}, 开始索引: ${startIndex}`)
  11674. // 从数据库重新加载这些歌曲,使用索引记录位置以保持顺序
  11675. const songMap: Map<number, VideoItem> = new Map()
  11676. let completedQueries = 0
  11677. Logger.info(`heanup 开始从数据库查询 ${songFilePaths.length} 首歌曲`)
  11678. // 遍历所有文件路径,使用索引记录位置
  11679. for (let i = 0; i < songFilePaths.length; i++) {
  11680. const filePath = songFilePaths[i]
  11681. const index = i
  11682. Logger.info(`heanup 正在查询歌曲[${index}]: ${filePath}`)
  11683. // 使用已初始化的MediaTable实例从数据库查询歌曲信息
  11684. const queryPromise = this.table.queryVideoByFilePath(filePath)
  11685. Logger.info(`heanup 创建了查询Promise,开始等待结果[${index}]: ${filePath}`)
  11686. queryPromise.then((videoItem) => {
  11687. completedQueries++
  11688. Logger.info(`heanup 查询Promise返回结果[${index}]: ${filePath}, 找到歌曲: ${videoItem ? videoItem.name : 'null'}`)
  11689. if (videoItem) {
  11690. // 使用索引作为key保存到Map中,保持原始顺序
  11691. songMap.set(index, videoItem)
  11692. Logger.info(`heanup 从数据库找到歌曲[${index}]: ${videoItem.name} (${completedQueries}/${songFilePaths.length})`)
  11693. } else {
  11694. Logger.warn(`heanup 数据库中未找到歌曲[${index}]: ${filePath} (${completedQueries}/${songFilePaths.length})`)
  11695. }
  11696. // 检查是否所有歌曲都已加载完成
  11697. if (completedQueries === songFilePaths.length) {
  11698. Logger.info(`heanup 所有数据库查询完成,共找到 ${songMap.size} 首歌曲`)
  11699. // 按照索引顺序重建歌曲数组
  11700. const songs: VideoItem[] = []
  11701. for (let j = 0; j < songFilePaths.length; j++) {
  11702. const song = songMap.get(j)
  11703. if (song) {
  11704. songs.push(song)
  11705. Logger.info(`heanup 按顺序添加歌曲[${j}]: ${song.name}`)
  11706. }
  11707. }
  11708. Logger.info(`heanup 最终歌曲列表顺序: ${songs.map((s, idx) => `[${idx}]${s.name}`).join(', ')}`)
  11709. this.finishLoadingPlaylist(songs, startIndex, playlistName)
  11710. }
  11711. }).catch((error: Error) => {
  11712. completedQueries++
  11713. Logger.error(`heanup 查询歌曲失败[${index}]: ${filePath}, 错误: ${error.message} (${completedQueries}/${songFilePaths.length})`)
  11714. // 即使出错也要检查是否完成所有查询
  11715. if (completedQueries === songFilePaths.length) {
  11716. Logger.info(`heanup 所有数据库查询完成(包含错误),共找到 ${songMap.size} 首歌曲`)
  11717. // 按照索引顺序重建歌曲数组
  11718. const songs: VideoItem[] = []
  11719. for (let j = 0; j < songFilePaths.length; j++) {
  11720. const song = songMap.get(j)
  11721. if (song) {
  11722. songs.push(song)
  11723. }
  11724. }
  11725. this.finishLoadingPlaylist(songs, startIndex, playlistName)
  11726. }
  11727. })
  11728. }
  11729. } catch (error) {
  11730. Logger.error('heanup 处理简化歌单播放请求失败: ' + error)
  11731. ToastUtil.showToast('播放失败')
  11732. }
  11733. }
  11734. /**
  11735. * 完成歌单加载并开始播放
  11736. */
  11737. private finishLoadingPlaylist(songs: VideoItem[], startIndex: number, playlistName: string) {
  11738. if (songs.length === 0) {
  11739. Logger.error('heanup 没有找到任何可播放的歌曲')
  11740. ToastUtil.showToast('没有找到可播放的歌曲')
  11741. return
  11742. }
  11743. this.songList = songs
  11744. this.sonDataSource.pushArrayData(songs)
  11745. this.sonDataSource.notifyDataReload()
  11746. this.curIndex = startIndex
  11747. if (songs[startIndex]) {
  11748. // 确保当前播放的歌曲也更新到存储
  11749. AppStorage.setOrCreate('currentSong', songs[startIndex])
  11750. // 设置isFromSonPlayList=true,避免doPlay方法重新从全局列表构建播放列表
  11751. this.doPlay(songs[startIndex], startIndex, true)
  11752. }
  11753. PreferencesUtil.putSync('LastMusicList', this.songList)
  11754. ToastUtil.showToast(`开始播放歌单: ${playlistName}`)
  11755. }
  11756. }
  11757. //视频气泡窗口的布局
  11758. @Builder
  11759. function customPopupBuilder(dataBu: BubbleBean) {
  11760. List() {
  11761. LazyForEach(new LazyDataSource(dataBu.data), (item: string, index: number) => {
  11762. ListItem() {
  11763. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  11764. Row() {
  11765. Column() {
  11766. Image(dataBu.imageRes[index])
  11767. .height(28)
  11768. .fillColor(dataBu.color)
  11769. .alignSelf(ItemAlign.Center)
  11770. }
  11771. .width(32)
  11772. Text(item)
  11773. .padding({
  11774. top: 10,
  11775. bottom: 10,
  11776. right: 10,
  11777. left: 10
  11778. })
  11779. .fontColor(dataBu.modeType == index ? dataBu.color : $r('app.color.index_tab_font_color'))
  11780. .textAlign(TextAlign.Start)
  11781. .width("100%")
  11782. }
  11783. }
  11784. .backgroundColor($r('app.color.settings_background_main'))
  11785. .margin({ top: 6, bottom: 6 })
  11786. }
  11787. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  11788. .animation({ duration: 500, curve: Curve.Ease, delay: 100 * index }),
  11789. TransitionEffect.scale({ x: 0, y: 0 })))
  11790. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  11791. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  11792. .onClick(() => {
  11793. dataBu.onItemClick?.(index)
  11794. })
  11795. })
  11796. }
  11797. .width(120)
  11798. .divider({
  11799. strokeWidth: 1,
  11800. color: "#22FFFFFF"
  11801. })
  11802. }
  11803. // Function to calculate a hash for the file list
  11804. function simpleHash(fileList: string[]): string {
  11805. let hash = 0;
  11806. const str = fileList.join(',');
  11807. for (let i = 0; i < str.length; i++) {
  11808. const char = str.charCodeAt(i);
  11809. hash = (hash << 5) - hash + char;
  11810. hash |= 0; // Convert to 32bit integer
  11811. }
  11812. return hash.toString();
  11813. }
  11814. interface MoreItem {
  11815. id: number;
  11816. image: Resource;
  11817. title: string;
  11818. }
  11819. //视频气泡窗口的布局
  11820. @Builder
  11821. function cutPopupBuilder(dataBu: BubbleBean) {
  11822. Column() {
  11823. Text(dataBu.isCopy ? '将文件复制到' : '将文件移动到')
  11824. .padding({
  11825. top: 10,
  11826. bottom: 10,
  11827. right: 10,
  11828. left: 10
  11829. })
  11830. .textAlign(TextAlign.Start)
  11831. .width(160)
  11832. .fontWeight(666)
  11833. .fontSize(16)
  11834. List() {
  11835. ForEach(dataBu.data, (item: string, index: number) => {
  11836. ListItem() {
  11837. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  11838. Row() {
  11839. Column() {
  11840. Image($r('app.media.music_group'))
  11841. .height(28)
  11842. .fillColor(dataBu.color)
  11843. .alignSelf(ItemAlign.Center)
  11844. }
  11845. .width(32)
  11846. Text(item.startsWith('.') ? item.replace(/\./g, '') : item)
  11847. .padding({
  11848. top: 10,
  11849. bottom: 10,
  11850. right: 10,
  11851. left: 10
  11852. })
  11853. .textAlign(TextAlign.Start).width("100%")// .fontColor(Color.Gray)
  11854. .fontSize(15)
  11855. }
  11856. }
  11857. .backgroundColor(Color.Transparent)
  11858. .margin({ top: 7, bottom: 7 })
  11859. }
  11860. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  11861. .animation({ duration: 500 }),
  11862. TransitionEffect.scale({ x: 0, y: 0 })))
  11863. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  11864. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  11865. .onClick(() => {
  11866. dataBu.onItemClick?.(index)
  11867. })
  11868. })
  11869. }
  11870. .width(150)
  11871. .divider({
  11872. strokeWidth: 1,
  11873. color: "#22FFFFFF"
  11874. })
  11875. }
  11876. .height(300)
  11877. .padding({
  11878. bottom: 30
  11879. })
  11880. }
  11881. function getFileDirName(filePath: string,rootPath:string): string{
  11882. if(filePath===rootPath){
  11883. return '首页'
  11884. }
  11885. let result = FileUtil.getFileName(filePath)
  11886. if(StrUtil.isEmpty(result))
  11887. return ''
  11888. if(result.startsWith('.'))
  11889. result = result.replace(/\./g, '')
  11890. return result
  11891. }