LocalMusic.ets 426 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517
  1. import TitleBar from './TitleBar'
  2. import { curves, display, PiPWindow, promptAction, router, SymbolGlyphModifier, window } from '@kit.ArkUI';
  3. import { VideoItem } from '../viewmodel/VideoItem';
  4. import {
  5. AppUtil,
  6. ArrayUtil,
  7. Base64Util,
  8. DateUtil,
  9. DeviceUtil,
  10. DisplayUtil,
  11. FileUtil,
  12. ImageUtil,
  13. LogUtil,
  14. MD5,
  15. PreferencesUtil,
  16. RandomUtil,
  17. StrUtil,
  18. ToastUtil
  19. } from '@pura/harmony-utils';
  20. import { imagePathToPixelMap } from '../common/util/CommUtils';
  21. import { unifiedDataChannel, uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
  22. import { CommonConstants } from '../common/constants/CommonConstants';
  23. import Logger from '../common/util/Logger';
  24. import { photoAccessHelper } from '@kit.MediaLibraryKit';
  25. import { BusinessError, emitter } from '@kit.BasicServicesKit';
  26. import { BubbleBean } from '../viewmodel/BubbleBean';
  27. import { PopupPosition, XPopup } from '@chinalike/popup';
  28. import { common, ConfigurationConstant } from '@kit.AbilityKit';
  29. import { AnimationHelper, DialogAction, DialogHelper } from '@pura/harmony-dialog';
  30. import { fileIo, fileUri, picker } from '@kit.CoreFileKit';
  31. import { MessageEvents, util, worker, ErrorEvent } from '@kit.ArkTS';
  32. import { Verify } from './Verify';
  33. import { RotatingCover } from './RotatingCover';
  34. import { PlayConstants } from '../common/constants/PlayConstants';
  35. import { effectKit } from '@kit.ArkGraphics2D';
  36. import { ColorConversion } from '../common/util/ColorConversion';
  37. import { LyricController, LyricParser, LyricView2 } from '@seagazer/cclyric';
  38. import { AvSessionController } from '../controller/AvSessionController';
  39. import { repairAudioMetadata, getApiLyric,changeMusicCover} from '../common/util/MusicTagUtils';
  40. import { FFMpegTags,Utility } from '../common/util/Utility';
  41. import { TagsContentCover } from '../view/TagsContentCover';
  42. import { ImageFancyModifier } from '../common/util/AttributeModifierUtil'
  43. import {
  44. // DeviceChangeReason,
  45. IjkMediaPlayer,
  46. InterruptEvent,
  47. InterruptHintType,
  48. LogUtils,
  49. OnBufferingUpdateListener,
  50. OnCompletionListener,
  51. OnErrorListener,
  52. OnInfoListener,
  53. OnPreparedListener,
  54. OnSeekCompleteListener,
  55. OnTimedTextListener,
  56. OnVideoSizeChangedListener
  57. } from '@ohos/ijkplayer';
  58. import { PlayStatus } from '../common/PlayStatus';
  59. import fs from '@ohos.file.fs';
  60. import { image } from '@kit.ImageKit';
  61. import { AVCastPicker, AVCastPickerState, AVCastPickerStyle, avSession } from '@kit.AVSessionKit';
  62. import { UniversalDetector } from '@ohos/juniversalchardet';
  63. import { SettingPage } from '../pages/SettingPage';
  64. import { secondToTime } from '../common/util/CommUtils';
  65. import { CommonConstants2 } from '../common/util/CommonConstants2';
  66. import { hilog } from '@kit.PerformanceAnalysisKit';
  67. import { LazyDataSource } from '../common/util/LazyDataSource';
  68. import MediaTable from '../common/util/MediaTable';
  69. import NetAxiosUtil from '../common/util/NetAxiosUtil';
  70. import ImageUtils from '../common/util/ImageUtils';
  71. import { ringtone } from '@kit.RingtoneKit';
  72. import { BreakpointType, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
  73. import { resourceManager } from '@kit.LocalizationKit';
  74. import { deviceInfo } from '@kit.BasicServicesKit';
  75. import { HSBColorPicker, HSBColorPickerLayout } from '@keke/color-picker'
  76. import app from '@system.app';
  77. import { TextNodeController } from './PipLyricTextBuilder';
  78. import { IndexerView } from './IndexerView';
  79. import { KeyCode } from '@kit.InputKit';
  80. import { KnockController } from '../controller/KnockController';
  81. import { DeleteComptent } from '../view/DeleteComptent'
  82. // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
  83. const TAG = 'LocalMusic';
  84. const DEFAULT_INDEX =
  85. ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  86. 'X', 'Y', 'Z']
  87. //排序类型
  88. function getTypeOrder(type: number) {
  89. switch (type) {
  90. case CommonConstants.TYPE_IS_DIR:
  91. return 1; // First
  92. case CommonConstants.TYPE_IS_CSJAD:
  93. return 2; // Middle
  94. case CommonConstants.TYPE_LOCAL:
  95. return 3; // Last
  96. default:
  97. return 4; // Unknown types, if any, go last
  98. }
  99. }
  100. const workerInstance = new worker.ThreadWorker("entry/ets/workers/Worker.ets");
  101. // 定义接口
  102. interface HiCarAspectRatio {
  103. ratio: number;
  104. name: string;
  105. }
  106. interface GeneratedObjectLiteralInterface_1 {
  107. assetId: string;
  108. title: string;
  109. artist: string;
  110. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  111. mediaUri: string;
  112. // 该字段大写,音频'AUDIO',视频'VIDEO'
  113. mediaType: string;
  114. mediaSize: number;
  115. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  116. startPosition: number;
  117. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  118. duration: number;
  119. albumCoverUri: string;
  120. albumTitle: string;
  121. appName: string;
  122. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  123. drmScheme: string;
  124. }
  125. const ITEM_HEIGHT_SMALL: number = 48; // 列表项小高度
  126. const ITEM_HEIGHT: number = 58; // 列表项中高度
  127. const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
  128. //功能强大的音乐播放器
  129. @Preview
  130. @Component
  131. export struct LocalMusic {
  132. @State isCanAuto:boolean = true
  133. @State opacityValueImage: number = 1;
  134. @State tipPopup:boolean = false
  135. @Consume mType: number;
  136. @StorageProp('themeColor') themeColor: string =
  137. PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  138. themeMode: number = 0;
  139. @State titleName: string = '首页'
  140. @State textStr: string = ''
  141. // static readonly STR_MUSIC_VIDEO: string = 'Audios';
  142. // private download_path: string = '';
  143. @Consume rootPath: string //音频根目录
  144. @Consume currentPath: string
  145. static readonly STR_LOCK_VIDEO: string = '.私密音频';
  146. static readonly STR_FAC_VIDEO: string = '.我的收藏';
  147. @State lockPath: string = ''
  148. @State favPath: string = ''
  149. static readonly STR_HISTORY_MUSIC: string = '.最近播放';
  150. @State historyPath: string = ''
  151. @State historyList: Array<VideoItem> = []
  152. @Consume isHistory: boolean
  153. static readonly HISTORY_MUSIC: string = 'music_historyList';
  154. private table: MediaTable = new MediaTable(getContext(this))
  155. @State isZero: boolean = false
  156. @State fileList: Array<string> = []
  157. @State dirList: Array<VideoItem> = []
  158. @Consume videoLocalList: Array<VideoItem>
  159. @State dataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.videoLocalList)
  160. @State mediaKuList: Array<VideoItem> = []; //媒体库文件
  161. @State artistList: Array<VideoItem> = []; //艺术家文件
  162. @State artistMap: Map<string, VideoItem[]> = new Map(); //艺术家Map
  163. @State albumList: Array<VideoItem> = []; //专辑文件
  164. @State albumMap: Map<string, VideoItem[]> = new Map(); //专辑Map
  165. private mScrollMap: Map<string, number> = new Map(); // 艺术家、专辑名->滚动index
  166. @State imageOpacities: number[] = [];
  167. @Consume isCanBack: boolean
  168. @Consume @Watch('onModeChange') modeType: number; // 0首页,1媒体库,2艺术家,3专辑
  169. @State showSingleLyric: boolean = false
  170. @State sortType: number = 4 //默认排序方式
  171. @State isShowSimi: boolean = false //是否显示私密音频
  172. @State isShowFAV: boolean = true //是否显示我的收藏
  173. @State isShowTitleBar: boolean = true //是否显示分类导航条
  174. @State isShowAllBar: boolean = true //是否显示播放全部条
  175. @State isShowSingleLineLyric: boolean = false //是否显示单行歌词
  176. @State isShowHistory: boolean = true //是否显示最近播放
  177. @State isCustomizeBg: boolean = false //自定义背景界面
  178. @State isGridMusic: boolean = false //是否网格布局
  179. @State isCircleBtn: boolean = false //是否圆形播放按钮
  180. @State twoFingerType: number = 3 //双支放大缩小的类型
  181. @State isScrollHide: boolean = false //是否滚动隐藏
  182. @State isSameTimePlay: boolean = false //是否和其他app同时播放
  183. @State isStartAutoPlay: boolean = false //启动后自动播放
  184. @State isShowPlayPageBack: boolean = false //是否显示播放页返回键
  185. @State isShowHeader: boolean = true
  186. @State isPlayListBgGrass: boolean = true //是否播放列表玻璃透明效果
  187. @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
  188. @State isCoverTopBig: boolean = false //顶部大封面部分手机显示会和播放控制页重叠
  189. @State isSwipe: boolean = false //listItem的左滑开关
  190. @State openSkipSongAnimate: boolean = true//切歌动画效果
  191. @State customizeBgPath: string | undefined = '';
  192. @State isDarkMode: boolean = false
  193. @State lyricTextWeight: number = 400
  194. @State lyricTextWeightPip: number = 400
  195. @State currentSwiperIndex: number = 0
  196. @State blurValue: number = 0 //背景模糊
  197. @State bgBrightness: number = 0 //背景亮度
  198. private listScroller: ListScroller = new ListScroller()
  199. private playListScroller: Scroller = new Scroller()
  200. @State isOneKeyTags:boolean = false
  201. @StorageProp('isLandscape') @Watch('onIsLandscapeChange') isLandscape: boolean = false;
  202. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  203. @StorageProp('windowWidth') windowWidth: number = 0;
  204. @StorageProp('windowHeight') windowHeight: number = 0;
  205. @StorageProp('isHiCarStatus') isHiCarStatus: boolean = false;
  206. @StorageProp('curDisplayIsHiCar') curDisplayIsHiCar: boolean = false;
  207. private UNKONWN:string = '';
  208. private listArea: Area = {
  209. width: 0,
  210. height: 0,
  211. position: {},
  212. globalPosition: {}
  213. }
  214. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  215. ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET;
  216. //瀑布流的列数横竖屏动态切换
  217. onIsLandscapeChange() {
  218. if(this.isLandscape){
  219. this.columns = 4
  220. }else{
  221. this.columns = PreferencesUtil.getNumberSync('lastColumns', 2);
  222. }
  223. }
  224. onColorModeChange() {
  225. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  226. if (this.isCustomizeBg) {
  227. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  228. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  229. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  230. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  231. } else {
  232. if (!this.isDarkMode) {
  233. this.titleBarModel.setTitleBarBackground(this.themeColor)
  234. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  235. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  236. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  237. } else {
  238. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  239. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  240. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  241. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  242. }
  243. }
  244. }
  245. onModeChange() {
  246. this.isFavMusic = false
  247. if (this.modeType === 2 || this.modeType === 3) {
  248. this.titleBarModel.setRightIcon(null)
  249. } else {
  250. this.titleBarModel.setRightIcon(($r('app.media.add')))
  251. }
  252. LogUtil.info('onecold onModeChange = ' + this.modeType)
  253. switch (this.modeType) {
  254. case 0:
  255. this.getSortedFiles(this.currentPath)
  256. break
  257. case 1:
  258. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  259. this.updateListData(this.mediaKuList)
  260. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  261. break
  262. case 2:
  263. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  264. this.updateListData(this.artistList)
  265. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  266. break
  267. case 3:
  268. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  269. this.updateListData(this.albumList)
  270. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  271. break
  272. }
  273. }
  274. @StorageLink('currentSong') currentSong: VideoItem | undefined = undefined;
  275. // @StorageLink('isPlay') isPlay: boolean = false;
  276. @StorageLink('isShowPlay') isShowPlay: boolean = false;
  277. @StorageLink('songList') songList: Array<VideoItem> = [];
  278. @State translateY: number = 0;
  279. @State isShowSheet: boolean = false;
  280. @State isShowSheetView: boolean = false;
  281. @State isShowTimeCloseView: boolean = false;
  282. private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Vertical });
  283. @StorageLink('currIndex') curIndex: number = 0;
  284. @Consume isShowDrawer: boolean;
  285. @Consume offsetX: number;
  286. @State isFac: boolean = false;
  287. @State favList: Array<VideoItem> = []
  288. @Consume isFavMusic: boolean
  289. @State isClickedPLayAll: boolean = false;
  290. private scrollerForlist: ListScroller = new ListScroller();
  291. private knockController: KnockController | undefined = undefined;
  292. imagesF: ImageFrameInfo[] = [
  293. { src: $r("app.media.app_loading0") },
  294. { src: $r("app.media.app_loading1") },
  295. { src: $r("app.media.app_loading2") },
  296. { src: $r("app.media.app_loading3") },
  297. ]
  298. @State animationState: AnimationStatus = AnimationStatus.Initial
  299. // 缓存机制
  300. private cache: Map<string, Array<VideoItem>> = new Map();
  301. private stringCache: Map<string, string> = new Map(); // 新增字符串缓存
  302. // 持久化缓存
  303. private async saveCacheToStorage() {
  304. const cacheArray = Array.from(this.cache.entries());
  305. const stringCacheArray = Array.from(this.stringCache.entries());
  306. await PreferencesUtil.putSync('music_cache', JSON.stringify(cacheArray));
  307. await PreferencesUtil.putSync('music_string_cache', JSON.stringify(stringCacheArray));
  308. }
  309. // 载入缓存
  310. private async loadCacheFromStorage() {
  311. const cacheString = await PreferencesUtil.getStringSync('music_cache', '');
  312. const stringCacheString = await PreferencesUtil.getStringSync('music_string_cache', ''); // 载入字符串缓存
  313. if (cacheString) {
  314. const cacheArray: [string, Array<VideoItem>][] = JSON.parse(cacheString);
  315. this.cache = new Map(cacheArray);
  316. }
  317. if (stringCacheString) {
  318. const stringCacheArray: [string, string][] = JSON.parse(stringCacheString);
  319. this.stringCache = new Map(stringCacheArray);
  320. }
  321. }
  322. // 查找缓存
  323. private findCache(key: string): Array<VideoItem> | undefined {
  324. return this.cache.get(key);
  325. }
  326. // 查找字符串缓存
  327. private findStringCache(key: string): string | undefined {
  328. return this.stringCache.get(key);
  329. }
  330. // 添加缓存
  331. private addCache(key: string, value: Array<VideoItem>) {
  332. this.cache.set(key, value);
  333. }
  334. // 添加字符串缓存
  335. private addStringCache(key: string, value: string) {
  336. this.stringCache.set(key, value);
  337. }
  338. // 删除缓存
  339. private deleteCache(key: string) {
  340. this.cache.delete(key);
  341. this.saveCacheToStorage()
  342. }
  343. // 删除字符串缓存
  344. private deleteStringCache(key: string) {
  345. this.stringCache.delete(key);
  346. }
  347. // 多选机制
  348. @State selectedFiles: Array<VideoItem> = [];
  349. @State isMultiSelect: boolean = false;
  350. @State isAllSelected: boolean = false;
  351. @State appName: string = ''
  352. @State isHasDir: boolean = false
  353. @State packName: string = ''
  354. context = this.getUIContext().getHostContext() as common.UIAbilityContext
  355. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  356. .setTitleTextStyle(FontStyle.Normal)
  357. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  358. .setLeftIcon($r('app.media.menu'))
  359. .setLeftIconWidth(26)
  360. .setLeftIconHeight(26)
  361. .setTitleName('首页')
  362. .setTitleFontSize(18)
  363. .setTitleFontColor(Color.White)
  364. .setTitleBarBackground(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  365. .setTitleBarBottomLineColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  366. .setLeftTitleStateNormalStyleColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  367. .setRightIcon($r('app.media.add'))
  368. .setOnRightClickListener(() => {
  369. this.showSheelDialog()
  370. })
  371. // .setOnTitleClickListener(() => {
  372. // this.showPupDialog()
  373. // })
  374. .setOnLeftClickListener(() => {
  375. this.doSwipBack()
  376. })
  377. doSwipBack() {
  378. this.isZero = false
  379. if (this.modeType !== 0 && this.isCanBack) {
  380. this.onModeChange()
  381. this.isCanBack = false
  382. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  383. // 返回专辑列表时恢复滚动偏移量,支持列表和网格
  384. setTimeout(() => {
  385. if (this.modeType == 2) {
  386. if (this.isGridMusic||this.twoFingerType==4) {
  387. let lastOffset = this.mScrollMap.get('lastGridArtistScrollOffset') ?? 0
  388. let lastWaterOffset = this.mScrollMap.get('lastWaterArtistScrollOffset') ?? 0
  389. if(this.twoFingerType==4){
  390. this.waterScroller.scrollTo({ xOffset: 0, yOffset: lastWaterOffset })
  391. }else{
  392. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  393. }
  394. } else {
  395. let lastOffset = this.mScrollMap.get('lastListArtistScrollOffset') ?? 0
  396. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  397. }
  398. } else if (this.modeType == 3) {
  399. if (this.isGridMusic||this.twoFingerType==4) {
  400. let lastOffset = this.mScrollMap.get('lastGridAlBumScrollOffset') ?? 0
  401. let lastWaterOffset = this.mScrollMap.get('lastWaterAlBumScrollOffset') ?? 0
  402. if(this.twoFingerType==4){
  403. this.waterScroller.scrollTo({ xOffset: 0, yOffset: lastWaterOffset })
  404. }else{
  405. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  406. }
  407. } else {
  408. let lastOffset = this.mScrollMap.get('lastListAlBumScrollOffset') ?? 0
  409. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  410. }
  411. }
  412. }, 200)
  413. return
  414. }
  415. if (this.isHistory || this.isFavMusic) {
  416. this.isHistory = false
  417. this.getSortedFiles(this.currentPath)
  418. return
  419. }
  420. if (this.currentPath === this.rootPath || this.modeType !== 0) {
  421. animateTo({ duration: 555 }, () => {
  422. // 动画闭包内控制Image组件的出现和消失
  423. this.isShowDrawer = !this.isShowDrawer
  424. this.offsetX = 0
  425. })
  426. return
  427. }
  428. //返回上一级歌单的滚动位置
  429. setTimeout(() => {
  430. if (this.modeType == 0) {
  431. if (this.isGridMusic||this.twoFingerType==4) {
  432. let lastOffset = this.mScrollMap.get('lastGridDirScrollOffset') ?? 0
  433. let lastWaterOffset = this.mScrollMap.get('lastWaterDirScrollOffset') ?? 0
  434. if(this.twoFingerType==4){
  435. this.waterScroller.scrollTo({ xOffset: 0, yOffset: lastWaterOffset })
  436. }else{
  437. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  438. }
  439. } else {
  440. let lastOffset = this.mScrollMap.get('lastListDirScrollOffset') ?? 0
  441. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  442. }
  443. }
  444. }, 300)
  445. this.currentPath = Utility.getParentDirectory(this.currentPath)
  446. Logger.info('this.currentPath2 = ' + this.currentPath)
  447. this.getSortedFiles(this.currentPath)
  448. }
  449. // 组件生命周期
  450. aboutToAppear() {
  451. this.sonTwoFingerType = PreferencesUtil.getNumberSync('sonTwoFingerType', 3);
  452. this.columns = PreferencesUtil.getNumberSync('lastColumns', 2);
  453. if(PreferencesUtil.getBooleanSync('isFirstTiped',true)){
  454. this.tipPopup = !this.tipPopup
  455. PreferencesUtil.putSync('isFirstTiped',false)
  456. }
  457. this.initSetting()
  458. this.UNKONWN = Utility.resourceToString(this.context, $r('app.string.unknown'));
  459. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  460. Utility.getAppName(getContext(this)).then((appName: string) => {
  461. this.appName = appName
  462. })
  463. this.packName = AppUtil.getBundleName()
  464. this.loadCacheFromStorage(); // 加载缓存
  465. this.mkDownLoadDir()
  466. let eventMusic: emitter.InnerEvent = { eventId: 2 }
  467. // 监听广播事件(打开其他应用处理)
  468. emitter.on(eventMusic, (eventData: emitter.EventData) => {
  469. this.saveVideoDatas([eventData.data?.message], true)
  470. });
  471. //侧滑广播接收时间
  472. let eventUpdateSwipeBack: emitter.InnerEvent = { eventId: 888 }
  473. // 监听广播事件(打开其他应用处理)
  474. emitter.on(eventUpdateSwipeBack, (eventData: emitter.EventData) => {
  475. animateTo({ duration: 555 }, () => {
  476. this.doSwipBack()
  477. })
  478. });
  479. //ScanFilePage广播接收时间
  480. let eventScanUpdate: emitter.InnerEvent = { eventId: 101 }
  481. // 监听ScanFilePage广播事件(更新数据库)
  482. emitter.on(eventScanUpdate, (eventData: emitter.EventData) => {
  483. this.doUpdateData()
  484. });
  485. let eventSetting: emitter.InnerEvent = { eventId: 333 }
  486. // 监听广播事件(通用设置配置更新)
  487. emitter.on(eventSetting, (eventData: emitter.EventData) => {
  488. this.doChangeSetting()
  489. });
  490. let event: Callback<InterruptEvent> = (event) => {
  491. // LogUtils.getInstance().LOGI(`onecold 与其他应用音频冲突 被截断点event: ${JSON.stringify(event)}`);
  492. console.info(`onecold 与其他应用音频冲突 被截断点event: ${JSON.stringify(event)}`)
  493. this.savePlaybackPosition()
  494. if (event.hintType === InterruptHintType.INTERRUPT_HINT_PAUSE) {
  495. this.pause();
  496. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_RESUME) {
  497. console.info(`onecold audioInterrupt startPlayOrResumePlay: ${JSON.stringify(event)}`)
  498. console.info('onecold startPlayOrResumePlay 514')
  499. this.startPlayOrResumePlay();
  500. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_STOP) {
  501. this.stop();
  502. }
  503. }
  504. this.mIjkMediaPlayer.on('audioInterrupt', event);
  505. // 音频设备断连回调处理
  506. // let deviceChangeEvent: Callback<InterruptEvent> = (event) => {
  507. // LogUtils.getInstance().LOGI(`Heanup deviceChange event: ${JSON.stringify(event)}`);
  508. // if (event.reason === DeviceChangeReason.REASON_OLD_DEVICE_UNAVAILABLE) { // 音频设备断开连接
  509. // this.pause();
  510. // }
  511. // }
  512. // this.mIjkMediaPlayer.on('deviceChange', deviceChangeEvent);
  513. this.makeWorker()
  514. //折叠屏的屏幕显示模式变化
  515. display.on('foldDisplayModeChange', (data) => {
  516. this.doChangeBarHeight()
  517. });
  518. display.on('foldStatusChange', (data) => {
  519. Logger.info('onecold foldStatusChange ')
  520. });
  521. this.isCoverRectangle = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_RECTANGLE, true)
  522. // 读取 themeMode 并同步 currentColorMode
  523. this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
  524. this.applyThemeMode(this.themeMode)
  525. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  526. AppStorage.setOrCreate('themeColor', themeColor);
  527. this.themeColor = themeColor;
  528. this.doChangeSetting()
  529. this.windowClass.on('windowSizeChange', (size) => {
  530. LogUtil.info('onecold windowSizeChange')
  531. this.doChangeBarHeight()
  532. let viewWidth = px2vp(size.width);
  533. let viewHeight = px2vp(size.height);
  534. if(this.isPhoneLan()){
  535. this.is_auto_hide_progress = false
  536. if(this.isHiCar()){
  537. return
  538. }
  539. setTimeout(() => {
  540. this.is_auto_hide_progress = true
  541. }, 6000)
  542. }else{
  543. this.startAutoHide()
  544. }
  545. });
  546. this.eventHub.on('onStateChange', (fg: boolean) => {
  547. if (fg && this.curState === 'STARTED') {
  548. this.stopPip();
  549. }
  550. });
  551. }
  552. startAutoHide() {
  553. if(this.isHiCar()){
  554. return
  555. }
  556. if(PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_HIDE_PROGRESS,false)){
  557. console.info('onecold startAutoHide')
  558. this.is_auto_hide_progress = false
  559. setTimeout(() => {
  560. this.is_auto_hide_progress = true
  561. }, 6000)
  562. }
  563. }
  564. applyThemeMode(mode: number) {
  565. let colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET
  566. if (mode === 1) {
  567. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
  568. } else if (mode === 2) {
  569. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  570. }
  571. AppStorage.setOrCreate('currentColorMode', colorMode)
  572. AppStorage.setOrCreate('isDarkMode', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK)
  573. PreferencesUtil.putSync(SettingPage.THEME_MODE, mode)
  574. AppStorage.setOrCreate('themeMode', mode)
  575. this.isDarkMode = colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  576. // 只有强制浅色/深色时才主动设置
  577. const context = getContext(this) as common.UIAbilityContext
  578. context.getApplicationContext().setColorMode(colorMode)
  579. }
  580. initSetting() {
  581. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  582. this.isCustomizeBg = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
  583. this.customizeBgPath = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
  584. this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, true)
  585. this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
  586. this.isSameTimePlay = PreferencesUtil.getBooleanSync(SettingPage.IS_SAMETIME_PLAY, false)
  587. this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
  588. this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
  589. this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
  590. this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
  591. this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
  592. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
  593. this.isShowAllBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_ALLBAR, true)
  594. this.twoFingerType = PreferencesUtil.getNumberSync(SettingPage.TWO_FINGER_TYPE, 3)
  595. this.isCoverTop = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP, false)
  596. this.isCircleBtn = PreferencesUtil.getBooleanSync(SettingPage.IS_CIRCLE_BTN, true)
  597. this.isShowPlayPageBack = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_PLAYPAGE_BACK, true)
  598. this.isCoverTopBig = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP_BIG, false)
  599. this.isShowSingleLineLyric = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SLLYRIC, false)
  600. this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
  601. this.isPlayListBgGrass = PreferencesUtil.getBooleanSync(SettingPage.IS_PLAYLIST_BG_GRASS, true)
  602. this.isShowHeader = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HEADER, true)
  603. this.volume = PreferencesUtil.getNumberSync('DefalutVolume', this.volume)
  604. this.isSwipe = PreferencesUtil.getBooleanSync(SettingPage.IS_SWIPE, false)
  605. this.openSkipSongAnimate = PreferencesUtil.getBooleanSync(SettingPage.OPEN_SKIPSONG_ANIMATE, true)
  606. this.volumeSmall = PreferencesUtil.getBooleanSync('volumeSmall', false)
  607. if(this.volumeSmall){
  608. this.volume = 0.5
  609. }else{
  610. this.volume = 1
  611. }
  612. //如果是hicar连接状态,这些都是false
  613. if(this.isHiCar()){
  614. this.isShowTitleBar = false//不显示导航栏
  615. if(!(this.windowWidth>1800&&this.windowHeight>=1200))//小屏幕不可以Grid
  616. {
  617. this.isShowHeader = false//二级菜单不显示头部
  618. this.isGridMusic= false//用list不用网格
  619. this.isCoverTopBig = false
  620. }
  621. this.isShowPlayPageBack = true //播放页返回键要显示,方便驾驶员操作
  622. }
  623. if (this.isSavePlayMode) {
  624. this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
  625. }
  626. if (this.isCustomizeBg) {
  627. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  628. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  629. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  630. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  631. } else {
  632. if (!this.isDarkMode) {
  633. this.titleBarModel.setTitleBarBackground(this.themeColor)
  634. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  635. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  636. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  637. } else {
  638. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  639. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  640. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  641. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  642. }
  643. }
  644. }
  645. doChangeSetting() {
  646. this.initSetting()
  647. this.deleteCache(this.currentPath)
  648. if (this.modeType === 0) {
  649. this.getSortedFiles(this.currentPath)
  650. }
  651. }
  652. doChangeBarHeight() {
  653. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  654. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  655. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  656. this.setBarHeightNormal()
  657. }
  658. }
  659. onPageShow() {
  660. this.knockController?.immersiveListening();
  661. app.setImageCacheCount(100);
  662. // 设置解码前图片数据内存缓存上限为100MB (100MB=100*1024*1024B=104857600B)
  663. app.setImageRawDataCacheSize(104857600);
  664. Logger.info('onecold onPageShow currentBreakpoint= ' + this.currentBreakpoint)
  665. }
  666. //开启线程查看各个数据库
  667. makeWorker() {
  668. setTimeout(() => {
  669. if (PreferencesUtil.getBooleanSync('isFirstApp', true)) {
  670. ToastUtil.showToast('请到文件扫描页面导入音乐!')
  671. //发送worker通知扫描文件入库,用户反馈4000多首用这个方法扫描会闪退。
  672. // workerInstance.postMessage({
  673. // code: 1,
  674. // data1: this.context,
  675. // data2: this.rootPath,
  676. // data3: this.lockPath,
  677. // data4: PreferencesUtil.getStringSync('COVER_API', ''),
  678. // });
  679. PreferencesUtil.putSync('isFirstApp', false)
  680. } else {
  681. workerInstance.postMessage({ code: 2, data: this.context });
  682. workerInstance.postMessage({ code: 3, data: this.context });
  683. workerInstance.postMessage({ code: 4, data: this.context });
  684. this.getHistoryList(false)
  685. }
  686. }, 1000)
  687. workerInstance.onmessage = (e: MessageEvents): void => {
  688. switch (e.data.code) {
  689. case 101: //第一次扫描文件夹入库
  690. ToastUtil.showToast('刷新同步数据库成功!')
  691. Logger.info('onecold 扫描数据库结束 this.mediaKuList length= ' + this.mediaKuList.length)
  692. this.doUpdateData()
  693. break;
  694. case 102: //查询媒体库列表
  695. this.mediaKuList = e.data.data
  696. Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
  697. Utility.doSortListAscending(this.mediaKuList)
  698. AppStorage.setOrCreate('mediaKuList', this.mediaKuList);
  699. if (this.modeType === 1) {
  700. this.updateListData(this.mediaKuList)
  701. }
  702. PreferencesUtil.putSync('mediaKuCount', this.mediaKuList.length)
  703. break;
  704. case 103: //收到查询艺术家列表
  705. this.artistMap = e.data.data1;
  706. this.artistList = e.data.data2;
  707. PreferencesUtil.putSync('artistCount', this.artistList.length)
  708. break;
  709. case 104: //收到查询专辑列表
  710. this.albumMap = e.data.data1;
  711. this.albumList = e.data.data2
  712. //查询完毕在启动是否自动播放
  713. if (this.isStartAutoPlay&&this.isCanAuto) {
  714. this.isCanAuto = false
  715. console.info('onecold startPlayOrResumePlay 757')
  716. this.startPlayOrResumePlay()
  717. }
  718. PreferencesUtil.putSync('albumCount', this.albumList.length)
  719. break;
  720. }
  721. };
  722. // 在调用terminate后,执行onexit
  723. workerInstance.onexit = (code) => {
  724. console.log("main thread terminate");
  725. }
  726. //若Worker处于已销毁或正在销毁等非运行状态时,调用其功能接口,会抛出相应的错误。
  727. // 使用Worker模块时,需要在主线程中注册onerror接口,否则当worker线程出现异常时会发生jscrash问题。
  728. workerInstance.onerror = (err: ErrorEvent) => {
  729. console.log("onerror" + err.message);
  730. }
  731. // let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  732. //碰一碰分享的监听
  733. this.knockController = KnockController.getInstance(this.context);
  734. this.knockController?.immersiveListening();
  735. }
  736. onPageHide(): void {
  737. this.knockController?.immersiveDisableListening();
  738. }
  739. @State isFirstStartPlay: boolean = false
  740. //获取download_path
  741. async mkDownLoadDir() {
  742. const documentViewPicker = new picker.DocumentViewPicker()
  743. let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
  744. this.rootPath = new fileUri.FileUri(documentSaveResult[0]).path
  745. // this.rootPath = this.download_path
  746. this.lockPath = this.rootPath + '/' + LocalMusic.STR_LOCK_VIDEO
  747. this.favPath = this.rootPath + '/' + LocalMusic.STR_FAC_VIDEO
  748. this.historyPath = this.rootPath + '/' + LocalMusic.STR_HISTORY_MUSIC
  749. Logger.info('onecold rootPath = ' + this.rootPath)
  750. Logger.info('onecold lockPath = ' + this.lockPath)
  751. if (!FileUtil.accessSync(this.lockPath)) {
  752. FileUtil.mkdirSync(this.lockPath)
  753. }
  754. if (!FileUtil.accessSync(this.favPath)) {
  755. FileUtil.mkdirSync(this.favPath)
  756. }
  757. if (!FileUtil.accessSync(this.historyPath)) {
  758. FileUtil.mkdirSync(this.historyPath)
  759. }
  760. this.getSortedFiles(this.rootPath).then(() => {
  761. this.isFavMusic = false
  762. //穿山甲
  763. // this.loadBannerAd(CSJUtil.getBannerID())
  764. this.songList = PreferencesUtil.getSync('LastMusicList', []) as Array<VideoItem>
  765. this.currentSong = PreferencesUtil.getSync('LastMusicInfo', undefined) as VideoItem
  766. if (ArrayUtil.isEmpty(this.songList)) {
  767. this.songList = this.getCurFileList()
  768. } else {
  769. this.curIndex = Utility.getIndexFromList(this.songList, this.currentSong.filePath)
  770. }
  771. if (ArrayUtil.isNotEmpty(this.songList)) {
  772. this.isFirstStartPlay = true
  773. this.sonDataSource.pushArrayData(this.songList)
  774. if (this.currentSong === undefined) {
  775. this.isFirstStartPlay = false
  776. this.currentSong = this.songList[0]
  777. }
  778. this.videoUrl = this.currentSong.filePath
  779. this.name = this.currentSong.name
  780. this.cover = this.currentSong.pixelMapPath
  781. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  782. } else {
  783. this.name = '空空如也'
  784. }
  785. })
  786. this.getFavList(false)
  787. }
  788. getFavList(isFavRefresh: boolean) {
  789. this.table.queryByisFav(1, async (result: VideoItem[]) => {
  790. this.favList = result
  791. if (isFavRefresh || this.isFavMusic) { //如果是我的收藏,更新我的收藏数据
  792. this.videoLocalList = this.favList
  793. this.updateListData(this.videoLocalList)
  794. }
  795. })
  796. }
  797. getHistoryList(isRefresh: boolean) {
  798. this.table.queryRecentPlayedRecords(50, async (result: VideoItem[]) => {
  799. this.historyList = result
  800. // for (let i = 0; i < this.historyList.length; i++) {
  801. //
  802. // console.info(`onecold gengxin 1: ${this.historyList[i].name}`);
  803. // console.info(`onecold gengxin 1: ${this.historyList[i].lastPlayedStr}`);
  804. // }
  805. if (isRefresh) {
  806. this.videoLocalList = this.historyList
  807. this.updateListData(this.videoLocalList, true)
  808. }
  809. })
  810. }
  811. // 组件消失生命周期
  812. aboutToDisappear() {
  813. console.info('LifeCycleComponent aboutToDisappear');
  814. this.knockController?.immersiveDisableListening();
  815. this.curIndex = 0
  816. emitter.off(2);
  817. emitter.off(101);
  818. emitter.off(888);
  819. emitter.off(333);
  820. this.mDestroyPage = true;
  821. this.mIjkMediaPlayer.setScreenOnWhilePlaying(false);
  822. if (this.CONTROL_PlayStatus != PlayStatus.INIT) {
  823. this.stop();
  824. }
  825. this.mIjkMediaPlayer.off('audioInterrupt');
  826. if (workerInstance) {
  827. workerInstance.terminate();
  828. }
  829. this.stopPip();
  830. this.destroyPipController()
  831. }
  832. async getSortedFiles(curPath: string, isWorkerPost?: boolean, destPath?: string, isOpen?: boolean) {
  833. this.isFavMusic = false
  834. if (isWorkerPost) {
  835. workerInstance.postMessage({ code: 2, data: this.context }); //刷新媒体库列表
  836. }
  837. if (this.modeType !== 0) {
  838. return
  839. }
  840. this.isCanBack = false
  841. this.currentPath = curPath
  842. this.titleBarModel.setTitleName(getFileDirName(this.currentPath, this.rootPath))
  843. if (curPath === this.rootPath) {
  844. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  845. } else {
  846. this.currentTitleName = getFileDirName(this.currentPath, this.rootPath)
  847. if (this.rootPath === Utility.getParentDirectory(curPath)) {
  848. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  849. }
  850. }
  851. // Get the current file list and calculate its hash
  852. this.fileList = FileUtil.listFileSync(curPath);
  853. const currentHash = simpleHash(this.fileList);
  854. // Check cache
  855. const cachedValue = this.findCache(curPath);
  856. Logger.info('onecold cachedValue = ' + cachedValue)
  857. const cachedHash = this.findStringCache(curPath + '_hash');
  858. const cachedDirList = this.findCache(curPath + "_dirList");
  859. if (cachedValue !== undefined) {
  860. // this.videoLocalList = cachedValue;
  861. Logger.info('onecold 有缓存 cachedValue = ' + cachedValue)
  862. if (this.currentPath != this.rootPath) { //第一个封面赋值给currentTitleCover
  863. this.currentTitleCover = Utility.getFirstCoverFromList(cachedValue)
  864. }
  865. this.updateListData(cachedValue)
  866. }
  867. if (cachedDirList !== undefined) {
  868. this.dirList = cachedDirList
  869. }
  870. //通过当前hash值和缓存hash判断list有没有变化
  871. if (cachedValue && cachedHash === currentHash) {
  872. return;
  873. }
  874. this.fileList = FileUtil.listFileSync(curPath)
  875. let directories: Array<VideoItem> = [];
  876. let files: Array<VideoItem> = [];
  877. for (let i = 0; i < this.fileList.length; i++) {
  878. console.info(`The name of file: ${this.fileList[i]}`);
  879. let path = curPath + '/' + this.fileList[i]
  880. if (FileUtil.isDirectory(path)) {
  881. let item: VideoItem =
  882. new VideoItem(this.fileList[i].toString(), this.fileList[i].toString(), path, CommonConstants.TYPE_IS_DIR, 0,
  883. '')
  884. if (this.isShowDir(item.name)) {
  885. directories.push(item);
  886. }
  887. // directories.sort((a, b) => a.cTime.localeCompare(b.cTime));
  888. // Utility.doSortListAscending(directories)
  889. } else {
  890. if (this.currentPath === this.lockPath&&Utility.isMeidaByExtension(path)) {
  891. let item: VideoItem =
  892. await Utility.uriGetMusicAssetsFromFile(this.context, path, CommonConstants.TYPE_LOCAL, false);
  893. if (!path.endsWith('.lrc') && Utility.isMeidaByExtension(path) && !path.endsWith('.srt')) {
  894. files.push(item);
  895. // files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  896. // this.doSortListAscending(files)
  897. }
  898. }
  899. }
  900. }
  901. this.table.queryByParentPath(curPath, async (result: VideoItem[]) => {
  902. if (this.currentPath !== this.lockPath) {
  903. files = result;
  904. }
  905. files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  906. Utility.doSortListAscending(files)
  907. if (this.currentPath === this.rootPath) {
  908. this.dirList = directories
  909. this.addCache(curPath + "_dirList", this.dirList);
  910. }
  911. //插入广告先注释掉
  912. // if (this.isShowAd && ArrayUtil.isNotEmpty(directories)) {
  913. // let adItem: VideoItem = new VideoItem('', '', '', CommonConstants.TYPE_IS_CSJAD, 0, '')
  914. // directories.push(adItem)
  915. // }
  916. // 合并文件夹和文件,文件夹在前,文件在后,广告在中间
  917. this.videoLocalList = directories.concat(files);
  918. this.updateListData(this.videoLocalList)
  919. if (ArrayUtil.isNotEmpty(files)) {
  920. if (this.currentPath != this.rootPath) {
  921. if (files) {
  922. this.currentTitleCover = Utility.getFirstCoverFromList(files)
  923. }
  924. }
  925. // 缓存结果
  926. this.addCache(curPath, this.videoLocalList);
  927. await this.saveCacheToStorage(); // 保存缓存至本地存储
  928. this.addStringCache(curPath + '_hash', currentHash);
  929. }
  930. console.info(`onecold gengxin 1: ${this.videoLocalList.length}`);
  931. // for (let i = 0; i < this.videoLocalList.length; i++) {
  932. //
  933. // console.info(`onecold gengxin 1: ${this.videoLocalList[i].pixelMapPath}`);
  934. //
  935. // }
  936. // this.setButtonStatus()
  937. if (isOpen) {
  938. if (destPath === undefined) {
  939. // 处理 destPath 为 undefined 的情况
  940. return
  941. }
  942. if (destPath.endsWith('.lrc')) {
  943. ToastUtil.showToast('导入歌词成功!请注意歌词文件和歌曲要同个歌单路径。')
  944. if (StrUtil.isNotEmpty(this.videoUrl)) {
  945. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  946. this.initLyric(lyricPath);
  947. }
  948. return
  949. }
  950. let item2 = new VideoItem(Utility.getMediaNameByUri(destPath), destPath, destPath, 0, 0, '')
  951. this.doPlay(item2)
  952. this.isShowPlay = true
  953. }
  954. });
  955. }
  956. //扫描文件夹入库
  957. async scanDirectory(curPath: string): Promise<VideoItem[]> {
  958. const files = FileUtil.listFileSync(curPath);
  959. let mediaItems: VideoItem[] = [];
  960. Logger.info('onecold scanDirectory start ')
  961. for (const file of files) {
  962. const fPath = `${curPath}/${file}`;
  963. if (fPath === this.lockPath) {
  964. Logger.info(`Skipping locked path: ${fPath}`);
  965. continue;
  966. }
  967. if (FileUtil.isDirectory(fPath)) {
  968. // Recursively scan subdirectories
  969. const subDirItems = await this.scanDirectory(fPath);
  970. mediaItems = mediaItems.concat(subDirItems);
  971. } else {
  972. Logger.info('onecold scanDirectory filePath = ' + fPath)
  973. // Process media files
  974. if (!fPath.endsWith('.lrc') && Utility.isMeidaByExtension(fPath) && !fPath.endsWith('.srt')) {
  975. let mediaItem: VideoItem =
  976. await Utility.uriGetMusicAssetsFromFile(this.context, fPath, CommonConstants.TYPE_LOCAL, true);
  977. mediaItems.push(mediaItem);
  978. this.table.insert(mediaItem, (id: number) => {
  979. });
  980. }
  981. }
  982. }
  983. return mediaItems;
  984. }
  985. updateListData(mList: Array<VideoItem>, noSort?: boolean) {
  986. animateTo({ duration: 888 }, () => {
  987. this.opacityItem = 0;
  988. });
  989. setTimeout(() => {
  990. this.videoLocalList = mList;
  991. if (!noSort) {
  992. if (this.modeType === 0 || this.modeType === 1) {
  993. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  994. this.doSortType(this.sortType)
  995. }
  996. }
  997. this.dataSource.pushArrayData(this.videoLocalList)
  998. animateTo({ duration: 888 }, () => {
  999. this.opacityItem = 1;
  1000. });
  1001. this.setButtonStatus()
  1002. }, 200);
  1003. }
  1004. //排序模式和多选模式
  1005. showPupDialog() {
  1006. if (this.modeType === 2 || this.modeType === 3) {
  1007. this.titleBarModel.setRightIcon(null)
  1008. } else {
  1009. this.titleBarModel.setRightIcon(($r('app.media.add')))
  1010. }
  1011. let dataBean = new BubbleBean()
  1012. dataBean.data = ["首页", "媒体库", "艺术家", "专辑", "同步数据"]
  1013. dataBean.color = this.themeColor
  1014. dataBean.modeType = this.modeType
  1015. dataBean.imageRes =
  1016. [$r('app.media.home_press'), $r('app.media.kp_music'), $r('app.media.music_menu'), $r('app.media.llq'),
  1017. $r('app.media.refresh')]
  1018. let pup: XPopup;
  1019. if (this.isDarkMode) {
  1020. pup = XPopup.Builder()
  1021. .setPopupPosition(PopupPosition.BOTTOM)
  1022. .atView('pup_positon_music')
  1023. .setBackgroundColor(Color.Black)
  1024. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  1025. .show()
  1026. } else {
  1027. pup = XPopup.Builder()
  1028. .setPopupPosition(PopupPosition.BOTTOM)
  1029. .atView('pup_positon_music')
  1030. .setBackgroundColor(Color.White)
  1031. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  1032. .show()
  1033. }
  1034. dataBean.onItemClick = (i) => {
  1035. XPopup.dismissTop()
  1036. switch (i) {
  1037. case 0: //首页
  1038. this.modeType = 0
  1039. this.getSortedFiles(this.currentPath)
  1040. break
  1041. case 1:
  1042. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1043. this.modeType = 1
  1044. this.updateListData(this.mediaKuList)
  1045. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  1046. break
  1047. case 2:
  1048. this.modeType = 2
  1049. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1050. this.updateListData(this.artistList)
  1051. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  1052. break
  1053. case 3:
  1054. this.modeType = 3
  1055. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1056. this.updateListData(this.albumList)
  1057. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  1058. break
  1059. case 4: //同步数据
  1060. this.asyncCurrentPathData()
  1061. break
  1062. }
  1063. }
  1064. }
  1065. getCurFileList(): Array<VideoItem> {
  1066. let files: Array<VideoItem> = [];
  1067. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1068. for (let i = 0; i < this.videoLocalList.length; i++) {
  1069. if (this.videoLocalList[i].type === CommonConstants.TYPE_LOCAL) {
  1070. files.push(this.videoLocalList[i]);
  1071. }
  1072. }
  1073. }
  1074. return files
  1075. }
  1076. setButtonStatus() {
  1077. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1078. this.isZero = false
  1079. } else {
  1080. this.isZero = true
  1081. }
  1082. if (this.currentPath !== this.rootPath &&
  1083. ArrayUtil.isNotEmpty(Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR))) {
  1084. this.isHasDir = true //不为空,说明有子文件夹
  1085. } else {
  1086. this.isHasDir = false
  1087. }
  1088. }
  1089. showRankDialog() {
  1090. if (this.modeType === 2 || this.modeType === 3) {
  1091. //动作面板
  1092. DialogHelper.showBottomSheetDialog({
  1093. title: "请选择排序模式",
  1094. maskColor: Color.Transparent,
  1095. // sheets: ["按名称升序", "按名称降序"],
  1096. sheets: [
  1097. { value: '按名称升序', fontColor: $r('app.color.text_color') },
  1098. { value: '按名称降序', fontColor: $r('app.color.text_color') },
  1099. ],
  1100. backgroundColor: $r('app.color.bg_card'),
  1101. height: '30%',
  1102. transition: AnimationHelper.transitionInDown(555),
  1103. onAction: (index) => {
  1104. switch (index) {
  1105. case 0:
  1106. Utility.doSortListAscending(this.videoLocalList)
  1107. break;
  1108. case 1:
  1109. Utility.doSortListDescending(this.videoLocalList)
  1110. break;
  1111. }
  1112. this.updateListData(this.videoLocalList)
  1113. }
  1114. })
  1115. return
  1116. }
  1117. //动作面板
  1118. DialogHelper.showBottomSheetDialog({
  1119. title: "请选择排序模式",
  1120. maskColor: Color.Transparent,
  1121. height: '75%',
  1122. // sheets: ["按艺术家升序", "按艺术家降序", "按专辑升序", "按专辑降序", "按名称升序", "按名称降序", "按添加时间升序","按添加时间降序"],
  1123. sheets: [
  1124. { value: "按艺术家升序", fontColor: $r('app.color.text_color') },
  1125. { value: "按艺术家降序", fontColor: $r('app.color.text_color') },
  1126. { value: "按专辑升序", fontColor: $r('app.color.text_color') },
  1127. { value: "按专辑降序", fontColor: $r('app.color.text_color') },
  1128. { value: "按名称升序", fontColor: $r('app.color.text_color') },
  1129. { value: "按名称降序", fontColor: $r('app.color.text_color') },
  1130. { value: "按添加时间升序", fontColor: $r('app.color.text_color') },
  1131. { value: "按添加时间降序", fontColor: $r('app.color.text_color') },
  1132. ],
  1133. backgroundColor: $r('app.color.bg_card'),
  1134. transition: AnimationHelper.transitionInDown(555),
  1135. onAction: (index) => {
  1136. this.doSortType(index)
  1137. PreferencesUtil.put(SettingPage.SORT_TYPE, index)
  1138. this.updateListData(this.videoLocalList, true)
  1139. }
  1140. })
  1141. }
  1142. doSortType(index: number) {
  1143. switch (index) {
  1144. case 0:
  1145. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1146. // 类型排序优先级
  1147. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1148. if (typeOrder !== 0) {
  1149. return typeOrder;
  1150. }
  1151. // 处理艺术家可能为undefined的字符串比较
  1152. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1153. const artistB = b.artist?.trim() || '';
  1154. return artistA.localeCompare(artistB);
  1155. });
  1156. break;
  1157. case 1:
  1158. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1159. // 类型排序优先级
  1160. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1161. if (typeOrder !== 0) {
  1162. return typeOrder;
  1163. }
  1164. // 处理艺术家可能为undefined的字符串比较
  1165. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1166. const artistB = b.artist?.trim() || '';
  1167. return artistB.localeCompare(artistA);
  1168. });
  1169. break;
  1170. case 2:
  1171. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1172. // 类型排序优先级
  1173. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1174. if (typeOrder !== 0) {
  1175. return typeOrder;
  1176. }
  1177. // 处理专辑可能为undefined的字符串比较
  1178. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1179. const albumB = b.album?.trim() || '';
  1180. return albumA.localeCompare(albumB);
  1181. });
  1182. break;
  1183. case 3:
  1184. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1185. // 类型排序优先级
  1186. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1187. if (typeOrder !== 0) {
  1188. return typeOrder;
  1189. }
  1190. // 处理专辑可能为undefined的字符串比较
  1191. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1192. const albumB = b.album?.trim() || '';
  1193. return albumB.localeCompare(albumA);
  1194. });
  1195. break;
  1196. case 4:
  1197. Utility.doSortListAscending(this.videoLocalList)
  1198. break;
  1199. case 5:
  1200. Utility.doSortListDescending(this.videoLocalList)
  1201. break;
  1202. case 6:
  1203. this.videoLocalList.sort((a, b) => {
  1204. // First, sort by type
  1205. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1206. if (typeOrder !== 0) {
  1207. return typeOrder;
  1208. }
  1209. // If types are the same, sort by cTime in ascending order
  1210. return a.cTime.localeCompare(b.cTime);
  1211. });
  1212. break;
  1213. case 7:
  1214. this.videoLocalList.sort((a, b) => {
  1215. // First, sort by type
  1216. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1217. if (typeOrder !== 0) {
  1218. return typeOrder;
  1219. }
  1220. // If types are the same, sort by cTime in descending order
  1221. return b.cTime.localeCompare(a.cTime);
  1222. });
  1223. break;
  1224. }
  1225. }
  1226. showSheelDialog() {
  1227. // if(PreferencesUtil.getBooleanSync('isFirstMusic',true)) {
  1228. // this.showTips()
  1229. // return
  1230. // }
  1231. this.showAddDialog()
  1232. }
  1233. showAddDialog() {
  1234. if (this.modeType === 2 || this.modeType === 3) {
  1235. return
  1236. }
  1237. DialogHelper.showActionSheetDialog({
  1238. title: "请选择添加方式(建议歌词文件一起导入)",
  1239. // sheets: ["新建歌单", "手动导入", "自动导入"],
  1240. sheets: [
  1241. { value: "新建歌单", fontColor: $r('app.color.text_color') },
  1242. { value: "手动导入", fontColor: $r('app.color.text_color') },
  1243. { value: "自动导入", fontColor: $r('app.color.text_color') },
  1244. { value: "全选导入", fontColor: $r('app.color.text_color') },
  1245. ],
  1246. maskColor: Color.Transparent,
  1247. backgroundColor: $r('app.color.bg_card'),
  1248. transition: AnimationHelper.transitionInDown(555),
  1249. onAction: (index) => {
  1250. switch (index) {
  1251. case 0:
  1252. if (this.modeType === 0) {
  1253. this.showMkDialog()
  1254. } else {
  1255. ToastUtil.showToast('请切换到首页才能新建歌单!')
  1256. }
  1257. break;
  1258. case 1:
  1259. this.callFilePickerSelectFile()
  1260. break;
  1261. case 2:
  1262. this.showTips()
  1263. break;
  1264. case 3:
  1265. this.goSelectMusic()
  1266. break;
  1267. }
  1268. }
  1269. })
  1270. }
  1271. //拉起音频
  1272. goSelectMusic() {
  1273. if (DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_TABLET ||
  1274. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_PC ||
  1275. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1
  1276. ) {
  1277. ToastUtil.showToast('暂时不支持该设备')
  1278. return
  1279. }
  1280. try {
  1281. let documentSelectOptions = new picker.DocumentSelectOptions();
  1282. documentSelectOptions.authMode = true
  1283. documentSelectOptions.multiAuthMode = true
  1284. documentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO;
  1285. let documentPicker = new picker.DocumentViewPicker(this.context);
  1286. documentPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => {
  1287. if (documentSelectResult !== null && documentSelectResult !== undefined) {
  1288. this.saveVideoDatas(documentSelectResult)
  1289. }
  1290. console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' +
  1291. JSON.stringify(documentSelectResult));
  1292. }).catch((err: BusinessError) => {
  1293. console.error(`DocumentViewPicker.select failed with err, code is: ${err.code}, message is: ${err.message}`);
  1294. });
  1295. } catch (error) {
  1296. let err: BusinessError = error as BusinessError;
  1297. console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1298. }
  1299. }
  1300. async showTips() {
  1301. DialogHelper.showTipsDialog({
  1302. title: '使用提示:自动导入教程',
  1303. content: '用系统自带的文件管理器将:\n\n1、音频文件放入' + '\n\n我的设备/Download/'
  1304. + this.appName + '\n\n2、无需繁琐的勾选和分类步骤。\n\n3、每个子文件夹将被组成一个分组。' +
  1305. '\n\n4、歌词文件的文件名必须和目标歌曲文件名相同(不包含后缀名)。\n\n5、歌词文件和目标歌曲文件必须同个目录。' +
  1306. '\n\n6、电脑上Download的目录是\nDownload/' + this.packName + '。\n\n7、放好文件后如果没显示点击刷新按钮。\n',
  1307. onAction: (action) => {
  1308. if (action == DialogAction.TWO) {
  1309. PreferencesUtil.putSync('isFirstMusic', false)
  1310. router.pushUrl({
  1311. url: 'pages/ScanFilePage'
  1312. });
  1313. }
  1314. }
  1315. })
  1316. }
  1317. showMkDialog() {
  1318. DialogHelper.showTextInputDialog({
  1319. title: '新建歌单',
  1320. maskColor: Color.Transparent,
  1321. text: '',
  1322. transition: AnimationHelper.transitionInDown(666),
  1323. onChange: (text) => {
  1324. console.error("onChange: " + text);
  1325. },
  1326. onAction: (action, dialogId, content) => {
  1327. // ToastUtil.showToast('content = ' +content)
  1328. if (action == DialogAction.TWO) {
  1329. const newName = content
  1330. const newPath = this.currentPath + '/' + newName
  1331. FileUtil.mkdir(newPath, true).then(() => {
  1332. this.cache.delete(this.currentPath); // 删除目标路径缓存
  1333. this.getSortedFiles(this.currentPath)
  1334. }).catch((error: BusinessError) => {
  1335. console.error(error.message);
  1336. });
  1337. }
  1338. }
  1339. })
  1340. }
  1341. @State progress: number = 0;
  1342. async saveVideoDatas(uris: string[], isOpen?: boolean) {
  1343. if (ArrayUtil.isEmpty(uris)) {
  1344. return;
  1345. }
  1346. let newUris: string[] = [];
  1347. this.progress = 0
  1348. DialogHelper.showLoadingProgress({
  1349. progress: this.progress,
  1350. backCancel: false,
  1351. autoCancel: false,
  1352. loadColor: this.themeColor,
  1353. fontColor: this.themeColor
  1354. });
  1355. // 计算所有文件的总大小
  1356. let totalSize = 0;
  1357. for (let uri of uris) {
  1358. const sourceFile = await fileIo.open(uri, fileIo.OpenMode.READ_ONLY);
  1359. totalSize += (await fileIo.stat(sourceFile.fd)).size;
  1360. await fileIo.close(sourceFile.fd);
  1361. }
  1362. let totalRead = 0;
  1363. let destPath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[0]);
  1364. Logger.info(TAG, 'destPath uri: ' + destPath);
  1365. for (let i = 0; i < uris.length; i++) {
  1366. let filePath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[i]);
  1367. Logger.info(TAG, 'filePath uri: ' + filePath);
  1368. newUris.push(filePath);
  1369. try {
  1370. const sourceFile = await fileIo.open(uris[i], fileIo.OpenMode.READ_ONLY);
  1371. const destFile = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  1372. const buffSize = 1024 * 1024; // 1MB 缓冲区大小
  1373. const buffer = new ArrayBuffer(buffSize);
  1374. let len = await fileIo.read(sourceFile.fd, buffer);
  1375. while (len > 0) {
  1376. await fileIo.write(destFile.fd, buffer.slice(0, len));
  1377. totalRead += len;
  1378. // 计算总进度
  1379. this.progress = Math.floor((totalRead / totalSize) * 100);
  1380. DialogHelper.updateLoading('正在导入', this.progress);
  1381. len = await fileIo.read(sourceFile.fd, buffer);
  1382. }
  1383. await fileIo.close(sourceFile.fd);
  1384. await fileIo.close(destFile.fd);
  1385. if (this.currentPath !== this.lockPath) { //判断不是私密音乐,才入库
  1386. if (!filePath.endsWith('.lrc') && Utility.isMeidaByExtension(filePath) && !filePath.endsWith('.srt')) {
  1387. let mediaItem: VideoItem =
  1388. await Utility.uriGetMusicAssetsFromFile(this.context, filePath, CommonConstants.TYPE_LOCAL, true);
  1389. this.table.insert(mediaItem, (id: number) => {
  1390. // 删除目标路径缓存
  1391. this.cache.delete(this.currentPath);
  1392. this.getSortedFiles(this.currentPath, true, destPath, isOpen)
  1393. });
  1394. }
  1395. }
  1396. } catch (error) {
  1397. Logger.error(TAG, 'saveVideoDatas failed with err: ' + JSON.stringify(error));
  1398. }
  1399. }
  1400. DialogHelper.closeLoading()
  1401. this.isZero = false
  1402. // setTimeout(() => {
  1403. // // 删除目标路径缓存
  1404. // this.cache.delete(this.currentPath);
  1405. // this.getSortedFiles(this.currentPath,true,destPath,isOpen)
  1406. // }, 500);
  1407. Logger.info(TAG, 'scan select video result:' + newUris)
  1408. }
  1409. //拉起音频
  1410. // goSelectMusic(){
  1411. //
  1412. // try {
  1413. // let audioSelectOptions = new picker.AudioSelectOptions();
  1414. // let audioPicker = new picker.AudioViewPicker(this.context);
  1415. // audioPicker.select(audioSelectOptions).then((audioSelectResult: Array<string>) => {
  1416. // if (audioSelectResult !== null && audioSelectResult !== undefined) {
  1417. // this.saveVideoDatas(audioSelectResult)
  1418. // }
  1419. // console.info('AudioViewPicker.select successfully, audioSelectResult uri: ' + JSON.stringify(audioSelectResult));
  1420. // }).catch((err: BusinessError) => {
  1421. //
  1422. // console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
  1423. // });
  1424. // } catch (error) {
  1425. // let err: BusinessError = error as BusinessError;
  1426. // console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1427. // }
  1428. //
  1429. //
  1430. //
  1431. // }
  1432. async goSelectImage(item: VideoItem): Promise<string | undefined> {
  1433. if (!item) {
  1434. return undefined;
  1435. }
  1436. try {
  1437. let selectUris: Array<string> = [];
  1438. let photoPicker = new photoAccessHelper.PhotoViewPicker();
  1439. let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  1440. photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
  1441. photoSelectOptions.maxSelectNumber = 1;
  1442. const photoSelectResult = await photoPicker.select(photoSelectOptions);
  1443. selectUris = photoSelectResult.photoUris;
  1444. console.info('photoViewPicker.select to file succeed and uris are:' + selectUris);
  1445. let file = fs.openSync(selectUris[0], fs.OpenMode.READ_ONLY);
  1446. console.info('file fd: ' + file.fd);
  1447. let name = await MD5.digestSync(this.videoUrl)+'.jpg'
  1448. let imagePath = this.context.filesDir + FileUtil.separator + name
  1449. imagePath = fileUri.getUriFromPath(imagePath)
  1450. let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  1451. fileIo.copyFileSync(file.fd, file2.fd)
  1452. fileIo.closeSync(file);
  1453. fileIo.closeSync(file2);
  1454. if (item.filePath == this.currentSong?.filePath) {
  1455. this.cover = imagePath
  1456. }
  1457. if (item) {
  1458. item.pixelMapPath = imagePath
  1459. }
  1460. this.table.updatePixelMapPath(item.filePath, imagePath, (success: boolean, error?: string) => {
  1461. if (success) {
  1462. this.doUpdateData()
  1463. console.log("onecold 更新音乐封面成功,数据库已同步");
  1464. } else {
  1465. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  1466. }
  1467. });
  1468. LogUtil.debug("onecold this.cover =" + this.cover)
  1469. return FileUtil.getFilePath(imagePath); // Return the image path here
  1470. } catch (err) {
  1471. console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
  1472. return undefined;
  1473. }
  1474. }
  1475. // 拉起picker选择文件管理器
  1476. async callFilePickerSelectFile(): Promise<void> {
  1477. try {
  1478. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  1479. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE) {
  1480. DocumentSelectOptions.fileSuffixFilters = CommonConstants.MEDIA_FORMAT
  1481. } else {
  1482. DocumentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO
  1483. }
  1484. let documentPicker = new picker.DocumentViewPicker();
  1485. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  1486. Logger.info(TAG,
  1487. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  1488. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  1489. this.saveVideoDatas(DocumentSelectResult)
  1490. }
  1491. }).catch((err: BusinessError) => {
  1492. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  1493. });
  1494. } catch (err) {
  1495. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  1496. }
  1497. }
  1498. //重命名的对话框
  1499. showReNameDialog(item: VideoItem, index: string, filePath: string) {
  1500. DialogHelper.showTextInputDialog({
  1501. title: '重命名',
  1502. text: item.type === CommonConstants.TYPE_IS_DIR ? item.name : item.fileName,
  1503. maskColor: Color.Transparent,
  1504. backgroundColor: Color.Grey,
  1505. transition: AnimationHelper.transitionInDown(666),
  1506. onChange: (text) => {
  1507. console.error("onChange: " + text);
  1508. },
  1509. onAction: (action, dialogId, content) => {
  1510. // ToastUtil.showToast('content = ' +content)
  1511. if (action == DialogAction.TWO) {
  1512. const newName = content
  1513. const newPath = this.currentPath + '/' + newName
  1514. console.log("onecold item = " + item.type);
  1515. this.doReName(index, newName, filePath, newPath, item)
  1516. }
  1517. }
  1518. })
  1519. }
  1520. //剪切 移动到另个文件夹的对话框
  1521. showCutDialog(isCurrent: boolean, item: VideoItem, index: number, id: string) {
  1522. Logger.info('onecold showCutDialog')
  1523. let mList: Array<string> = []
  1524. let rPath = this.rootPath
  1525. if (isCurrent) {
  1526. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1527. rPath = this.currentPath
  1528. } else {
  1529. mList = Utility.getNameList(this.dirList);
  1530. rPath = this.rootPath
  1531. }
  1532. let dataBean = new BubbleBean()
  1533. dataBean.data = mList
  1534. dataBean.color = this.themeColor
  1535. dataBean.onItemClick = (i) => {
  1536. const newPath = rPath + '/' + mList[i] + '/' + item.fileName
  1537. Logger.info('newPath = ' + newPath)
  1538. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  1539. ToastUtil.showToast('移动成功')
  1540. this.table.deleteData(item, () => {
  1541. });
  1542. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  1543. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  1544. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  1545. CommonConstants.TYPE_LOCAL, true);
  1546. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  1547. this.table.insert(newItem, (id: number) => {
  1548. //加入数据库
  1549. });
  1550. }
  1551. this.cache.delete(this.currentPath); // 删除原路径缓存
  1552. this.cache.delete(rPath + '/' + mList[i]); // 删除目标路径缓存
  1553. this.getSortedFiles(this.currentPath, true)
  1554. }).catch((error: BusinessError) => {
  1555. console.error(error.message);
  1556. });
  1557. XPopup.dismissTop()
  1558. }
  1559. let popupPosition: PopupPosition = PopupPosition.BOTTOM
  1560. if (ArrayUtil.isNotEmpty(this.videoLocalList) && this.videoLocalList.length > 7) {
  1561. popupPosition = PopupPosition.TOP
  1562. }
  1563. if (index <= 3) {
  1564. popupPosition = PopupPosition.BOTTOM
  1565. }
  1566. let pup: XPopup
  1567. if (this.isDarkMode) {
  1568. pup = XPopup.Builder()
  1569. .setPopupPosition(popupPosition)
  1570. .atView(id)// .setHeight(this.isCoverOpacity()?100:420)
  1571. .setBackgroundColor(Color.Black)
  1572. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1573. .show()
  1574. } else {
  1575. pup = XPopup.Builder()
  1576. .setPopupPosition(popupPosition)
  1577. .atView(id)// .setHeight(this.isCoverOpacity()?280:420)
  1578. .setBackgroundColor(Color.White)
  1579. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1580. .show()
  1581. }
  1582. }
  1583. //复制 到另个文件夹的对话框
  1584. showCopyDialog(isCurrent: boolean, item: VideoItem, index: number, id: string) {
  1585. Logger.info('onecoldv showCopyDialog')
  1586. let mList: Array<string> = []
  1587. let rPath = this.rootPath
  1588. if (isCurrent) {
  1589. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1590. rPath = this.currentPath
  1591. } else {
  1592. mList = Utility.getNameList(this.dirList);
  1593. rPath = this.rootPath
  1594. }
  1595. let dataBean = new BubbleBean()
  1596. dataBean.data = mList
  1597. dataBean.isCopy = true
  1598. dataBean.color = this.themeColor
  1599. dataBean.onItemClick = (i) => {
  1600. const newPath = rPath + '/' + mList[i] + '/' + item.fileName
  1601. Logger.info('newPath = ' + newPath)
  1602. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  1603. ToastUtil.showToast('复制成功')
  1604. this.cache.delete(rPath + '/' + mList[i]); // 删除目标路径缓存
  1605. this.getSortedFiles(this.currentPath)
  1606. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  1607. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  1608. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  1609. CommonConstants.TYPE_LOCAL, true);
  1610. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  1611. this.table.insert(newItem, (id: number) => {
  1612. //加入数据库
  1613. });
  1614. }
  1615. }).catch((error: BusinessError) => {
  1616. console.error(error.message);
  1617. });
  1618. XPopup.dismissTop()
  1619. }
  1620. let popupPosition: PopupPosition = PopupPosition.BOTTOM
  1621. if (ArrayUtil.isNotEmpty(this.videoLocalList) && this.videoLocalList.length > 7) {
  1622. popupPosition = PopupPosition.TOP
  1623. }
  1624. if (index <= 3) {
  1625. popupPosition = PopupPosition.BOTTOM
  1626. }
  1627. let pup: XPopup
  1628. if (this.isDarkMode) {
  1629. pup = XPopup.Builder()
  1630. .setPopupPosition(popupPosition)
  1631. .atView(id)
  1632. .setMaxHeight('60%')
  1633. .setBackgroundColor(Color.Black)
  1634. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1635. .show();
  1636. } else {
  1637. pup = XPopup.Builder()
  1638. .setPopupPosition(popupPosition)
  1639. .atView(id)
  1640. .setMaxHeight('60%')
  1641. .setBackgroundColor(Color.White)
  1642. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  1643. .show();
  1644. }
  1645. }
  1646. //重命名索引index的视频
  1647. doReName(index: string, newName: string, oldPath: string, newPath: string, info: VideoItem) {
  1648. FileUtil.rename(oldPath, newPath).then(async () => {
  1649. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1650. if (info.type === CommonConstants.TYPE_IS_DIR) {
  1651. //如果是文件夹先删除源数据,再添加新数据
  1652. this.table.deleteDataForParentPath(oldPath, (success: boolean, error?: string) => {
  1653. if (success) {
  1654. console.log(" onecold deleteDataForParentPath 文件夹重命名成功,数据库已同步");
  1655. } else {
  1656. console.error(" onecold deleteDataForParentPath 文件夹重命名数据库失败原因: " + error);
  1657. }
  1658. });
  1659. this.scanDirectory(newPath)
  1660. } else if (info.type === CommonConstants.TYPE_LOCAL) {
  1661. this.table.updateRename(newName, oldPath, newPath, (success: boolean, error?: string) => {
  1662. if (success) {
  1663. console.log(" onecold 重命名成功,数据库已同步");
  1664. } else {
  1665. console.error(" onecold 重命名数据库失败原因: " + error);
  1666. }
  1667. });
  1668. }
  1669. let mediaItem: VideoItem =
  1670. await Utility.uriGetMusicAssetsFromFile(this.context, newPath, CommonConstants.TYPE_LOCAL, true);
  1671. this.videoLocalList[index] = mediaItem;
  1672. }
  1673. this.cache.delete(this.currentPath)
  1674. this.getSortedFiles(this.currentPath, true)
  1675. }).catch((error: BusinessError) => {
  1676. console.error(error.message);
  1677. });
  1678. }
  1679. build() {
  1680. Scroll() {
  1681. Column() {
  1682. if (!this.isShowCoverHeader()) {
  1683. Column() {
  1684. Line().width('100%').height('100%')
  1685. }
  1686. .height(this.topRectHeight)
  1687. .backgroundColor(this.isCustomizeBg ? Color.Transparent :
  1688. (this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor))
  1689. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  1690. TitleBar({ model: $titleBarModel })
  1691. .id('pup_positon_music')
  1692. }
  1693. Stack() {
  1694. Column() {
  1695. XComponent({
  1696. id: 'xcomponentId',
  1697. type: 'surface',
  1698. libraryname: 'ijkplayer_napi',
  1699. controller: this.xcomponentController
  1700. })
  1701. .onLoad((event?: object) => {
  1702. if (!!event) {
  1703. this.initDelayPlay(event);
  1704. }
  1705. })
  1706. .onKeyEvent((event?: KeyEvent) => {
  1707. // If the button type is pressed, the subsequent code will not be executed; the specific button logic will be executed upon release.
  1708. if (!event || event.type !== KeyType.Down) {
  1709. return;
  1710. }
  1711. //空格键 Space key controls pause/play
  1712. if (event.keyCode === KeyCode.KEYCODE_SPACE) {
  1713. console.info('onecold playOrPause 1999')
  1714. this.playOrPause()
  1715. }
  1716. // Right-click to fast forward
  1717. if (event.keyCode === KeyCode.KEYCODE_DPAD_RIGHT) {
  1718. this.sessionFastForwardCallback(15);
  1719. }
  1720. // Left-click to rewind
  1721. if (event.keyCode === KeyCode.KEYCODE_DPAD_LEFT) {
  1722. this.sessionRewindCallback(15);
  1723. }
  1724. })
  1725. .onDestroy(() => {
  1726. })
  1727. .width('100%')// .width(this.videoWidth)
  1728. .aspectRatio(this.videoAspectRatio)
  1729. }
  1730. .aspectRatio(this.videoAspectRatio)
  1731. .justifyContent(FlexAlign.Center)
  1732. .backgroundColor(Color.Transparent)
  1733. .visibility(Visibility.Hidden)
  1734. .height(CommonConstants.FULL_PERCENT)
  1735. .width(CommonConstants.FULL_PERCENT)
  1736. Stack() {
  1737. Row() {
  1738. Blank()
  1739. .layoutWeight(1)
  1740. IndexerView(
  1741. {
  1742. indexArray: DEFAULT_INDEX,
  1743. selectedIndex: this.selectedIndex,
  1744. textSize: 12,
  1745. selectedColor: "#ff419ee5",
  1746. normalColor: "#ffa0a0a0",
  1747. floatSelectedTextColor: "#ffffff",
  1748. floatSelectedViewColor: "#ff419ee5",
  1749. onIndexChanged: (index) => {
  1750. this.listScroller.scrollToIndex(index)
  1751. }
  1752. })
  1753. .width(24)
  1754. .height("50%")
  1755. }.visibility(Visibility.None)
  1756. Column() {
  1757. if (!this.isShowCoverHeader()) {
  1758. this.tabTitle()
  1759. }
  1760. if(this.twoFingerType==4){
  1761. this.getWaterView()
  1762. }else{
  1763. if(this.isGridMusic){
  1764. this.getGridView()
  1765. }else {
  1766. this.getListView()
  1767. }
  1768. }
  1769. if (this.modeType == 0) {
  1770. Column() {
  1771. Button('同步数据', { type: ButtonType.Capsule, stateEffect: true })
  1772. .width(130)
  1773. .height(50)
  1774. .margin({ top: 100, bottom: 40 })
  1775. .backgroundColor(this.themeColor)
  1776. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  1777. .onClick(() => {
  1778. this.asyncCurrentPathData()
  1779. })
  1780. }
  1781. .height(100)
  1782. .position({ top: 260 })
  1783. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  1784. .animation({ duration: 500 }),
  1785. TransitionEffect.scale({ x: 0, y: 0 })))
  1786. .justifyContent(FlexAlign.Center)
  1787. .opacity(this.isZero ? 1 : 0)
  1788. .visibility(this.isZero && !this.isFavMusic && !this.isHistory
  1789. && this.modeType === 0 ? Visibility.Visible : Visibility.None)
  1790. .animation({
  1791. duration: 500,
  1792. curve: 'ease-in-out' // 可选动画曲线
  1793. })
  1794. .width('100%')
  1795. }
  1796. }
  1797. .layoutWeight(1)
  1798. .height('100%')
  1799. }
  1800. .layoutWeight(1)
  1801. .height('100%')
  1802. Row() {
  1803. Button(this.isAllSelected ? '全不选' : '全选', { type: ButtonType.Circle, stateEffect: true })
  1804. .width('35%')
  1805. .height(60)
  1806. .margin({ top: 10, bottom: 10, right: 6 })
  1807. .backgroundColor(this.themeColor)
  1808. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1809. .onClick(() => {
  1810. if (this.isAllSelected) {
  1811. // 全不选
  1812. this.selectedFiles = [];
  1813. } else {
  1814. // 全选
  1815. this.selectedFiles = [...this.getCurFileList()];
  1816. }
  1817. this.isAllSelected = !this.isAllSelected;
  1818. })
  1819. Button('内嵌标签', { type: ButtonType.Capsule, stateEffect: true })
  1820. .width(100)
  1821. .height(60)
  1822. .margin({ top: 10, bottom: 10, right: 6 })
  1823. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1824. .backgroundColor(this.themeColor)
  1825. .bindContentCover($$this.isOneKeyTags, this.TagsContentCoverBuilder(), {
  1826. transition: TransitionEffect.translate({ x: 500 }).animation({ curve: curves.springMotion(0.6, 0.8) })
  1827. })
  1828. .onClick(() => {
  1829. this.isOneKeyTags = !this.isOneKeyTags
  1830. })
  1831. // Button('剪切', { type: ButtonType.Circle, stateEffect: true })
  1832. // .width('35%')
  1833. // .height(60)
  1834. // .id('music_cut')
  1835. // .margin({ top: 10, bottom: 10, right: 6 })
  1836. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1837. // .backgroundColor(this.themeColor)
  1838. // .onClick(() => {
  1839. // this.showCutDialogForMultipleFiles(false, 'music_cut')
  1840. // })
  1841. //
  1842. // Button('移动', { type: ButtonType.Circle, stateEffect: true })
  1843. // .width('35%')
  1844. // .height(60)
  1845. // .id('music_cut_current')
  1846. // .visibility(this.isHasDir ? Visibility.Visible : Visibility.None)
  1847. // .margin({ top: 10, bottom: 10, right: 6 })
  1848. // .backgroundColor(this.themeColor)
  1849. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1850. // .onClick(() => {
  1851. //
  1852. // this.showCutDialogForMultipleFiles(true, 'music_cut_current')
  1853. // })
  1854. // Button('复制', { type: ButtonType.Circle, stateEffect: true })
  1855. // .width('35%')
  1856. // .height(60)
  1857. // .id('music_copy_current')// .visibility(this.isHasDir?Visibility.None:Visibility.None)
  1858. // .margin({ top: 10, bottom: 10, right: 6 })
  1859. // .backgroundColor(this.themeColor)
  1860. // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1861. // .onClick(() => {
  1862. // this.showCopyDialogForMultipleFiles(false, 'music_copy_current')
  1863. // })
  1864. Button('删除', { type: ButtonType.Circle, stateEffect: true })
  1865. .width('35%')
  1866. .height(60)
  1867. .margin({ top: 10, bottom: 10, right: 6 })
  1868. .visibility(this.isFavMusic ? Visibility.None : Visibility.Visible)
  1869. .backgroundColor(this.themeColor)
  1870. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1871. .onClick(() => {
  1872. this.showWarnIsDelete()
  1873. })
  1874. Button('取消', { type: ButtonType.Circle, stateEffect: true })
  1875. .width('35%')
  1876. .height(60)
  1877. .margin({ top: 10, bottom: 10, right: 6 })
  1878. .backgroundColor(this.themeColor)
  1879. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1880. .onClick(() => {
  1881. this.selectedFiles = [];
  1882. this.isAllSelected = false
  1883. this.isMultiSelect = false
  1884. })
  1885. }
  1886. .width('100%')
  1887. .justifyContent(FlexAlign.Center)
  1888. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  1889. .opacity(this.isMultiSelect ? 1 : 0)
  1890. .animation({
  1891. duration: 666,
  1892. curve: 'ease-in-out' // 可选动画曲线
  1893. })
  1894. .position(this.isShowCoverHeader() ? { bottom: 78 }
  1895. : { bottom: this.isPhoneLan() ? 130 : 168 }) // 将 Row 固定在底部
  1896. }
  1897. .width('100%')
  1898. .height('100%')
  1899. .alignContent(Alignment.Top)
  1900. Column() {
  1901. this.PlayController()
  1902. }
  1903. .hitTestBehavior(HitTestMode.Transparent)
  1904. .position({ bottom: 0 }) // 将 Row 固定在底部
  1905. .opacity(this.barBottomOpacity)
  1906. }
  1907. .width('100%')
  1908. .height('100%')
  1909. .backgroundImage(this.isCustomizeBg ? this.customizeBgPath : $r('app.color.bottom_control_background'))
  1910. .backgroundImageSize(this.isCoverOpacity() ? { width: '100%' } : { height: '100%' })
  1911. .backgroundImagePosition(Alignment.Center)
  1912. .backdropBlur(this.blurValue)
  1913. .backgroundBrightness({ rate: this.isCustomizeBg ? 0.1 : 0, lightUpDegree: this.bgBrightness })
  1914. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
  1915. }
  1916. }
  1917. @Builder
  1918. TagsContentCoverBuilder() {
  1919. Scroll() {
  1920. Column() {
  1921. TagsContentCover(
  1922. {
  1923. selectedFiles:this.selectedFiles,
  1924. isShowDrawer:this.isOneKeyTags,
  1925. onTagsResult:(result: boolean)=>{
  1926. this.isMultiSelect = false
  1927. if(result){//如果嵌入成功,更新数据
  1928. this.doUpdateData()
  1929. }
  1930. }
  1931. }
  1932. )
  1933. }
  1934. }
  1935. .width('100%')
  1936. .height('100%')
  1937. }
  1938. asyncCurrentPathData() {
  1939. if (this.modeType == 0) {
  1940. workerInstance.postMessage({
  1941. code: 1,
  1942. data1: this.context,
  1943. data2: this.currentPath,
  1944. data3: this.lockPath,
  1945. data4: PreferencesUtil.getStringSync('COVER_API', ''),
  1946. });
  1947. }
  1948. }
  1949. // 处理文件选择的函数
  1950. handleFileSelection(item: VideoItem, checked: boolean) {
  1951. if (checked) {
  1952. if (!this.selectedFiles.some(x => x.filePath == item.filePath)) {
  1953. this.selectedFiles.push(item);
  1954. }
  1955. } else {
  1956. const index = this.selectedFiles.findIndex(x => x.filePath == item.filePath);
  1957. if (index > -1) {
  1958. this.selectedFiles.splice(index, 1);
  1959. }
  1960. }
  1961. }
  1962. private deleteComponentId: number = 0
  1963. //多选删除文件
  1964. showWarnIsDelete(){
  1965. this.getUIContext().getPromptAction().openCustomDialog({
  1966. builder: () => {
  1967. this.deleteComptentBuilder()
  1968. },
  1969. isModal:true,
  1970. showInSubWindow:false,
  1971. maskColor: Color.Transparent,
  1972. dialogTransition: // 设置弹窗内容显示的过渡效果
  1973. TransitionEffect.translate({ x: 0, y: 290, z: 0 })
  1974. .animation({ duration: 600, curve: Curve.Smooth }),
  1975. maskTransition: // 设置蒙层显示的过渡效果
  1976. TransitionEffect.opacity(0)
  1977. .animation({ duration: 600, curve: Curve.Smooth })
  1978. }).then((dialogId: number) => {
  1979. this.deleteComponentId = dialogId
  1980. })
  1981. .catch((error: BusinessError) => {
  1982. console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`)
  1983. })
  1984. }
  1985. @Builder
  1986. deleteComptentBuilder(){
  1987. DeleteComptent({
  1988. selectedFiles:this.selectedFiles,
  1989. onCancel:()=>{
  1990. this.isMultiSelect = false
  1991. this.getUIContext().getPromptAction().closeCustomDialog(this.deleteComponentId)
  1992. },
  1993. onDeleteResult:(result: boolean,item: VideoItem)=>{
  1994. this.isMultiSelect = false
  1995. this.getUIContext().getPromptAction().closeCustomDialog(this.deleteComponentId)
  1996. if(result){//如果删除成功,更新数据
  1997. this.videoLocalList = this.videoLocalList.filter(v => v !== item);
  1998. this.selectedFiles = [];
  1999. this.isAllSelected = false
  2000. this.cache.delete(this.currentPath);
  2001. this.getSortedFiles(this.currentPath, true);
  2002. }
  2003. }
  2004. })
  2005. }
  2006. //多选移动文件
  2007. showCutDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  2008. Logger.info('onecold showCutDialogForMultipleFiles')
  2009. let mList: Array<string> = []
  2010. let rPath = this.rootPath
  2011. if (isCurrent) {
  2012. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  2013. rPath = this.currentPath
  2014. } else {
  2015. mList = Utility.getNameList(this.dirList);
  2016. rPath = this.rootPath
  2017. }
  2018. let dataBean = new BubbleBean();
  2019. dataBean.data = mList;
  2020. dataBean.color = this.themeColor
  2021. dataBean.onItemClick = (i) => {
  2022. const newDirPath = rPath + '/' + mList[i];
  2023. // Logger.info('newDirPath = ' + newDirPath)
  2024. this.selectedFiles.forEach((item) => {
  2025. const newPath = newDirPath + '/' + item.fileName;
  2026. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  2027. ToastUtil.showToast('移动成功');
  2028. this.table.deleteData(item, () => {
  2029. this.cache.delete(this.currentPath); // 删除原路径缓存
  2030. this.cache.delete(newDirPath); // 删除目标路径缓存
  2031. this.getSortedFiles(this.currentPath, true);
  2032. });
  2033. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2034. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2035. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2036. CommonConstants.TYPE_LOCAL, true);
  2037. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2038. this.table.insert(newItem, (id: number) => {
  2039. //加入数据库
  2040. });
  2041. }
  2042. }).catch((error: Error) => {
  2043. console.error(error.message);
  2044. });
  2045. });
  2046. this.isMultiSelect = false
  2047. this.selectedFiles = [];
  2048. this.isAllSelected = false
  2049. XPopup.dismissTop();
  2050. };
  2051. let pup: XPopup
  2052. if (this.isDarkMode) {
  2053. pup = XPopup.Builder()
  2054. .setPopupPosition(PopupPosition.TOP)
  2055. .atView(viewId)
  2056. .setBackgroundColor(Color.Black)
  2057. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2058. .show();
  2059. } else {
  2060. pup = XPopup.Builder()
  2061. .setPopupPosition(PopupPosition.TOP)
  2062. .atView(viewId)
  2063. .setBackgroundColor(Color.White)
  2064. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2065. .show();
  2066. }
  2067. }
  2068. doFav(item: VideoItem) {
  2069. LogUtil.info('onecold doFav isFav=' + item.isFav)
  2070. let isFav = 0
  2071. if (Utility.getIsFav(this.favList, item)) {
  2072. isFav = 0
  2073. } else {
  2074. isFav = 1
  2075. }
  2076. this.table.updateIsFavByFilePath(item.filePath, isFav, async (result: boolean) => {
  2077. if (result) {
  2078. if (isFav === 1) {
  2079. ToastUtil.showToast('收藏成功');
  2080. } else {
  2081. ToastUtil.showToast('取消收藏成功');
  2082. }
  2083. this.deleteCache(this.currentPath)
  2084. this.getFavList(false)
  2085. if (this.modeType === 0 && !this.isFavMusic) {
  2086. LogUtil.info('onecold doFav currentPath =' + this.currentPath)
  2087. this.getSortedFiles(this.currentPath)
  2088. }
  2089. workerInstance.postMessage({ code: 2, data: this.context });
  2090. workerInstance.postMessage({ code: 3, data: this.context });
  2091. workerInstance.postMessage({ code: 4, data: this.context });
  2092. }
  2093. })
  2094. }
  2095. //多选复制文件
  2096. showCopyDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  2097. console.log('onecold showCopyDialogForMultipleFiles');
  2098. let mList: Array<string> = []
  2099. let rPath = this.rootPath
  2100. if (isCurrent) {
  2101. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  2102. rPath = this.currentPath
  2103. } else {
  2104. mList = Utility.getNameList(this.dirList);
  2105. rPath = this.rootPath
  2106. }
  2107. let dataBean = new BubbleBean();
  2108. dataBean.data = mList;
  2109. dataBean.isCopy = true
  2110. dataBean.color = this.themeColor
  2111. dataBean.onItemClick = (i) => {
  2112. const newDirPath = rPath + '/' + mList[i];
  2113. // Logger.info('newDirPath = ' + newDirPath)
  2114. this.selectedFiles.forEach((item) => {
  2115. const newPath = newDirPath + '/' + item.fileName;
  2116. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  2117. ToastUtil.showToast('复制成功');
  2118. this.cache.delete(newDirPath); // 删除目标路径缓存
  2119. this.getSortedFiles(this.currentPath);
  2120. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2121. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2122. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2123. CommonConstants.TYPE_LOCAL, true);
  2124. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2125. this.table.insert(newItem, (id: number) => {
  2126. //加入数据库
  2127. });
  2128. }
  2129. }).catch((error: Error) => {
  2130. console.error(error.message);
  2131. });
  2132. });
  2133. this.isMultiSelect = false
  2134. this.selectedFiles = [];
  2135. this.isAllSelected = false
  2136. XPopup.dismissTop();
  2137. };
  2138. let pup: XPopup
  2139. if (this.isDarkMode) {
  2140. pup = XPopup.Builder()
  2141. .setPopupPosition(PopupPosition.TOP)
  2142. .atView(viewId)
  2143. .setBackgroundColor(Color.Black)
  2144. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2145. .show();
  2146. } else {
  2147. pup = XPopup.Builder()
  2148. .setPopupPosition(PopupPosition.TOP)
  2149. .atView(viewId)
  2150. .setBackgroundColor(Color.White)
  2151. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2152. .show();
  2153. }
  2154. }
  2155. @Builder
  2156. private DirItem(item: VideoItem, index?: number) {
  2157. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2158. Row() {
  2159. Image(this.modeType !== 0 && StrUtil.isNotEmpty(item.pixelMapPath) ? item.pixelMapPath :
  2160. $r('app.media.music_group'))
  2161. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2162. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2163. .fillColor(this.themeColor)// .fontSize(33)
  2164. .alt($r('app.media.music_group'))
  2165. .borderRadius('100%')
  2166. .clip(true)
  2167. .margin({ left: 20, top: 8, bottom: 8 })
  2168. Column() {
  2169. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  2170. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2171. .maxLines(1)// .width('88%')
  2172. .animation({
  2173. duration: 555,
  2174. curve: 'ease-in-out',
  2175. })
  2176. .transition({
  2177. type: TransitionType.Insert,
  2178. opacity: 0,
  2179. translate: { x: 160 }
  2180. })
  2181. .margin({ left: 10, right: 20 })
  2182. .fontColor($r('app.color.text_color'))
  2183. Row() {
  2184. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  2185. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2186. .padding({ top: 8 })
  2187. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2188. .fontColor($r('app.color.text_color'))
  2189. .margin({ left: 10 })
  2190. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  2191. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2192. .padding({ top: 8 })
  2193. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2194. .fontColor($r('app.color.text_color'))
  2195. .margin({ left: 10 })
  2196. Blank()
  2197. }
  2198. }
  2199. .height('100%')
  2200. .layoutWeight(1)
  2201. .justifyContent(FlexAlign.Center)
  2202. .alignItems(HorizontalAlign.Start)
  2203. Blank()
  2204. Image($r('app.media.arrow_right'))
  2205. .height(25)
  2206. .margin({ right: 10 })
  2207. .alignSelf(ItemAlign.Center)
  2208. .id(item.filePath)
  2209. }
  2210. }
  2211. .backgroundColor(Color.Transparent)
  2212. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2213. .width('100%')
  2214. .visibility(this.isShowDir(item.name) ? Visibility.Visible : Visibility.None)
  2215. .opacity(this.opacityItem) // 绑定透明度
  2216. }
  2217. isShowDir(dirName: string) {
  2218. this.isShowSimi = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, false)
  2219. this.isShowFAV = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_FAV, true)
  2220. this.isShowHistory = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HISTORY, true)
  2221. if (dirName === undefined) {
  2222. return true
  2223. }
  2224. if (dirName === LocalMusic.STR_LOCK_VIDEO) {
  2225. return this.isShowSimi
  2226. }
  2227. if (dirName === LocalMusic.STR_FAC_VIDEO) {
  2228. return this.isShowFAV
  2229. }
  2230. if (dirName === LocalMusic.STR_HISTORY_MUSIC) {
  2231. return this.isShowHistory
  2232. }
  2233. return true
  2234. }
  2235. @State opacityItem: number = 1; // 控制透明度的状态变量
  2236. @Builder
  2237. private MusicItem(item: VideoItem, index?: number) {
  2238. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2239. Row() {
  2240. Stack() {
  2241. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  2242. .fillColor(this.themeColor)
  2243. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2244. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2245. .alt($r('app.media.music_red'))
  2246. .borderRadius('100%')
  2247. .clip(true)
  2248. .draggable(false)
  2249. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  2250. .autoResize(true) // 重采样,可减少内存占用
  2251. .opacity(this.opacityItem)// 绑定透明度
  2252. .margin({ left: 20 })
  2253. .gesture(LongPressGesture()
  2254. .onAction(async () => {
  2255. //如果是专辑和艺术家的首页,不能长按
  2256. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2257. return
  2258. //如果是我的收藏 最近播放等也不能长按
  2259. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2260. item.name === LocalMusic.STR_HISTORY_MUSIC
  2261. )
  2262. return
  2263. this.longItemFilePath = item.filePath
  2264. this.tempLyricContent = await this.getLyricContent(item)
  2265. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2266. })
  2267. .onActionEnd((event: GestureEvent) => {
  2268. }))
  2269. }
  2270. Column() {
  2271. Column() {
  2272. Text(item.name)
  2273. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2274. .maxLines(1)
  2275. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  2276. .animation({
  2277. duration: 555,
  2278. curve: 'Linear',
  2279. })
  2280. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2281. $r('app.color.text_color'))
  2282. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2283. .padding({right:25})
  2284. .bindPopup(this.longItemFilePath === item.filePath, {
  2285. builder: this.MenuBuilder(item,index,item.filePath),
  2286. placement: Placement.Top,
  2287. // autoCancel: true,
  2288. mask: {color:'#33000000'},
  2289. // popupColor: Color.Yellow,
  2290. enableArrow: false,//是否显示箭头
  2291. showInSubWindow: false,
  2292. onStateChange: (e) => {
  2293. if (!e.isVisible) {
  2294. this.longItemFilePath = ''
  2295. this.tempLyricContent = ''
  2296. }
  2297. }
  2298. })
  2299. .gesture(LongPressGesture()
  2300. .onAction(async () => {
  2301. //如果是专辑和艺术家的首页,不能长按
  2302. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2303. return
  2304. //如果是我的收藏 最近播放等也不能长按
  2305. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2306. item.name === LocalMusic.STR_HISTORY_MUSIC
  2307. )
  2308. return
  2309. this.longItemFilePath = item.filePath
  2310. this.tempLyricContent = await this.getLyricContent(item)
  2311. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2312. })
  2313. .onActionEnd((event: GestureEvent) => {
  2314. })
  2315. )
  2316. Row() {
  2317. Column(){
  2318. Text(item.md5Str?.includes('Lossless')?
  2319. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  2320. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  2321. .padding({ top: 3,right:6,left:6,bottom:3 })
  2322. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2323. $r('app.color.text_color'))
  2324. .fontWeight(500)
  2325. .borderRadius(12)
  2326. .visibility(StrUtil.isEmpty(item.md5Str)?Visibility.None:Visibility.Visible)
  2327. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2328. .backgroundColor('#FFC107')
  2329. }
  2330. .padding({ top: 8 })
  2331. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  2332. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2333. .padding({ top: 8 ,right:25})
  2334. .maxLines(1)
  2335. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2336. $r('app.color.text_color'))
  2337. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2338. Blank()
  2339. Text(item.size)
  2340. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2341. .padding({ top: 8 })
  2342. .maxLines(1)
  2343. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  2344. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2345. $r('app.color.text_color'))
  2346. .margin({ left: 10 })
  2347. }
  2348. .visibility(this.twoFingerType==1?Visibility.None:Visibility.Visible)
  2349. .gesture(LongPressGesture()
  2350. .onAction(async () => {
  2351. //如果是专辑和艺术家的首页,不能长按
  2352. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2353. return
  2354. //如果是我的收藏 最近播放等也不能长按
  2355. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2356. item.name === LocalMusic.STR_HISTORY_MUSIC
  2357. )
  2358. return
  2359. this.longItemFilePath = item.filePath
  2360. this.tempLyricContent = await this.getLyricContent(item)
  2361. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2362. })
  2363. .onActionEnd((event: GestureEvent) => {
  2364. })
  2365. )
  2366. }
  2367. .height('100%')
  2368. .width('100%')
  2369. .justifyContent(FlexAlign.Center)
  2370. .alignItems(HorizontalAlign.Start)
  2371. }
  2372. .height('100%')
  2373. .margin({ left: 5 })
  2374. .layoutWeight(1)
  2375. Column() {
  2376. Checkbox({ name: 'checkbox' + index })
  2377. .select(this.selectedFiles.some(x => x.filePath === item.filePath))
  2378. .selectedColor(this.themeColor)
  2379. .shape(CheckBoxShape.CIRCLE)
  2380. .opacity(this.isMultiSelect ? 1 : 0)
  2381. .animation({
  2382. duration: 666,
  2383. curve: 'Smooth' // 可选动画曲线
  2384. })
  2385. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  2386. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  2387. .margin({ left: 20, top: 8, bottom: 8,right:18 })
  2388. .width(22)
  2389. .height(22)
  2390. ImageAnimator()
  2391. .images(this.imagesF)// 动画数组
  2392. .duration(1000)// 持续
  2393. .state(this.animationState)// 动画状态
  2394. .fillMode(FillMode.Forwards)
  2395. .width(18)
  2396. .margin({ right: 20, top: 8, bottom: 8 })
  2397. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  2398. Visibility.None)
  2399. .height(18)
  2400. .iterations(-1) // 播放次数
  2401. }
  2402. }
  2403. }
  2404. .backgroundColor(Color.Transparent)
  2405. .width('100%')
  2406. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2407. }
  2408. private readonly tabs: string[] = ['文件夹', '媒体库', '艺术家', '专辑']
  2409. @Builder
  2410. tabTitle() {
  2411. Column() {
  2412. // 使用 Stack 布局来实现绝对定位效果
  2413. Stack() {
  2414. // 背景动画容器
  2415. Row() {
  2416. ForEach(this.tabs, (i: string, index) => {
  2417. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2418. Flex()
  2419. .backgroundColor(this.isDarkMode ? $r('app.color.tab_item_bg') : this.themeColor)
  2420. .borderRadius(20)
  2421. .padding(10)
  2422. .margin(6)
  2423. .width('100%')
  2424. .height('100%')
  2425. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2426. .visibility(this.modeType === index ? Visibility.Visible : Visibility.None)
  2427. .opacity(this.modeType === index ? 1 : 0)
  2428. .animation({
  2429. duration: 666,
  2430. playMode: PlayMode.Normal,
  2431. curve: 'ease-in-out'
  2432. });
  2433. }
  2434. .layoutWeight(1)
  2435. .margin({
  2436. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5,
  2437. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5, bottom: 1
  2438. });
  2439. });
  2440. }
  2441. .width('100%')
  2442. .height(50);
  2443. // 导航栏容器
  2444. Row() {
  2445. ForEach(this.tabs, (item: string, index) => {
  2446. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2447. Text(item)
  2448. .fontSize(16)
  2449. .fontColor(this.modeType === index ? Color.White : $r('app.color.text_color'))
  2450. .padding(15)
  2451. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2452. .onClick(() => {
  2453. this.modeType = index;
  2454. this.onModeChange();
  2455. });
  2456. }
  2457. .layoutWeight(1)
  2458. .stateStyles({
  2459. pressed: { opacity: 0.6 } // 按压反馈
  2460. });
  2461. });
  2462. }
  2463. .width('100%')
  2464. .height(this.topBarHeight)
  2465. .opacity(this.barOpacity)
  2466. .backgroundColor(Color.Transparent);
  2467. }
  2468. .width('100%')
  2469. .height(this.topBarHeight)
  2470. .opacity(this.barOpacity)
  2471. Line()
  2472. .width('100%')
  2473. .height(1)
  2474. .backgroundColor($r('app.color.index_background'))
  2475. .opacity(this.barOpacity)
  2476. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  2477. }
  2478. .visibility(this.isShowTitleBar ? Visibility.Visible : Visibility.None)
  2479. }
  2480. @State currentTitleName: string = '' //点击歌单,艺术家,专辑进去后的标题
  2481. @State currentTitleCover: string | ResourceStr = '' //点击歌单,艺术家,专辑进去后的封面
  2482. isShowCoverHeader() {
  2483. if (!this.isShowHeader) {
  2484. return false
  2485. }
  2486. if (this.modeType == 0) {
  2487. if (this.isHistory || this.isFavMusic) {
  2488. return true
  2489. }
  2490. if (this.currentPath != this.rootPath) {
  2491. return true
  2492. }
  2493. }
  2494. return (this.modeType == 2 || this.modeType == 3) && this.isCanBack
  2495. }
  2496. @Builder
  2497. coverHeader() {
  2498. if (this.isShowCoverHeader()) {
  2499. Column() {
  2500. Stack() {
  2501. // 居中标题
  2502. Text('')
  2503. .fontSize(18)
  2504. .fontColor(Color.White)
  2505. .align(Alignment.Center)
  2506. // 左右按钮
  2507. Row() {
  2508. Image($r('app.media.left_back_white'))
  2509. .width(28)
  2510. .height(28)
  2511. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2512. .margin({ left: 12, right: 8 })
  2513. .onClick(() => {
  2514. animateTo({ duration: 555 }, () => {
  2515. this.doSwipBack()
  2516. })
  2517. })
  2518. Blank().flexGrow(1)
  2519. if (this.modeType == 0 && !this.isHistory && !this.isFavMusic) {
  2520. Image($r('app.media.add'))
  2521. .width(25)
  2522. .height(25)
  2523. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2524. .margin({ left: 8, right: 15 })
  2525. .onClick(() => {
  2526. this.showAddDialog()
  2527. })
  2528. }
  2529. }
  2530. .height(48)
  2531. .width('100%')
  2532. .alignItems(VerticalAlign.Center)
  2533. }
  2534. .height(48)
  2535. .width('100%')
  2536. Row() {
  2537. Column() {
  2538. Image(this.currentTitleCover)
  2539. .height(100)
  2540. .width(100)
  2541. .alt(this.imageLabel)
  2542. .borderRadius(8)
  2543. .clickEffect({ level: ClickEffectLevel.HEAVY })
  2544. }
  2545. .alignItems(HorizontalAlign.Start)
  2546. .margin({ left: 30, top: 3, bottom: 15 })
  2547. Column() {
  2548. Column() {
  2549. Text(this.currentTitleName)
  2550. .fontSize(16)
  2551. .maxLines(1)
  2552. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  2553. .fontWeight(FontWeight.Bold)
  2554. .fontColor($r('app.color.text_color'))
  2555. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2556. if (this.modeType == 3 && ArrayUtil.isNotEmpty(this.videoLocalList)) {
  2557. Text(`艺术家:${this.videoLocalList[0].artist}`)
  2558. .fontSize(14)
  2559. .padding({ top: 8 })
  2560. .maxLines(1)
  2561. .fontWeight(FontWeight.Bold)
  2562. .fontColor($r('app.color.text_color'))
  2563. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2564. if(this.videoLocalList[0].genre){
  2565. Text(`风格:${this.videoLocalList[0].genre}`)
  2566. .fontSize(14)
  2567. .padding({ top: 8 })
  2568. .maxLines(1)
  2569. .visibility(StrUtil.isEmpty(this.videoLocalList[0].genre)||
  2570. this.videoLocalList[0].genre.includes(this.UNKONWN)
  2571. ?Visibility.None:Visibility.Visible)
  2572. .fontWeight(FontWeight.Bold)
  2573. .fontColor($r('app.color.text_color'))
  2574. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2575. }
  2576. if(this.videoLocalList[0].year){
  2577. Text(`发行时间:${this.videoLocalList[0].year}`)
  2578. .fontSize(14)
  2579. .padding({ top: 8 })
  2580. .maxLines(1)
  2581. .visibility(StrUtil.isEmpty(this.videoLocalList[0].year)||
  2582. this.videoLocalList[0].year.includes(this.UNKONWN)
  2583. ?Visibility.None:Visibility.Visible)
  2584. .fontWeight(FontWeight.Bold)
  2585. .fontColor($r('app.color.text_color'))
  2586. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2587. }
  2588. }
  2589. if(this.modeType != 3){
  2590. Row() {
  2591. Text(`共${this.videoLocalList.length}首歌`)
  2592. .fontSize(13)
  2593. .fontWeight(FontWeight.Bold)
  2594. .padding({ top: 8 })
  2595. .fontColor($r('app.color.text_color'))
  2596. .margin({ left: this.currentLyricAlignMode === 0 ? 8 : 0 })
  2597. Blank()
  2598. }
  2599. }
  2600. }
  2601. .height('100%')
  2602. .width('100%')
  2603. .justifyContent(FlexAlign.Center)
  2604. .alignItems(HorizontalAlign.Start)
  2605. }
  2606. .height('100%')
  2607. .layoutWeight(1)
  2608. .margin({ left: 20 })
  2609. }
  2610. this.listViewTitle()
  2611. }
  2612. .backgroundImage(this.getCoverTitleBg())
  2613. .height(250)
  2614. .width('100%')
  2615. .backgroundImageSize({ height: '100%', width: '100%' })
  2616. .backgroundBlurStyle(this.isCustomizeBg ? BlurStyle.NONE : BlurStyle.BACKGROUND_ULTRA_THICK)
  2617. .padding({ top: this.topRectHeight, bottom: this.bottomBarHeight + 48 })
  2618. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  2619. .justifyContent(FlexAlign.SpaceBetween)
  2620. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.7, y: 0.7 }).animation({ duration: 500 }),
  2621. TransitionEffect.scale({ x: 0, y: 0 })))
  2622. } else {
  2623. this.listViewTitle()
  2624. }
  2625. }
  2626. getCoverTitleBg(): ResourceStr | image.PixelMap {
  2627. if (this.isCustomizeBg) {
  2628. return ('rgba(255,255,255,0.2)')
  2629. }
  2630. if (this.isDarkMode) {
  2631. return $r('app.color.user_center_card_background')
  2632. }
  2633. return this.currentTitleCover
  2634. }
  2635. @Builder
  2636. listViewTitle() {
  2637. Column() {
  2638. Row({ space: 8 }) {
  2639. Row({ space: 8 }) {
  2640. Image($r("app.media.hm_playlist"))
  2641. .width(25)
  2642. .margin({ left: 8 })
  2643. .fillColor(this.themeColor)
  2644. Text(`共找到${this.artistList.length}位艺术家`)
  2645. .fontColor($r('app.color.text_color'))
  2646. .fontSize(14)
  2647. .opacity(this.opacityItem)
  2648. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2649. Text(`共找到${this.albumList.length}张专辑`)
  2650. .fontColor($r('app.color.text_color'))
  2651. .opacity(this.opacityItem)
  2652. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2653. .fontSize(14)
  2654. }
  2655. .layoutWeight(1)
  2656. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  2657. Row() {
  2658. TextInput({
  2659. placeholder: this.modeType === 2 ? '输入艺术家名称...' : '输入专辑名称...',
  2660. text: this.searchText
  2661. })
  2662. .height(35)
  2663. .onChange((value: string) => {
  2664. this.onSearchInput(value);
  2665. })
  2666. .layoutWeight(1)
  2667. Text(`取消`)
  2668. .margin({ left: 10, right: 10 })
  2669. .fontColor($r('app.color.text_color'))
  2670. .fontSize(16)
  2671. .onClick(() => {
  2672. this.isSearchMode = false
  2673. this.searchText = ''
  2674. if (this.modeType === 2) {
  2675. this.updateListData(this.artistList)
  2676. } else {
  2677. this.updateListData(this.albumList)
  2678. }
  2679. })
  2680. }
  2681. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  2682. .animation({
  2683. duration: 666,
  2684. curve: 'ease-in-out' // 可选动画曲线
  2685. })
  2686. Blank()
  2687. Image($r("app.media.search"))
  2688. .width(25)
  2689. .visibility(this.modeType === 2 || this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2690. .animation({
  2691. duration: 666,
  2692. curve: 'ease-in-out' // 可选动画曲线
  2693. })// .opacity(this.opacityItem)
  2694. .fillColor(this.themeColor)
  2695. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2696. .onClick(() => {
  2697. this.isSearchMode = true
  2698. })
  2699. Image($r("app.media.top_rank"))
  2700. .width(25)// .opacity(this.opacityItem)
  2701. .fillColor(this.themeColor)
  2702. .animation({
  2703. duration: 666,
  2704. curve: 'ease-in-out' // 可选动画曲线
  2705. })
  2706. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2707. .onClick(() => {
  2708. this.showRankDialog()
  2709. })
  2710. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  2711. .width(25)
  2712. .animation({
  2713. duration: 666,
  2714. curve: 'ease-in-out' // 可选动画曲线
  2715. })
  2716. .fillColor(this.themeColor)
  2717. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2718. .onClick(() => {
  2719. this.isGridMusic = !this.isGridMusic
  2720. })
  2721. }
  2722. .visibility(((this.modeType === 2 || this.modeType === 3) && !this.isCanBack) ? Visibility.Visible :
  2723. Visibility.None)
  2724. .width('100%')
  2725. .padding(10)
  2726. .height(50)
  2727. .border({
  2728. width: { bottom: 1 },
  2729. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2730. })
  2731. Row({ space: 8 }) {
  2732. Row({ space: 8 }) {
  2733. Image($r("app.media.hm_play"))
  2734. .width(25)
  2735. .margin({ left: 8 })
  2736. .fillColor(this.themeColor)
  2737. Text(`播放全部`)
  2738. .fontColor($r('app.color.text_color'))
  2739. .fontSize(14)
  2740. .animation({
  2741. duration: 666,
  2742. curve: 'ease-in-out' // 可选动画曲线
  2743. })
  2744. if(Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length>0){
  2745. Text(`(${Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length}首)`)
  2746. .fontColor($r('app.color.text_color'))
  2747. .fontSize(14)
  2748. .opacity(this.opacityItem)
  2749. .animation({
  2750. duration: 666,
  2751. curve: 'ease-in-out' // 可选动画曲线
  2752. })
  2753. }
  2754. }
  2755. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2756. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  2757. .animation({
  2758. duration: 666,
  2759. curve: 'ease-in-out' // 可选动画曲线
  2760. })
  2761. // .backgroundColor(this.isClickedPLayAll ? $r('app.color.button_click') : Color.Transparent)
  2762. .onTouch((event: TouchEvent) => {
  2763. if (event.type === TouchType.Down) {
  2764. this.isClickedPLayAll = true;
  2765. } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
  2766. this.isClickedPLayAll = false;
  2767. }
  2768. })
  2769. .onClick(() => {
  2770. // ToastUtil.showToast('当前的手机的折叠状态 ='+DisplayUtil.getFoldStatus())
  2771. if (this.modeType === 0) {
  2772. if (ArrayUtil.isNotEmpty(this.getCurFileList())) {
  2773. this.doPlay(this.getCurFileList()[0])
  2774. }
  2775. } else {
  2776. if (ArrayUtil.isNotEmpty(this.mediaKuList)) {
  2777. this.doPlay(this.mediaKuList[0])
  2778. }
  2779. }
  2780. })
  2781. Row() {
  2782. TextInput({ placeholder: '输入名称...', text: this.searchText })
  2783. .height(35)
  2784. .onChange((value: string) => {
  2785. this.onSearchInput(value);
  2786. })
  2787. .layoutWeight(1)
  2788. Text(`取消`)
  2789. .margin({ left: 10, right: 10 })
  2790. .fontColor($r('app.color.text_color'))
  2791. .fontSize(16)
  2792. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2793. .onClick(() => {
  2794. this.isSearchMode = false
  2795. this.searchText = ''
  2796. if(this.modeType==0){
  2797. this.updateListData(this.videoLocalList)
  2798. } else if(this.modeType==1){
  2799. this.updateListData(this.mediaKuList)
  2800. } else if(this.modeType==2&&!this.isCanBack){
  2801. this.updateListData(this.artistList)
  2802. } else if(this.modeType==3&&!this.isCanBack){
  2803. this.updateListData(this.albumList)
  2804. }
  2805. })
  2806. }
  2807. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  2808. .animation({
  2809. duration: 666,
  2810. curve: 'ease-in-out' // 可选动画曲线
  2811. })
  2812. Blank()
  2813. Image($r("app.media.search"))
  2814. .width(25)// .visibility(this.modeType===1?Visibility.Visible:Visibility.None)
  2815. .animation({
  2816. duration: 666,
  2817. curve: 'ease-in-out' // 可选动画曲线
  2818. })// .opacity(this.opacityItem)
  2819. .fillColor(this.themeColor)
  2820. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2821. .onClick(() => {
  2822. this.isSearchMode = true
  2823. })
  2824. Image($r("app.media.refresh"))
  2825. .fillColor(this.themeColor)
  2826. .width(25)
  2827. .visibility(this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
  2828. .animation({
  2829. duration: 666,
  2830. curve: 'ease-in-out' // 可选动画曲线
  2831. })
  2832. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2833. .onClick(() => {
  2834. if (this.isFavMusic) {
  2835. this.getFavList(true)
  2836. } else {
  2837. if(this.modeType == 0){
  2838. this.asyncCurrentPathData()
  2839. }else if(this.modeType ==1){
  2840. workerInstance.postMessage({ code: 2, data: this.context });
  2841. }
  2842. }
  2843. })
  2844. Image($r("app.media.top_rank"))
  2845. .width(25)
  2846. .visibility(this.isHistory || this.isSearchMode ? Visibility.None :
  2847. Visibility.Visible)// .opacity(this.opacityItem)
  2848. .animation({
  2849. duration: 666,
  2850. curve: 'ease-in-out' // 可选动画曲线
  2851. })
  2852. .fillColor(this.themeColor)
  2853. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2854. .onClick(() => {
  2855. this.showRankDialog()
  2856. })
  2857. Image(this.isMultiSelect ? $r("app.media.cancel_multi") : $r("app.media.top_flower"))
  2858. .width(24)
  2859. .visibility(this.isHistory || this.isSearchMode ? Visibility.None : Visibility.Visible)
  2860. .animation({
  2861. duration: 666,
  2862. curve: 'ease-in-out' // 可选动画曲线
  2863. })
  2864. .fillColor(this.themeColor)
  2865. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2866. .onClick(() => {
  2867. this.isMultiSelect = !this.isMultiSelect
  2868. })
  2869. SymbolGlyph($r('sys.symbol.trash'))
  2870. .fontColor([this.themeColor])
  2871. .fontSize(25)
  2872. .effectStrategy(1)
  2873. .visibility(this.isHistory ? Visibility.Visible : Visibility.None)
  2874. .animation({
  2875. duration: 666,
  2876. curve: 'ease-in-out' // 可选动画曲线
  2877. })
  2878. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2879. .onClick(() => {
  2880. this.clearVideoHistory() //清空播放记录
  2881. })
  2882. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  2883. .width(24)
  2884. .animation({
  2885. duration: 666,
  2886. curve: 'ease-in-out' // 可选动画曲线
  2887. })
  2888. .fillColor(this.themeColor)
  2889. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2890. .bindPopup($$this.tipPopup, {
  2891. builder: this.popupBuilder,
  2892. placement: Placement.Bottom,
  2893. maskColor: 0x33000000,
  2894. enableArrow: true,
  2895. onStateChange: (e) => {
  2896. if (!e.isVisible) {
  2897. this.tipPopup = false;
  2898. }
  2899. }
  2900. })
  2901. .onClick(() => {
  2902. this.isGridMusic = !this.isGridMusic
  2903. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  2904. })
  2905. }
  2906. .width('100%')
  2907. .padding(10)
  2908. .height(50)
  2909. .visibility(this.modeType === 0 || this.modeType === 1 || this.isCanBack ? Visibility.Visible : Visibility.None)
  2910. .border({
  2911. width: { bottom: 1 },
  2912. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2913. })
  2914. }
  2915. .visibility(this.isShowAllBar ? Visibility.Visible : Visibility.None)
  2916. }
  2917. // 第二步:popup构造器定义弹框内容
  2918. @Builder popupBuilder() {
  2919. Column({ space: 2 }) {
  2920. Text('友情提示:双指缩放可以放大缩小列表')
  2921. .fontSize(12)
  2922. .fontWeight(FontWeight.Regular)
  2923. .fontColor($r('app.color.text_color'))
  2924. }
  2925. .justifyContent(FlexAlign.SpaceAround)
  2926. .width(220)
  2927. .height(55)
  2928. .padding(15)
  2929. }
  2930. //搜索功能的实现
  2931. @State searchText: string = ''; // 用户输入内容
  2932. @State filteredList: Array<VideoItem> = []; // 过滤后的结果
  2933. @State isSearchMode: boolean = false
  2934. // 实时搜索逻辑(带防抖)
  2935. private onSearchInput(value: string) {
  2936. this.searchText = value.trim();
  2937. let mSearchList: Array<VideoItem> = []
  2938. switch (this.modeType) {
  2939. case 0:
  2940. mSearchList = this.videoLocalList
  2941. break;
  2942. case 1:
  2943. mSearchList = this.mediaKuList
  2944. break;
  2945. case 2:
  2946. mSearchList = this.artistList
  2947. break;
  2948. case 3:
  2949. mSearchList = this.albumList
  2950. break;
  2951. }
  2952. // 新增条件判断:空输入时显示所有数据
  2953. if (this.searchText === '') {
  2954. this.filteredList = [...mSearchList]; // 创建新数组以触发状态更新
  2955. } else {
  2956. this.filteredList = mSearchList.filter((item: VideoItem) => {
  2957. return item.name.toLowerCase().includes(this.searchText.toLowerCase());
  2958. });
  2959. }
  2960. this.updateListData(this.filteredList);
  2961. // this.isSearchMode = false; // 根据业务需求决定是否启用
  2962. }
  2963. @State dragItem: number = -1
  2964. @State scaleItem: number = -1
  2965. @State neighborItem: number = -1
  2966. @State neighborScale: number = -1
  2967. @State offsetY: number = 0
  2968. private dragRefOffset: number = 0
  2969. private ITEM_INTV: number = 78
  2970. scaleSelect(item: number): number {
  2971. if (this.scaleItem === item) {
  2972. return 1.05
  2973. } else if (this.neighborItem === item) {
  2974. return this.neighborScale
  2975. } else {
  2976. return 1
  2977. }
  2978. }
  2979. itemMove(index: number, newIndex: number): void {
  2980. if (newIndex < 0 || newIndex >= this.videoLocalList.length) {
  2981. return;
  2982. }
  2983. let tmp = this.videoLocalList.splice(index, 1);
  2984. this.videoLocalList.splice(newIndex, 0, tmp[0]);
  2985. this.dataSource.pushArrayData(this.videoLocalList)
  2986. }
  2987. //瀑布流布局 支持双指缩放
  2988. @State columns: number = 2;
  2989. @State waterFlowScale: number = 1;
  2990. @State imageScale: number = 1;
  2991. @State waterFlowOpacity: number = 1;
  2992. @State waterFlowSnapshot: image.PixelMap | undefined = undefined;
  2993. private columnChanged: boolean = false;
  2994. private oldColumn: number = this.columns;
  2995. private pinchTime: number = 0;
  2996. // 根据缩放阈值改变列数,触发WaterFlow重新布局
  2997. changeColumns(scale: number) {
  2998. if (scale > (this.columns / (this.columns - 0.5)) && this.columns > 1) {
  2999. this.columns--;
  3000. this.columnChanged = true;
  3001. } else if (scale < 1 && this.columns < 4) {
  3002. this.columns++;
  3003. this.columnChanged = true;
  3004. }
  3005. }
  3006. @Builder
  3007. getWaterView(){
  3008. Scroll(this.scroller) {
  3009. Column() {
  3010. if(this.isShowCoverHeader()){
  3011. this.coverHeader()
  3012. }else {
  3013. this.listViewTitle()
  3014. }
  3015. WaterFlow({
  3016. scroller:this.waterScroller,
  3017. layoutMode: WaterFlowLayoutMode.SLIDING_WINDOW
  3018. }) {
  3019. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3020. FlowItem() {
  3021. this.MusicWaterCardItem(item,index)
  3022. }
  3023. .width('100%')
  3024. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.9 })
  3025. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3026. {
  3027. preview: MenuPreviewMode.IMAGE,
  3028. previewAnimationOptions: { scale: [0.8, 1.0] },
  3029. })
  3030. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3031. {
  3032. preview: MenuPreviewMode.IMAGE,
  3033. previewAnimationOptions: { scale: [0.8, 1.0] },
  3034. })
  3035. .transition(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }))
  3036. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3037. TransitionEffect.scale({ x: 0, y: 0 }) ))
  3038. .gesture(
  3039. GestureGroup(GestureMode.Exclusive,
  3040. SwipeGesture({ direction: SwipeDirection.Horizontal })
  3041. .onAction((event: GestureEvent) => {
  3042. if (event) {
  3043. // this.sideBarController.openSideBar()
  3044. }
  3045. }),
  3046. TapGesture({ count: 1, fingers: 1 })
  3047. .onAction(async () => {
  3048. })
  3049. )
  3050. )
  3051. }, (item: VideoItem) => item.filePath)
  3052. }
  3053. // .columnsTemplate('repeat(auto-fit, 160)')
  3054. .id('waterflow') // 设置id用于截图
  3055. .columnsTemplate('1fr '.repeat(this.columns)) // 动态生成列模板,如:'1fr 1fr 1fr'表示3列等宽
  3056. .columnsGap(12) // 列间距
  3057. .rowsGap(16) // 行间距
  3058. .cachedCount(6)
  3059. .margin({bottom:this.isShowCoverHeader()? 25:
  3060. this.isCoverOpacity()?this.topBarHeight+this.bottomBarHeight+78
  3061. :this.topBarHeight+this.bottomBarHeight+108})
  3062. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3063. .animation({ duration: 500, curve: Curve.Ease }))
  3064. .scrollBar(BarState.Off)
  3065. // .fadingEdge(true, { fadingEdgeLength: LengthMetrics.vp(38) })
  3066. // 效果:只有向上或者向下滑动到顶部时才会有弹簧回弹效果
  3067. .edgeEffect(EdgeEffect.Spring, { alwaysEnabled: true })
  3068. .width('100%')
  3069. .height('100%')
  3070. .padding(10)
  3071. .opacity(this.waterFlowOpacity)
  3072. .scale({
  3073. x: this.waterFlowScale,
  3074. y: this.waterFlowScale,
  3075. centerX: 0,
  3076. centerY: 0
  3077. })
  3078. .onAppear(() => {
  3079. this.scroller.scrollEdge(Edge.Top)
  3080. })
  3081. .nestedScroll({
  3082. scrollForward: NestedScrollMode.PARENT_FIRST,
  3083. scrollBackward: NestedScrollMode.SELF_FIRST
  3084. })
  3085. .priorityGesture(
  3086. PinchGesture()
  3087. .onActionStart((event: GestureEvent) => {
  3088. // 双指捏合手势识别成功时截图
  3089. this.pinchTime = event.timestamp;
  3090. this.columnChanged = false;
  3091. this.oldColumn = this.columns;
  3092. this.getUIContext().getComponentSnapshot().get('waterflow', (error: Error, pixmap: image.PixelMap) => {
  3093. if (error) {
  3094. console.info('error:' + JSON.stringify(error));
  3095. return;
  3096. }
  3097. this.waterFlowSnapshot = pixmap;
  3098. if ((this.oldColumn === 1 ) && event.scale > 1|| (this.oldColumn === 4 && event.scale < 1)) {
  3099. console.info("onecold onActionStart oldColumn:" + this.oldColumn)
  3100. if (this.oldColumn ===4) {
  3101. this.twoFingerType =3
  3102. this.isGridMusic = true
  3103. }else if (this.oldColumn ===1) {
  3104. this.twoFingerType =1
  3105. this.isGridMusic = false
  3106. }
  3107. return;
  3108. }
  3109. })
  3110. })
  3111. .onActionUpdate((event: GestureEvent) => {
  3112. // 手势更新:处理缩放逻辑和视觉效果
  3113. // 边界限制:防止超出列数范围时继续缩放
  3114. if ((this.oldColumn === 1 && event.scale > 1) || (this.oldColumn === 4 && event.scale < 1)) {
  3115. return;
  3116. }
  3117. // 节流处理:避免过于频繁的更新,提升性能
  3118. if (event.timestamp - this.pinchTime < 10000000) {
  3119. return;
  3120. }
  3121. this.pinchTime = event.timestamp;
  3122. this.waterFlowScale = event.scale;
  3123. this.imageScale = event.scale;
  3124. // 根据缩放比例设置WaterFlow透明度
  3125. this.waterFlowOpacity = (this.waterFlowScale > 1) ? (this.waterFlowScale - 1) : (1 - this.waterFlowScale);
  3126. this.waterFlowOpacity *= 3;
  3127. if (!this.columnChanged) {
  3128. this.changeColumns(event.scale);
  3129. }
  3130. // 列数改变后的缩放比例调整:避免出现空白区域
  3131. if (this.columnChanged) {
  3132. this.waterFlowScale = this.imageScale * this.columns / this.oldColumn;
  3133. // 限制缩放范围,确保视觉效果自然
  3134. if (event.scale < 1) {
  3135. this.waterFlowScale = this.waterFlowScale > 1 ? this.waterFlowScale : 1;
  3136. } else {
  3137. this.waterFlowScale = this.waterFlowScale < 1 ? this.waterFlowScale : 1;
  3138. }
  3139. }
  3140. })
  3141. .onActionEnd((event: GestureEvent) => {
  3142. // 手势结束:执行归位动画并保存状态
  3143. // 执行归位动画:平滑过渡到正常状态
  3144. this.getUIContext()?.animateTo({ duration: 300 }, () => {
  3145. this.waterFlowScale = 1;
  3146. this.waterFlowOpacity = 1;
  3147. })
  3148. // 持久化保存当前列数:下次启动时恢复
  3149. PreferencesUtil.putSync('lastColumns', this.columns);
  3150. })
  3151. )
  3152. //允许拖拽音乐和视频到List或Grid上自动导入视频
  3153. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3154. .onDrop((event?: DragEvent) => {
  3155. try {
  3156. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3157. if (dragData !== undefined) {
  3158. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3159. if (records.length > 0) {
  3160. for (let i = 0; i < records.length; i++) {
  3161. let types = records[i].getTypes();
  3162. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3163. const fileUriUds =
  3164. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3165. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3166. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3167. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3168. this.targetFile = fileUriUds.oriUri;
  3169. this.saveVideoDatas([this.targetFile])
  3170. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3171. }
  3172. }
  3173. }
  3174. } else {
  3175. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3176. }
  3177. } else {
  3178. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3179. }
  3180. } catch (error) {
  3181. const err = error as BusinessError;
  3182. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3183. }
  3184. })
  3185. }
  3186. }
  3187. .scrollBar(BarState.Off)
  3188. }
  3189. //瀑布流卡片布局
  3190. @Builder
  3191. private MusicWaterCardItem(item: VideoItem, index: number) {
  3192. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3193. Stack() {
  3194. Column() {
  3195. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3196. .backgroundImageSize(ImageSize.Auto)
  3197. .borderRadius({
  3198. topLeft: 12,
  3199. topRight : 12,
  3200. bottomLeft: 0,
  3201. bottomRight: 0
  3202. })
  3203. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  3204. .draggable(false)// 禁止长按手势拖动
  3205. .autoResize(true) // 重采样,可减少内存占用
  3206. .width('100%')
  3207. .height('auto')
  3208. .objectFit(ImageFit.Auto)
  3209. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3210. height: '99%' ,
  3211. dragBar: true,
  3212. onDisappear: () => {
  3213. this.longItemFilePath = '';
  3214. this.tempLyricContent = ''
  3215. },
  3216. showClose: true,
  3217. preferType: SheetType.CENTER ,
  3218. title: { title: '编辑标签' }
  3219. })
  3220. .draggable(false)
  3221. .opacity(this.opacityItem)// 绑定透明度
  3222. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3223. // .animation({ duration: 500, curve: Curve.Ease }))
  3224. .animation({
  3225. duration: 666,
  3226. curve: 'ease-in-out' // 可选动画曲线
  3227. })
  3228. .margin({
  3229. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3230. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3231. })
  3232. Column() {
  3233. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3234. .fontSize(this.columns == 4 ||this.columns==3? 12 : this.columns == 2 ? 15 : 18)
  3235. .maxLines(1)
  3236. .fontWeight(FontWeight.Bold)
  3237. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3238. .animation({
  3239. duration: 555,
  3240. curve: 'Linear',
  3241. })
  3242. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3243. height: '95%',
  3244. dragBar: true,
  3245. showClose: true,
  3246. onDisappear: () => {
  3247. this.longItemFilePathDetail = '';
  3248. },
  3249. blurStyle:BlurStyle.Thin,
  3250. backgroundColor:Color.Transparent,
  3251. preferType: SheetType.CENTER ,
  3252. title: { title: '详情' }
  3253. })
  3254. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3255. $r('app.color.text_color'))
  3256. Column() {
  3257. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  3258. .fontSize(11)
  3259. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 14)
  3260. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3261. .fontColor($r('app.color.text_color'))
  3262. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  3263. .fontSize(11)
  3264. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 14)
  3265. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3266. .fontColor($r('app.color.text_color'))
  3267. Row(){
  3268. Column(){
  3269. Text(item.md5Str?.includes('Lossless')?
  3270. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  3271. .fontSize(this.columns == 4 ||this.columns==3? 8 : this.columns == 2 ? 9 : 11)
  3272. .padding({ top: 3,right:6,left:6,bottom:3 })
  3273. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3274. $r('app.color.text_color'))
  3275. .fontWeight(500)
  3276. .borderRadius(12)
  3277. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  3278. .backgroundColor('#FFC107')
  3279. .visibility(StrUtil.isEmpty(item.md5Str)||this.twoFingerType==1?Visibility.None:Visibility.Visible)
  3280. }
  3281. .margin({ top: 2 ,right:6})
  3282. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  3283. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  3284. Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  3285. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 13)
  3286. .maxLines(1)
  3287. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3288. .margin({ top: 2})
  3289. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  3290. || item.type == CommonConstants.TYPE_IS_ALBUM
  3291. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3292. .fontWeight(FontWeight.Medium)
  3293. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3294. $r('app.color.text_color'))
  3295. }
  3296. }
  3297. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  3298. }
  3299. .height(this.columns == 4 ||this.columns==3? item.type==CommonConstants.TYPE_IS_DIR?30:40
  3300. : this.columns == 2 ? (item.type==CommonConstants.TYPE_IS_DIR?38:48) :
  3301. (item.type==CommonConstants.TYPE_IS_DIR?48:58))
  3302. .width('100%')
  3303. .justifyContent(FlexAlign.Center)
  3304. .margin({
  3305. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3306. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3307. })
  3308. }
  3309. .width('100%')
  3310. .borderRadius(12)
  3311. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  3312. .backgroundImageSize({ height: '100%', width: '100%' })
  3313. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  3314. .animation({ curve: Curve.Sharp, duration: 300 })
  3315. Checkbox({ name: 'checkbox' + index })
  3316. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  3317. .selectedColor(this.themeColor)
  3318. .shape(CheckBoxShape.CIRCLE)
  3319. .opacity(this.isMultiSelect ? 1 : 0)
  3320. .animation({
  3321. duration: 666,
  3322. curve: 'Smooth' // 可选动画曲线
  3323. })
  3324. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  3325. Visibility.None)
  3326. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  3327. .margin({ left: 20, top: 8, bottom: 8 })
  3328. .width(38)
  3329. .height(38)
  3330. }
  3331. }
  3332. .backgroundColor(Color.Transparent)
  3333. .width('100%')
  3334. .height('auto')
  3335. .padding({top:2})
  3336. .reuseId('card_item')
  3337. .onClick(() => {
  3338. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3339. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3340. this.handleFileSelection(item, !isChecked);
  3341. } else {
  3342. this.doPlay(item, index)
  3343. }
  3344. })
  3345. }
  3346. // Grid布局的开始
  3347. private dragRefOffSetX: number = 0;
  3348. private dragRefOffSetY: number = 0;
  3349. private FIX_VP_X: number = 180;
  3350. private FIX_VP_Y: number = 84;
  3351. isDraggable(index: number): boolean {
  3352. return index >= 0;
  3353. }
  3354. getRowEnd(item: number) {
  3355. if (item.toString() === '0') {
  3356. return 1;
  3357. } else {
  3358. return 0;
  3359. }
  3360. }
  3361. // [Start itemMove_start]
  3362. // itemMoveGrid(index: number, newIndex: number): void {
  3363. // if (!this.isDraggable(newIndex)) {
  3364. // return;
  3365. // }
  3366. // let tmp = this.videoLocalList.splice(index, 1);
  3367. // this.videoLocalList.splice(newIndex, 0, tmp[0]);
  3368. // // this.bigItemIndex = this.videoLocalList.findIndex((item) => item === 0);
  3369. // }
  3370. isInLeft(index: number) {
  3371. return index % 2 == 0;
  3372. }
  3373. down(index: number): void {
  3374. if ([this.videoLocalList.length - 1, this.videoLocalList.length - 2].includes(index)) {
  3375. return;
  3376. }
  3377. this.offsetY -= this.FIX_VP_Y;
  3378. this.dragRefOffSetY += this.FIX_VP_Y;
  3379. this.itemMove(index, index + 1);
  3380. }
  3381. up(index: number): void {
  3382. if (!this.isDraggable(index - 2)) {
  3383. return;
  3384. }
  3385. this.offsetY += this.FIX_VP_Y;
  3386. this.dragRefOffSetY -= this.FIX_VP_Y;
  3387. this.itemMove(index, index - 1);
  3388. }
  3389. left(index: number): void {
  3390. if (this.isInLeft(index)) {
  3391. return;
  3392. }
  3393. if (!this.isDraggable(index - 1)) {
  3394. return;
  3395. }
  3396. this.offsetX += this.FIX_VP_X;
  3397. this.dragRefOffSetX -= this.FIX_VP_X;
  3398. this.itemMove(index, index - 1)
  3399. }
  3400. right(index: number): void {
  3401. if (!this.isInLeft(index)) {
  3402. return;
  3403. }
  3404. if (!this.isDraggable(index + 1)) {
  3405. return;
  3406. }
  3407. this.offsetX -= this.FIX_VP_X;
  3408. this.dragRefOffSetX += this.FIX_VP_X;
  3409. this.itemMove(index, index + 1)
  3410. }
  3411. private scroller: Scroller = new Scroller();
  3412. private waterScroller: Scroller = new Scroller();
  3413. @State startIndex: number = 0
  3414. @State endIndex: number = 0
  3415. @State scaleValue: number = 1
  3416. @State pinchValue: number = 1
  3417. layoutOptionsForHeader: GridLayoutOptions = {
  3418. regularSize: [1, 1], // 只支持[1, 1]
  3419. irregularIndexes: [0], // 索引为0的GridItem占用一行
  3420. };
  3421. @Builder
  3422. getGridView() {
  3423. Grid(this.scroller, this.layoutOptionsForHeader) {
  3424. GridItem() {
  3425. if (this.isShowCoverHeader()) {
  3426. this.coverHeader()
  3427. } else {
  3428. this.listViewTitle()
  3429. }
  3430. }
  3431. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3432. GridItem() {
  3433. Stack({ alignContent: Alignment.Center }) {
  3434. this.MusicItemGrid(item, index)
  3435. }
  3436. }
  3437. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3438. {
  3439. preview: MenuPreviewMode.IMAGE,
  3440. previewAnimationOptions: { scale: [0.8, 1.0] },
  3441. })
  3442. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3443. {
  3444. preview: MenuPreviewMode.IMAGE,
  3445. previewAnimationOptions: { scale: [0.8, 1.0] },
  3446. })
  3447. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3448. TransitionEffect.scale({ x: 0, y: 0 })))
  3449. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3450. .scale({ x: this.scaleItem === index ? 1.02 : 1, y: this.scaleItem === index ? 1.02 : 1 })
  3451. .zIndex(this.dragItem === index ? 1 : 0)
  3452. .translate(this.dragItem === index ? { x: this.offsetX, y: this.offsetY } : { x: 0, y: 0 })
  3453. // .hitTestBehavior(this.isDraggable(this.videoLocalList.indexOf(item)) ? HitTestMode.Default : HitTestMode.None)
  3454. }, (item: VideoItem) => item.filePath)
  3455. }
  3456. .width(this.isShowHeader ? '100%' : '94%')
  3457. .height('100%')
  3458. .editMode(true)
  3459. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3460. .animation({ duration: 500, curve: Curve.Ease }))
  3461. // .margin({ bottom: this.isCoverOpacity() ? 80 : 175 })
  3462. .margin({
  3463. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+30 : this.topBarHeight+90)
  3464. : (this.isShowCoverHeader() ? this.topBarHeight+45 : this.topBarHeight+128)
  3465. })
  3466. .reuseId('grid_item')
  3467. .layoutWeight(1)
  3468. .scrollBar(BarState.Off)
  3469. .supportAnimation(true)
  3470. .cachedCount(this.twoFingerType==1?5:this.twoFingerType==2?4:3)
  3471. // .columnsTemplate('1fr '.repeat(this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM ? 2 : 5))
  3472. .columnsTemplate(
  3473. this.twoFingerType == 3 ? 'repeat(auto-fit, 160)' :
  3474. this.twoFingerType == 2 ? 'repeat(auto-fit, 110)' : 'repeat(auto-fit, 80)'
  3475. )
  3476. .rowsGap(this.isShowDrawer ? 25 : (this.twoFingerType == 3 ? 10 : this.twoFingerType == 2 ? 5 : 1))
  3477. .visibility(this.isGridMusic ? Visibility.Visible : Visibility.None)
  3478. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3479. .gesture(PinchGesture({ fingers: 2 })
  3480. .onActionEnd((event: GestureEvent) => {
  3481. this.setGridTwoFingers()
  3482. })
  3483. .onActionUpdate(e => {
  3484. this.scaleValue = this.pinchValue * e.scale
  3485. })
  3486. .onActionStart(e => {
  3487. }))
  3488. .enableScrollInteraction(true)
  3489. // 滚轴滑动,记录下滑动时的起始位置和终点位置
  3490. .onScrollIndex((start: number, end: number) => {
  3491. this.startIndex = start
  3492. this.endIndex = end
  3493. })
  3494. .onScrollFrameBegin((offset: number) => {
  3495. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  3496. // if (this.isPhoneLan()) {
  3497. // this.setBarHeightHide(offset)
  3498. // } else
  3499. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3500. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3501. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3502. if (this.isScrollHide) {
  3503. this.setBarHeightHide2(offset)
  3504. } else {
  3505. this.setBarHeightNormal()
  3506. }
  3507. } else {
  3508. this.setBarHeightHide(offset)
  3509. }
  3510. return { offsetRemain: offset };
  3511. })
  3512. //允许拖拽音乐和视频到List或Grid上自动导入视频
  3513. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3514. .onDrop((event?: DragEvent) => {
  3515. try {
  3516. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3517. if (dragData !== undefined) {
  3518. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3519. if (records.length > 0) {
  3520. for (let i = 0; i < records.length; i++) {
  3521. let types = records[i].getTypes();
  3522. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3523. const fileUriUds =
  3524. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3525. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3526. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3527. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3528. this.targetFile = fileUriUds.oriUri;
  3529. this.saveVideoDatas([this.targetFile])
  3530. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3531. }
  3532. }
  3533. }
  3534. } else {
  3535. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3536. }
  3537. } else {
  3538. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3539. }
  3540. } catch (error) {
  3541. const err = error as BusinessError;
  3542. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3543. }
  3544. })
  3545. }
  3546. @State targetFile: string = '';
  3547. setGridTwoFingers() {
  3548. this.pinchValue = this.scaleValue;
  3549. Logger.info('this.pinchValue = ' + this.pinchValue);
  3550. if (this.pinchValue >= 1) {
  3551. this.twoFingerType++
  3552. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3553. if(this.twoFingerType >= 4){
  3554. this.twoFingerType = 4//切换成瀑布流
  3555. this.columns = 4
  3556. }
  3557. } else {
  3558. this.twoFingerType--
  3559. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3560. if (this.twoFingerType < 1) {
  3561. this.twoFingerType = 3
  3562. this.isGridMusic = false
  3563. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3564. }
  3565. }
  3566. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3567. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3568. this.pinchValue = 1;
  3569. this.scaleValue = 1;
  3570. }
  3571. @State longItemFilePath: string = ''
  3572. @State tempLyricContent: string = ''
  3573. @Builder
  3574. private MusicItemGrid(item: VideoItem, index: number) {
  3575. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3576. Stack() {
  3577. Column() {
  3578. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3579. .height(this.getGridHeight())
  3580. .width(this.getGridWight())
  3581. .draggable(false)
  3582. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  3583. .autoResize(true) // 重采样,可减少内存占用
  3584. .alt($r('app.media.ic_avatar2'))
  3585. .clip(true)
  3586. .borderRadius({
  3587. topLeft: 12,
  3588. topRight: 12,
  3589. bottomLeft: 0,
  3590. bottomRight: 0
  3591. })
  3592. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3593. height: '99%' ,
  3594. dragBar: true,
  3595. onDisappear: () => {
  3596. this.longItemFilePath = '';
  3597. this.tempLyricContent = ''
  3598. },
  3599. showClose: true,
  3600. preferType: SheetType.CENTER ,
  3601. title: { title: '编辑标签' }
  3602. })
  3603. .draggable(false)
  3604. .opacity(this.opacityItem)// 绑定透明度
  3605. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3606. // .animation({ duration: 500, curve: Curve.Ease }))
  3607. .animation({
  3608. duration: 666,
  3609. curve: 'ease-in-out' // 可选动画曲线
  3610. })
  3611. .margin({
  3612. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3613. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3614. })
  3615. Column() {
  3616. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3617. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  3618. .maxLines(1)
  3619. .fontWeight(FontWeight.Bold)
  3620. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3621. .animation({
  3622. duration: 555,
  3623. curve: 'Linear',
  3624. })
  3625. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3626. height: '95%',
  3627. dragBar: true,
  3628. showClose: true,
  3629. onDisappear: () => {
  3630. this.longItemFilePathDetail = '';
  3631. },
  3632. blurStyle:BlurStyle.Thin,
  3633. backgroundColor:Color.Transparent,
  3634. preferType: SheetType.CENTER ,
  3635. title: { title: '详情' }
  3636. })
  3637. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3638. $r('app.color.text_color'))
  3639. Column() {
  3640. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  3641. .fontSize(11)
  3642. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3643. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3644. .fontColor($r('app.color.text_color'))
  3645. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  3646. .fontSize(11)
  3647. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3648. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3649. .fontColor($r('app.color.text_color'))
  3650. Row(){
  3651. Column(){
  3652. Text(item.md5Str?.includes('Lossless')?
  3653. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  3654. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  3655. .padding({ top: 3,right:6,left:6,bottom:3 })
  3656. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3657. $r('app.color.text_color'))
  3658. .fontWeight(500)
  3659. .borderRadius(12)
  3660. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  3661. .backgroundColor('#FFC107')
  3662. .visibility(StrUtil.isEmpty(item.md5Str)||this.twoFingerType==1?Visibility.None:Visibility.Visible)
  3663. }
  3664. .margin({ top: 2 ,right:6})
  3665. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  3666. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  3667. Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  3668. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 13)
  3669. .maxLines(1)
  3670. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3671. .margin({ top: 2})
  3672. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  3673. || item.type == CommonConstants.TYPE_IS_ALBUM
  3674. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3675. .fontWeight(FontWeight.Medium)
  3676. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3677. $r('app.color.text_color'))
  3678. }
  3679. }
  3680. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  3681. }
  3682. .height(this.twoFingerType == 3 ? 60 : this.twoFingerType == 2 ? 48 : 35)
  3683. .width(this.getGridWight())
  3684. .justifyContent(FlexAlign.Center)
  3685. .margin({
  3686. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3687. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3688. })
  3689. }
  3690. .width(this.getGridWight())
  3691. .borderRadius(12)
  3692. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  3693. .backgroundImageSize({ height: '100%', width: '100%' })
  3694. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  3695. .animation({ curve: Curve.Sharp, duration: 300 })
  3696. Checkbox({ name: 'checkbox' + index })
  3697. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  3698. .selectedColor(this.themeColor)
  3699. .shape(CheckBoxShape.CIRCLE)
  3700. .opacity(this.isMultiSelect ? 1 : 0)
  3701. .animation({
  3702. duration: 666,
  3703. curve: 'Smooth' // 可选动画曲线
  3704. })
  3705. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  3706. Visibility.None)
  3707. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  3708. .margin({ left: 20, top: 8, bottom: 8 })
  3709. .width(38)
  3710. .height(38)
  3711. }
  3712. }
  3713. .backgroundColor(Color.Transparent)
  3714. .width('100%')
  3715. .padding({ top: 15 })
  3716. .height(this.getGridAllHeight())
  3717. .onClick(() => {
  3718. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3719. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3720. this.handleFileSelection(item, !isChecked);
  3721. } else {
  3722. this.doPlay(item, index)
  3723. }
  3724. })
  3725. }
  3726. getGridAllHeight() {
  3727. let heightG = 222
  3728. switch (this.twoFingerType) {
  3729. case 1:
  3730. heightG = 118
  3731. break;
  3732. case 2:
  3733. heightG = 168
  3734. break;
  3735. case 3:
  3736. heightG = 222
  3737. break;
  3738. }
  3739. return heightG
  3740. }
  3741. getGridHeight() {
  3742. let heightG = 150
  3743. switch (this.twoFingerType) {
  3744. case 1:
  3745. heightG = 55
  3746. break;
  3747. case 2:
  3748. heightG = 100
  3749. break;
  3750. case 3:
  3751. heightG = 150
  3752. break;
  3753. }
  3754. return heightG
  3755. }
  3756. getGridWight() {
  3757. let wightG = 158
  3758. switch (this.twoFingerType) {
  3759. case 1:
  3760. wightG = 80
  3761. break;
  3762. case 2:
  3763. wightG = 110
  3764. break;
  3765. case 3:
  3766. wightG = 158
  3767. break;
  3768. }
  3769. return wightG
  3770. }
  3771. @State isShowDetail:boolean = false
  3772. // @State isShowDetailGrid:boolean = false
  3773. // @State isShowEditGrid:boolean = false
  3774. @State longItemFilePathDetail:string =''
  3775. @Builder
  3776. MenuBuilder(item: VideoItem, index: number, filePath: string) {
  3777. if(
  3778. ((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  3779. ||(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3780. item.name === LocalMusic.STR_HISTORY_MUSIC)
  3781. ){
  3782. //如果是专辑和艺术家的首页,不能长按
  3783. //如果是我的收藏 最近播放等也不能长按
  3784. }else{
  3785. Scroll() {
  3786. Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
  3787. Menu() {
  3788. MenuItem({
  3789. symbolStartIcon: new SymbolGlyphModifier(Utility.getIsFav(this.favList, item) ?
  3790. $r('sys.symbol.heart_fill') : $r('sys.symbol.heart')),
  3791. content: Utility.getIsFav(this.favList, item) ? '取消收藏' : '收藏'
  3792. })
  3793. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3794. .onClick(() => {
  3795. if (item) {
  3796. this.doFav(item)
  3797. }
  3798. this.longItemFilePath = ''
  3799. })
  3800. MenuItem({
  3801. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.forward_end_fill')),
  3802. content: '下一首播放'
  3803. })
  3804. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3805. .onClick(() => {
  3806. this.addToNextPlay(item);
  3807. this.longItemFilePath = ''
  3808. })
  3809. MenuItem({
  3810. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
  3811. content: '编辑标签'
  3812. })
  3813. .bindSheet($$this.isShowEdit, this.editSheet(item), {
  3814. height: '99%',
  3815. dragBar: true,
  3816. showClose: true,
  3817. preferType: SheetType.CENTER ,
  3818. title: { title: '编辑标签' }
  3819. })
  3820. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3821. .onClick(async() => {
  3822. this.setEditStrEmpty()
  3823. this.tempLyricContent = await this.getLyricContent(item);
  3824. // console.info('onecold 长按this.tempLyricContent' +this.tempLyricContent)
  3825. if(this.isGridMusic||this.twoFingerType==4){
  3826. this.longItemFilePath = item.filePath
  3827. }else{
  3828. this.isShowEdit = !this.isShowEdit;
  3829. }
  3830. })
  3831. MenuItem({
  3832. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.checkmark_square_on_square')),
  3833. content: $r('app.string.select_all')
  3834. })
  3835. .onClick(() => {
  3836. this.isMultiSelect = !this.isMultiSelect
  3837. this.longItemFilePath = ''
  3838. this.selectedFiles.push(item)
  3839. })
  3840. MenuItem({
  3841. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.rename')),
  3842. content: $r('app.string.rename')
  3843. })
  3844. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3845. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3846. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3847. .onClick(() => {
  3848. this.showReNameDialog(item, index + '', filePath)
  3849. this.longItemFilePath = ''
  3850. })
  3851. MenuItem({
  3852. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
  3853. content: $r('app.string.delete')
  3854. })
  3855. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3856. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3857. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3858. .onClick(() => {
  3859. this.selectedFiles.push(item)
  3860. this.showWarnIsDelete()
  3861. this.longItemFilePath = ''
  3862. })
  3863. MenuItem({
  3864. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.info_circle')),
  3865. content: $r('app.string.detail')
  3866. })
  3867. .bindSheet($$this.isShowDetail, this.detailSheet(item), {
  3868. height:'95%',
  3869. dragBar: true,
  3870. showClose: true,
  3871. blurStyle:BlurStyle.Thin,
  3872. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  3873. backgroundColor:Color.Transparent,
  3874. title: { title: '详情信息' }
  3875. })
  3876. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3877. .onClick(() => {
  3878. if(this.isGridMusic||this.twoFingerType==4){
  3879. this.longItemFilePathDetail = item.filePath
  3880. }else{
  3881. this.isShowDetail = !this.isShowDetail
  3882. }
  3883. })
  3884. MenuItem({
  3885. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.share')),
  3886. content: $r('app.string.share')
  3887. })
  3888. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3889. .onClick(() => {
  3890. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  3891. this.longItemFilePath = ''
  3892. })
  3893. }
  3894. .font({ size: 15, weight: FontWeight.Normal })
  3895. }
  3896. .width(180)
  3897. }
  3898. .height('auto')
  3899. }
  3900. }
  3901. private listMaxScrollOffsetY: number = 0
  3902. @State selectedIndex: number = -1
  3903. setlistTwoFingers() {
  3904. this.pinchValue = this.scaleValue;
  3905. Logger.info('this.pinchValue = ' + this.pinchValue);
  3906. if (this.pinchValue >= 1) {
  3907. this.twoFingerType++
  3908. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3909. if (this.twoFingerType > 3) {
  3910. this.twoFingerType = 1
  3911. this.isGridMusic = true
  3912. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3913. }
  3914. } else {
  3915. this.twoFingerType--
  3916. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3917. if (this.twoFingerType < 1) {
  3918. this.twoFingerType = 4
  3919. this.columns = 1
  3920. }
  3921. }
  3922. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3923. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3924. this.pinchValue = 1;
  3925. this.scaleValue = 1;
  3926. }
  3927. @Builder
  3928. getListView() {
  3929. List({ scroller: this.listScroller }) {
  3930. ListItemGroup({ header: this.coverHeader() }) {
  3931. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3932. ListItem() {
  3933. Column() {
  3934. if (item.type === CommonConstants.TYPE_IS_DIR
  3935. || item.type === CommonConstants.TYPE_IS_ARTIST || item.type === CommonConstants.TYPE_IS_ALBUM) {
  3936. this.DirItem(item, index)
  3937. } else if (item.type === CommonConstants.TYPE_IS_CSJAD) { //如果是穿山甲广告
  3938. } else {
  3939. this.MusicItem(item, index)
  3940. }
  3941. }
  3942. .shadow(this.scaleItem === index ? {
  3943. radius: 70,
  3944. color: '#15000000',
  3945. offsetX: 0,
  3946. offsetY: 0
  3947. } :
  3948. {
  3949. radius: 0,
  3950. color: '#15000000',
  3951. offsetX: 0,
  3952. offsetY: 0
  3953. })
  3954. .animation({ curve: Curve.Sharp, duration: 300 })
  3955. }
  3956. // .transition(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }))
  3957. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  3958. .animation({ duration: 500 }),
  3959. TransitionEffect.scale({ x: 0, y: 0 })))
  3960. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3961. .swipeAction((
  3962. (this.isSwipe&&this.modeType == 0 || this.modeType == 1 || ((this.modeType == 3 || this.modeType == 2) && this.isCanBack))
  3963. && item.type !== CommonConstants.TYPE_IS_CSJAD &&
  3964. !this.isHistory) ? { end: this.DeleteButton(item, index, item.filePath) } : {}) //左滑
  3965. .onClick(() => {
  3966. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3967. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3968. this.handleFileSelection(item, !isChecked);
  3969. } else {
  3970. this.doPlay(item, index)
  3971. }
  3972. })
  3973. //拖动List关键代码开始
  3974. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  3975. .zIndex(this.dragItem === index ? 1 : 0)
  3976. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  3977. .gesture(
  3978. GestureGroup(GestureMode.Sequence,
  3979. LongPressGesture({ repeat: true })
  3980. .onAction((event?: GestureEvent) => {
  3981. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3982. this.scaleItem = index
  3983. })
  3984. })
  3985. .onActionEnd(() => {
  3986. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3987. this.scaleItem = -1
  3988. })
  3989. }),
  3990. PanGesture({ fingers: 1, direction: null, distance: 0 })
  3991. .onActionStart(() => {
  3992. this.dragItem = index // 记录当前拖动项索引
  3993. this.dragRefOffset = 0 // 重置偏移基准
  3994. })
  3995. .onActionUpdate((event: GestureEvent) => {
  3996. this.offsetY = event.offsetY - this.dragRefOffset;
  3997. this.neighborItem = -1;
  3998. let indexA = this.videoLocalList.indexOf(item);
  3999. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  4000. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  4001. let value: number = 0;
  4002. if (this.offsetY < 0) {
  4003. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  4004. this.neighborItem = indexA - 1;
  4005. this.neighborScale = 1 - value / 20;
  4006. } else if (this.offsetY > 0) {
  4007. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  4008. this.neighborItem = indexA + 1;
  4009. this.neighborScale = 1 - value / 20;
  4010. }
  4011. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.videoLocalList.length) {
  4012. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4013. this.offsetY -= this.ITEM_INTV;
  4014. this.dragRefOffset += this.ITEM_INTV;
  4015. this.itemMove(indexA, indexA + 1);
  4016. });
  4017. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  4018. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4019. this.offsetY += this.ITEM_INTV;
  4020. this.dragRefOffset -= this.ITEM_INTV;
  4021. this.itemMove(indexA, indexA - 1);
  4022. });
  4023. }
  4024. let curListOffset = this.listScroller.currentOffset()
  4025. // 获取手指信息
  4026. let fingerInfo = event.fingerList[0]
  4027. let clickPercentY =
  4028. (fingerInfo.globalY - Number(this.listArea.globalPosition.y)) / Number(this.listArea.height)
  4029. if (clickPercentY > 0.8 && !this.listScroller.isAtEnd()) {
  4030. let scrollVelocity = clickPercentY > 0.9 ? 4 : 2
  4031. if (this.listMaxScrollOffsetY - curListOffset.yOffset > scrollVelocity + 5) {
  4032. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset += scrollVelocity })
  4033. }
  4034. } else if (clickPercentY < 0.2 && curListOffset.yOffset >= 0) {
  4035. let scrollVelocity = clickPercentY < 0.1 ? 4 : 2
  4036. if (curListOffset.yOffset > scrollVelocity + 5) {
  4037. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset -= scrollVelocity })
  4038. }
  4039. }
  4040. })
  4041. .onActionEnd((event: GestureEvent) => {
  4042. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4043. this.dragItem = -1
  4044. this.neighborItem = -1
  4045. })
  4046. animateTo({
  4047. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  4048. }, () => {
  4049. this.scaleItem = -1
  4050. })
  4051. })
  4052. )
  4053. .onCancel(() => {
  4054. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4055. this.dragItem = -1
  4056. this.neighborItem = -1
  4057. })
  4058. animateTo({
  4059. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  4060. }, () => {
  4061. this.scaleItem = -1
  4062. })
  4063. })
  4064. ) //拖动List关键代码结束
  4065. }, (item: VideoItem) => item.filePath)
  4066. }
  4067. }
  4068. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  4069. .gesture(PinchGesture({ fingers: 2 })
  4070. .onActionEnd((event: GestureEvent) => {
  4071. this.setlistTwoFingers()
  4072. })
  4073. .onActionUpdate(e => {
  4074. this.scaleValue = this.pinchValue * e.scale
  4075. })
  4076. .onActionStart(e => {
  4077. }))
  4078. // .divider({ strokeWidth: 1, color: this.isDarkMode? '#333333':'#ffe9f0f0' })
  4079. .margin({
  4080. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+25 : this.topBarHeight+80)
  4081. : (this.isShowCoverHeader() ? this.topBarHeight+35 : this.isHiCarSmall()?this.topBarHeight+90:this.topBarHeight+125)
  4082. })
  4083. .cachedCount(6)
  4084. .reuseId('list_item')
  4085. .borderRadius(20)
  4086. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  4087. TransitionEffect.scale({ x: 0, y: 0 })))
  4088. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  4089. // .animation({ duration: 500, curve: Curve.Ease }))
  4090. .layoutWeight(1)
  4091. .onScrollIndex((start) => {
  4092. this.selectedIndex = start
  4093. })
  4094. .visibility(this.isGridMusic ? Visibility.None : Visibility.Visible)
  4095. .lanes(
  4096. new BreakpointType<number>({
  4097. sm: 1,
  4098. md: 2,
  4099. lg: 2,
  4100. xl: 3,
  4101. xxl: 4
  4102. }).getValue(this.currentBreakpoint),
  4103. new BreakpointType<number>({
  4104. sm: 0,
  4105. md: 12,
  4106. lg: 12,
  4107. xl: 16,
  4108. xxl: 20
  4109. }).getValue(this.currentBreakpoint)
  4110. )
  4111. .onAreaChange((oldValue: Area, newValue: Area) => {
  4112. this.listArea = newValue
  4113. if (this.twoFingerType == 3) {
  4114. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_BIG) - 10
  4115. } else if (this.twoFingerType == 2) {
  4116. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT) - 10
  4117. } else if (this.twoFingerType == 1) {
  4118. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_SMALL) - 10
  4119. }
  4120. })
  4121. .onScrollFrameBegin((offset: number) => {
  4122. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  4123. // if (this.isPhoneLan()) {
  4124. // this.setBarHeightHide(offset)
  4125. // } else
  4126. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  4127. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  4128. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  4129. if (this.isScrollHide) {
  4130. this.setBarHeightHide2(offset)
  4131. } else {
  4132. this.setBarHeightNormal()
  4133. }
  4134. } else {
  4135. this.setBarHeightHide(offset)
  4136. }
  4137. return { offsetRemain: offset };
  4138. })
  4139. //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
  4140. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  4141. .onDrop((event?: DragEvent) => {
  4142. try {
  4143. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  4144. if (dragData !== undefined) {
  4145. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  4146. if (records.length > 0) {
  4147. for (let i = 0; i < records.length; i++) {
  4148. let types = records[i].getTypes();
  4149. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  4150. const fileUriUds =
  4151. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  4152. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  4153. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  4154. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  4155. this.targetFile = fileUriUds.oriUri;
  4156. this.saveVideoDatas([this.targetFile])
  4157. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  4158. }
  4159. }
  4160. }
  4161. } else {
  4162. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  4163. }
  4164. } else {
  4165. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  4166. }
  4167. } catch (error) {
  4168. const err = error as BusinessError;
  4169. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  4170. }
  4171. })
  4172. }
  4173. setBarHeightNormal() {
  4174. this.hideDone = false;
  4175. this.getUIContext().animateTo({
  4176. duration: 300
  4177. }, () => {
  4178. this.bottomBarHeight = 55 + 0;
  4179. this.topBarHeight = 50 + 0;
  4180. this.barOpacity = 1;
  4181. this.barBottomOpacity = 1
  4182. this.currentYOffset = 0;
  4183. this.isHiding = false;
  4184. });
  4185. }
  4186. setBarHeightHide(offset: number) {
  4187. if (offset > 0 && !this.hideDone) {
  4188. this.currentYOffset += offset;
  4189. if (this.currentYOffset <= 100) {
  4190. this.bottomBarHeight = this.bottomBarHeight * (1 - this.currentYOffset / 100);
  4191. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  4192. this.barOpacity = 1 - this.currentYOffset / 100;
  4193. this.barBottomOpacity = 1 - this.currentYOffset / 100;
  4194. } else {
  4195. this.topBarHeight = 0;
  4196. this.bottomBarHeight = 0;
  4197. this.barBottomOpacity = 0
  4198. this.barOpacity = 0;
  4199. this.hideDone = true;
  4200. }
  4201. this.isHiding = true;
  4202. }
  4203. if (offset < 0 && this.isHiding) {
  4204. this.hideDone = false;
  4205. this.getUIContext().animateTo({
  4206. duration: 300
  4207. }, () => {
  4208. this.bottomBarHeight = 55 + 0;
  4209. this.topBarHeight = 50 + 0;
  4210. this.barOpacity = 1;
  4211. this.barBottomOpacity = 1
  4212. this.currentYOffset = 0;
  4213. this.isHiding = false;
  4214. });
  4215. }
  4216. }
  4217. //这个方法没隐藏bottomBar,只隐藏topbar
  4218. setBarHeightHide2(offset: number) {
  4219. if (offset > 0 && !this.hideDone) {
  4220. this.currentYOffset += offset;
  4221. if (this.currentYOffset <= 100) {
  4222. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  4223. this.barOpacity = 1 - this.currentYOffset / 100;
  4224. } else {
  4225. this.topBarHeight = 0;
  4226. this.barOpacity = 0;
  4227. this.hideDone = true;
  4228. }
  4229. this.isHiding = true;
  4230. }
  4231. if (offset < 0 && this.isHiding) {
  4232. this.hideDone = false;
  4233. this.getUIContext().animateTo({
  4234. duration: 300
  4235. }, () => {
  4236. this.topBarHeight = 50 + 0;
  4237. this.barOpacity = 1;
  4238. this.currentYOffset = 0;
  4239. this.isHiding = false;
  4240. });
  4241. }
  4242. }
  4243. private doPlay(item: VideoItem, index?: number, isFromSonPlayList?: boolean) {
  4244. switch (item.type) {
  4245. case CommonConstants.TYPE_IS_DIR:
  4246. // 进入歌单前安全保存当前滚动偏移量,支持列表和网格
  4247. let offsetB = 0
  4248. if(this.twoFingerType==4){
  4249. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4250. let cur = this.waterScroller.currentOffset()
  4251. if (cur && typeof cur.yOffset === 'number') {
  4252. offsetB = cur.yOffset
  4253. }
  4254. }
  4255. this.mScrollMap.set('lastWaterDirScrollOffset', offsetB)
  4256. }else
  4257. if (this.isGridMusic) {
  4258. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4259. let cur = this.scroller.currentOffset()
  4260. if (cur && typeof cur.yOffset === 'number') {
  4261. offsetB = cur.yOffset
  4262. }
  4263. }
  4264. this.mScrollMap.set('lastGridDirScrollOffset', offsetB)
  4265. } else {
  4266. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4267. let cur = this.listScroller.currentOffset()
  4268. if (cur && typeof cur.yOffset === 'number') {
  4269. offsetB = cur.yOffset
  4270. }
  4271. }
  4272. this.mScrollMap.set('lastListDirScrollOffset', offsetB)
  4273. }
  4274. if (item.name === LocalMusic.STR_LOCK_VIDEO) {
  4275. this.showVerifyDialog()
  4276. this.currentTitleName = '私密音频'
  4277. this.currentTitleCover = $r('app.media.ic_avatar5')
  4278. } else if (item.name === LocalMusic.STR_HISTORY_MUSIC) {
  4279. this.titleBarModel.setTitleName('最近播放')
  4280. this.currentTitleCover = $r('app.media.ic_avatar2')
  4281. this.currentTitleName = '最近播放'
  4282. //加载动画效果
  4283. this.updateListData(this.historyList, true)
  4284. // this.videoLocalList = this.historyList
  4285. if (ArrayUtil.isEmpty(this.historyList)) {
  4286. ToastUtil.showToast('最近播放记录空空如也')
  4287. } else {
  4288. this.currentTitleCover = Utility.getFirstCoverFromList(this.historyList)
  4289. }
  4290. this.isHistory = true
  4291. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4292. } else if (item.name === LocalMusic.STR_FAC_VIDEO) {
  4293. this.titleBarModel.setTitleName('我的收藏')
  4294. this.currentTitleName = '我的收藏'
  4295. this.currentTitleCover = $r('app.media.ic_avatar1')
  4296. //加载动画效果
  4297. this.updateListData(this.favList)
  4298. if (ArrayUtil.isEmpty(this.favList)) {
  4299. ToastUtil.showToast('无音乐收藏记录')
  4300. } else {
  4301. this.currentTitleCover = Utility.getFirstCoverFromList(this.favList)
  4302. }
  4303. this.isFavMusic = true
  4304. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4305. } else {
  4306. this.currentTitleName = item.name
  4307. this.currentPath = item.filePath
  4308. this.currentTitleCover = $r('app.media.ic_avatar5')
  4309. this.getSortedFiles(this.currentPath)
  4310. }
  4311. //进入歌单的时候的滚动位置在顶部
  4312. if(this.twoFingerType==4){
  4313. setTimeout(() => {
  4314. this.waterScroller.scrollEdge(Edge.Top)
  4315. this.scroller.scrollEdge(Edge.Top)
  4316. }, 380)
  4317. }else{
  4318. if (this.isGridMusic) {
  4319. this.scroller.scrollEdge(Edge.Top)
  4320. }
  4321. }
  4322. break;
  4323. case CommonConstants.TYPE_IS_ARTIST:
  4324. // 进入艺术家前安全保存当前滚动偏移量,支持列表和网格
  4325. let offsetA = 0
  4326. if(this.twoFingerType==4){
  4327. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4328. let cur = this.waterScroller.currentOffset()
  4329. if (cur && typeof cur.yOffset === 'number') {
  4330. offsetA = cur.yOffset
  4331. }
  4332. }
  4333. this.mScrollMap.set('lastWaterArtistScrollOffset', offsetA)
  4334. }else
  4335. if (this.isGridMusic) {
  4336. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4337. let cur = this.scroller.currentOffset()
  4338. if (cur && typeof cur.yOffset === 'number') {
  4339. offsetA = cur.yOffset
  4340. }
  4341. }
  4342. this.mScrollMap.set('lastGridArtistScrollOffset', offsetA)
  4343. } else {
  4344. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4345. let cur = this.listScroller.currentOffset()
  4346. if (cur && typeof cur.yOffset === 'number') {
  4347. offsetA = cur.yOffset
  4348. }
  4349. }
  4350. this.mScrollMap.set('lastListArtistScrollOffset', offsetA)
  4351. }
  4352. let mList = this.artistMap.get(item.name)
  4353. if (mList !== undefined && ArrayUtil.isNotEmpty(mList)) {
  4354. Utility.doSortListAscending(mList)
  4355. this.isCanBack = true
  4356. this.titleBarModel.setTitleName(item.name)
  4357. this.currentTitleName = '艺术家:' + item.name
  4358. if (item.pixelMapPath) {
  4359. this.currentTitleCover = item.pixelMapPath
  4360. }
  4361. this.updateListData(mList)
  4362. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4363. }
  4364. //进入歌单的时候的滚动位置在顶部
  4365. if(this.twoFingerType==4){
  4366. setTimeout(() => {
  4367. this.waterScroller.scrollEdge(Edge.Top)
  4368. this.scroller.scrollEdge(Edge.Top)
  4369. }, 380)
  4370. }else{
  4371. if (this.isGridMusic) {
  4372. this.scroller.scrollEdge(Edge.Top)
  4373. }
  4374. }
  4375. break;
  4376. case CommonConstants.TYPE_IS_ALBUM:
  4377. // 进入专辑前安全保存当前滚动偏移量,支持列表和网格
  4378. let offset = 0
  4379. if(this.twoFingerType==4){
  4380. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4381. let cur = this.waterScroller.currentOffset()
  4382. if (cur && typeof cur.yOffset === 'number') {
  4383. offset = cur.yOffset
  4384. }
  4385. }
  4386. this.mScrollMap.set('lastWaterAlBumScrollOffset', offset)
  4387. }else
  4388. if (this.isGridMusic) {
  4389. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4390. let cur = this.scroller.currentOffset()
  4391. if (cur && typeof cur.yOffset === 'number') {
  4392. offset = cur.yOffset
  4393. }
  4394. }
  4395. this.mScrollMap.set('lastGridAlBumScrollOffset', offset)
  4396. } else {
  4397. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4398. let cur = this.listScroller.currentOffset()
  4399. if (cur && typeof cur.yOffset === 'number') {
  4400. offset = cur.yOffset
  4401. }
  4402. }
  4403. this.mScrollMap.set('lastListAlBumScrollOffset', offset)
  4404. }
  4405. let albumList = this.albumMap.get(item.name)
  4406. if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
  4407. Utility.doSortListAscending(albumList)
  4408. this.isCanBack = true
  4409. this.titleBarModel.setTitleName(item.name)
  4410. this.currentTitleName = '专辑:' + item.name
  4411. if (item.pixelMapPath) {
  4412. this.currentTitleCover = item.pixelMapPath
  4413. }
  4414. this.updateListData(albumList)
  4415. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4416. this.mScrollMap.set(item.name, this.selectedIndex)
  4417. }
  4418. //进入歌单的时候的滚动位置在顶部
  4419. if(this.twoFingerType==4){
  4420. setTimeout(() => {
  4421. this.waterScroller.scrollEdge(Edge.Top)
  4422. this.scroller.scrollEdge(Edge.Top)
  4423. }, 380)
  4424. }else{
  4425. if (this.isGridMusic) {
  4426. this.scroller.scrollEdge(Edge.Top)
  4427. }
  4428. }
  4429. break;
  4430. case CommonConstants.TYPE_IS_CSJAD:
  4431. return
  4432. break;
  4433. case CommonConstants.TYPE_LOCAL:
  4434. if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
  4435. this.stop();
  4436. }
  4437. if (isFromSonPlayList) { //点击来自右下角的播放列表
  4438. this.currentSong = item
  4439. if (index !== undefined) {
  4440. this.curIndex = index
  4441. }
  4442. } else {
  4443. let globalVideoList = Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL) as VideoItem[];
  4444. this.curIndex = Utility.getCurIndexFromGlobalList(globalVideoList, item.filePath)
  4445. this.songList = globalVideoList
  4446. this.sonDataSource.pushArrayData(this.songList)
  4447. this.currentSong = globalVideoList[this.curIndex]
  4448. }
  4449. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  4450. this.videoUrl = this.currentSong.filePath
  4451. this.name = this.currentSong.name
  4452. this.cover = this.currentSong.pixelMapPath
  4453. this.artist = this.currentSong.artist
  4454. LogUtil.info('this.currentSong.duration =' + this.currentSong.duration)
  4455. LogUtil.info('this.currentSong.sampleRate =' + this.currentSong.sampleRate)
  4456. LogUtil.info('this.currentSongmimeType =' + this.currentSong.mimeType)
  4457. console.info('onecold startPlayOrResumePlay 4547')
  4458. this.startPlayOrResumePlay()
  4459. break;
  4460. }
  4461. }
  4462. @Builder
  4463. PlayController() {
  4464. Column() {
  4465. Line().width('100%').height(1).backgroundColor($r('app.color.index_background'))
  4466. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4467. Row() {
  4468. if(this.isHiCar()){
  4469. this.playConRigth()
  4470. Column(){
  4471. this.centerName()
  4472. }.layoutWeight(1)
  4473. this.playConLeft(false)
  4474. }else{
  4475. this.playConLeft()
  4476. this.playConRigth()
  4477. }
  4478. }
  4479. .width('100%')
  4480. .height(this.bottomBarHeight)
  4481. .justifyContent(FlexAlign.Center)
  4482. .hitTestBehavior(HitTestMode.Transparent)
  4483. .backgroundColor(this.isCustomizeBg ? Color.Transparent : $r('app.color.bottom_control_background'))
  4484. .bindContentCover($$this.isShowPlay, this.MusicPlayBuilder(), {
  4485. // modalTransition: ModalTransition.DEFAULT,
  4486. transition: AnimationHelper.transitionInDown(666),
  4487. backgroundColor: 'rgba(0, 0, 0, 0.9)',
  4488. })
  4489. .padding({
  4490. left: 16,
  4491. right: 16
  4492. })
  4493. Line()
  4494. .width('100%')
  4495. .height(25)
  4496. .backgroundColor($r('app.color.bottom_control_background'))// .visibility(this.isPhoneLan()?Visibility.None:this.isCustomizeBg?Visibility.Hidden:Visibility.Visible)
  4497. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4498. }
  4499. .clickEffect({ level: ClickEffectLevel.HEAVY })
  4500. }
  4501. @State isFrontWhite: boolean = false
  4502. @Builder
  4503. centerName() {
  4504. Column() {
  4505. Text(this.currentSong?.name)
  4506. .fontSize(16)
  4507. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4508. .maxLines(1)
  4509. .fontColor($r('app.color.text_color'))
  4510. .fontWeight(500);
  4511. Row() {
  4512. Text(this.currentSong?.artist)
  4513. .margin({ top: 2 })
  4514. .fontSize(13)
  4515. .textAlign(TextAlign.Start)
  4516. .maxLines(1)
  4517. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4518. .fontColor($r('app.color.text_color'));
  4519. }
  4520. .visibility(this.currentSong?.artist? Visibility.Visible:Visibility.None)
  4521. }
  4522. .alignItems(HorizontalAlign.Center)
  4523. }
  4524. @Builder
  4525. playConLeft(isLeft: boolean = true) {
  4526. Row() {
  4527. RotatingCover({ songLabel: this.currentSong?.pixelMapPath });
  4528. Column() {
  4529. Text(this.currentSong?.name)
  4530. .fontSize(16)
  4531. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4532. .maxLines(1)
  4533. .fontColor($r('app.color.text_color'))
  4534. .fontWeight(500);
  4535. Row() {
  4536. Text(this.currentSong?.artist)
  4537. .margin({ top: 2 })
  4538. .fontSize(13)
  4539. .textAlign(TextAlign.Start)
  4540. .maxLines(1)
  4541. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4542. .fontColor($r('app.color.text_color'));
  4543. }
  4544. .visibility(this.currentSong?.artist? Visibility.Visible:Visibility.None)
  4545. }
  4546. .alignItems(isLeft?HorizontalAlign.Start:HorizontalAlign.End)
  4547. .margin({ right: isLeft?22:10 })
  4548. .visibility(isLeft? Visibility.Visible:Visibility.None)
  4549. }
  4550. .padding({ right: 18 })
  4551. .layoutWeight(isLeft?1:0)
  4552. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4553. .onClick(() => {
  4554. if (ArrayUtil.isNotEmpty(this.songList)) {
  4555. this.isShowPlay = true;
  4556. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc';
  4557. this.initLyric(lyricPath);
  4558. this.startAutoHide();
  4559. } else {
  4560. ToastUtil.showToast('当前播放列表为空,请先导入音乐。');
  4561. }
  4562. })
  4563. }
  4564. @Builder
  4565. playConRigth() {
  4566. Row() {
  4567. Image($r('app.media.hm_previous'))
  4568. .height(28)
  4569. .width(28)
  4570. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4571. .margin({ left: 8, right: 16 })
  4572. .fillColor(this.themeColor)
  4573. .displayPriority(2)
  4574. .onClick(() => {
  4575. if (ArrayUtil.isNotEmpty(this.songList)) {
  4576. this.playPrevious()
  4577. } else {
  4578. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4579. }
  4580. })
  4581. //播放进度条
  4582. Stack() {
  4583. Progress({
  4584. value: Math.floor(this.progressValue),
  4585. type: ProgressType.Ring,
  4586. })
  4587. .color(this.themeColor)// 进度条前景色为灰色
  4588. .backgroundColor($r('app.color.index_background'))
  4589. .height(40)
  4590. .aspectRatio(CommonConstants.ASPECT_RATIO)
  4591. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
  4592. .height(38)
  4593. .width(38)
  4594. .displayPriority(3)
  4595. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4596. .fillColor(this.themeColor)
  4597. .onClick(() => {
  4598. if (ArrayUtil.isNotEmpty(this.songList)) {
  4599. console.info('onecold playOrPause 4642')
  4600. this.playOrPause()
  4601. } else {
  4602. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4603. }
  4604. })
  4605. }
  4606. Image($r('app.media.hm_next'))
  4607. .height(28)
  4608. .width(28)
  4609. .margin({
  4610. right: 16,
  4611. left: 16
  4612. })
  4613. .fillColor(this.themeColor)
  4614. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4615. .displayPriority(2)
  4616. .onClick(() => {
  4617. if (ArrayUtil.isNotEmpty(this.songList)) {
  4618. this.playNext()
  4619. } else {
  4620. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4621. }
  4622. })
  4623. Image($r('app.media.hm_playlist'))
  4624. .height(28)
  4625. .width(28)
  4626. .displayPriority(1)
  4627. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4628. .fillColor(this.themeColor)
  4629. .bindSheet($$this.isShowSheet, this.PlayListSheet(), {
  4630. height: '95%',
  4631. dragBar: true,
  4632. showClose: true,
  4633. blurStyle: BlurStyle.Thin,
  4634. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  4635. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  4636. title: {
  4637. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  4638. + `(${this.songList.length}首)`
  4639. }
  4640. })
  4641. .onClick(() => {
  4642. if (ArrayUtil.isNotEmpty(this.songList)) {
  4643. this.isShowSheet = !this.isShowSheet;
  4644. this.isFrontWhite = false
  4645. LogUtil.info('onecold scrollToIndex = ' + this.curIndex)
  4646. this.scrollIndex()
  4647. } else {
  4648. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4649. }
  4650. })
  4651. }
  4652. }
  4653. scrollIndex(){
  4654. if(this.curIndex>500)//条数太大的时候 滚动非常卡 导致闪退,先改为不滚
  4655. return
  4656. try {
  4657. setTimeout(() => {
  4658. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  4659. this.playListScroller.scrollToIndex(this.curIndex,true, ScrollAlign.CENTER)
  4660. })
  4661. }, 123)
  4662. }catch (error) {
  4663. console.error(`onecold scrollIndex出错: ${error}`);
  4664. }
  4665. }
  4666. //播放列表布局
  4667. @Builder
  4668. PlayListSheet() {
  4669. Column() {
  4670. this.PlayList()
  4671. }
  4672. .width('100%')
  4673. .height('100%')
  4674. }
  4675. @State titleStr: string = ''
  4676. @State ablumStr: string = ''
  4677. @State artistStr: string = ''
  4678. @State lyricConStr: string = ''
  4679. @State currentEditItem: string = ''
  4680. @State yearStr: string = ''
  4681. @State trackStr: string = ''
  4682. @State genreStr: string = ''
  4683. @State imagePathStr: string = ''
  4684. @State albumArtistStr: string = ''
  4685. @State composerStr: string = ''
  4686. @State lyricistStr: string = ''
  4687. @State commentStr: string = ''
  4688. @State discStr: string = ''
  4689. doUpdateData() {
  4690. setTimeout(() => {
  4691. if (this.modeType === 0) {
  4692. this.deleteCache(this.currentPath)
  4693. this.getSortedFiles(this.currentPath)
  4694. }
  4695. workerInstance.postMessage({ code: 2, data: this.context });
  4696. workerInstance.postMessage({ code: 3, data: this.context });
  4697. workerInstance.postMessage({ code: 4, data: this.context });
  4698. }, 999)
  4699. }
  4700. //编辑信息
  4701. async doEdit(item: VideoItem) {
  4702. if (!item) {
  4703. return
  4704. }
  4705. if (StrUtil.isEmpty(this.titleStr)) {
  4706. ToastUtil.showToast('标题不能为空')
  4707. return
  4708. }
  4709. // let doChangeLyric = false
  4710. // if(item.filePath==this.currentSong?.filePath){
  4711. // if(this.lyricConStr !== this.lyricContent){
  4712. // doChangeLyric = true
  4713. // }
  4714. // }else if(this.lyricConStr !== this.tempLyricContent){
  4715. // doChangeLyric = true
  4716. // }
  4717. //用户更改了封面,那就内嵌下封面
  4718. if(StrUtil.isNotEmpty(this.imagePathStr)){
  4719. const resultCover:boolean = await changeMusicCover(this.context,
  4720. item.filePath,this.imagePathStr,true);
  4721. this.imagePathStr = ''
  4722. if(resultCover){
  4723. ToastUtil.showToast('内嵌封面成功')
  4724. }
  4725. }
  4726. const metadata:FFMpegTags = {
  4727. title: this.titleStr,
  4728. artist: this.artistStr,
  4729. album: this.ablumStr,
  4730. // LYRICS:this.lyricConStr,
  4731. // USLT:this.lyricConStr,
  4732. TYER:this.yearStr,
  4733. genre:this.genreStr,
  4734. track:this.trackStr,
  4735. album_artist:this.albumArtistStr,
  4736. TPE2:this.albumArtistStr,//ID3v2 中通常没有专门的 "专辑艺术家" 字段,但有些软件会使用 TPE2 来表示专辑艺
  4737. COMPOSER:this.composerStr,
  4738. lyricist:this.lyricistStr,
  4739. TEXT:this.lyricistStr,//ID3v2 使用 TEXT 字段来表示作词者
  4740. comment:this.commentStr,
  4741. // comm:this.commentStr,//ID3v2:使用 COMM(Comment)字段。
  4742. disc:this.discStr,
  4743. };
  4744. //内嵌下标签的值,设置overwrite为true会直接修改原文件
  4745. const result:boolean = await repairAudioMetadata(
  4746. item.filePath,
  4747. this.lyricConStr,
  4748. metadata,
  4749. true
  4750. );
  4751. if (result) {
  4752. this.table.updateMediaInfo(item.filePath, this.titleStr, this.artistStr, this.ablumStr,this.lyricConStr,
  4753. this.yearStr,this.genreStr,this.trackStr,this.albumArtistStr,this.composerStr, this.lyricistStr,this.commentStr,this.discStr,
  4754. (success: boolean, error?: string) => {
  4755. // this.isShowEdit = false
  4756. if (success) {
  4757. console.log(" onecold 编辑信息成功,数据库已同步");
  4758. ToastUtil.showToast('内嵌音乐标签成功')
  4759. this.isShowMoreView = false
  4760. this.name = this.titleStr
  4761. if (item.filePath == this.currentSong?.filePath) {
  4762. this.currentSong.name = this.titleStr
  4763. this.artist = this.artistStr
  4764. this.currentSong.artist = this.artistStr
  4765. this.currentSong.album = this.ablumStr
  4766. this.currentSong.year = this.yearStr
  4767. this.currentSong.genre = this.genreStr
  4768. this.currentSong.track = this.trackStr
  4769. this.currentSong.lyricContent = this.lyricConStr
  4770. this.initLyric(item.filePath)
  4771. this.currentSong.ALBUMARTIST = this.albumArtistStr
  4772. this.currentSong.COMPOSER = this.composerStr
  4773. this.currentSong.LYRICIST = this.lyricistStr
  4774. this.currentSong.COMMENT = this.commentStr
  4775. }
  4776. this.doUpdateData()
  4777. } else {
  4778. // ToastUtil.showToast('保存失败' + error?.toString())
  4779. console.error(" onecold 编辑信息数据库失败原因: " + error);
  4780. }
  4781. });
  4782. console.log(' onecold 元数据标签更新成功,');
  4783. } else {
  4784. ToastUtil.showToast('内嵌音乐标签失败')
  4785. console.log('onecold 内嵌音乐标签失败');
  4786. }
  4787. this.longItemFilePath = ''
  4788. this.tempLyricContent = ''
  4789. this.isShowEdit = false
  4790. }
  4791. updateLyricToDB() {
  4792. }
  4793. @Builder
  4794. editSheet(item: VideoItem) {
  4795. Scroll() {
  4796. Column() {
  4797. this.editDetail(item)
  4798. }
  4799. }
  4800. .width('100%')
  4801. .height('100%')
  4802. }
  4803. @Builder
  4804. editDetail(item: VideoItem) {
  4805. Column() {
  4806. if (item) {
  4807. Row() {
  4808. Stack() {
  4809. Image(StrUtil.isNotEmpty(this.imagePathStr)?this.imagePathStr.startsWith('http')?
  4810. this.imagePathStr:fileUri.getUriFromPath(this.imagePathStr):
  4811. StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.add_image2') :
  4812. item.pixelMapPath)
  4813. .fillColor(this.themeColor)
  4814. .height(88)
  4815. .width(88)
  4816. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
  4817. .borderRadius(12)
  4818. .clip(true)
  4819. .opacity(this.opacityItem)// 绑定透明度
  4820. .margin({ left: 25 })
  4821. }
  4822. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
  4823. .onClick(async () => {
  4824. const imagePath:string | undefined = await this.goSelectImage(item);
  4825. if (imagePath) {
  4826. //用户更改过图片
  4827. this.imagePathStr = imagePath
  4828. }
  4829. })
  4830. .width('28%')
  4831. Row() {
  4832. Column() {
  4833. Text(item.name)
  4834. .fontSize(17)
  4835. .maxLines(1)
  4836. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4837. .animation({
  4838. duration: 555,
  4839. curve: 'Linear',
  4840. })
  4841. .fontColor(this.themeColor)
  4842. .margin({ left: 8 })
  4843. Row() {
  4844. Text(item.artist)
  4845. .fontSize(14)
  4846. .maxLines(1)
  4847. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4848. .padding({ top: 8 })
  4849. .fontColor(this.themeColor)
  4850. .margin({ left: 8 })
  4851. }
  4852. }
  4853. .height('100%')
  4854. .width(100)
  4855. .layoutWeight(1)
  4856. .visibility(this.isDarkMode ? Visibility.None : Visibility.Visible)
  4857. .justifyContent(FlexAlign.Center)
  4858. .alignItems(HorizontalAlign.Start)
  4859. Column() {
  4860. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  4861. Row(){
  4862. SymbolGlyph($r('sys.symbol.picture'))
  4863. .fontSize(18)
  4864. .fontColor([Color.White])
  4865. Text('获取封面')
  4866. .margin({ left: 4 })
  4867. .fontSize(11)
  4868. .fontColor(Color.White)
  4869. .fontWeight(480)
  4870. .textAlign(TextAlign.Center)
  4871. }
  4872. .justifyContent(FlexAlign.Center)
  4873. }
  4874. .height(38)
  4875. .width(100)
  4876. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4877. .backgroundColor(this.themeColor)
  4878. .stateEffect(true)
  4879. .margin({ right: 35 })
  4880. .onClick(async () => {
  4881. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  4882. this.showTipsDialog();
  4883. return; // Return empty string when no API is configured
  4884. }
  4885. const imagePath:string | undefined = await this.doSearchCover(item);
  4886. console.info('onecold imagePath = '+imagePath)
  4887. if (StrUtil.isNotEmpty(imagePath)) {
  4888. //用户更改过图片
  4889. this.imagePathStr = imagePath
  4890. ToastUtil.showToast('获取封面成功')
  4891. }else{
  4892. ToastUtil.showToast('获取封面失败,请重试')
  4893. }
  4894. })
  4895. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  4896. Row(){
  4897. SymbolGlyph($r('sys.symbol.input_mode'))
  4898. .fontSize(18)
  4899. .fontColor([Color.White])
  4900. Text('获取歌词')
  4901. .margin({ left: 4 })
  4902. .fontSize(11)
  4903. .fontColor(Color.White)
  4904. .fontWeight(480)
  4905. .textAlign(TextAlign.Center)
  4906. }
  4907. .justifyContent(FlexAlign.Center)
  4908. }
  4909. .height(38)
  4910. .width(100)
  4911. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4912. .backgroundColor(this.themeColor)
  4913. .stateEffect(true)
  4914. .margin({ top: 9, right: 35 })
  4915. .onClick(async () => {
  4916. //判断有没有设置api
  4917. let apiUrl = PreferencesUtil.getStringSync('LRC_API', '')
  4918. if (StrUtil.isEmpty(apiUrl)) {
  4919. this.isLyricSetting = false
  4920. this.showTipsDialog()
  4921. return
  4922. }
  4923. let artist = item.artist
  4924. let title = item.name
  4925. if(!artist)
  4926. artist = ''
  4927. if(!title)
  4928. title = ''
  4929. let res: string | undefined = await getApiLyric(apiUrl,title, artist, false);
  4930. if (res && StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  4931. this.lyricConStr = res;
  4932. ToastUtil.showToast('获取歌词成功')
  4933. }else{
  4934. ToastUtil.showToast('获取歌词失败,请重试')
  4935. }
  4936. })
  4937. }
  4938. .justifyContent(FlexAlign.Start)
  4939. }
  4940. .height('100%')
  4941. .justifyContent(FlexAlign.Start)
  4942. .layoutWeight(1)
  4943. }
  4944. .width('100%')
  4945. .height(98)
  4946. Row() {
  4947. Text('标题:')
  4948. .fontSize(14)
  4949. .fontColor($r('app.color.text_color'))
  4950. .margin({ left: 22 })
  4951. TextInput({ text: item.name })
  4952. .height(40)
  4953. .maxLines(1)
  4954. .fontSize(14)
  4955. .layoutWeight(1)
  4956. .fontColor($r('app.color.text_color'))
  4957. .margin({ right: 20, left: 10 })
  4958. .onChange((val: string) => {
  4959. this.titleStr = val
  4960. })
  4961. }
  4962. .width('100%')
  4963. .margin({ top: 10, bottom: 10 })
  4964. .justifyContent(FlexAlign.Start)
  4965. Row() {
  4966. Text('艺术家:')
  4967. .fontSize(14)
  4968. .fontColor($r('app.color.text_color'))
  4969. .margin({ left: 22 })
  4970. TextInput({ text: item.artist })
  4971. .height(40)
  4972. .maxLines(1)
  4973. .fontSize(14)
  4974. .layoutWeight(1)
  4975. .fontColor($r('app.color.text_color'))
  4976. .margin({ right: 20, left: 10 })
  4977. .onChange((val: string) => {
  4978. this.artistStr = val
  4979. })
  4980. }
  4981. .width('100%')
  4982. .margin({ top: 10, bottom: 10 })
  4983. .justifyContent(FlexAlign.Start)
  4984. Row() {
  4985. Text('专辑名:')
  4986. .fontSize(14)
  4987. .fontColor($r('app.color.text_color'))
  4988. .margin({ left: 22 })
  4989. TextInput({ text: item.album })
  4990. .height(40)
  4991. .maxLines(1)
  4992. .fontSize(14)
  4993. .layoutWeight(1)
  4994. .fontColor($r('app.color.text_color'))
  4995. .margin({ right: 20, left: 10 })
  4996. .onChange((val: string) => {
  4997. this.ablumStr = val
  4998. })
  4999. }
  5000. .width('100%')
  5001. .margin({ top: 10, bottom: 10 })
  5002. .justifyContent(FlexAlign.Start)
  5003. Row() {
  5004. Column(){
  5005. Column(){
  5006. Text('歌词:')
  5007. .fontSize(14)
  5008. .fontColor($r('app.color.text_color'))
  5009. .margin({ top:9,left: 22 })
  5010. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5011. SymbolGlyph($r('sys.symbol.trash_fill'))
  5012. .fontSize(25)
  5013. .alignSelf(ItemAlign.Center)
  5014. .margin({ left: 22,top:25})
  5015. }
  5016. .backgroundColor(Color.Transparent)
  5017. .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
  5018. Visibility.None:Visibility.Visible)
  5019. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5020. .onClick(()=>{
  5021. this.lyricConStr = ''
  5022. this.lyricContent = ''
  5023. this.tempLyricContent = ''
  5024. })
  5025. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5026. SymbolGlyph($r('sys.symbol.plus'))
  5027. .fontSize(25)
  5028. .alignSelf(ItemAlign.Center)
  5029. .margin({ left: 22,top:25})
  5030. }
  5031. .backgroundColor(Color.Transparent)
  5032. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5033. .onClick( ()=>{
  5034. this.callFilePickerSelectFileForLyric()
  5035. })
  5036. }
  5037. .layoutWeight(1)
  5038. }
  5039. TextArea({ text: StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr:
  5040. this.tempLyricContent })
  5041. .type(TextAreaType.NORMAL)
  5042. .height(StrUtil.isEmpty(this.lyricConStr)&&StrUtil.isEmpty(this.tempLyricContent)?100:'auto')
  5043. .fontSize(14)
  5044. .layoutWeight(1)
  5045. .fontColor($r('app.color.text_color'))
  5046. .margin({ right: 20, left: 10 })
  5047. .onChange((val: string) => {
  5048. this.lyricConStr = val
  5049. })
  5050. }
  5051. .width('100%')
  5052. .height(StrUtil.isEmpty(this.lyricConStr)&&StrUtil.isEmpty(this.tempLyricContent)?100:'auto')
  5053. .margin({ top: 10, bottom: 10 })
  5054. .justifyContent(FlexAlign.Start)
  5055. Row() {
  5056. Text('年份:')
  5057. .fontSize(14)
  5058. .fontColor($r('app.color.text_color'))
  5059. .margin({ left: 22 })
  5060. TextInput({ text: item.year })
  5061. .height(40)
  5062. .maxLines(1)
  5063. .fontSize(14)
  5064. .type(InputType.Number)
  5065. .layoutWeight(1)
  5066. .fontColor($r('app.color.text_color'))
  5067. .margin({ right: 20, left: 10 })
  5068. .onChange((val: string) => {
  5069. this.yearStr = val
  5070. })
  5071. }
  5072. .width('100%')
  5073. .margin({ top: 10, bottom: 10 })
  5074. .justifyContent(FlexAlign.Start)
  5075. Row() {
  5076. Text('音轨号:')
  5077. .fontSize(14)
  5078. .fontColor($r('app.color.text_color'))
  5079. .margin({ left: 22 })
  5080. TextInput({ text:item.track=='未知'?'': item.track })
  5081. .height(40)
  5082. .maxLines(1)
  5083. .fontSize(14)
  5084. .type(InputType.Number)
  5085. .layoutWeight(1)
  5086. .fontColor($r('app.color.text_color'))
  5087. .margin({ right: 20, left: 10 })
  5088. .onChange((val: string) => {
  5089. this.trackStr = val
  5090. })
  5091. }
  5092. .width('100%')
  5093. .margin({ top: 10, bottom: 10 })
  5094. .justifyContent(FlexAlign.Start)
  5095. Row() {
  5096. Text('碟号:')
  5097. .fontSize(14)
  5098. .fontColor($r('app.color.text_color'))
  5099. .margin({ left: 22 })
  5100. TextInput({ text:item.disc })
  5101. .height(40)
  5102. .maxLines(1)
  5103. .fontSize(14)
  5104. .type(InputType.Number)
  5105. .layoutWeight(1)
  5106. .fontColor($r('app.color.text_color'))
  5107. .margin({ right: 20, left: 10 })
  5108. .onChange((val: string) => {
  5109. this.discStr = val
  5110. })
  5111. }
  5112. .width('100%')
  5113. .margin({ top: 10, bottom: 10 })
  5114. .justifyContent(FlexAlign.Start)
  5115. Row() {
  5116. Text('风格:')
  5117. .fontSize(14)
  5118. .fontColor($r('app.color.text_color'))
  5119. .margin({ left: 22 })
  5120. TextInput({ text: item.genre })
  5121. .height(40)
  5122. .maxLines(1)
  5123. .fontSize(14)
  5124. .layoutWeight(1)
  5125. .fontColor($r('app.color.text_color'))
  5126. .margin({ right: 20, left: 10 })
  5127. .onChange((val: string) => {
  5128. this.genreStr = val
  5129. })
  5130. }
  5131. .width('100%')
  5132. .margin({ top: 10, bottom: 10 })
  5133. .justifyContent(FlexAlign.Start)
  5134. Row() {
  5135. Text('专辑艺术家:')
  5136. .fontSize(14)
  5137. .fontColor($r('app.color.text_color'))
  5138. .margin({ left: 22 })
  5139. TextInput({ text: item.ALBUMARTIST })
  5140. .height(40)
  5141. .maxLines(1)
  5142. .fontSize(14)
  5143. .layoutWeight(1)
  5144. .fontColor($r('app.color.text_color'))
  5145. .margin({ right: 20, left: 10 })
  5146. .onChange((val: string) => {
  5147. this.albumArtistStr = val
  5148. })
  5149. }
  5150. .width('100%')
  5151. .margin({ top: 10, bottom: 10 })
  5152. .justifyContent(FlexAlign.Start)
  5153. Row() {
  5154. Text('作曲:')
  5155. .fontSize(14)
  5156. .fontColor($r('app.color.text_color'))
  5157. .margin({ left: 22 })
  5158. TextInput({ text: item.COMPOSER })
  5159. .height(40)
  5160. .maxLines(1)
  5161. .fontSize(14)
  5162. .layoutWeight(1)
  5163. .fontColor($r('app.color.text_color'))
  5164. .margin({ right: 20, left: 10 })
  5165. .onChange((val: string) => {
  5166. this.composerStr = val
  5167. })
  5168. }
  5169. .width('100%')
  5170. .margin({ top: 10, bottom: 10 })
  5171. .justifyContent(FlexAlign.Start)
  5172. Row() {
  5173. Text('作词:')
  5174. .fontSize(14)
  5175. .fontColor($r('app.color.text_color'))
  5176. .margin({ left: 22 })
  5177. TextInput({ text: item.LYRICIST })
  5178. .height(40)
  5179. .maxLines(1)
  5180. .fontSize(14)
  5181. .layoutWeight(1)
  5182. .fontColor($r('app.color.text_color'))
  5183. .margin({ right: 20, left: 10 })
  5184. .onChange((val: string) => {
  5185. this.lyricistStr = val
  5186. })
  5187. }
  5188. .width('100%')
  5189. .margin({ top: 10, bottom: 10 })
  5190. .justifyContent(FlexAlign.Start)
  5191. Row() {
  5192. Text('注释:')
  5193. .fontSize(14)
  5194. .fontColor($r('app.color.text_color'))
  5195. .margin({ left: 22 })
  5196. TextInput({ text: item.COMMENT })
  5197. .height(40)
  5198. .maxLines(1)
  5199. .fontSize(14)
  5200. .layoutWeight(1)
  5201. .fontColor($r('app.color.text_color'))
  5202. .margin({ right: 20, left: 10 })
  5203. .onChange((val: string) => {
  5204. this.commentStr = val
  5205. })
  5206. }
  5207. .width('100%')
  5208. .margin({ top: 10, bottom: 10 })
  5209. .justifyContent(FlexAlign.Start)
  5210. Row() {
  5211. Button('保存')
  5212. .fontColor(Color.White)
  5213. .layoutWeight(1)
  5214. .height(50)
  5215. .width(100)
  5216. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5217. .backgroundColor(this.themeColor)
  5218. .stateEffect(true)
  5219. .margin({ right: 20, bottom: 20 })
  5220. .onClick(async () => {
  5221. this.doEdit(item)
  5222. })
  5223. Button('取消')
  5224. .fontColor(Color.White)
  5225. .layoutWeight(1)
  5226. .height(50)
  5227. .width(100)
  5228. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5229. .backgroundColor(this.themeColor)
  5230. .stateEffect(true)
  5231. .margin({ left: 20, bottom: 20 })
  5232. .onClick(async () => {
  5233. if(this.isGridMusic){
  5234. this.longItemFilePath =''
  5235. }else{
  5236. this.isShowEdit = false
  5237. }
  5238. this.setEditStrEmpty()
  5239. if(this.isShowPlay){
  5240. this.isShowEdit = false
  5241. }
  5242. })
  5243. }
  5244. .margin({
  5245. left: 38,
  5246. right: 38,
  5247. top: 10,
  5248. bottom: 10
  5249. })
  5250. .width(250)
  5251. .height(60)
  5252. }
  5253. }
  5254. .margin({ bottom: 20 })
  5255. }
  5256. setEditStrEmpty(){
  5257. this.imagePathStr = ''
  5258. this.lyricConStr = ''
  5259. this.artistStr = ''
  5260. this.titleStr = ''
  5261. this.ablumStr = ''
  5262. this.genreStr = ''
  5263. this.yearStr = ''
  5264. this.trackStr = ''
  5265. this.albumArtistStr = ''
  5266. this.composerStr = ''
  5267. this.lyricistStr = ''
  5268. this.commentStr = ''
  5269. this.discStr = ''
  5270. }
  5271. @Builder
  5272. detailSheet(item:VideoItem) {
  5273. Scroll() {
  5274. Column() {
  5275. this.songDetail(item)
  5276. }
  5277. }
  5278. .width('100%')
  5279. .height('100%')
  5280. }
  5281. @Builder
  5282. songDetail(currentItem:VideoItem) {
  5283. Column() {
  5284. if (currentItem) {
  5285. Row() {
  5286. Stack() {
  5287. Image(StrUtil.isEmpty(currentItem.pixelMapPath) ? $r('app.media.music_red') :
  5288. currentItem.pixelMapPath)
  5289. .fillColor(this.themeColor)
  5290. .height(80)
  5291. .width(80)
  5292. .borderRadius(10)
  5293. .opacity(this.opacityItem)// 绑定透明度
  5294. .margin({ left: 22 })
  5295. }
  5296. Column() {
  5297. Column() {
  5298. Text(currentItem.name)
  5299. .fontSize(16)
  5300. .maxLines(1)
  5301. .animation({
  5302. duration: 555,
  5303. curve: 'Linear',
  5304. })
  5305. .fontColor($r('app.color.text_color'))
  5306. .margin({ left: 15 })
  5307. }
  5308. .height('100%')
  5309. .width('100%')
  5310. .justifyContent(FlexAlign.Center)
  5311. .alignItems(HorizontalAlign.Start)
  5312. }
  5313. .height('100%')
  5314. }
  5315. .width('100%')
  5316. .height(90)
  5317. .justifyContent(FlexAlign.SpaceBetween)
  5318. Row() {
  5319. Text('艺术家:')
  5320. .fontSize(14)
  5321. .fontColor($r('app.color.text_color'))
  5322. .margin({ left: 22 })
  5323. Text(currentItem?.artist ? currentItem.artist : '未知歌手')
  5324. .fontSize(14)
  5325. .fontColor($r('app.color.text_color'))
  5326. .margin({ left: 10 })
  5327. .layoutWeight(1)
  5328. }
  5329. .width('100%')
  5330. .margin({ top: 10, bottom: 10 })
  5331. .justifyContent(FlexAlign.Start)
  5332. Row() {
  5333. Text('专辑名:')
  5334. .fontSize(14)
  5335. .fontColor($r('app.color.text_color'))
  5336. .margin({ left: 22 })
  5337. Text(currentItem?.album ?currentItem.album : '未知专辑')
  5338. .fontSize(14)
  5339. .margin({ left: 10 })
  5340. .fontColor($r('app.color.text_color'))
  5341. .layoutWeight(1)
  5342. }
  5343. .width('100%')
  5344. .margin({ top: 10, bottom: 10 })
  5345. .justifyContent(FlexAlign.Start)
  5346. Row() {
  5347. Text('时长:')
  5348. .fontSize(14)
  5349. .fontColor($r('app.color.text_color'))
  5350. .margin({ left: 22 })
  5351. Text(StrUtil.isEmpty(currentItem.duration)?
  5352. (this.isShowDetailMore?this.totalTime:'未知'):currentItem.duration)
  5353. .fontSize(14)
  5354. .margin({ left: 10 })
  5355. .fontColor($r('app.color.text_color'))
  5356. .layoutWeight(1)
  5357. }
  5358. .width('100%')
  5359. .margin({ top: 10, bottom: 10 })
  5360. .justifyContent(FlexAlign.Start)
  5361. Row() {
  5362. Text('采样率:')
  5363. .fontSize(14)
  5364. .fontColor($r('app.color.text_color'))
  5365. .margin({ left: 22 })
  5366. Text(Utility.convertToKHz(currentItem.sampleRate))
  5367. .fontSize(14)
  5368. .margin({ left: 10 })
  5369. .fontColor($r('app.color.text_color'))
  5370. .layoutWeight(1)
  5371. }
  5372. .width('100%')
  5373. .margin({ top: 10, bottom: 10 })
  5374. .justifyContent(FlexAlign.Start)
  5375. Row() {
  5376. Text('比特率:')
  5377. .fontSize(14)
  5378. .fontColor($r('app.color.text_color'))
  5379. .margin({ left: 22 })
  5380. Text(currentItem.bit_rate)
  5381. .fontSize(14)
  5382. .margin({ left: 10 })
  5383. .fontColor($r('app.color.text_color'))
  5384. .layoutWeight(1)
  5385. }
  5386. .width('100%')
  5387. .margin({ top: 10, bottom: 10 })
  5388. .justifyContent(FlexAlign.Start)
  5389. Row() {
  5390. Text('位深:')
  5391. .fontSize(14)
  5392. .fontColor($r('app.color.text_color'))
  5393. .margin({ left: 22 })
  5394. Text(`${currentItem.bits_per_raw_sample} bits`)
  5395. .fontSize(14)
  5396. .margin({ left: 10 })
  5397. .fontColor($r('app.color.text_color'))
  5398. .layoutWeight(1)
  5399. }
  5400. .width('100%')
  5401. .margin({ top: 10, bottom: 10 })
  5402. .justifyContent(FlexAlign.Start)
  5403. Row() {
  5404. Text('声道:')
  5405. .fontSize(14)
  5406. .fontColor($r('app.color.text_color'))
  5407. .margin({ left: 22 })
  5408. Text(`${currentItem.channels}`)
  5409. .fontSize(14)
  5410. .margin({ left: 10 })
  5411. .fontColor($r('app.color.text_color'))
  5412. .layoutWeight(1)
  5413. }
  5414. .width('100%')
  5415. .margin({ top: 10, bottom: 10 })
  5416. .justifyContent(FlexAlign.Start)
  5417. Row() {
  5418. Text('声道布局:')
  5419. .fontSize(14)
  5420. .fontColor($r('app.color.text_color'))
  5421. .margin({ left: 22 })
  5422. Text(`${currentItem.channel_layout}`)
  5423. .fontSize(14)
  5424. .margin({ left: 10 })
  5425. .fontColor($r('app.color.text_color'))
  5426. .layoutWeight(1)
  5427. }
  5428. .width('100%')
  5429. .margin({ top: 10, bottom: 10 })
  5430. .justifyContent(FlexAlign.Start)
  5431. Row() {
  5432. Text('起始播放点:')
  5433. .fontSize(14)
  5434. .fontColor($r('app.color.text_color'))
  5435. .margin({ left: 22 })
  5436. Text(`${currentItem.start_time}`)
  5437. .fontSize(14)
  5438. .margin({ left: 10 })
  5439. .fontColor($r('app.color.text_color'))
  5440. .layoutWeight(1)
  5441. }
  5442. .width('100%')
  5443. .margin({ top: 10, bottom: 10 })
  5444. .justifyContent(FlexAlign.Start)
  5445. Row() {
  5446. Text('风格:')
  5447. .fontSize(14)
  5448. .fontColor($r('app.color.text_color'))
  5449. .margin({ left: 22 })
  5450. Text(currentItem.genre)
  5451. .fontSize(14)
  5452. .margin({ left: 10 })
  5453. .fontColor($r('app.color.text_color'))
  5454. .layoutWeight(1)
  5455. }
  5456. .width('100%')
  5457. .margin({ top: 10, bottom: 10 })
  5458. .justifyContent(FlexAlign.Start)
  5459. Row() {
  5460. Text('发行时间:')
  5461. .fontSize(14)
  5462. .fontColor($r('app.color.text_color'))
  5463. .margin({ left: 22 })
  5464. Text(currentItem.year)
  5465. .fontSize(14)
  5466. .margin({ left: 10 })
  5467. .fontColor($r('app.color.text_color'))
  5468. .layoutWeight(1)
  5469. }
  5470. .width('100%')
  5471. .margin({ top: 10, bottom: 10 })
  5472. .justifyContent(FlexAlign.Start)
  5473. Row() {
  5474. Text('质量评分:')
  5475. .fontSize(14)
  5476. .fontColor($r('app.color.text_color'))
  5477. .margin({ left: 22 })
  5478. Text(currentItem.probe_score+"")
  5479. .fontSize(14)
  5480. .margin({ left: 10 })
  5481. .fontColor($r('app.color.text_color'))
  5482. .layoutWeight(1)
  5483. }
  5484. .width('100%')
  5485. .margin({ top: 10, bottom: 10 })
  5486. .justifyContent(FlexAlign.Start)
  5487. Row() {
  5488. Text('音轨号:')
  5489. .fontSize(14)
  5490. .fontColor($r('app.color.text_color'))
  5491. .margin({ left: 22 })
  5492. Text(currentItem.track)
  5493. .fontSize(14)
  5494. .margin({ left: 10 })
  5495. .fontColor($r('app.color.text_color'))
  5496. .layoutWeight(1)
  5497. }
  5498. .width('100%')
  5499. .margin({ top: 10, bottom: 10 })
  5500. .justifyContent(FlexAlign.Start)
  5501. Row() {
  5502. Text('碟号:')
  5503. .fontSize(14)
  5504. .fontColor($r('app.color.text_color'))
  5505. .margin({ left: 22 })
  5506. Text(currentItem.disc)
  5507. .fontSize(14)
  5508. .margin({ left: 10 })
  5509. .fontColor($r('app.color.text_color'))
  5510. .layoutWeight(1)
  5511. }
  5512. .width('100%')
  5513. .margin({ top: 10, bottom: 10 })
  5514. .justifyContent(FlexAlign.Start)
  5515. Row() {
  5516. Text('专辑艺术家:')
  5517. .fontSize(14)
  5518. .fontColor($r('app.color.text_color'))
  5519. .margin({ left: 22 })
  5520. Text(currentItem.ALBUMARTIST)
  5521. .fontSize(14)
  5522. .margin({ left: 10 })
  5523. .fontColor($r('app.color.text_color'))
  5524. .layoutWeight(1)
  5525. }
  5526. .width('100%')
  5527. .margin({ top: 10, bottom: 10 })
  5528. .justifyContent(FlexAlign.Start)
  5529. Row() {
  5530. Text('作曲家:')
  5531. .fontSize(14)
  5532. .fontColor($r('app.color.text_color'))
  5533. .margin({ left: 22 })
  5534. Text(currentItem.COMPOSER)
  5535. .fontSize(14)
  5536. .margin({ left: 10 })
  5537. .fontColor($r('app.color.text_color'))
  5538. .layoutWeight(1)
  5539. }
  5540. .width('100%')
  5541. .margin({ top: 10, bottom: 10 })
  5542. .justifyContent(FlexAlign.Start)
  5543. Row() {
  5544. Text('作词家:')
  5545. .fontSize(14)
  5546. .fontColor($r('app.color.text_color'))
  5547. .margin({ left: 22 })
  5548. Text(currentItem.LYRICIST)
  5549. .fontSize(14)
  5550. .margin({ left: 10 })
  5551. .fontColor($r('app.color.text_color'))
  5552. .layoutWeight(1)
  5553. }
  5554. .width('100%')
  5555. .margin({ top: 10, bottom: 10 })
  5556. .justifyContent(FlexAlign.Start)
  5557. Row() {
  5558. Text('注释:')
  5559. .fontSize(14)
  5560. .fontColor($r('app.color.text_color'))
  5561. .margin({ left: 22 })
  5562. Text(currentItem.COMMENT)
  5563. .fontSize(14)
  5564. .margin({ left: 10 })
  5565. .fontColor($r('app.color.text_color'))
  5566. .layoutWeight(1)
  5567. }
  5568. .width('100%')
  5569. .margin({ top: 10, bottom: 10 })
  5570. .justifyContent(FlexAlign.Start)
  5571. Row() {
  5572. Text('格式:')
  5573. .fontSize(14)
  5574. .fontColor($r('app.color.text_color'))
  5575. .margin({ left: 22 })
  5576. Text(Utility.formatMimeType(currentItem.mimeType))
  5577. .fontSize(14)
  5578. .margin({ left: 10 })
  5579. .fontColor($r('app.color.text_color'))
  5580. .layoutWeight(1)
  5581. }
  5582. .width('100%')
  5583. .margin({ top: 10, bottom: 10 })
  5584. .justifyContent(FlexAlign.Start)
  5585. Row() {
  5586. Text('播放次数:')
  5587. .fontSize(14)
  5588. .fontColor($r('app.color.text_color'))
  5589. .margin({ left: 22 })
  5590. Text(currentItem.playCount?.toString())
  5591. .fontSize(14)
  5592. .margin({ left: 10 })
  5593. .fontColor($r('app.color.text_color'))
  5594. .layoutWeight(1)
  5595. }
  5596. .width('100%')
  5597. .margin({ top: 10, bottom: 10 })
  5598. .justifyContent(FlexAlign.Start)
  5599. Row() {
  5600. Text('流数量:')
  5601. .fontSize(14)
  5602. .fontColor($r('app.color.text_color'))
  5603. .margin({ left: 22 })
  5604. Text(currentItem.nb_streams?.toString())
  5605. .fontSize(14)
  5606. .margin({ left: 10 })
  5607. .fontColor($r('app.color.text_color'))
  5608. .layoutWeight(1)
  5609. }
  5610. .width('100%')
  5611. .margin({ top: 10, bottom: 10 })
  5612. .justifyContent(FlexAlign.Start)
  5613. Row() {
  5614. Text('文件大小:')
  5615. .fontSize(14)
  5616. .fontColor($r('app.color.text_color'))
  5617. .margin({ left: 22 })
  5618. Text(currentItem.size)
  5619. .fontSize(14)
  5620. .margin({ left: 10 })
  5621. .fontColor($r('app.color.text_color'))
  5622. .layoutWeight(1)
  5623. }
  5624. .width('100%')
  5625. .margin({ top: 10, bottom: 10 })
  5626. .justifyContent(FlexAlign.Start)
  5627. Row() {
  5628. Text('文件名:')
  5629. .fontSize(14)
  5630. .fontColor($r('app.color.text_color'))
  5631. .margin({ left: 22 })
  5632. Text(currentItem.fileName)
  5633. .fontSize(14)
  5634. .margin({ left: 10 })
  5635. .fontColor($r('app.color.text_color'))
  5636. .layoutWeight(1)
  5637. }
  5638. .width('100%')
  5639. .margin({ top: 10, bottom: 10 })
  5640. .justifyContent(FlexAlign.Start)
  5641. Row() {
  5642. Text('修改时间:')
  5643. .fontSize(14)
  5644. .fontColor($r('app.color.text_color'))
  5645. .margin({ left: 22 })
  5646. Text(currentItem.cTime)
  5647. .fontSize(14)
  5648. .margin({ left: 10 })
  5649. .fontColor($r('app.color.text_color'))
  5650. .layoutWeight(1)
  5651. }
  5652. .width('100%')
  5653. .margin({ top: 10, bottom: 10 })
  5654. .justifyContent(FlexAlign.Start)
  5655. Row() {
  5656. Text('存放目录:')
  5657. .fontSize(14)
  5658. .fontColor($r('app.color.text_color'))
  5659. .margin({ left: 22 })
  5660. Text(currentItem.filePath)
  5661. .fontSize(12)
  5662. .margin({ left: 10 })
  5663. .fontColor($r('app.color.text_color'))
  5664. .layoutWeight(1)
  5665. }
  5666. .margin({ top: 10, bottom: 10 })
  5667. .width('100%')
  5668. .justifyContent(FlexAlign.Start)
  5669. Row() {
  5670. Text('内嵌歌词:')
  5671. .fontSize(14)
  5672. .fontColor($r('app.color.text_color'))
  5673. .margin({ left: 22 })
  5674. Text(currentItem.lyricContent)
  5675. .fontSize(12)
  5676. .copyOption(CopyOptions.InApp)
  5677. .margin({ left: 10 })
  5678. .fontColor($r('app.color.text_color'))
  5679. .layoutWeight(1)
  5680. }
  5681. .margin({ top: 10, bottom: 10 })
  5682. .width('100%')
  5683. .justifyContent(FlexAlign.Start)
  5684. }
  5685. }
  5686. .margin({ bottom: 20 })
  5687. }
  5688. //定时关闭布局
  5689. @Builder
  5690. TimeCloseSheet() {
  5691. Scroll() {
  5692. Column() {
  5693. this.TimeClose()
  5694. }
  5695. }
  5696. .width('100%')
  5697. .height('100%')
  5698. }
  5699. //倒计时关闭音乐,退出App功能实现。
  5700. @State selectedMinutes: number = 0 // 0表示未开启
  5701. @State remainingSeconds: number = 0
  5702. // 预设时间选项
  5703. private presetTimes: number[] = [0, 5, 15, 30, 45, 60, -1]
  5704. private formatTime(seconds: number): string {
  5705. const mins = Math.floor(seconds / 60)
  5706. const secs = seconds % 60
  5707. return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
  5708. }
  5709. // 开始倒计时
  5710. private handleTimeSelect(minutes: number) {
  5711. if (minutes === this.selectedMinutes) {
  5712. this.stopCountdown();
  5713. this.selectedMinutes = 0;
  5714. return;
  5715. }
  5716. this.selectedMinutes = minutes;
  5717. this.remainingSeconds = minutes * 60;
  5718. this.startCountdown(); // 新增调用
  5719. }
  5720. @Builder
  5721. TimeClose() {
  5722. Column() {
  5723. // 倒计时显示区域
  5724. Text(this.selectedMinutes > 0 ?
  5725. `剩余时间:${this.formatTime(this.remainingSeconds)}` :
  5726. "定时关闭未开启")
  5727. .fontSize(17)
  5728. .fontColor($r('app.color.text_color'))
  5729. .margin({ top: 2, bottom: 8 });
  5730. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  5731. ForEach(this.presetTimes, (minutes: number, index: number) => {
  5732. // 单行时间选项容器
  5733. Row() {
  5734. // 文字描述区域
  5735. Text(this.getDisplayText(minutes))
  5736. .fontSize(15)
  5737. .fontColor(minutes === this.selectedMinutes ? this.themeColor :
  5738. $r('app.color.text_color'))// 选中态颜色变化
  5739. .textAlign(TextAlign.Start)
  5740. .layoutWeight(1); // 占据剩余空间
  5741. // 复选框样式的选择器
  5742. Row() {
  5743. if (minutes === this.selectedMinutes) {
  5744. // 选中状态 - 带勾号的圆形复选框
  5745. Row() {
  5746. // 使用系统内置的勾号图标
  5747. Image($r('sys.media.ohos_ic_public_ok'))
  5748. .width(14)
  5749. .height(14)
  5750. .fillColor(Color.White)
  5751. }
  5752. .width(24)
  5753. .height(24)
  5754. .borderRadius(12)
  5755. .backgroundColor(this.themeColor)
  5756. .justifyContent(FlexAlign.Center)
  5757. .alignItems(VerticalAlign.Center)
  5758. } else {
  5759. // 未选中状态的圆形边框
  5760. Row()
  5761. .width(24)
  5762. .height(24)
  5763. .borderRadius(12)
  5764. .border({
  5765. width: 2,
  5766. color: $r('app.color.text_color'),
  5767. style: BorderStyle.Solid
  5768. })
  5769. .backgroundColor(Color.Transparent)
  5770. }
  5771. }
  5772. .width(24)
  5773. .height(24)
  5774. .margin({ left: 20 })
  5775. .justifyContent(FlexAlign.Center)
  5776. .alignItems(VerticalAlign.Center)
  5777. }
  5778. .width('100%')
  5779. .padding({
  5780. top: 18,
  5781. bottom: 18,
  5782. left: 18,
  5783. right: 18
  5784. })
  5785. .backgroundColor(minutes === this.selectedMinutes ? $r('app.color.timeColor_bg') :
  5786. $r('app.color.bottom_control_background')) // 选中背景高亮
  5787. .borderRadius(12)
  5788. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  5789. .margin({ bottom: 18 })
  5790. .onClick(() => this.handleSelect(minutes)); // 点击整行触发选择
  5791. });
  5792. }
  5793. .width('100%')
  5794. .padding(16)
  5795. }
  5796. }
  5797. // 获取显示文本
  5798. private getDisplayText(minutes: number): string {
  5799. if (minutes === -1) {
  5800. return Utility.resourceToString(getContext(this), $r('app.string.customize'));
  5801. }
  5802. return minutes === 0 ? Utility.resourceToString(getContext(this), $r('app.string.close')) :
  5803. `${minutes}` + Utility.resourceToString(getContext(this), $r('app.string.minute_after'));
  5804. }
  5805. // 处理选择事件
  5806. private handleSelect(minutes: number): void {
  5807. if (minutes === -1) { // 自定义
  5808. // 弹出自定义时间对话框
  5809. DialogHelper.showTextInputDialog({
  5810. title: '自定义时间',
  5811. maskColor: Color.Transparent,
  5812. inputType: InputType.Number,
  5813. text: '',
  5814. onChange: (text) => {
  5815. console.error("onChange: " + text);
  5816. },
  5817. onAction: (action, dialogId, content) => {
  5818. if (action == DialogAction.TWO) {
  5819. const customMinutes = Number(content);
  5820. if (customMinutes > 0) {
  5821. this.handleTimeSelect(customMinutes); // 设置自定义时间
  5822. ToastUtil.showToast("设置成功," + customMinutes + "分钟后定时关闭");
  5823. }
  5824. }
  5825. }
  5826. });
  5827. } else {
  5828. this.handleTimeSelect(minutes); // 统一调用选择处理方法
  5829. }
  5830. }
  5831. // 添加定时器引用
  5832. private timerId: number = -1;
  5833. // 启动/重置倒计时
  5834. private startCountdown() {
  5835. // 清除旧定时器
  5836. if (this.timerId !== -1) {
  5837. clearInterval(this.timerId);
  5838. }
  5839. // 创建新定时器
  5840. if (this.selectedMinutes > 0) {
  5841. this.timerId = setInterval(() => {
  5842. if (this.remainingSeconds === 15) {
  5843. this.showConfirmationDialog();
  5844. }
  5845. if (this.remainingSeconds > 0) {
  5846. this.remainingSeconds -= 1;
  5847. } else {
  5848. this.stopCountdown();
  5849. this.handleTimeout();
  5850. }
  5851. }, 1000);
  5852. }
  5853. }
  5854. // 15倒计时后再次提示显示确认是否关闭App对话框
  5855. private showConfirmationDialog() {
  5856. DialogHelper.showAlertDialog({
  5857. backgroundColor: $r('app.color.btn_green'),
  5858. title: '确认关闭',
  5859. maskColor: Color.Transparent,
  5860. content: "马上到达定时关闭时间,您是否确定要退出应用?",
  5861. borderStyle: BorderStyle.Dashed,
  5862. primaryButton: '暂不关闭',
  5863. secondaryButton: '确定',
  5864. onAction: (action) => {
  5865. if (action == DialogAction.ONE) { //暂不关闭,取消定时
  5866. this.stopCountdown();
  5867. this.selectedMinutes = 0
  5868. } else if (action == DialogAction.TWO) {
  5869. }
  5870. }
  5871. })
  5872. }
  5873. // 停止倒计时
  5874. private stopCountdown() {
  5875. if (this.timerId !== -1) {
  5876. clearInterval(this.timerId);
  5877. this.timerId = -1;
  5878. }
  5879. }
  5880. // 超时处理
  5881. private handleTimeout() {
  5882. // 执行播放器关闭逻辑
  5883. this.selectedMinutes = 0;
  5884. ToastUtil.showToast(" 定时关闭已完成");
  5885. this.stop(); // 假设存在的播放器实例
  5886. //退出APP
  5887. const mContext = getContext(this) as common.UIAbilityContext
  5888. mContext.terminateSelf();
  5889. AvSessionController.getInstance(true).unregisterSessionListener()
  5890. }
  5891. //倒计时关闭音乐,退出App功能实现结束。
  5892. //播放列表的拖动List 重新排序
  5893. @State sonDataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.songList)
  5894. //左滑操作 移动文件 重命名 删除等操作
  5895. @Builder
  5896. sonButton(item: VideoItem, index: number, filePath: string) {
  5897. Row() {
  5898. //加入下一首播放
  5899. Button() {
  5900. Image($r('app.media.next_to_play'))
  5901. .fillColor(Color.White)
  5902. .width(20)
  5903. }
  5904. .width(40)
  5905. .height(40)
  5906. .type(ButtonType.Circle)
  5907. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5908. .backgroundColor(this.themeColor)
  5909. .margin(5)
  5910. .onClick(() => {
  5911. this.addToNextPlay(item);
  5912. })
  5913. Button() {
  5914. Image($r('app.media.close'))
  5915. .fillColor(Color.White)
  5916. .width(20)
  5917. }
  5918. .width(40)
  5919. .height(40)
  5920. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5921. .type(ButtonType.Circle)
  5922. .backgroundColor(this.themeColor)
  5923. .margin(5)
  5924. .onClick(() => {
  5925. this.songList.splice(Number(index), 1)
  5926. this.sonDataSource.pushArrayData(this.songList)
  5927. })
  5928. Button() {
  5929. Image($r('app.media.share2'))
  5930. .fillColor(Color.White)
  5931. .width(20)
  5932. }
  5933. .width(40)
  5934. .height(40)
  5935. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5936. .type(ButtonType.Circle)
  5937. .backgroundColor(this.themeColor)
  5938. .margin(5)
  5939. .onClick(() => {
  5940. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  5941. })
  5942. }
  5943. }
  5944. itemMoveSon(index: number, newIndex: number): void {
  5945. if (newIndex < 0 || newIndex >= this.songList.length) {
  5946. return;
  5947. }
  5948. let tmp = this.songList.splice(index, 1);
  5949. this.songList.splice(newIndex, 0, tmp[0]);
  5950. this.sonDataSource.pushArrayData(this.songList)
  5951. this.curIndex = Utility.getIndexFromList(this.songList, this.videoUrl)
  5952. }
  5953. @Builder
  5954. PlayList() {
  5955. List({ scroller: this.playListScroller }) {
  5956. LazyForEach(this.sonDataSource, (item: VideoItem, index: number) => {
  5957. ListItem() {
  5958. this.MusicItemSon(item, index)
  5959. }
  5960. .swipeAction({ end: this.sonButton(item, index, item.filePath) }) //左滑
  5961. .animation({
  5962. duration: 666,
  5963. curve: 'ease-in-out' // 可选动画曲线
  5964. })
  5965. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 600 }),
  5966. TransitionEffect.scale({ x: 0, y: 0 })))
  5967. .clickEffect({ level: ClickEffectLevel.MIDDLE })
  5968. //拖动List关键代码开始
  5969. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  5970. .zIndex(this.dragItem === index ? 1 : 0)
  5971. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  5972. .gesture(
  5973. GestureGroup(GestureMode.Sequence,
  5974. LongPressGesture({ repeat: true })
  5975. .onAction((event?: GestureEvent) => {
  5976. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5977. this.scaleItem = index
  5978. })
  5979. })
  5980. .onActionEnd(() => {
  5981. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5982. this.scaleItem = -1
  5983. })
  5984. }),
  5985. PanGesture({ fingers: 1, direction: null, distance: 0 })
  5986. .onActionStart(() => {
  5987. this.dragItem = index // 记录当前拖动项索引
  5988. this.dragRefOffset = 0 // 重置偏移基准
  5989. })
  5990. .onActionUpdate((event: GestureEvent) => {
  5991. this.offsetY = event.offsetY - this.dragRefOffset;
  5992. this.neighborItem = -1;
  5993. let indexA = this.songList.indexOf(item);
  5994. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  5995. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  5996. let value: number = 0;
  5997. if (this.offsetY < 0) {
  5998. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  5999. this.neighborItem = indexA - 1;
  6000. this.neighborScale = 1 - value / 20;
  6001. } else if (this.offsetY > 0) {
  6002. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  6003. this.neighborItem = indexA + 1;
  6004. this.neighborScale = 1 - value / 20;
  6005. }
  6006. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.songList.length) {
  6007. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6008. this.offsetY -= this.ITEM_INTV;
  6009. this.dragRefOffset += this.ITEM_INTV;
  6010. this.itemMoveSon(indexA, indexA + 1);
  6011. });
  6012. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  6013. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6014. this.offsetY += this.ITEM_INTV;
  6015. this.dragRefOffset -= this.ITEM_INTV;
  6016. this.itemMoveSon(indexA, indexA - 1);
  6017. });
  6018. }
  6019. })
  6020. .onActionEnd((event: GestureEvent) => {
  6021. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6022. this.dragItem = -1
  6023. this.neighborItem = -1
  6024. })
  6025. animateTo({
  6026. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  6027. }, () => {
  6028. this.scaleItem = -1
  6029. })
  6030. })
  6031. )
  6032. .onCancel(() => {
  6033. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6034. this.dragItem = -1
  6035. this.neighborItem = -1
  6036. })
  6037. animateTo({
  6038. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  6039. }, () => {
  6040. this.scaleItem = -1
  6041. })
  6042. })
  6043. ) //拖动List关键代码结束
  6044. .onClick(() => {
  6045. this.doPlay(item, index, true)
  6046. })
  6047. }, (item: VideoItem) => item.filePath)
  6048. }
  6049. .width('100%')
  6050. .height('100%')
  6051. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  6052. // .animation({ duration: 500, curve: Curve.Ease }))
  6053. .cachedCount(10)
  6054. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  6055. .gesture(PinchGesture({ fingers: 2 })
  6056. .onActionEnd((event: GestureEvent) => {
  6057. this.setSonListTwoFingers()
  6058. })
  6059. .onActionUpdate(e => {
  6060. this.scaleValue = this.pinchValue * e.scale
  6061. })
  6062. .onActionStart(e => {
  6063. }))
  6064. .padding({
  6065. bottom: 0
  6066. })
  6067. }
  6068. setSonListTwoFingers() {
  6069. this.pinchValue = this.scaleValue;
  6070. Logger.info('this.pinchValue = ' + this.pinchValue);
  6071. if (this.pinchValue >= 1) {
  6072. this.sonTwoFingerType++
  6073. Logger.info('this.twoFingerType1 = ' + this.sonTwoFingerType);
  6074. if (this.sonTwoFingerType > 3) {
  6075. this.sonTwoFingerType = 1
  6076. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  6077. }
  6078. } else {
  6079. this.sonTwoFingerType--
  6080. Logger.info('this.twoFingerType2 = ' + this.sonTwoFingerType);
  6081. if (this.sonTwoFingerType < 1) {
  6082. this.sonTwoFingerType = 1
  6083. }
  6084. }
  6085. PreferencesUtil.put('sonTwoFingerType', this.sonTwoFingerType)
  6086. this.pinchValue = 1;
  6087. this.scaleValue = 1;
  6088. }
  6089. @State sonTwoFingerType:number = 3
  6090. @Builder
  6091. private MusicItemSon(item: VideoItem, index?: number) {
  6092. Button({ type: ButtonType.Normal, stateEffect: true }) {
  6093. Row() {
  6094. Stack() {
  6095. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  6096. .height(this.sonTwoFingerType == 3||this.sonTwoFingerType==4 ? 55 : this.sonTwoFingerType == 2 ? 48 : 40)
  6097. .width(this.sonTwoFingerType == 3||this.sonTwoFingerType==4 ? 55 : this.sonTwoFingerType == 2 ? 48 : 40)
  6098. .alt($r('app.media.music_red'))
  6099. .fillColor(this.themeColor)
  6100. .borderRadius('100%')
  6101. .clip(true)
  6102. .margin({ left: 20 })
  6103. }
  6104. .width('15%')
  6105. Column() {
  6106. Column() {
  6107. Text(item.name)
  6108. .fontSize(this.sonTwoFingerType == 1 ? 12 : this.sonTwoFingerType == 2 ? 15 : 18)
  6109. .fontColor(this.curIndex === index ? this.themeColor :
  6110. this.isFrontWhite ? Color.White : $r('app.color.text_color'))
  6111. .maxLines(1)
  6112. .margin({ left: this.sonTwoFingerType == 3 ? 18 : 10 })
  6113. Row() {
  6114. Column(){
  6115. Text(item.md5Str?.includes('Lossless')?
  6116. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  6117. .fontSize(this.sonTwoFingerType == 1 ? 8 : this.sonTwoFingerType == 2 ? 9 : 11)
  6118. .padding({ top: 3,right:6,left:6,bottom:3 })
  6119. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  6120. $r('app.color.text_color'))
  6121. .fontWeight(500)
  6122. .borderRadius(12)
  6123. .margin({ left: this.sonTwoFingerType == 3 ? 12 : 10 })
  6124. .backgroundColor('#FFC107')
  6125. }
  6126. .padding({ top: 8 })
  6127. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  6128. .fontSize(this.sonTwoFingerType == 1 ? 11 : this.sonTwoFingerType == 2 ? 12 : 14)
  6129. .padding({ top: 8 })
  6130. .fontColor(this.curIndex === index ? this.themeColor :
  6131. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  6132. .margin({ left: this.sonTwoFingerType == 3 ? 5 : 3 })
  6133. Blank()
  6134. Text(item.size)
  6135. .fontSize(this.sonTwoFingerType == 1 ? 11 : this.sonTwoFingerType == 2 ? 12 : 14)
  6136. .padding({ top: 8 })
  6137. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  6138. .fontColor(this.curIndex === index ? $r('app.color.title_bar_bg_text') :
  6139. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  6140. .margin({ left: 10 })
  6141. }
  6142. }
  6143. .height('100%')
  6144. .width('100%')
  6145. .justifyContent(FlexAlign.Center)
  6146. .alignItems(HorizontalAlign.Start)
  6147. }
  6148. .height('100%')
  6149. .width('65%')
  6150. Column() {
  6151. ImageAnimator()
  6152. .images(this.imagesF)// 动画数组
  6153. .duration(1000)// 持续
  6154. .state(this.animationState)// 动画状态
  6155. .fillMode(FillMode.Forwards)
  6156. .width(18)
  6157. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  6158. Visibility.None)
  6159. .height(18)
  6160. .iterations(-1) // 播放次数
  6161. }
  6162. .width('20%')
  6163. }
  6164. }
  6165. .backgroundColor(Color.Transparent)
  6166. .width('100%')
  6167. .reuseId('son_item')
  6168. .height(this.sonTwoFingerType == 3 ? ITEM_HEIGHT_BIG : this.sonTwoFingerType == 2 ? ITEM_HEIGHT+10 : ITEM_HEIGHT_SMALL+10)
  6169. .shadow(this.scaleItem === index ? {
  6170. radius: 70,
  6171. color: '#15000000',
  6172. offsetX: 0,
  6173. offsetY: 0
  6174. } :
  6175. {
  6176. radius: 0,
  6177. color: '#15000000',
  6178. offsetX: 0,
  6179. offsetY: 0
  6180. })
  6181. .animation({ curve: Curve.Sharp, duration: 300 })
  6182. }
  6183. @Builder
  6184. MusicPlayBuilder() {
  6185. Column() {
  6186. this.IjkMusicPlayerView()
  6187. }
  6188. .height('100%')
  6189. .width('100%')
  6190. .onDisAppear(() => {
  6191. this.translateY = 0;
  6192. })
  6193. .translate({ y: this.translateY })
  6194. .gesture(
  6195. PanGesture(this.panOption)
  6196. .onActionUpdate((event?: GestureEvent) => {
  6197. if (event) {
  6198. // 只允许向下滑动,向上滑动时限制为0
  6199. this.translateY = Math.max(0, event.offsetY);
  6200. }
  6201. })
  6202. .onActionEnd((event?: GestureEvent) => {
  6203. // 使用更低的阈值和滑动速度判断
  6204. const minDistance = 100; // 最小滑动距离 100vp
  6205. const minVelocity = 500; // 最小滑动速度
  6206. // 获取滑动速度(如果可用)
  6207. const velocity = event?.velocityY || 0;
  6208. // 判断是否应该关闭:距离足够 或者 速度足够快
  6209. const shouldClose = this.translateY > minDistance || velocity > minVelocity;
  6210. if (shouldClose) {
  6211. // 添加关闭动画
  6212. this.getUIContext().animateTo({
  6213. duration: 300,
  6214. curve: Curve.Smooth
  6215. }, () => {
  6216. this.isShowPlay = false;
  6217. this.translateY = 0;
  6218. })
  6219. } else {
  6220. // 回弹动画
  6221. this.getUIContext().animateTo({
  6222. duration: 300,
  6223. curve: Curve.Smooth
  6224. }, () => {
  6225. this.translateY = 0;
  6226. })
  6227. }
  6228. })
  6229. )
  6230. }
  6231. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD; //一多界面适配
  6232. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  6233. HeightBreakpoint.HEIGHT_LG;
  6234. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  6235. @State topBarHeight: number = 50
  6236. @State barOpacity: number = 1
  6237. @State barBottomOpacity: number = 1
  6238. private hideDone: boolean = false;
  6239. @State currentYOffset: number = 0;
  6240. @State bottomBarHeight: number = 60;
  6241. private isHiding: boolean = false;
  6242. //是否是Pura X外屏,或者小屏幕
  6243. isPuraWP() {
  6244. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  6245. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  6246. }
  6247. //是否是Pura X外屏,或者小屏幕,手机横屏
  6248. /**
  6249. * 是否是Pura X外屏,或者小屏幕,手机横屏
  6250. * @returns
  6251. */
  6252. isCoverOpacity() {
  6253. if (this.isPuraWP()) {
  6254. return true
  6255. }
  6256. if (this.isPhoneLan()) {
  6257. return true
  6258. }
  6259. if (deviceInfo.marketName.includes('Pura X')
  6260. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  6261. return true
  6262. }
  6263. return false
  6264. }
  6265. //是不是手机横屏
  6266. isPhoneLan() {
  6267. // LogUtil.info('twocold this.currentHeightBreakpoint = '+this.currentHeightBreakpoint)
  6268. // LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
  6269. LogUtil.info('hicar isPhoneLan width= ' + this.windowWidth);
  6270. LogUtil.info('hicar isPhoneLan height= ' + this.windowHeight);
  6271. LogUtil.info(`twocold hicarWindow size: ${this.windowWidth}x${this.windowHeight}, this.isHiCarStatus: ${this.isHiCarStatus}`);
  6272. LogUtil.info(`twocold hicar Window size: ${this.windowWidth}x${this.windowHeight}, isHiCarSmall: ${this.isHiCarSmall()}`);
  6273. if (this.isHiCarKuanBianPing()) {
  6274. return true
  6275. }
  6276. if (this.isHiCar()) {
  6277. return false
  6278. }
  6279. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  6280. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_SM
  6281. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_MD&&this.isLandscape) { //如果是手机横屏,返回true
  6282. return true
  6283. }
  6284. return false
  6285. }
  6286. //是不是1920x720的hicar的屏幕分辨率
  6287. isHiCarKuanBianPing(){
  6288. if(!this.isHiCar()){
  6289. return false
  6290. }
  6291. const hiCarAspectRatios: HiCarAspectRatio[] = [
  6292. { ratio: 1920 / 720, name: "1920x720" },
  6293. ];
  6294. const currentRatio: number = this.windowWidth / this.windowHeight;
  6295. const RATIO_TOLERANCE: number = 0.22; // 宽高比容差
  6296. LogUtil.info('twocold isHiCarKuanBianPing currentRatio = ' + currentRatio)
  6297. for (const hiCarRatio of hiCarAspectRatios) {
  6298. LogUtil.info('twocold isHiCarKuanBianPing hiCarRatio= ' + hiCarRatio.ratio)
  6299. LogUtil.info('twocold isHiCarKuanBianPing Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  6300. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  6301. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  6302. return true;
  6303. }
  6304. }
  6305. return false;
  6306. }
  6307. //是不是hicar的屏幕分辨率
  6308. isHiCarSmall() {
  6309. if(!this.isHiCar()){
  6310. return false
  6311. }
  6312. if(this.windowWidth>1800&&this.windowHeight>=1200)//大屏幕可以Grid
  6313. return false
  6314. const hiCarAspectRatios: HiCarAspectRatio[] = [
  6315. { ratio: 800 / 480, name: "800x480" },
  6316. { ratio: 1280 / 720, name: "1280x720" },
  6317. { ratio: 1920 / 1080, name: "1920x1080" },
  6318. ];
  6319. const currentRatio: number = this.windowWidth / this.windowHeight;
  6320. const RATIO_TOLERANCE: number = 0.22; // 宽高比容差
  6321. LogUtil.info('twocold isHiCarSmall currentRatio = ' + currentRatio)
  6322. for (const hiCarRatio of hiCarAspectRatios) {
  6323. LogUtil.info('twocold isHiCarSmall hiCarRatio= ' + hiCarRatio.ratio)
  6324. LogUtil.info('twocold isHiCarSmall Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  6325. LogUtil.info('twocold isHiCarSmall isHiCarStatus= ' + this.isHiCarStatus);
  6326. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  6327. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  6328. return true;
  6329. }
  6330. }
  6331. return false;
  6332. }
  6333. isHiCar() {
  6334. return this.isHiCarStatus&&this.curDisplayIsHiCar;
  6335. }
  6336. //是不是正常的手机竖屏
  6337. isPhonePortrait() {
  6338. // LogUtil.info('twocold this.currentHeightBreakpoint = ' + this.currentHeightBreakpoint)
  6339. // LogUtil.info('twocold this.currentWidthBreakpoint = ' + this.currentWidthBreakpoint)
  6340. // LogUtil.info('Heanup 当前设备类型:' + DeviceUtil.getDeviceType())
  6341. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  6342. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG
  6343. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_SM) { //如果是手机横屏,返回false
  6344. return true
  6345. }
  6346. return false
  6347. }
  6348. @State showSpeedDialog: boolean = false
  6349. @State longPressSpeed: number = 3 //长按默认倍数
  6350. @Builder
  6351. SpeedDialog() {
  6352. Stack() {
  6353. Column() {
  6354. Text('已切换至' + this.longPressSpeed + '倍速播放')
  6355. .fontColor(Color.White)
  6356. .visibility(Visibility.Hidden)
  6357. }
  6358. .backgroundColor(Color.Black)
  6359. .borderRadius(20)
  6360. .padding({
  6361. top: 10,
  6362. right: 20,
  6363. left: 15,
  6364. bottom: 20
  6365. })
  6366. .opacity(0.6)
  6367. Text('已切换至' + this.longPressSpeed + '倍速播放')
  6368. .fontColor(Color.White)
  6369. }
  6370. .transition(TransitionEffect.OPACITY.animation({ duration: 500, curve: Curve.Ease }))
  6371. .zIndex(5)
  6372. .margin({ top: 80 })
  6373. }
  6374. @Builder
  6375. IjkMusicPlayerView() {
  6376. Column() {
  6377. Column() {
  6378. Column() {
  6379. //播放标题
  6380. Column() {
  6381. this.PlayTitle()
  6382. }
  6383. .position({ x: 0, y: this.isCoverOpacity() ? 15 : 40 })
  6384. .width('100%')
  6385. .margin({ top: 0 })
  6386. .height(PlayConstants.HEIGHT)
  6387. .visibility(DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1 ?
  6388. Visibility.Visible : this.isShowPlayPageBack ? Visibility.Visible : Visibility.None)
  6389. if (this.showSpeedDialog) {
  6390. this.SpeedDialog()
  6391. }
  6392. Stack() {
  6393. //手势拖动快进
  6394. Column()
  6395. .width(CommonConstants.FULL_PERCENT)
  6396. .height('100%')
  6397. .gesture(
  6398. GestureGroup(GestureMode.Parallel,
  6399. // 长按屏幕倍数播放
  6400. LongPressGesture({ repeat: true })
  6401. .onAction(() => {
  6402. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6403. this.showSpeedDialog = true;
  6404. this.mIjkMediaPlayer.setSpeed(this.longPressSpeed + 'f');
  6405. }
  6406. })
  6407. .onActionEnd(() => {
  6408. this.showSpeedDialog = false;
  6409. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  6410. }),
  6411. //双击屏幕暂停或者播放
  6412. TapGesture({ count: 2 })
  6413. .onAction((event: GestureEvent) => {
  6414. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6415. ToastUtil.showToast('已暂停')
  6416. }
  6417. console.info('onecold playOrPause 6693')
  6418. this.playOrPause()
  6419. })
  6420. )
  6421. )
  6422. }
  6423. .height('65%')
  6424. Swiper() {
  6425. this.CoverInfo()
  6426. this.PlayerLyrics()
  6427. }
  6428. .onChange((index: number) => {
  6429. this.currentSwiperIndex = index
  6430. })
  6431. .indicator(false)
  6432. // .indicator(this.currentBreakpoint === BreakpointTypeEnum.SM ?
  6433. // new DotIndicator()
  6434. // .top(this.isCoverOpacity()?0:10)
  6435. //
  6436. // .selectedColor($r('app.color.select_swiper'))
  6437. // .color($r('app.color.slider_track')):false
  6438. // )
  6439. .displayCount(new BreakpointType({
  6440. sm: 1,
  6441. md: 2,
  6442. lg: 2,
  6443. xl: 2,
  6444. xxl: 2
  6445. }).getValue(this.currentBreakpoint))
  6446. .clip(false)
  6447. .loop(false)
  6448. .autoPlay(false)
  6449. // .interval(8000)
  6450. .position({ x: 0, y: this.isCoverOpacity() ? 30 : 40 })
  6451. .height('100%')
  6452. .hitTestBehavior(HitTestMode.Transparent)
  6453. Image($r('app.media.icon_replay'))
  6454. .objectFit(ImageFit.Auto)
  6455. .width('120px')
  6456. .height('120px')
  6457. .position({ x: '45.1%', y: '47.5%' })// .visibility(this.replayVisible)
  6458. .border({ width: 0 })
  6459. .visibility(Visibility.None)
  6460. .borderStyle(BorderStyle.Dashed)// .hitTestBehavior(HitTestMode.Transparent)
  6461. .onClick(() => {
  6462. console.info('onecold startPlayOrResumePlay 6744')
  6463. this.startPlayOrResumePlay();
  6464. })
  6465. }
  6466. .width(CommonConstants.FULL_PERCENT)
  6467. .height(CommonConstants.FULL_PERCENT)
  6468. .justifyContent(FlexAlign.End)
  6469. }
  6470. .justifyContent(FlexAlign.End)
  6471. .margin({ bottom: 8 })
  6472. }
  6473. // .backgroundImage(this.imageLabelBg)
  6474. .backgroundImage(this.isPuraWP() && this.currentSwiperIndex === 0 ?
  6475. (StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover) : this.imageLabelBg)
  6476. .backgroundImageSize(this.isPuraWP() ? { width: '100%' } : { height: '150%', width: '100%' })
  6477. // .backgroundImagePosition(Alignment.Center)
  6478. .animation({
  6479. duration: 666,
  6480. curve: 'ease-in-out' // 可选动画曲线
  6481. })
  6482. .backgroundBlurStyle(this.isPuraWP() && this.currentSwiperIndex === 0 ? BlurStyle.NONE :
  6483. BlurStyle.BACKGROUND_ULTRA_THICK)
  6484. .hitTestBehavior(HitTestMode.Transparent)
  6485. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  6486. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  6487. .backgroundBrightness({ rate: this.isPuraWP() ? 0.1 : 0, lightUpDegree: -0.1 })
  6488. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
  6489. .onClick(() => {
  6490. // this.startAutoHide()
  6491. if(this.isHiCar())
  6492. return
  6493. if(this.is_auto_hide_progress){
  6494. this.is_auto_hide_progress = false
  6495. }
  6496. this.startAutoHide()
  6497. })
  6498. }
  6499. @State progressValue: number = 0;
  6500. @State currentTime: string = "00:00";
  6501. @State totalTime: string = "00:00";
  6502. @State loadingVisible: Visibility = Visibility.None;
  6503. @State replayVisible: Visibility = Visibility.None;
  6504. @State slideEnable: boolean = false;
  6505. @State aspRatio: number = 0.5;
  6506. @State mContext: object | undefined = undefined;
  6507. // private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
  6508. @State mFirst: boolean = true;
  6509. @State mDestroyPage: boolean = false;
  6510. @State playSpeed: number = 1;
  6511. @State oldSeconds: number = 0;
  6512. @State isSeekTo: boolean = false;
  6513. @State isCurrentTime: boolean = false;
  6514. @State videoWidth: string = '100%';
  6515. @State videoHeight: string = '100%';
  6516. @State initAspectRatio: number = 1;
  6517. @State videoAspectRatio: number = this.initAspectRatio;
  6518. private videoUrl: string = '';
  6519. private last: number = 0;
  6520. @State videoParentAspectRatio: number = this.initAspectRatio;
  6521. private mIjkMediaPlayer = IjkMediaPlayer.getInstance();
  6522. @State CONTROL_PlayStatus: number = PlayStatus.INIT;
  6523. @State PROGRESS_MAX_VALUE: number = 100;
  6524. @State updateProgressTimer: number = 0;
  6525. @State isHide: boolean = false; //是否因此播放器的按钮,默认是进入横屏模式隐藏,点击视频的时候显示
  6526. @State name: string = '';
  6527. // @State loop: boolean = false;
  6528. @State playType: number = 0; //0:连续播放 1:单片重复播放 2:正常播放 3:随机播放
  6529. @State multiple: string = '1.0X';
  6530. xcomponentController: XComponentController = new XComponentController()
  6531. private panOptionBright: PanGestureOptions =
  6532. new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down });
  6533. private panOptionVolume: PanGestureOptions =
  6534. new PanGestureOptions({ direction: PanDirection.Vertical | PanDirection.Up | PanDirection.Down });
  6535. private panOptionSeekTo: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Horizontal });
  6536. //手势的音量控制和亮度控制
  6537. private positionX: number = PlayConstants.POSITION_X;
  6538. private positionY: number = PlayConstants.POSITION_Y;
  6539. private windowClass: window.Window = globalThis.windowClass
  6540. @State volume: number = 0.5;
  6541. @State volumeSmall: boolean = false
  6542. @State volumeShow: boolean = PlayConstants.VOLUME_SHOW;
  6543. @State bright: number = PlayConstants.BRIGHT;
  6544. @State brightShow: boolean = PlayConstants.BRIGHT_SHOW;
  6545. @State seekToShow: boolean = PlayConstants.BRIGHT_SHOW;
  6546. @State screenWidth: number = 0
  6547. @State screenHeight: number = 0
  6548. @State statusBarHeight: number = 0
  6549. @State isYesFull: boolean = false
  6550. private seekValue: number = 0
  6551. @State isVideoLock: boolean = false; // Whether the video playback is locked
  6552. eventHub = getContext().eventHub;
  6553. //投播组件
  6554. private avSessionController: AvSessionController = AvSessionController.getInstance(false);
  6555. private castController: avSession.AVCastController | undefined = undefined;
  6556. @State isCastPlaying: boolean = false;
  6557. @State currentTime2: number = 0;
  6558. @State currentStringTime: string = '00:00';
  6559. @State duration: number = 0;
  6560. @State isReady: boolean = false;
  6561. @State durationTime: number = 0;
  6562. @State durationStringTime: string = '00:00';
  6563. @StorageLink('isPlaying') @Watch('animationRoFun') isPlaying: boolean = false;
  6564. // @State isPlaying: boolean = false;
  6565. private castSeek: boolean = false;
  6566. private castItem: avSession.AVQueueItem | undefined = undefined;
  6567. // @State isBgPlayOpen:boolean = true //是否启用后台播放
  6568. @State imageLabel: PixelMap | Resource = CommonConstants.musicBgList[0];
  6569. @State imageLabelBg: PixelMap | Resource = CommonConstants.musicBgList[0];
  6570. @State rotateAngle2: number = -9
  6571. @StorageLink('imageColor') imageColor: string = 'rgba(0, 0, 2, 1.00)';
  6572. @State cover: string | undefined = '';
  6573. @State artist: string | undefined = ''
  6574. // 1.初始化controller
  6575. private lyricController: LyricController = new LyricController()
  6576. private lyricControllerXF: LyricController = new LyricController() //悬浮歌词控制器
  6577. private lyricControllerSingle: LyricController = new LyricController() //播放页单行歌词控制器
  6578. private parser = new LyricParser()
  6579. @State randomColor: string = 'rgb(0,0,0)'
  6580. @State randomShakenX: number = 0
  6581. @State randomShakenY: number = 0
  6582. @State lyricTextSize: number = 24
  6583. @State lyricContent: string = ''
  6584. @State isDebug: boolean = false
  6585. @State isHightLightCenter: boolean = true
  6586. /**
  6587. * 初始化歌词加载与展示逻辑
  6588. * @param lyricPath 歌词文件路径(支持普通.lrc和加密.lrcc)
  6589. * @param isOnLineAndToast 是否弹出Toast提示(可选)获取在线歌词为true
  6590. * @param isApi2 是否使用API2获取歌词(可选)
  6591. *
  6592. * 主要流程:
  6593. * 1. 设置歌词显示样式(字号、颜色、行距、对齐、动画等)。
  6594. * 2. 优先尝试本地读取歌词文件(支持加密和普通两种后缀)。
  6595. * 3. 若本地无歌词且满足条件(调试模式或会员且安装时间超过2天),则联网获取歌词。
  6596. * 4. 获取到歌词后,解析并设置到lyricController,并保存到本地。
  6597. * 5. 本地有歌词时,读取文件内容(自动检测编码,支持解密),解析后设置到lyricController。
  6598. * 6. 解析失败或读取失败时,清空歌词显示。
  6599. *
  6600. * 注意事项:
  6601. * - 仅会员且安装时间超过2天才可联网获取歌词(调试模式isDebug=true时跳过限制)。
  6602. * - 支持加密歌词文件(.lrcc),自动检测并解密。
  6603. * - 歌词内容解析后通过lyricController驱动UI渲染。
  6604. */
  6605. async initLyric(lyricPath: string, isOnLineAndToast?: boolean, isApi2?: boolean, isLocal?: boolean) {
  6606. if (StrUtil.isEmpty(lyricPath)) {
  6607. return
  6608. }
  6609. this.initPipLyricSetting()
  6610. this.lyricControllerSingle
  6611. .setTextSize(15)
  6612. .setCacheSize(4)
  6613. .setTextColor("#FFFFFF")
  6614. .setHighlightColor("#FFFFFF")
  6615. .setHighlightScale(1.2)
  6616. .setEmptyHint("")
  6617. .setAlignMode('center')
  6618. .setAnimationDuration(500)
  6619. .setSingleLine(true)
  6620. this.lyricContent = ''
  6621. this.lyricController
  6622. .setTextSize(this.currentLyricSize)
  6623. .setCacheSize(4)
  6624. .setTextColor("#DDDDDD")
  6625. .setHighlightColor("#FFFFFF")
  6626. .setEmptyHint("")
  6627. .setAnimationDuration(1000)
  6628. this.currentLyricAlignMode = PreferencesUtil.getNumberSync('LyricAlignMode', 1)
  6629. this.blurDegree = PreferencesUtil.getNumberSync('setBlurDegree', 3)
  6630. this.setBlurDegree(this.blurDegree, false)
  6631. this.setLyricAlignMode(this.currentLyricAlignMode, false)
  6632. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSize', 18), false)
  6633. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSize', 1.23), false)
  6634. this.lyricController.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpace', 10))
  6635. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColor', '#FFFFFF'), false)
  6636. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColor', '#FFFFFF'), false)
  6637. this.isHightLightCenter = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, true)
  6638. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  6639. this.lyricTextWeight = PreferencesUtil.getNumberSync('lyricTextWeight', 400)
  6640. this.lyricController.setTextWeight(this.lyricTextWeight)
  6641. this.showSingleLyric = false
  6642. this.timeOffset = 0
  6643. this.lyricController.setLyric(null)
  6644. this.lyricControllerSingle.setLyric(null)
  6645. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc'
  6646. console.log("onecold lyricPath =" + lyricPath)
  6647. let neiqianLrc = ''
  6648. let lyContent = this.currentSong?.lyricContent
  6649. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  6650. neiqianLrc = lyContent
  6651. }
  6652. if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast&&!isLocal&&!isLocal) {
  6653. console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
  6654. //赋值给this.lyricContent,播控中心才可以显示歌词
  6655. this.lyricContent = neiqianLrc
  6656. // 将文件内容按行分割成字符串数组
  6657. let lines = neiqianLrc.split('\n').map(line => line.trim());
  6658. // 3.解析歌词
  6659. let lyric = this.parser.parse(lines);
  6660. // 4.设置歌词
  6661. this.lyricController.setLyric(lyric);
  6662. this.lyricControllerXF.setLyric(lyric)
  6663. this.lyricControllerSingle.setLyric(lyric)
  6664. return
  6665. }
  6666. if (isOnLineAndToast || ((!FileUtil.accessSync(lyricPath) && !FileUtil.accessSync(jiaMilyricPath))
  6667. && !Utility.isVideoByExtension(this.videoUrl))) {
  6668. if (this.currentSong !== undefined) {
  6669. // ToastUtil.showShort('正在为你搜索在线歌词!')
  6670. //判断是不是赞助会员,是会员的话才开启歌词功能
  6671. // if (!this.isDebug) {
  6672. // if (!Utility.isNoble()) {
  6673. // LogUtil.debug("onecold 不是赞助会员")
  6674. // return
  6675. // }
  6676. // if(!Utility.isPassInstallTime(33)){
  6677. // LogUtil.debug("onecold not pass time")
  6678. // // LogUtil.debug("onecold 用户安装app没超过12天" )
  6679. // return
  6680. // }
  6681. // }
  6682. let artist = this.currentSong?.artist
  6683. if (artist === undefined) {
  6684. artist = ''
  6685. }
  6686. if (isApi2 === undefined) {
  6687. isApi2 = false
  6688. }
  6689. NetAxiosUtil.getLyric(this.name, artist, isApi2).then((res) => {
  6690. // LogUtil.debug("onecold res =" + res)
  6691. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  6692. if (StrUtil.isNotEmpty(res)) {
  6693. this.lyricContent = res
  6694. let lines = res.split('\n').map(line => line.trim());
  6695. // 3.解析歌词
  6696. let lyric = this.parser.parse(lines);
  6697. // 4.设置歌词
  6698. this.lyricController.setLyric(lyric);
  6699. this.lyricControllerXF.setLyric(lyric)
  6700. this.lyricControllerSingle.setLyric(lyric)
  6701. this.showSingleLyric = true
  6702. // 4.保存歌词文件lyric到本地
  6703. //2025年8月28日歌词不再加密下载
  6704. this.saveDataToFile(res, lyricPath, false)
  6705. } else {
  6706. this.lyricController.setLyric(null)
  6707. this.lyricControllerXF.setLyric(null)
  6708. this.lyricControllerSingle.setLyric(null)
  6709. if (isOnLineAndToast) {
  6710. ToastUtil.showShort('未获取到歌词!')
  6711. }
  6712. }
  6713. } else {
  6714. this.lyricController.setLyric(null)
  6715. this.lyricControllerXF.setLyric(null)
  6716. this.lyricControllerSingle.setLyric(null)
  6717. if (isOnLineAndToast) {
  6718. ToastUtil.showShort('未获取到歌词!')
  6719. }
  6720. }
  6721. })
  6722. } else {
  6723. this.lyricController.setLyric(null)
  6724. this.lyricControllerXF.setLyric(null)
  6725. this.lyricControllerSingle.setLyric(null)
  6726. if (isOnLineAndToast) {
  6727. ToastUtil.showShort('未获取到歌词!')
  6728. }
  6729. }
  6730. return
  6731. }
  6732. try {
  6733. let isJiaMi = false;
  6734. let realLyricPath = lyricPath
  6735. if (FileUtil.accessSync(jiaMilyricPath)) {
  6736. isJiaMi = true
  6737. realLyricPath = jiaMilyricPath
  6738. console.info("onecold 找到加密本地歌词 ");
  6739. } else {
  6740. isJiaMi = false
  6741. realLyricPath = lyricPath
  6742. console.info("onecold 找到本地歌词 ");
  6743. }
  6744. // 3.读取文件内容并指定编码为 UTF-8
  6745. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  6746. const stat = await fileIo.stat(file.fd);
  6747. const arrayBuffer = new ArrayBuffer(stat.size);
  6748. fs.read(file.fd, arrayBuffer)
  6749. .then((readLen: number) => {
  6750. console.info("read file data succeed");
  6751. // let buf = buffer.from(arrayBuffer, 0, readLen);
  6752. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  6753. // 检查 buf 是否为空
  6754. if (buf.length === 0) {
  6755. throw new Error("Buffer is empty after reading the file");
  6756. }
  6757. try {
  6758. // 检测文件编码
  6759. // let detectedEncoding = chardet.detect(buf);
  6760. // console.info("onecoldT Detected encoding: " + detectedEncoding);
  6761. let detectedEncoding = this.detect(arrayBuffer)
  6762. console.info("onecoldT Detected encoding: " + detectedEncoding);
  6763. // 使用检测到的编码解码,解决中文乱码问题
  6764. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  6765. console.info("onecoldT Detected textDecoder: " + textDecoder);
  6766. let fileContent = textDecoder.decode(buf);
  6767. console.info(`onecoldT The content of file1: ${fileContent}`);
  6768. //解密
  6769. if (isJiaMi) {
  6770. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent))
  6771. }
  6772. console.info(`onecold The content of file2: ${fileContent}`);
  6773. this.lyricContent = fileContent
  6774. if(isLocal){//编辑标签选择本地歌词需要赋值给this.lyricConStr
  6775. this.lyricConStr = fileContent
  6776. }
  6777. // 将文件内容按行分割成字符串数组
  6778. let lines = fileContent.split('\n').map(line => line.trim());
  6779. console.info(`onecold The content of file: ${fileContent}`);
  6780. // 3.解析歌词
  6781. let lyric = this.parser.parse(lines);
  6782. // 4.设置歌词
  6783. this.lyricController.setLyric(lyric);
  6784. this.lyricControllerXF.setLyric(lyric)
  6785. this.lyricControllerSingle.setLyric(lyric)
  6786. this.showSingleLyric = true
  6787. console.info(`The content of file: ${fileContent}`);
  6788. } catch (chardetError) {
  6789. console.error("chardet.detect failed with error: " + chardetError.message);
  6790. this.lyricController.setLyric(null);
  6791. this.lyricControllerXF.setLyric(null)
  6792. this.lyricControllerSingle.setLyric(null)
  6793. }
  6794. })
  6795. .catch((err: BusinessError) => {
  6796. this.lyricController.setLyric(null)
  6797. this.lyricControllerXF.setLyric(null)
  6798. this.lyricControllerSingle.setLyric(null)
  6799. console.error("read file data failed with error message: " + err.message + ", error code: " + err.code);
  6800. })
  6801. .catch((err: Error) => {
  6802. this.lyricController.setLyric(null)
  6803. this.lyricControllerXF.setLyric(null)
  6804. this.lyricControllerSingle.setLyric(null)
  6805. console.error("read file 2 data failed with error message: " + err.message);
  6806. })
  6807. .finally(() => {
  6808. fs.closeSync(file);
  6809. });
  6810. } catch (error) {
  6811. this.lyricController.setLyric(null)
  6812. this.lyricControllerSingle.setLyric(null)
  6813. this.lyricControllerXF.setLyric(null)
  6814. Logger.error(TAG, 'init Lyric failed with err: ' + JSON.stringify(error));
  6815. }
  6816. }
  6817. detect(data: ArrayBuffer): string {
  6818. //创建检测对象
  6819. let detector: UniversalDetector = new UniversalDetector();
  6820. // 传入检测数据并实时判断编码格式
  6821. detector.handleData(data, 0, data.byteLength);
  6822. // 标记检测数据 读取结束
  6823. detector.dataEnd();
  6824. // 获取检测结果
  6825. let detected: string = detector.getDetectedCharset();
  6826. // 释放资源
  6827. detector.reset();
  6828. return detected;
  6829. }
  6830. //初始化悬浮歌词的自定义设置
  6831. initPipLyricSetting() {
  6832. this.lyricControllerXF
  6833. .setTextSize(this.currentLyricSize)
  6834. .setCacheSize(4)
  6835. .setTextColor("#DDDDDD")
  6836. .setHighlightColor("#FFFFFF")// .setLineSpace(18)
  6837. .setEmptyHint("")
  6838. .setAnimationDuration(1000)
  6839. this.currentLyricAlignModePip = PreferencesUtil.getNumberSync('LyricAlignModePip', 0)
  6840. this.blurDegreePip = PreferencesUtil.getNumberSync('setBlurDegreePip', 3)
  6841. this.setBlurDegree(this.blurDegreePip, true)
  6842. this.setLyricAlignMode(this.currentLyricAlignModePip, true)
  6843. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSizePip', 18), true)
  6844. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSizePip', 1.23), true)
  6845. this.lyricControllerXF.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpacePip', 10))
  6846. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColorPip', '#FFFFFF'), true)
  6847. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColorPip', '#FFFFFF'), true)
  6848. this.lyricControllerXF.setHightLightCenter(true)
  6849. this.lyricTextWeightPip = PreferencesUtil.getNumberSync('lyricTextWeightPip', 400)
  6850. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  6851. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  6852. this.pipBgIndex = PreferencesUtil.getNumberSync('pipBgIndex', 0)
  6853. if (this.pipBgIndex === 0) {
  6854. if (this.cover) {
  6855. this.pipBg = this.cover
  6856. } else {
  6857. this.pipBg = this.imageColor
  6858. }
  6859. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  6860. }
  6861. }
  6862. //根据item返回歌词内容
  6863. async getLyricContent(item: VideoItem): Promise<string> {
  6864. let neiqianLrc = ''
  6865. let lyContent = item?.lyricContent
  6866. if(lyContent&&StrUtil.isNotEmpty(lyContent)){
  6867. neiqianLrc = lyContent
  6868. return neiqianLrc
  6869. }
  6870. try {
  6871. //取数据库里面的歌词lyContent
  6872. const lyricContent = await this.table.getLyricContentByFilePath(item.filePath);
  6873. if (lyricContent&&StrUtil.isNotEmpty(lyricContent)) {
  6874. console.log("onecold Lyrics:", lyricContent);
  6875. neiqianLrc = lyricContent
  6876. return neiqianLrc
  6877. }
  6878. } catch (error) {
  6879. console.error("Error fetching lyrics:", error);
  6880. }
  6881. try {
  6882. let filePath = item.filePath;
  6883. let lyricPath = filePath.substring(0, filePath.lastIndexOf('.')) + '.lrc';
  6884. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc';
  6885. let isJiaMi = false;
  6886. let realLyricPath = lyricPath;
  6887. if (FileUtil.accessSync(jiaMilyricPath)) {
  6888. isJiaMi = true;
  6889. realLyricPath = jiaMilyricPath;
  6890. console.info("onecold 找到加密本地歌词");
  6891. } else {
  6892. console.info("onecold 找到本地歌词");
  6893. }
  6894. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  6895. const stat = await fileIo.stat(file.fd);
  6896. const arrayBuffer = new ArrayBuffer(stat.size);
  6897. const readLen = await fs.read(file.fd, arrayBuffer);
  6898. console.info("read file data succeed");
  6899. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  6900. if (buf.length === 0) {
  6901. throw new Error("Buffer is empty after reading the file");
  6902. }
  6903. // let detectedEncoding = chardet.detect(buf);
  6904. let detectedEncoding = this.detect(arrayBuffer)
  6905. console.info("Detected encoding: " + detectedEncoding);
  6906. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  6907. let fileContent = textDecoder.decode(buf);
  6908. console.info(`onecold The content of file1: ${fileContent}`);
  6909. if (isJiaMi) {
  6910. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent));
  6911. }
  6912. console.info(`onecold The content of file2: ${fileContent}`);
  6913. fs.closeSync(file);
  6914. return fileContent;
  6915. } catch (error) {
  6916. console.error('init Lyric failed with err: ' + JSON.stringify(error));
  6917. return '';
  6918. }
  6919. }
  6920. async saveDataToFile(content: string, filePath: string, isJiaMi?: boolean) {
  6921. if (StrUtil.isEmpty(filePath)) {
  6922. return
  6923. }
  6924. try {
  6925. //将content进行加密
  6926. // let jiaMilyricPath = filePath.substring(0,filePath.lastIndexOf('.'))+'.lrcc'
  6927. let lyricContent = ''
  6928. if (isJiaMi) {
  6929. lyricContent = Base64Util.encodeToStrSync(StrUtil.strToUint8Array(content))
  6930. } else {
  6931. lyricContent = content
  6932. }
  6933. const file = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  6934. // 清空文件内容
  6935. await fileIo.truncate(file.fd, 0);
  6936. await fileIo.write(file.fd, lyricContent);
  6937. await fileIo.close(file);
  6938. console.log('onecold lyric file Data saved successfully.');
  6939. } catch (error) {
  6940. console.error('onecold lyric file Failed to save data:', error);
  6941. }
  6942. }
  6943. /**
  6944. * Get largest proportion color of an image.
  6945. */
  6946. getImageColor() {
  6947. if (!this.context) {
  6948. return;
  6949. }
  6950. let bg = Utility.getMusisBg()
  6951. this.imageLabel = bg
  6952. ColorConversion.setSysBarLightBackground(true);
  6953. this.context.resourceManager.getMediaContent(bg)
  6954. .then((value: Uint8Array) => {
  6955. let buffer = value.buffer as ArrayBuffer;
  6956. image.createImageSource(buffer).createPixelMap().then((pixelMap) => {
  6957. effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
  6958. if (error) {
  6959. Logger.error('Failed to create color picker.');
  6960. } else {
  6961. let color = colorPicker.getLargestProportionColor();
  6962. let colorArr = ColorConversion.dealColor(color.red, color.green, color.blue);
  6963. this.imageColor = `rgba(${colorArr[0]}, ${colorArr[1]}, ${colorArr[2]}, 1)`;
  6964. }
  6965. })
  6966. let headFilter = effectKit.createEffect(pixelMap);
  6967. if (headFilter !== null) {
  6968. headFilter.blur(15);
  6969. headFilter.getEffectPixelMap().then((value) => {
  6970. this.imageLabelBg = value;
  6971. })
  6972. }
  6973. })
  6974. .catch((error: BusinessError) => {
  6975. Logger.error(`${error.code} + ${error.message}`)
  6976. })
  6977. })
  6978. .catch((error: BusinessError) => {
  6979. Logger.error(`${error.code} + ${error.message}`)
  6980. })
  6981. }
  6982. setImageColor(cover: string) {
  6983. if (!this.context) {
  6984. return;
  6985. }
  6986. if (cover === undefined) {
  6987. return;
  6988. }
  6989. imagePathToPixelMap(cover).then((value) => {
  6990. let headFilter = effectKit.createEffect(value);
  6991. if (headFilter !== null) {
  6992. headFilter.blur(15);
  6993. headFilter.getEffectPixelMap().then((value) => {
  6994. this.imageLabelBg = value;
  6995. })
  6996. }
  6997. }).catch((error: BusinessError) => {
  6998. Logger.error(`${error.code} + ${error.message}`)
  6999. })
  7000. }
  7001. setImageColor2(cover: string) {
  7002. if (!this.context) {
  7003. return;
  7004. }
  7005. if (cover === undefined) {
  7006. return;
  7007. }
  7008. LogUtils.getInstance().LOGI("setImageColor2--> cover ==" + cover);
  7009. ImageUtils.getImageDealData(getContext(this), cover, this.videoUrl).then((data) => {
  7010. this.imageColor = data.imageColor;
  7011. if (data.blurPixelMap) {
  7012. this.imageLabelBg = data.blurPixelMap;
  7013. }
  7014. })
  7015. }
  7016. // 定义开始旋转的方法
  7017. // 定时器用于一百毫秒执行一次旋转角度
  7018. @State timer: number = 0
  7019. @State rotateAngle: number = 0
  7020. //封面旋转动画
  7021. animationRoFun() {
  7022. if (this.isPlaying && !this.isCoverRectangle) {
  7023. this.timer = setInterval(() => {
  7024. this.rotateAngle += 1
  7025. }, 100)
  7026. this.startRotation()
  7027. } else {
  7028. clearInterval(this.timer)
  7029. this.stopRotation()
  7030. }
  7031. }
  7032. // 定义开始旋转的方法
  7033. startRotation() {
  7034. if (this.isPlaying) {
  7035. animateTo({
  7036. duration: 777,
  7037. iterations: 1,
  7038. curve: Curve.Linear
  7039. }, () => {
  7040. this.rotateAngle2 = -9
  7041. })
  7042. }
  7043. }
  7044. // 回调,暂停和播放按钮回调,下一首和上一首
  7045. playChange() {
  7046. // if(this.isCoverRectangle){
  7047. // return
  7048. // }
  7049. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  7050. this.setIsPlaying(true)
  7051. this.animationState = AnimationStatus.Running
  7052. } else {
  7053. this.setIsPlaying(false)
  7054. this.animationState = AnimationStatus.Paused
  7055. }
  7056. }
  7057. // 定义停止旋转的方法
  7058. stopRotation() {
  7059. if (this.isCoverRectangle) {
  7060. this.rotateAngle = 0
  7061. } else {
  7062. //唱针以左上角为点选择逆时针40度
  7063. animateTo({
  7064. duration: 1000,
  7065. curve: Curve.Linear,
  7066. iterations: 1,
  7067. }, () => {
  7068. this.rotateAngle2 = -45;
  7069. });
  7070. }
  7071. }
  7072. @Builder
  7073. private LyricsTopItem() {
  7074. Row() {
  7075. Stack() {
  7076. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  7077. .height(55)
  7078. .width(55)
  7079. .alt(this.imageLabel)
  7080. .borderRadius(8)
  7081. .clickEffect({ level: ClickEffectLevel.HEAVY })
  7082. .margin({ left: this.currentLyricAlignMode === 0 ? 28 : -15 })
  7083. }
  7084. .width('18%')
  7085. Column() {
  7086. Column() {
  7087. Text(this.name)
  7088. .fontSize(16)
  7089. .maxLines(1)
  7090. .fontWeight(FontWeight.Bolder)
  7091. .fontColor(this.currentLyricColor)
  7092. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  7093. Row() {
  7094. Text(this.currentSong?.artist !== undefined ? this.currentSong?.artist : '')
  7095. .fontSize(13)
  7096. .fontWeight(FontWeight.Bold)
  7097. .padding({ top: 8 })
  7098. .fontColor(this.currentLyricColor)
  7099. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  7100. Blank()
  7101. }
  7102. }
  7103. .height('100%')
  7104. .width('100%')
  7105. .justifyContent(FlexAlign.Center)
  7106. .alignItems(HorizontalAlign.Start)
  7107. }
  7108. .height('100%')
  7109. .width('65%')
  7110. Column() {
  7111. Image($r('app.media.lyric'))
  7112. .width(28)
  7113. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7114. .margin({ right: 30 })
  7115. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7116. .onClick(() => {
  7117. this.isLyricSetting = !this.isLyricSetting;
  7118. })
  7119. .bindSheet($$this.isLyricSetting, this.lyricSettingSheet(false), {
  7120. height: '95%',
  7121. dragBar: true,
  7122. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7123. showClose: true,
  7124. blurStyle: BlurStyle.Thin,
  7125. backgroundColor: Color.Transparent,
  7126. // title: { title: $r('app.string.lyric_setting') }
  7127. })
  7128. }
  7129. .width('18%')
  7130. }
  7131. .width('82%')
  7132. .height(58)
  7133. .justifyContent(FlexAlign.SpaceBetween)
  7134. }
  7135. //歌词显示
  7136. @Builder
  7137. PlayerLyrics() {
  7138. Column() {
  7139. Column() {
  7140. this.LyricsTopItem()
  7141. }
  7142. .height(this.isPuraWP() ? 15 : 58)
  7143. .visibility(this.currentBreakpoint !== BreakpointTypeEnum.SM ?
  7144. Visibility.None : Visibility.Visible)
  7145. .margin({ left: 6, top: this.isPuraWP() ? 5 : 38 })
  7146. .width("100%")
  7147. Column() {
  7148. LyricView2({
  7149. controller: this.lyricController,
  7150. enableSeek: true,
  7151. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  7152. seekLineColor: "#80ffffff", // 滑动定位线颜色
  7153. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  7154. onSeekAction: (position: number) => { // 滑动歌词触发seek定位回调
  7155. if (!this.isPlaying) {
  7156. console.info('onecold startPlayOrResumePlay 7527')
  7157. this.startPlayOrResumePlay()
  7158. }
  7159. else {
  7160. this.isSeekTo = true;
  7161. this.mDestroyPage = false;
  7162. this.showLoadIng();
  7163. this.seekTo(position + "");
  7164. this.isSeekTo = false;
  7165. }
  7166. return true
  7167. }
  7168. })
  7169. .width("100%")
  7170. .layoutWeight(1)
  7171. .margin({ left: this.currentLyricAlignMode === 0 ? 0 : 50, top: 2, bottom: this.isPhoneLan()||this.isHiCarKuanBianPing() ? 40 : 10 })
  7172. if (this.isPhoneLan()) {
  7173. Column() {
  7174. this.playProgressView()
  7175. // this.playCenterView()
  7176. }
  7177. .margin({ bottom: 30, right: this.currentLyricAlignMode == 0 ? 0 : 30 })
  7178. }
  7179. }
  7180. .position({
  7181. top: this.currentBreakpoint !== BreakpointTypeEnum.SM ? (this.isPhoneLan() ? 0 : 45) :
  7182. (this.isPuraWP() ? 58 : 99)
  7183. })
  7184. .justifyContent(FlexAlign.Center)
  7185. .height(this.isCoverOpacity() ? this.isPhoneLan()?'95%':'90%' : '82%')
  7186. }
  7187. }
  7188. @Builder
  7189. SingleLyricView() {
  7190. Column() {
  7191. Column() {
  7192. LyricView2({
  7193. controller: this.lyricControllerSingle,
  7194. enableSeek: false,
  7195. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  7196. seekLineColor: "#80ffffff", // 滑动定位线颜色
  7197. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  7198. })
  7199. }
  7200. .height(66)
  7201. .margin({ bottom: 20 })
  7202. }
  7203. }
  7204. //播放器的底部控制中心,上一首,暂停,下一首,播放进度条等
  7205. @Builder
  7206. BottomControl() {
  7207. Column() {
  7208. this.TopPlayProgressView()
  7209. //播放 暂停,下一首,上一首
  7210. this.playCenterView()
  7211. //播放进度条
  7212. this.BottomView()
  7213. }
  7214. .position({ bottom: this.isHiCarSmall()?50:(this.isCoverOpacity() ? 55 : 70) }) // 将 固定在底部
  7215. }
  7216. //播放控制上一首 下一首 暂停和播放
  7217. @Builder
  7218. playCenterView(){
  7219. Row() {
  7220. Row({ space: 20 }) {
  7221. Button({type:ButtonType.Circle,stateEffect:true}){
  7222. //更多功能
  7223. Image($r('app.media.menu'))
  7224. .width(24)
  7225. .clickEffect({level:ClickEffectLevel.MIDDLE})
  7226. .bindSheet($$this.isShowMoreView, this.PlayMoreSheet(), {
  7227. height: this.isCoverOpacity() ? '95%' : '93%',
  7228. preferType: this.currentBreakpoint!==BreakpointTypeEnum.SM?SheetType.CENTER:SheetType.BOTTOM,
  7229. dragBar: true,
  7230. showClose: true,
  7231. blurStyle: BlurStyle.Thin,
  7232. backgroundColor: Color.Transparent,
  7233. })
  7234. }
  7235. .margin({ left: 5 })
  7236. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7237. .backgroundColor(Color.Transparent)
  7238. .onClick(() => {
  7239. this.isShowMoreView = !this.isShowMoreView;
  7240. })
  7241. Button({type:ButtonType.Circle,stateEffect:true}){
  7242. Image($r('app.media.ic_previous'))
  7243. .width(33)
  7244. .clickEffect({level:ClickEffectLevel.HEAVY})
  7245. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7246. }
  7247. .onClick(async () => {
  7248. this.playPrevious()
  7249. })
  7250. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7251. .backgroundColor(Color.Transparent)
  7252. .margin({ left: 5 })
  7253. }
  7254. Button({type:ButtonType.Circle,stateEffect:true}){
  7255. Column() {
  7256. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ?
  7257. (this.isCircleBtn?$r('app.media.hm_pause'):$r('app.media.ic_public_play'))
  7258. : (this.isCircleBtn?$r('app.media.hm_play2'):$r('app.media.ic_public_pause')))
  7259. .width(this.isPhoneLan()?45:55)
  7260. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7261. .fillColor(Color.White)
  7262. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7263. .onClick(async () => {
  7264. console.info('onecold playOrPause 7651')
  7265. this.playOrPause()
  7266. })
  7267. }
  7268. }
  7269. .backgroundColor(Color.Transparent)
  7270. .layoutWeight(1)
  7271. // .margin({ left: 38, right: 38 })
  7272. Row({ space: 20 }) {
  7273. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7274. Image($r('app.media.ic_next'))
  7275. .width(33)
  7276. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7277. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7278. .onClick(() => {
  7279. this.playNext();
  7280. })
  7281. }
  7282. .backgroundColor(Color.Transparent)
  7283. .margin({ right: 5 })
  7284. .width(33)
  7285. if(this.isPhoneLan()){
  7286. this.fullButton()
  7287. }else{
  7288. Button({type:ButtonType.Circle,stateEffect:true}){
  7289. //添加或取消收藏
  7290. SymbolGlyph(Utility.getIsFav(this.favList,this.currentSong)?
  7291. $r('sys.symbol.heart_fill'):$r('sys.symbol.heart'))
  7292. .fontSize(23)
  7293. .fontColor([Color.White])
  7294. .alignSelf(ItemAlign.Center)
  7295. // .width(24)
  7296. .clickEffect({level:ClickEffectLevel.MIDDLE})
  7297. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7298. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7299. .onClick(async () => {
  7300. if(this.currentSong){
  7301. this.doFav(this.currentSong)
  7302. }
  7303. })
  7304. }
  7305. .backgroundColor(Color.Transparent)
  7306. .width(24)
  7307. }
  7308. }
  7309. // .margin({ left: 5 })
  7310. }
  7311. .width('95%')
  7312. .margin({ bottom:this.isCoverOpacity()?0:20 })
  7313. .justifyContent(FlexAlign.SpaceEvenly)
  7314. }
  7315. @Builder
  7316. TopPlayProgressView(){
  7317. Row() {
  7318. Column(){
  7319. Row(){
  7320. Slider({
  7321. value: this.progressValue,
  7322. min: 0,
  7323. max: this.PROGRESS_MAX_VALUE,
  7324. step: 1,
  7325. style: SliderStyle.InSet
  7326. })
  7327. .height(20)
  7328. .blockColor('rgba(255,255,255,1)')
  7329. .trackColor('rgba(255,255,255,0.3)')
  7330. .selectedColor(Color.White)
  7331. .trackThickness(4)
  7332. .layoutWeight(1)
  7333. .showSteps(false)
  7334. .showTips(true)
  7335. .alignSelf(ItemAlign.Center)
  7336. .enabled(this.slideEnable)
  7337. .onChange((value: number, mode: SliderChangeMode) => {
  7338. // if (mode == 2) {
  7339. this.isSeekTo = true;
  7340. this.mDestroyPage = false;
  7341. this.showLoadIng();
  7342. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  7343. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  7344. this.seekTo(seekValue + "");
  7345. // this.setProgress()
  7346. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  7347. this.isSeekTo = false;
  7348. // }
  7349. })
  7350. }
  7351. .padding({ right: 7,left:20 })
  7352. Row(){
  7353. Text(this.currentTime)
  7354. .fontSize(10)
  7355. .fontColor(Color.White)
  7356. Blank()
  7357. .layoutWeight(1)
  7358. Text(this.totalTime)
  7359. .fontSize(10)
  7360. .fontColor(Color.White)
  7361. }
  7362. .justifyContent(FlexAlign.Start)
  7363. .padding({ right: 18,left:36 })
  7364. }
  7365. }
  7366. //x5的竖屏模式需要99%
  7367. .width(this.isLandscape?'80%':'93%')
  7368. .justifyContent(FlexAlign.Center)
  7369. .margin({bottom:6})
  7370. .animation({
  7371. duration: 666,
  7372. curve: 'ease-in-out' // 可选动画曲线
  7373. })
  7374. }
  7375. //播放进度条
  7376. @Builder
  7377. BottomView(){
  7378. Row() {
  7379. Button({type:ButtonType.Circle,stateEffect:true}){
  7380. Column() {
  7381. if (this.playType === 0) {
  7382. Image($r('app.media.loop'))
  7383. .width(27)
  7384. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7385. } else if (this.playType === 1) {
  7386. Image($r('app.media.single'))
  7387. .width(27)
  7388. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7389. } else if (this.playType === 2) {
  7390. Image($r('app.media.normal_play'))
  7391. .width(27)
  7392. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7393. } else if (this.playType === 3) {
  7394. Image($r('app.media.random'))
  7395. .width(27)
  7396. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7397. }
  7398. }
  7399. }
  7400. .layoutWeight(1)
  7401. .margin({ left: 5 })
  7402. .backgroundColor(Color.Transparent)
  7403. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7404. .onClick(async () => {
  7405. this.setLoopMode()
  7406. })
  7407. this.fullButton()
  7408. Button({type:ButtonType.Circle,stateEffect:true}){
  7409. Column() {
  7410. Image($r('app.media.lyric'))
  7411. .width(26)
  7412. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7413. }
  7414. }
  7415. .layoutWeight(1)
  7416. .backgroundColor(Color.Transparent)
  7417. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7418. .onClick(async () => {
  7419. this.isLyricSetting = !this.isLyricSetting;
  7420. })
  7421. //播放列表
  7422. Button({type:ButtonType.Circle,stateEffect:true}){
  7423. Image($r('app.media.hm_playlist'))
  7424. .width(24)
  7425. .fillColor(Color.White)
  7426. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7427. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  7428. height: '95%',
  7429. dragBar: true,
  7430. showClose: true,
  7431. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7432. blurStyle: BlurStyle.Thin,
  7433. backgroundColor: this.isPlayListBgGrass?Color.Transparent:$r('app.color.silvery'),
  7434. title: {
  7435. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  7436. + `(${this.songList.length}首)`
  7437. }
  7438. })
  7439. }
  7440. .layoutWeight(1)
  7441. .backgroundColor(Color.Transparent)
  7442. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7443. .onClick(() => {
  7444. this.isShowSheetView = !this.isShowSheetView;
  7445. if(this.isPlayListBgGrass){
  7446. this.isFrontWhite = true
  7447. }else{
  7448. this.isFrontWhite = false
  7449. }
  7450. this.scrollIndex()
  7451. })
  7452. }
  7453. .width(this.isLandscape?'88%':'95%')
  7454. .justifyContent(FlexAlign.SpaceAround)
  7455. .height(30)
  7456. .margin({top:3})
  7457. .animation({
  7458. duration: 666,
  7459. curve: 'ease-in-out' // 可选动画曲线
  7460. })
  7461. }
  7462. @Builder
  7463. fullButton(){
  7464. Button({type:ButtonType.Circle,stateEffect:true}){
  7465. Column() {
  7466. Image($r('app.media.full_4'))
  7467. .width(25)
  7468. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7469. }
  7470. }
  7471. .layoutWeight(1)
  7472. .backgroundColor(Color.Transparent)
  7473. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7474. .onClick(async () => {
  7475. if (this.isLandscape) {
  7476. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  7477. } else {
  7478. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  7479. }
  7480. })
  7481. }
  7482. //旧版本播放进度条
  7483. @Builder
  7484. playProgressView() {
  7485. Row() {
  7486. Button({ type: ButtonType.Circle, stateEffect: true }) {
  7487. Column() {
  7488. if (this.playType === 0) {
  7489. Image($r('app.media.loop'))
  7490. .width($r('app.float.control_image_width'))
  7491. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7492. } else if (this.playType === 1) {
  7493. Image($r('app.media.single'))
  7494. .width($r('app.float.control_image_width'))
  7495. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7496. } else if (this.playType === 2) {
  7497. Image($r('app.media.normal_play'))
  7498. .width($r('app.float.control_image_width'))
  7499. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7500. } else if (this.playType === 3) {
  7501. Image($r('app.media.random'))
  7502. .width($r('app.float.control_image_width'))
  7503. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7504. }
  7505. }
  7506. }
  7507. .visibility(this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  7508. .animation({
  7509. duration: 666,
  7510. curve: 'ease-in-out' // 可选动画曲线
  7511. })
  7512. .backgroundColor(Color.Transparent)
  7513. .margin({ right: 10 })
  7514. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7515. .onClick(async () => {
  7516. this.setLoopMode()
  7517. })
  7518. Text(this.currentTime)
  7519. .fontSize($r('app.float.slider_font_size'))
  7520. .fontColor(Color.White)
  7521. .margin(3)
  7522. Slider({
  7523. value: this.progressValue,
  7524. min: 0,
  7525. max: this.PROGRESS_MAX_VALUE,
  7526. step: 1,
  7527. style: SliderStyle.OutSet
  7528. })
  7529. .width('600px')
  7530. .blockColor('rgba(255,255,255,1)')
  7531. .trackColor('rgba(255,255,255,0.3)')
  7532. .selectedColor(Color.White)
  7533. .trackThickness(PlayConstants.PROGRESS_TRACK_THICKNESS)
  7534. .layoutWeight(1)
  7535. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  7536. .showSteps(false)
  7537. .showTips(true)
  7538. .enabled(this.slideEnable)
  7539. .onChange((value: number, mode: SliderChangeMode) => {
  7540. // if (mode == 2) {
  7541. this.isSeekTo = true;
  7542. this.mDestroyPage = false;
  7543. this.showLoadIng();
  7544. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  7545. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  7546. this.seekTo(seekValue + "");
  7547. // this.setProgress()
  7548. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  7549. this.isSeekTo = false;
  7550. // }
  7551. })
  7552. Text(this.totalTime)
  7553. .fontSize($r('app.float.slider_font_size'))
  7554. .fontColor(Color.White)
  7555. .margin(3)
  7556. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  7557. //播放列表
  7558. Button({ type: ButtonType.Circle, stateEffect: true }) {
  7559. Image($r('app.media.hm_playlist'))
  7560. .width($r('app.float.control_image_width'))
  7561. .fillColor(Color.White)
  7562. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7563. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  7564. height: '95%',
  7565. dragBar: true,
  7566. showClose: true,
  7567. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7568. blurStyle: BlurStyle.Thin,
  7569. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  7570. title: {
  7571. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  7572. + `(${this.songList.length}首)`
  7573. }
  7574. })
  7575. }
  7576. .visibility( this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  7577. .animation({
  7578. duration: 666,
  7579. curve: 'ease-in-out' // 可选动画曲线
  7580. })
  7581. .backgroundColor(Color.Transparent)
  7582. .margin({ right: 20, left: 10 })
  7583. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7584. .onClick(() => {
  7585. this.isShowSheetView = !this.isShowSheetView;
  7586. if (this.isPlayListBgGrass) {
  7587. this.isFrontWhite = true
  7588. } else {
  7589. this.isFrontWhite = false
  7590. }
  7591. this.scrollIndex()
  7592. })
  7593. }
  7594. //x5的竖屏模式需要99%
  7595. .width(this.isPhonePortrait() ? '93.4%'
  7596. : this.currentHeightBreakpoint == 1 && this.currentWidthBreakpoint == 2 ? '99%' : '82%')
  7597. .height(this.isPhoneLan() ? 25 : 33)
  7598. .animation({
  7599. duration: 666,
  7600. curve: 'ease-in-out' // 可选动画曲线
  7601. })
  7602. }
  7603. isBigScreen() {
  7604. if (this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_LG) {
  7605. return true
  7606. }
  7607. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  7608. && this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  7609. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG) {
  7610. return false
  7611. } else {
  7612. return true
  7613. }
  7614. return false
  7615. }
  7616. @State is_auto_hide_progress: boolean = false //手机横屏自动隐藏播放进退条,点击屏幕可以显示,倒计时4秒后又自动隐藏
  7617. @State isCoverRectangle: boolean = false
  7618. @State isCoverTop: boolean = true
  7619. // 添加控制缩放的状态变量
  7620. @State scaleValueImage: number = 1
  7621. @Builder
  7622. CoverInfo() {
  7623. Column() {
  7624. //如果是方形,判断是不是封面在顶部,如果不是顶部,显示musicNameInfo, 如果是圆形显示musicNameInfo
  7625. if (this.isCoverRectangle) {
  7626. if (!this.isCoverTop) {
  7627. this.musicNameInfo(false)
  7628. }
  7629. } else {
  7630. this.musicNameInfo(false)
  7631. }
  7632. Stack() {
  7633. // 唱片旋转效果
  7634. Image($r('app.media.ic_music_disc'))
  7635. .width(245)
  7636. .height(245)
  7637. .margin({ right: 20, left: 20 ,top:this.isCoverRectangle||this.isLandscape?0:43})
  7638. .aspectRatio(1)
  7639. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  7640. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  7641. .borderRadius('100%')
  7642. .align(Alignment.Center)
  7643. .clip(true)// .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
  7644. .rotate({
  7645. angle: this.rotateAngle,
  7646. centerX: "50%",
  7647. centerY: "50%",
  7648. })
  7649. .animation({
  7650. duration: 100,
  7651. curve: Curve.Linear
  7652. })
  7653. .shadow({
  7654. radius: 30,
  7655. color: this.randomColor
  7656. })
  7657. Column() {
  7658. if (this.isCoverTop && !this.isCoverOpacity() && this.isCoverRectangle) {
  7659. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)// .height(this.isCoverOpacity() ? 250 : this.isCoverRectangle ? 320 : 162)
  7660. .width(this.isBigScreen() ? '72%' : this.isCoverTopBig ? '100%' : '86%')
  7661. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  7662. .alt(this.imageLabel)
  7663. .margin({ right: 8, left: 8, top: 8 })
  7664. .aspectRatio(1)
  7665. .opacity(this.opacityValueImage)
  7666. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7667. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  7668. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  7669. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  7670. .align(Alignment.Center)//
  7671. .clip(true)
  7672. .rotate({
  7673. x: 0,
  7674. y: 0,
  7675. z: 1,
  7676. angle: this.rotateAngle
  7677. })
  7678. .onClick(() => {
  7679. this.getImageColor()
  7680. })
  7681. this.musicNameInfo(false)
  7682. } else {
  7683. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  7684. .height(this.isHiCarSmall()?(this.isHiCarKuanBianPing()?140:px2vp(this.windowHeight)*0.38):
  7685. (this.isCoverOpacity() ? (px2vp(this.windowHeight)*0.62) : this.isCoverRectangle ? 320 : 162))
  7686. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  7687. .alt(this.imageLabel)
  7688. .margin({ right: 20, left: 20,top:this.isCoverRectangle||this.isLandscape?0:43 })
  7689. .aspectRatio(1)
  7690. .opacity(this.opacityValueImage)
  7691. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7692. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  7693. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  7694. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  7695. .align(Alignment.Center)//
  7696. .clip(true)
  7697. .rotate({
  7698. x: 0,
  7699. y: 0,
  7700. z: 1,
  7701. angle: this.rotateAngle
  7702. })
  7703. .onClick(() => {
  7704. this.getImageColor()
  7705. })
  7706. if (this.isPhoneLan()) {
  7707. Text(this.name)
  7708. .fontSize(18)
  7709. .fontWeight(FontWeight.Bold)
  7710. .margin({ top: 13 })
  7711. .textOverflow({ overflow: TextOverflow.Ellipsis })
  7712. .maxLines(1)
  7713. .width('99%')
  7714. .textAlign(TextAlign.Center)
  7715. .fontColor(Color.White)
  7716. }
  7717. }
  7718. }
  7719. // 唱针以左上角为点选择逆时针40度
  7720. Image($r('app.media.ic_music_cover_hand'))
  7721. .height(130)
  7722. .margin({ bottom: 220, top: 0 })
  7723. .align(Alignment.Top)
  7724. .rotate({ angle: this.rotateAngle2, centerX: 0, centerY: 0 })
  7725. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  7726. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  7727. Column({ space: 8 }) {
  7728. Text(this.name)
  7729. .fontSize(this.isPuraWP() ? 24 : (this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22))
  7730. .fontWeight(FontWeight.Bold)
  7731. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7732. .maxLines(1)
  7733. .width('48%')
  7734. .textAlign(TextAlign.Center)
  7735. .fontColor(Color.White)
  7736. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  7737. Text(this.artist)
  7738. .fontSize(this.isPuraWP() ? 18 : (this.isCoverOpacity() ? 12 : 15))
  7739. .fontColor(Color.White)
  7740. .fontWeight(FontWeight.Bold)
  7741. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  7742. }
  7743. .justifyContent(FlexAlign.Start)
  7744. .zIndex(1)
  7745. .visibility(this.isCoverOpacity() ? Visibility.Visible : Visibility.None)
  7746. }
  7747. .margin({
  7748. bottom: this.isCoverOpacity() || this.isCoverRectangle ?
  7749. (this.isPhonePortrait() && this.isShowSingleLineLyric ? 20 : 55) : 0,
  7750. top: this.isCoverOpacity() ? 0 : 20
  7751. })
  7752. if (this.isPhonePortrait() && this.isShowSingleLineLyric) {
  7753. this.SingleLyricView()
  7754. }
  7755. if (this.isPhoneLan()) {
  7756. Column() {
  7757. this.playCenterView()
  7758. // this.playProgressView()
  7759. }
  7760. .position({ left: 28, bottom: 38 })
  7761. } else {
  7762. this.BottomControl()
  7763. }
  7764. }
  7765. .width(CommonConstants.FULL_PERCENT)
  7766. .clip(true)
  7767. }
  7768. @Builder
  7769. private musicNameInfo(isHidden: boolean) {
  7770. Column({ space: 8 }) {
  7771. Text(this.name)
  7772. .fontSize(this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22)
  7773. .fontWeight(FontWeight.Bold)
  7774. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7775. .maxLines(1)
  7776. .width('99%')
  7777. .textAlign(TextAlign.Center)
  7778. .fontColor(Color.White)
  7779. Text(this.artist + ' ' + this.currentSong?.album)
  7780. .fontSize(this.isCoverOpacity() ? 12 : 15)
  7781. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7782. .fontColor(Color.White)
  7783. .textAlign(TextAlign.Center)
  7784. .visibility(StrUtil.isEmpty(this.artist)?Visibility.None:Visibility.Visible)
  7785. .width('99%')
  7786. .maxLines(1)
  7787. }
  7788. .margin({ top: this.isCoverOpacity() ? 20 : isHidden ? 40 : 20 })
  7789. .zIndex(1)
  7790. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7791. .visibility(this.isCoverOpacity() || isHidden ? Visibility.None : Visibility.Visible)
  7792. }
  7793. @Builder
  7794. private PlayTitle() {
  7795. Row() {
  7796. Row() {
  7797. Image($r('app.media.ic_back_down'))
  7798. .width($r('app.float.title_image_size'))// .aspectRatio(CommonConstants.ASPECT_RATIO)
  7799. .hitTestBehavior(HitTestMode.Transparent)
  7800. Text(this.name + ' ' + this.artist)
  7801. .fontColor(Color.White)
  7802. .fontSize($r('app.float.title_font_size'))
  7803. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7804. .maxLines(1)
  7805. .visibility(Visibility.None)
  7806. .margin({ left: 2, right: 30 })
  7807. }
  7808. .layoutWeight(1)
  7809. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7810. .visibility(this.isHide ? Visibility.Hidden : Visibility.Visible)
  7811. .onClick(() => {
  7812. this.isShowPlay = false;
  7813. })
  7814. Column() {
  7815. AVCastPicker({
  7816. normalColor: Color.White,
  7817. onStateChange: this.onStateVastChange
  7818. })
  7819. .width(24)
  7820. .height(24)
  7821. }
  7822. .visibility(this.isHide ? Visibility.Hidden : Visibility.None)
  7823. }
  7824. .width(PlayConstants.ROW_WIDTH)
  7825. }
  7826. @Builder
  7827. lyricSettingSheet(isPip: boolean) {
  7828. Scroll() {
  7829. this.lyricSetting(isPip)
  7830. }
  7831. .width('100%')
  7832. .height('100%')
  7833. }
  7834. @Builder
  7835. lyricSetting(isPip: boolean) {
  7836. Column() {
  7837. // 时间调节模块
  7838. if (!isPip) {
  7839. this.BuildTimeControls()
  7840. }
  7841. // 字号控制模块
  7842. this.BuildFontControls(isPip)
  7843. }
  7844. }
  7845. // 歌词时间偏移状态
  7846. @State timeOffset: number = 0.0
  7847. @State currentLyricColor: string = '#FFFFFF'
  7848. @State currentLyricColorPip: string = '#FFFFFF'
  7849. @State currentHighLightLyricColor: string = '#FF4081'
  7850. @State currentHighLightLyricColorPip: string = '#FF4081'
  7851. // 歌词字号状态
  7852. @State currentLyricSize: number = 20
  7853. @State currentLyricSizePip: number = 20
  7854. // 高亮歌词放大倍数
  7855. @State currentHightLyricSize: number = 1.2
  7856. @State currentHightLyricSizePip: number = 1.2
  7857. @State currentLyricLineSpace: number = 10
  7858. @State currentLyricLineSpacePip: number = 10
  7859. @State currentLyricAlignMode: number = 1
  7860. @State currentLyricAlignModePip: number = 1
  7861. @State blurDegree: number = 2
  7862. @State blurDegreePip: number = 2
  7863. @State isShowSelectColor: boolean = false
  7864. @State isShowHLSelectColor: boolean = false
  7865. @State isShowPipBgSelectColor: boolean = false
  7866. @State pipLyWidth: number = 330
  7867. @State pipLyHeight: number = 120
  7868. // 构建颜色选择器
  7869. @Builder
  7870. SelectColor(isHighColor: boolean, isPip: boolean, isBGPip?: boolean) {
  7871. Row({ space: 10 }) {
  7872. HSBColorPicker({
  7873. color: '#FFFFFF',
  7874. radius: 8,
  7875. layout: HSBColorPickerLayout.COLUMN,
  7876. predefine: ['#8b27f4', '#73f9fc', '#fffe55', '#f5cee3', '#eb4827', '#e93bf4', '#3e68f4', '#c5e6d3', '#e4e4e4',
  7877. '#fa7105'],
  7878. onChange: (value: string) => isHighColor ? this.changeLyricHightLightColor(value, isPip) :
  7879. this.changeLyricColor(value, isPip, isBGPip)
  7880. })
  7881. .height(250)
  7882. .layoutWeight(1)
  7883. .padding(25)
  7884. }
  7885. .width('66%')
  7886. }
  7887. @State isOpenPip: boolean = false
  7888. @State pipBgIndex: number = 0
  7889. // 构建字号控制器
  7890. @Builder
  7891. BuildFontControls(isPip: boolean) {
  7892. Column() {
  7893. if (isPip) {
  7894. Column() {
  7895. Row() {
  7896. Text('悬浮歌词')
  7897. .margin({ left: 18 })
  7898. .fontSize(15)
  7899. .fontColor(Color.White)
  7900. .fontWeight(480)
  7901. .layoutWeight(1)
  7902. Toggle({ type: ToggleType.Switch, isOn: this.isOpenPip })
  7903. .selectedColor(this.themeColor)
  7904. .switchPointColor(Color.White)
  7905. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7906. .margin({ right: 18 })
  7907. .onChange((checked: boolean) => {
  7908. this.isOpenPip = checked;
  7909. if (this.isOpenPip) {
  7910. this.startPip()
  7911. } else {
  7912. this.stopPip()
  7913. }
  7914. PreferencesUtil.put('isOpenPip', this.isOpenPip)
  7915. })
  7916. .width(50)
  7917. .height(30);
  7918. }
  7919. .height(55)
  7920. }
  7921. .backgroundColor(Color.Transparent)
  7922. .borderRadius(15)
  7923. .margin({
  7924. left: 30,
  7925. right: 30,
  7926. top: 0,
  7927. bottom: 20
  7928. })
  7929. .padding(0)
  7930. .border({
  7931. color: Color.White,
  7932. width: 1.8
  7933. })
  7934. }else{
  7935. Column() {
  7936. Row() {
  7937. Text('单行歌词')
  7938. .margin({ left: 18 })
  7939. .fontSize(15)
  7940. .fontColor(Color.White)
  7941. .fontWeight(480)
  7942. .layoutWeight(1)
  7943. Toggle({ type: ToggleType.Switch, isOn: this.isShowSingleLineLyric })
  7944. .selectedColor(this.themeColor)
  7945. .switchPointColor(Color.White)
  7946. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7947. .margin({ right: 18 })
  7948. .onChange((checked: boolean) => {
  7949. this.isShowSingleLineLyric = checked;
  7950. PreferencesUtil.put(SettingPage.IS_SHOW_SLLYRIC, this.isShowSingleLineLyric)
  7951. })
  7952. .width(50)
  7953. .height(30);
  7954. }
  7955. .height(55)
  7956. }
  7957. .backgroundColor(Color.Transparent)
  7958. .borderRadius(15)
  7959. .margin({
  7960. left: 30,
  7961. right: 30,
  7962. top: 10,
  7963. bottom: 10
  7964. })
  7965. .padding(0)
  7966. .border({
  7967. color: Color.White,
  7968. width: 1.8
  7969. })
  7970. }
  7971. Row() {
  7972. Text(`歌词居中:`)
  7973. .fontSize(14)
  7974. .fontColor(Color.White)
  7975. .margin({ left: 2 })
  7976. Row() {
  7977. ForEach(['居中', '居左'], (size: string, index: number) => {
  7978. Button(size)
  7979. .width(60)
  7980. .height(28)
  7981. .fontSize(12)
  7982. .fontColor('#FFFFFF')
  7983. .backgroundColor((!isPip && this.currentLyricAlignMode === index) ||
  7984. (isPip && this.currentLyricAlignModePip === index) ? this.themeColor : Color.Transparent)
  7985. .border({
  7986. color: (!isPip && this.currentLyricAlignMode === index) ||
  7987. (isPip && this.currentLyricAlignModePip === index) ?
  7988. '#007DFF' : '#DDDDDD',
  7989. width: 1.8
  7990. })
  7991. .onClick(() => {
  7992. this.setLyricAlignMode(index, isPip)
  7993. })
  7994. .margin({ left: 10, right: 8 })
  7995. })
  7996. }
  7997. .width('76%')
  7998. Blank()
  7999. }
  8000. .margin({
  8001. top: 10,
  8002. bottom: 10,
  8003. right: 20,
  8004. left: 20
  8005. })
  8006. if (isPip) {
  8007. Row() {
  8008. Text(`悬浮背景:`)
  8009. .fontSize(14)
  8010. .fontColor(Color.White)
  8011. Select([
  8012. { value: CommonConstants.PIP_LYRIC_BG[0] },
  8013. { value: CommonConstants.PIP_LYRIC_BG[1] }])
  8014. .font({ size: 13, weight: FontWeight.Medium })
  8015. .fontColor(Color.White)
  8016. .margin({ left: 10 })
  8017. .selected(this.pipBgIndex)
  8018. .value(CommonConstants.PIP_LYRIC_BG[this.pipBgIndex])
  8019. .onSelect(async (_index: number, text?: string | undefined) => {
  8020. this.pipBgIndex = _index
  8021. PreferencesUtil.put('pipBgIndex', this.pipBgIndex)
  8022. if (this.pipBgIndex === 0) {
  8023. if (this.cover) {
  8024. this.pipBg = this.cover
  8025. } else {
  8026. this.pipBg = this.imageColor
  8027. }
  8028. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  8029. } else {
  8030. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  8031. }
  8032. })
  8033. Column() {
  8034. }
  8035. .backgroundColor(this.pipBg)
  8036. .margin({ left: 10, right: 10 })
  8037. .borderRadius(20)
  8038. .height(28)
  8039. .width(28)
  8040. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8041. Row() {
  8042. SymbolGlyph($r('sys.symbol.paintbrush'))
  8043. .fontColor([Color.White])
  8044. .effectStrategy(1)
  8045. Text(`选择颜色`)
  8046. .fontSize(13)
  8047. .margin({ left: 10 })
  8048. .fontColor(Color.White)
  8049. }
  8050. }
  8051. .visibility(this.pipBgIndex === 1 ? Visibility.Visible : Visibility.None)
  8052. .backgroundColor(Color.Transparent)
  8053. .border({
  8054. color: '#FFFFFF',
  8055. radius: 20,
  8056. width: 1.8
  8057. })
  8058. .height(36)
  8059. .width(110)
  8060. .onClick(() => {
  8061. this.isShowPipBgSelectColor = !this.isShowPipBgSelectColor
  8062. })
  8063. .bindPopup(this.isShowPipBgSelectColor, {
  8064. builder: this.SelectColor(false, isPip, true),
  8065. placement: Placement.Top,
  8066. mask: { color: '#33000000' },
  8067. enableArrow: false, //是否显示箭头
  8068. showInSubWindow: false,
  8069. onStateChange: (e) => {
  8070. if (!e.isVisible) {
  8071. this.isShowPipBgSelectColor = false
  8072. }
  8073. }
  8074. })
  8075. }
  8076. .width('76%')
  8077. .margin({ bottom: 5, right: 45, left: 20 })
  8078. }
  8079. if (!isPip) {
  8080. Row() {
  8081. Text(`高亮居中:`)
  8082. .fontSize(14)
  8083. .fontColor(Color.White)
  8084. Column() {
  8085. Toggle({ type: ToggleType.Switch, isOn: this.isHightLightCenter })
  8086. .selectedColor(this.themeColor)
  8087. .switchPointColor(Color.White)
  8088. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8089. .onChange((checked: boolean) => {
  8090. this.isHightLightCenter = checked;
  8091. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isHightLightCenter)
  8092. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  8093. })
  8094. .width(50)
  8095. .height(30)
  8096. .alignSelf(ItemAlign.Start)
  8097. .margin({ left: 12 })
  8098. Blank()
  8099. }
  8100. .width('76%')
  8101. }
  8102. .margin({
  8103. left: 20,
  8104. right: 15,
  8105. top: 10,
  8106. bottom: 10
  8107. })
  8108. }
  8109. Row() {
  8110. Text(`歌词颜色:`)
  8111. .fontSize(14)
  8112. .fontColor(Color.White)
  8113. Text(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  8114. .fontSize(15)
  8115. .fontColor(Color.White)
  8116. .margin({ left: 12, right: 12 })
  8117. Column() {
  8118. }
  8119. .backgroundColor(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  8120. .margin({ right: 12 })
  8121. .borderRadius(20)
  8122. .height(28)
  8123. .width(28)
  8124. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8125. Row() {
  8126. SymbolGlyph($r('sys.symbol.paintbrush'))
  8127. .fontColor([Color.White])
  8128. .effectStrategy(1)
  8129. Text(`选择颜色`)
  8130. .fontSize(13)
  8131. .margin({ left: 10 })
  8132. .fontColor(Color.White)
  8133. }
  8134. }
  8135. .backgroundColor(Color.Transparent)
  8136. .border({
  8137. color: '#FFFFFF',
  8138. radius: 20,
  8139. width: 1.8
  8140. })
  8141. .height(36)
  8142. .width(110)
  8143. .onClick(() => {
  8144. this.isShowSelectColor = !this.isShowSelectColor
  8145. })
  8146. .bindPopup(this.isShowSelectColor, {
  8147. builder: this.SelectColor(false, isPip),
  8148. placement: Placement.Top,
  8149. mask: { color: '#33000000' },
  8150. enableArrow: false, //是否显示箭头
  8151. showInSubWindow: false,
  8152. onStateChange: (e) => {
  8153. if (!e.isVisible) {
  8154. this.isShowSelectColor = false
  8155. }
  8156. }
  8157. })
  8158. }
  8159. .width('76%')
  8160. .margin({
  8161. top: 10,
  8162. bottom: 10,
  8163. right: 45,
  8164. left: 20
  8165. })
  8166. Row() {
  8167. Text(`高亮颜色:`)
  8168. .fontSize(14)
  8169. .fontColor(Color.White)
  8170. Text(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  8171. .fontSize(15)
  8172. .fontColor(Color.White)
  8173. .margin({ left: 12, right: 12 })
  8174. Column() {
  8175. }
  8176. .backgroundColor(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  8177. .margin({ right: 12 })
  8178. .borderRadius(20)
  8179. .height(28)
  8180. .width(28)
  8181. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8182. Row() {
  8183. SymbolGlyph($r('sys.symbol.paintbrush'))
  8184. .fontColor([Color.White])
  8185. .effectStrategy(1)
  8186. Text(`选择颜色`)
  8187. .fontSize(13)
  8188. .margin({ left: 10 })
  8189. .fontColor(Color.White)
  8190. }
  8191. }
  8192. .backgroundColor(Color.Transparent)
  8193. .border({
  8194. color: '#FFFFFF',
  8195. radius: 20,
  8196. width: 1.8
  8197. })
  8198. .height(36)
  8199. .width(110)
  8200. .onClick(() => {
  8201. this.isShowHLSelectColor = !this.isShowHLSelectColor
  8202. })
  8203. .bindPopup(this.isShowHLSelectColor, {
  8204. builder: this.SelectColor(true, isPip),
  8205. placement: Placement.Top,
  8206. mask: { color: '#33000000' },
  8207. enableArrow: false, //是否显示箭头
  8208. showInSubWindow: false,
  8209. onStateChange: (e) => {
  8210. if (!e.isVisible) {
  8211. this.isShowHLSelectColor = false
  8212. }
  8213. }
  8214. })
  8215. }
  8216. .width('76%')
  8217. .margin({
  8218. top: 10,
  8219. bottom: 10,
  8220. right: 45,
  8221. left: 20
  8222. })
  8223. if (isPip) {
  8224. Row() {
  8225. Text(`显示宽度:`)
  8226. .fontSize(14)
  8227. .fontColor(Color.White)
  8228. Slider({
  8229. value: this.pipLyWidth,
  8230. min: 10,
  8231. max: 800,
  8232. step: 1,
  8233. style: SliderStyle.OutSet
  8234. })
  8235. .blockColor(this.themeColor)
  8236. .trackColor($r('app.color.speed_text_color'))
  8237. .selectedColor(Color.White)
  8238. .trackThickness(6)
  8239. .onChange((value: number) => {
  8240. this.pipLyWidth = value
  8241. if (this.pipController) {
  8242. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8243. PreferencesUtil.putSync('pipLyWidth', this.pipLyWidth)
  8244. }
  8245. })
  8246. .width('76%')
  8247. }
  8248. .margin({
  8249. left: 20,
  8250. right: 15,
  8251. top: 5,
  8252. bottom: 5
  8253. })
  8254. Row() {
  8255. Text(`显示高度:`)
  8256. .fontSize(14)
  8257. .fontColor(Color.White)
  8258. Slider({
  8259. value: this.pipLyHeight,
  8260. min: 10,
  8261. max: 1000,
  8262. step: 1,
  8263. style: SliderStyle.OutSet
  8264. })
  8265. .blockColor(this.themeColor)
  8266. .trackColor($r('app.color.speed_text_color'))
  8267. .selectedColor(Color.White)
  8268. .trackThickness(6)
  8269. .onChange((value: number) => {
  8270. this.pipLyHeight = value
  8271. if (this.pipController) {
  8272. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8273. PreferencesUtil.putSync('pipLyHeight', this.pipLyHeight)
  8274. }
  8275. })
  8276. .width('76%')
  8277. }
  8278. .margin({
  8279. left: 20,
  8280. right: 15,
  8281. top: 5,
  8282. bottom: 5
  8283. })
  8284. }
  8285. Row() {
  8286. Text(`歌词字号:`)
  8287. .fontSize(14)
  8288. .fontColor(Color.White)
  8289. Slider({
  8290. value: isPip ? this.currentLyricSizePip : this.currentLyricSize,
  8291. min: 12,
  8292. max: 30,
  8293. step: 0.1,
  8294. style: SliderStyle.OutSet
  8295. })
  8296. .blockColor(this.themeColor)
  8297. .trackColor($r('app.color.speed_text_color'))
  8298. .selectedColor(Color.White)
  8299. .trackThickness(6)
  8300. .onChange((value: number) => {
  8301. this.setLyricTextSize(value, isPip)
  8302. })
  8303. .width('76%')
  8304. }
  8305. .margin({
  8306. left: 20,
  8307. right: 15,
  8308. top: 5,
  8309. bottom: 5
  8310. })
  8311. Row() {
  8312. Text(`高亮倍数:`)
  8313. .fontSize(14)
  8314. .fontColor(Color.White)
  8315. Slider({
  8316. value: isPip ? this.currentHightLyricSizePip : this.currentHightLyricSize,
  8317. min: 1,
  8318. max: 2,
  8319. step: 0.1,
  8320. style: SliderStyle.OutSet
  8321. })
  8322. .blockColor(this.themeColor)
  8323. .trackColor($r('app.color.speed_text_color'))
  8324. .selectedColor(Color.White)
  8325. .trackThickness(6)
  8326. .onChange((value: number) => {
  8327. this.setHighLyricTextSize(value, isPip)
  8328. })
  8329. .width('76%')
  8330. }
  8331. .margin({
  8332. left: 20,
  8333. right: 15,
  8334. top: 5,
  8335. bottom: 5
  8336. })
  8337. Row() {
  8338. Text(`歌词间隙:`)
  8339. .fontSize(14)
  8340. .fontColor(Color.White)
  8341. Slider({
  8342. value: isPip ? this.currentLyricLineSpacePip : this.currentLyricLineSpace,
  8343. min: 0,
  8344. max: 100,
  8345. step: 1,
  8346. style: SliderStyle.OutSet
  8347. })
  8348. .blockColor(this.themeColor)
  8349. .trackColor($r('app.color.speed_text_color'))
  8350. .selectedColor(Color.White)
  8351. .trackThickness(6)
  8352. .onChange((value: number) => {
  8353. this.setLyricLineSpace(value, isPip)
  8354. })
  8355. .width('76%')
  8356. }
  8357. .margin({
  8358. left: 20,
  8359. right: 15,
  8360. top: 5,
  8361. bottom: 5
  8362. })
  8363. //取值间隔为100,默认为400,取值越大,字体越粗
  8364. Row() {
  8365. Text(`歌词字重:`)
  8366. .fontSize(14)
  8367. .fontColor(Color.White)
  8368. Slider({
  8369. value: isPip ? this.lyricTextWeightPip : this.lyricTextWeight,
  8370. min: 100,
  8371. max: 900,
  8372. step: 100,
  8373. style: SliderStyle.OutSet
  8374. })
  8375. .blockColor(this.themeColor)
  8376. .trackColor($r('app.color.speed_text_color'))
  8377. .selectedColor(Color.White)
  8378. .trackThickness(6)
  8379. .onChange((value: number) => {
  8380. if (isPip) {
  8381. this.lyricTextWeightPip = value
  8382. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  8383. PreferencesUtil.putSync('lyricTextWeightPip', this.lyricTextWeightPip)
  8384. } else {
  8385. this.lyricTextWeight = value
  8386. this.lyricController.setTextWeight(this.lyricTextWeight)
  8387. PreferencesUtil.putSync('lyricTextWeight', this.lyricTextWeight)
  8388. }
  8389. })
  8390. .width('76%')
  8391. }
  8392. .margin({
  8393. left: 20,
  8394. right: 15,
  8395. top: 5,
  8396. bottom: 5
  8397. })
  8398. if (!isPip) {
  8399. Row() {
  8400. Text(`歌词模糊:`)
  8401. .fontSize(14)
  8402. .fontColor(Color.White)
  8403. Slider({
  8404. value: isPip ? this.blurDegreePip : this.blurDegree,
  8405. min: 0,
  8406. max: 5,
  8407. step: 0.1,
  8408. style: SliderStyle.OutSet
  8409. })
  8410. .blockColor(this.themeColor)
  8411. .trackColor($r('app.color.speed_text_color'))
  8412. .selectedColor(Color.White)
  8413. .trackThickness(6)
  8414. .onChange((value: number) => {
  8415. this.setBlurDegree(value, isPip)
  8416. })
  8417. .width('76%')
  8418. }
  8419. .margin({
  8420. left: 20,
  8421. right: 15,
  8422. top: 5,
  8423. bottom: 15
  8424. })
  8425. }
  8426. Row() {
  8427. this.pushLyricButton($r('app.media.cut_current'), 0, '本地歌词')
  8428. this.pushLyricButton($r('app.media.white_search'), 1, '获取歌词')
  8429. }
  8430. .justifyContent(FlexAlign.Center)
  8431. .margin({ top: 3, bottom: 10 })
  8432. }
  8433. }
  8434. private setBlurDegree(index: number, isPip: boolean) {
  8435. if (isPip) {
  8436. this.blurDegreePip = index
  8437. this.lyricControllerXF.setBlurDegree(this.blurDegreePip)
  8438. PreferencesUtil.putSync('setBlurDegreePip', this.blurDegreePip)
  8439. } else {
  8440. this.blurDegree = index
  8441. this.lyricController.setBlurDegree(this.blurDegree)
  8442. PreferencesUtil.putSync('setBlurDegree', this.blurDegree)
  8443. }
  8444. }
  8445. private setLyricAlignMode(index: number, isPip: boolean) {
  8446. if (isPip) {
  8447. this.currentLyricAlignModePip = index
  8448. if (this.currentLyricAlignModePip === 1) {
  8449. this.lyricControllerXF.setAlignMode("left")
  8450. } else {
  8451. this.lyricControllerXF.setAlignMode("center")
  8452. }
  8453. PreferencesUtil.putSync('LyricAlignModePip', this.currentLyricAlignModePip)
  8454. } else {
  8455. this.currentLyricAlignMode = index
  8456. if (this.currentLyricAlignMode === 1) {
  8457. this.lyricController.setAlignMode("left")
  8458. } else {
  8459. this.lyricController.setAlignMode("center")
  8460. }
  8461. PreferencesUtil.putSync('LyricAlignMode', this.currentLyricAlignMode)
  8462. }
  8463. }
  8464. private setLyricTextSize(index: number, isPip: boolean) {
  8465. if (isPip) {
  8466. this.currentLyricSizePip = index
  8467. this.lyricControllerXF.setTextSize(this.currentLyricSizePip)
  8468. PreferencesUtil.putSync('LyricTextSizePip', this.currentLyricSizePip)
  8469. } else {
  8470. this.currentLyricSize = index
  8471. this.lyricController.setTextSize(this.currentLyricSize)
  8472. PreferencesUtil.putSync('LyricTextSize', this.currentLyricSize)
  8473. }
  8474. }
  8475. private setHighLyricTextSize(scale: number, isPip: boolean) {
  8476. if (isPip) {
  8477. this.currentHightLyricSizePip = scale
  8478. this.lyricControllerXF
  8479. .setHighlightScale(this.currentHightLyricSizePip)
  8480. PreferencesUtil.putSync('HighLyricTextSizePip', scale)
  8481. } else {
  8482. this.currentHightLyricSize = scale
  8483. this.lyricController
  8484. .setHighlightScale(this.currentHightLyricSize)
  8485. PreferencesUtil.putSync('HighLyricTextSize', scale)
  8486. }
  8487. }
  8488. private setLyricLineSpace(index: number, isPip: boolean) {
  8489. if (isPip) {
  8490. this.currentLyricLineSpacePip = index
  8491. this.lyricControllerXF.setLineSpace(this.currentLyricLineSpacePip)
  8492. PreferencesUtil.putSync('LyricLineSpacePip', this.currentLyricLineSpacePip)
  8493. } else {
  8494. this.currentLyricLineSpace = index
  8495. this.lyricController.setLineSpace(this.currentLyricLineSpace)
  8496. PreferencesUtil.putSync('LyricLineSpace', this.currentLyricLineSpace)
  8497. }
  8498. }
  8499. private changeLyricColor(color: string, isPip: boolean, isBG?: boolean) {
  8500. LogUtil.info('onecold isBG = ' + isBG)
  8501. if (isBG) { //如果是设置悬浮背景
  8502. this.pipBg = color
  8503. PreferencesUtil.putSync('BGColorPip', this.pipBg)
  8504. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  8505. return
  8506. }
  8507. if (isPip) {
  8508. this.currentLyricColorPip = color
  8509. this.lyricControllerXF
  8510. .setTextColor(this.currentLyricColorPip)
  8511. PreferencesUtil.putSync('LyricColorPip', this.currentLyricColorPip)
  8512. } else {
  8513. this.currentLyricColor = color
  8514. this.lyricController
  8515. .setTextColor(this.currentLyricColor)
  8516. PreferencesUtil.putSync('LyricColor', this.currentLyricColor)
  8517. }
  8518. }
  8519. private changeLyricHightLightColor(color: string, isPip: boolean) {
  8520. if (isPip) {
  8521. this.currentHighLightLyricColorPip = color
  8522. this.lyricControllerXF
  8523. .setHighlightColor(this.currentHighLightLyricColorPip)
  8524. PreferencesUtil.putSync('LyricHighLightColorPip', this.currentHighLightLyricColorPip)
  8525. } else {
  8526. this.currentHighLightLyricColor = color
  8527. this.lyricController
  8528. .setHighlightColor(this.currentHighLightLyricColor)
  8529. PreferencesUtil.putSync('LyricHighLightColor', this.currentHighLightLyricColor)
  8530. }
  8531. }
  8532. // 构建时间控制器
  8533. @Builder
  8534. BuildTimeControls() {
  8535. Column() {
  8536. // 时间显示
  8537. Text(this.getTimeText())
  8538. .fontSize(18)
  8539. .fontColor(Color.White)
  8540. .margin({ bottom: 10 })
  8541. Row() {
  8542. this.PrecisionTimeButton($r('app.media.ic_previous'), -0.5, ' -0.5s ')
  8543. this.PrecisionTimeButton($r('app.media.loop'), 0, '重置')
  8544. this.PrecisionTimeButton($r('app.media.ic_next'), 0.5, ' +0.5s ')
  8545. }
  8546. .justifyContent(FlexAlign.Center)
  8547. }
  8548. .margin({ top: 12, bottom: 8 })
  8549. }
  8550. // 精度按钮组件
  8551. @Builder
  8552. PrecisionTimeButton(icon: Resource, step: number, label: string) {
  8553. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8554. Column() {
  8555. Image(icon)
  8556. .width(28)
  8557. .margin({ bottom: 5 })
  8558. .opacity(this.isButtonDisabled(step) ? 0.5 : 1)
  8559. Text(label)
  8560. .fontSize(12)
  8561. .fontColor('#FFFFFF')
  8562. }
  8563. }
  8564. .backgroundColor(Color.Transparent)
  8565. .enabled(!this.isButtonDisabled(step))
  8566. .onClick(() => this.handlePrecisionAdjust(step))
  8567. .padding(5)
  8568. .width(66)
  8569. .height(66)
  8570. .margin({ left: 18, right: 18 })
  8571. .border({
  8572. color: '#FFFFFF',
  8573. width: 1.8
  8574. })
  8575. }
  8576. private handlePrecisionAdjust(step: number) {
  8577. if (step === 0) {
  8578. this.timeOffset = 0
  8579. return
  8580. }
  8581. // 精度处理:保留1位小数
  8582. const newOffset = Number((this.timeOffset + step).toFixed(5))
  8583. // 边界保护(±15.0秒)
  8584. if (newOffset < -30.0 || newOffset > 30.0) {
  8585. // this.triggerEdgeFeedback(newOffset) // 触发边界反馈
  8586. return
  8587. }
  8588. // 状态更新
  8589. this.timeOffset = newOffset
  8590. }
  8591. // 按钮禁用逻辑
  8592. private isButtonDisabled(step: number): boolean {
  8593. const futureOffset = this.timeOffset + step
  8594. return (futureOffset < -30.0) || (futureOffset > 30.0)
  8595. }
  8596. // 时间显示文本升级
  8597. private getTimeText(): string {
  8598. const absValue = Math.abs(this.timeOffset)
  8599. return this.timeOffset === 0
  8600. ? '歌词时间已重置'
  8601. : `歌词已${this.timeOffset < 0 ? '延后' : '提前'} ${absValue.toFixed(1)} 秒`
  8602. }
  8603. // 导入 本地歌词 搜索歌词
  8604. @Builder
  8605. pushLyricButton(icon: Resource, step: number, label: string) {
  8606. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8607. Row() {
  8608. Image(icon)
  8609. .width(14)
  8610. .margin({ left: 13 })
  8611. Text(label)
  8612. .fontSize(12)
  8613. .margin({ left: 6 })
  8614. .fontColor('#FFFFFF')
  8615. }
  8616. }
  8617. .onClick(() => {
  8618. switch (step) {
  8619. case 0:
  8620. this.callFilePickerSelectFileForLyric()
  8621. break;
  8622. case 1:
  8623. //判断有没有设置api
  8624. if (PreferencesUtil.getStringSync('LRC_API', '') === '') {
  8625. this.isLyricSetting = false
  8626. this.showTipsDialog()
  8627. return
  8628. }
  8629. if (StrUtil.isNotEmpty(this.videoUrl)) {
  8630. ToastUtil.showToast('正在获取')
  8631. this.isLyricSetting = false
  8632. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  8633. this.initLyric(lyricPath, true);
  8634. }
  8635. break;
  8636. }
  8637. })
  8638. .padding(5)
  8639. .width(110)
  8640. .backgroundColor(Color.Transparent)
  8641. .height(40)
  8642. .margin({ left: 6, right: 6 })
  8643. .border({
  8644. color: '#FFFFFF',
  8645. radius: 20,
  8646. width: 1.8
  8647. })
  8648. }
  8649. showVipDialog() {
  8650. DialogHelper.showCustomContentDialog({
  8651. dialogId: 'vip',
  8652. title: "友情提示",
  8653. autoCancel: false, //点击遮障层时,不关闭弹窗
  8654. backCancel: true, //点击返回键,不关闭弹窗
  8655. contentBuilder: () => {
  8656. this.customVipBuilder("该功能需开通会员,非常感谢您的支持!")
  8657. },
  8658. buttons: [],
  8659. })
  8660. }
  8661. //去赞助的自定义内容
  8662. @Builder
  8663. customVipBuilder(content: string) {
  8664. Column() {
  8665. Text(content)
  8666. .fontColor(Color.Gray)
  8667. .fontSize(16)
  8668. .alignSelf(ItemAlign.Start)
  8669. .margin({ bottom: 15 })
  8670. .fontSize(16)
  8671. Row() {
  8672. Button('取消')
  8673. .fontColor(Color.White)
  8674. .backgroundColor(this.themeColor)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  8675. .height(50)
  8676. .layoutWeight(1)
  8677. .stateEffect(true)
  8678. .margin({ right: 6 })
  8679. .onClick(() => {
  8680. DialogHelper.closeDialog('vip'); //关闭弹框
  8681. })
  8682. Button('开通')
  8683. .fontColor(Color.White)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  8684. .layoutWeight(1)
  8685. .height(50)
  8686. .backgroundColor(this.themeColor)
  8687. .stateEffect(true)
  8688. .margin({ left: 6 })
  8689. .onClick(() => {
  8690. DialogHelper.closeDialog('vip'); //关闭弹框
  8691. this.isShowPlay = false
  8692. this.mType = 1 //跳转到用户中心
  8693. // router.pushUrl({
  8694. // url: 'pages/VipPage'
  8695. // }, router.RouterMode.Single);
  8696. })
  8697. }
  8698. }
  8699. .width("100%")
  8700. .padding(10)
  8701. }
  8702. showTipsDialog() {
  8703. DialogHelper.showCustomContentDialog({
  8704. dialogId: 'tips',
  8705. title: "友情提示",
  8706. autoCancel: false, //点击遮障层时,不关闭弹窗
  8707. backCancel: true, //点击返回键,不关闭弹窗
  8708. contentBuilder: () => {
  8709. this.customTipsBuilder("请到设置界面配置API服务器地址!")
  8710. },
  8711. buttons: [],
  8712. })
  8713. }
  8714. @Builder
  8715. customTipsBuilder(content: string) {
  8716. Column() {
  8717. Text(content)
  8718. .fontColor(Color.Gray)
  8719. .fontSize(16)
  8720. .alignSelf(ItemAlign.Start)
  8721. .margin({ bottom: 15 })
  8722. .fontSize(16)
  8723. Row() {
  8724. Button('取消')
  8725. .fontColor(Color.White)
  8726. .backgroundColor(this.themeColor)
  8727. .height(50)
  8728. .layoutWeight(1)
  8729. .stateEffect(true)
  8730. .margin({ right: 6 })
  8731. .onClick(() => {
  8732. DialogHelper.closeDialog('tips'); //关闭弹框
  8733. })
  8734. Button('跳转')
  8735. .fontColor(Color.White)//
  8736. .layoutWeight(1)
  8737. .height(50)
  8738. .backgroundColor(this.themeColor)
  8739. .stateEffect(true)
  8740. .margin({ left: 6 })
  8741. .onClick(() => {
  8742. DialogHelper.closeDialog('tips'); //关闭弹框
  8743. this.isShowEdit = false
  8744. this.longItemFilePath = ''
  8745. // if(this.isGridMusic&&!this.isShowPlay){
  8746. // this.longItemFilePath== ''
  8747. // }else{
  8748. // this.isShowEdit = false
  8749. // }
  8750. this.isShowMoreView = false;
  8751. this.isShowPlay = false
  8752. this.mType = 4
  8753. // router.pushUrl({
  8754. // url: 'pages/SettingPage'
  8755. // }, router.RouterMode.Single);
  8756. })
  8757. }
  8758. }
  8759. .width("100%")
  8760. .padding(10)
  8761. }
  8762. @Builder
  8763. PlayMoreSheet() {
  8764. Column() {
  8765. this.MoreList()
  8766. }
  8767. .width('100%')
  8768. .height('100%')
  8769. }
  8770. @Builder
  8771. MoreList() {
  8772. Scroll() {
  8773. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  8774. ForEach(this.moreItems, (more: MoreItem, index: number) => {
  8775. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8776. Row() {
  8777. if (more.id === 3&&this.currentSong) {
  8778. Image(more.image)
  8779. .width(24)
  8780. .height(24)
  8781. .margin({ left: 10, right: 10 })
  8782. Text(more.title)
  8783. .fontSize(16)
  8784. .fontColor(Color.White)
  8785. .bindSheet($$this.isShowDetailMore, this.detailSheet(this.currentSong), {
  8786. height: this.isCoverOpacity() ? '95%' : '95%',
  8787. dragBar: true,
  8788. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8789. showClose: true,
  8790. blurStyle: BlurStyle.Thin,
  8791. backgroundColor: Color.Transparent,
  8792. title: { title: '歌曲信息' }
  8793. })
  8794. } else if (more.id === 15 && this.currentSong) { //编辑标签
  8795. Image(more.image)
  8796. .width(24)
  8797. .height(24)
  8798. .margin({ left: 10, right: 10 })
  8799. Text(more.title)
  8800. .fontSize(16)
  8801. .fontColor(Color.White)
  8802. .bindSheet($$this.isShowEdit, this.editSheet(this.currentSong), {
  8803. height: '99%',
  8804. dragBar: true,
  8805. showClose: true,
  8806. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8807. // blurStyle:BlurStyle.Thin,
  8808. // backgroundColor:Color.Transparent,
  8809. title: { title: '编辑标签' }
  8810. })
  8811. } else if (more.id === 5) { //定时关闭
  8812. Image(more.image)
  8813. .width(24)
  8814. .height(24)
  8815. .margin({ left: 10, right: 10 })
  8816. Text(more.title)
  8817. .fontSize(16)
  8818. .fontColor(Color.White)
  8819. .onClick(() => {
  8820. this.doMore(more.id)
  8821. })
  8822. .bindSheet($$this.isShowTimeCloseMore, this.TimeCloseSheet(), {
  8823. height: this.isCoverOpacity() ? '95%' : '95%',
  8824. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8825. dragBar: true,
  8826. showClose: true,
  8827. title: { title: $r('app.string.time_close') }
  8828. })
  8829. } else if (more.id === 2) { //歌词设置
  8830. Image(more.image)
  8831. .width(24)
  8832. .height(24)
  8833. .margin({ left: 10, right: 10 })
  8834. Text(more.title)
  8835. .fontSize(16)
  8836. .fontColor(Color.White)
  8837. } else if (more.id === 16) { //悬浮歌词设置
  8838. Image(more.image)
  8839. .width(24)
  8840. .height(24)
  8841. .margin({ left: 10, right: 10 })
  8842. Text(more.title)
  8843. .fontSize(16)
  8844. .fontColor(Color.White)
  8845. .bindSheet($$this.showPipLyric, this.lyricSettingSheet(true), {
  8846. height: this.isCoverOpacity() ? '95%' : '95%',
  8847. dragBar: true,
  8848. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8849. showClose: true,
  8850. blurStyle: BlurStyle.Thin,
  8851. backgroundColor: Color.Transparent,
  8852. title: { title: '悬浮歌词' }
  8853. })
  8854. } else if (more.id === 11) {
  8855. Image(more.image)
  8856. .width(24)
  8857. .height(24)
  8858. .margin({ left: 10, right: 10 })
  8859. Text(more.title)
  8860. .fontSize(16)
  8861. .fontColor(Color.White)
  8862. .bindSheet($$this.isJumpSetting, this.JumpTopEndSheet(), {
  8863. height: this.isCoverOpacity() ? '95%' : '60%',
  8864. dragBar: true,
  8865. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8866. showClose: true,
  8867. blurStyle: BlurStyle.Thin,
  8868. backgroundColor: Color.Transparent,
  8869. title: { title: '跳过头尾' }
  8870. })
  8871. } else if (more.id === 12) { //投播
  8872. AVCastPicker({
  8873. customPicker: (): void => this.TPImageBuilder(more),
  8874. onStateChange: (state) => {
  8875. if (state == AVCastPickerState.STATE_APPEARING) {
  8876. console.log(' The picker starts showing.');
  8877. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  8878. console.log(' The picker finishes presenting.');
  8879. }
  8880. },
  8881. pickerStyle: AVCastPickerStyle.STYLE_PANEL,
  8882. sessionType: 'video'
  8883. })
  8884. .id('AVCastPicker')
  8885. } else {
  8886. Image(more.image)
  8887. .width(24)
  8888. .height(24)
  8889. .margin({ left: 10, right: 10 })
  8890. .onClick(() => {
  8891. this.doMore(more.id)
  8892. })
  8893. Text(more.id == 17 ? (this.isLandscape ? '竖屏模式' : '横屏模式') : more.title)
  8894. .fontSize(16)
  8895. .fontColor(Color.White)
  8896. .onClick(() => {
  8897. this.doMore(more.id)
  8898. })
  8899. Select([//倍速
  8900. { value: '0.25x' },
  8901. { value: '0.5x' },
  8902. { value: '0.75x' },
  8903. { value: '1x' },
  8904. { value: '1.25x' },
  8905. { value: '1.5x' },
  8906. { value: '1.75x' },
  8907. { value: '2x' },
  8908. { value: '3x' }])
  8909. .font({ size: 16, weight: FontWeight.Medium })
  8910. .fontColor($r('sys.color.white'))
  8911. .margin({ left: 25 })
  8912. .visibility(more.id === 1 ? Visibility.Visible : Visibility.None)
  8913. .selected(CommonConstants.video_speed_list.indexOf(this.playSpeed))
  8914. .value(Utility.optimizedFormat(this.playSpeed))
  8915. .onSelect(async (_index: number, text?: string | undefined) => {
  8916. let speed = parseFloat(text?.replace('x', '') || '1');
  8917. if (!CommonConstants.video_speed_list.includes(speed)) {
  8918. speed = 1;
  8919. }
  8920. this.playSpeed = speed
  8921. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  8922. })
  8923. Slider({
  8924. value: this.volume,
  8925. min: 0,
  8926. max: 1,
  8927. step: 0.1,
  8928. style: SliderStyle.OutSet
  8929. })
  8930. .margin({ left: 18, right: 8 })
  8931. .blockColor(this.themeColor)
  8932. .trackColor($r('app.color.speed_text_color'))
  8933. .selectedColor(Color.White)
  8934. .trackThickness(9)
  8935. .visibility(more.id === 9 ? Visibility.Visible : Visibility.None)
  8936. .onChange((value: number) => {
  8937. this.volume = value;
  8938. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  8939. PreferencesUtil.putSync('DefalutVolume',this.volume)
  8940. })
  8941. .layoutWeight(1)
  8942. Blank()
  8943. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  8944. .selectedColor(this.themeColor)
  8945. .switchPointColor(Color.White)
  8946. .margin({ right: 15 })
  8947. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8948. .visibility(more.id == 6 ? Visibility.Visible : Visibility.None)
  8949. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8950. if (more.id == 6) {
  8951. this.isMusicMemoryPlay = checked;
  8952. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  8953. if (this.isMusicMemoryPlay) {
  8954. ToastUtil.showToast('记忆播放已开启')
  8955. } else {
  8956. ToastUtil.showToast('记忆播放已关闭')
  8957. }
  8958. }
  8959. })
  8960. .width(48)
  8961. .height(24);
  8962. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  8963. .selectedColor(this.themeColor)
  8964. .switchPointColor(Color.White)
  8965. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8966. .margin({ right: 15 })
  8967. .visibility(more.id == 7 ? Visibility.Visible : Visibility.None)
  8968. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8969. if (more.id == 7) {
  8970. this.isMusicBGCover = checked;
  8971. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  8972. if (this.isMusicBGCover) {
  8973. ToastUtil.showToast('播放背景随音乐封面已开启')
  8974. } else {
  8975. ToastUtil.showToast('播放背景随音乐封面已关闭')
  8976. }
  8977. }
  8978. })
  8979. .width(48)
  8980. .height(24);
  8981. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  8982. .selectedColor(this.themeColor)
  8983. .switchPointColor(Color.White)
  8984. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8985. .margin({ right: 15 })
  8986. .visibility(more.id == 8 ? Visibility.Visible : Visibility.None)
  8987. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8988. if (more.id == 8) {
  8989. this.isSavePlayMode = checked;
  8990. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  8991. if (this.isSavePlayMode) {
  8992. ToastUtil.showToast('保存播放模式已开启')
  8993. } else {
  8994. ToastUtil.showToast('保存播放模式已关闭')
  8995. }
  8996. }
  8997. })
  8998. .width(48)
  8999. .height(24);
  9000. Toggle({ type: ToggleType.Switch, isOn: this.isCoverRectangle })
  9001. .selectedColor(this.themeColor)
  9002. .switchPointColor(Color.White)
  9003. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  9004. .margin({ right: 15 })
  9005. .visibility(more.id == 13 ? Visibility.Visible : Visibility.None)
  9006. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  9007. if (more.id == 13) {
  9008. this.isCoverRectangle = checked;
  9009. PreferencesUtil.put(SettingPage.IS_COVER_RECTANGLE, this.isCoverRectangle)
  9010. if (this.isCoverRectangle) {
  9011. ToastUtil.showToast('封面方形已开启')
  9012. this.animationRoFun()
  9013. } else {
  9014. ToastUtil.showToast('封面圆形已开启')
  9015. this.animationRoFun()
  9016. }
  9017. }
  9018. })
  9019. .width(48)
  9020. .height(24);
  9021. }
  9022. }
  9023. .width('100%')
  9024. .height(45)
  9025. .padding(15)
  9026. .backgroundColor(Color.Transparent)
  9027. .borderRadius(12)
  9028. .margin({ bottom: 6 })
  9029. }
  9030. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.9 })
  9031. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  9032. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  9033. .backgroundColor(Color.Transparent)
  9034. .onClick(() => {
  9035. this.doMore(more.id)
  9036. })
  9037. });
  9038. }
  9039. .width('100%')
  9040. .padding(16)
  9041. }.margin({ bottom: 18 })
  9042. }
  9043. @Builder
  9044. TPImageBuilder(more: MoreItem): void {
  9045. Row() {
  9046. Image($r('app.media.tuoping'))
  9047. .width(22)
  9048. .height(22)
  9049. .margin({ left: 10, right: 10 })
  9050. Text(more.title)
  9051. .fontSize(16)
  9052. .fontColor(Color.White)
  9053. }
  9054. .width('100%')
  9055. .layoutWeight(1)
  9056. .alignItems(VerticalAlign.Center)
  9057. .justifyContent(FlexAlign.Start)
  9058. }
  9059. private moreItems: MoreItem[] = [
  9060. { id: 1, image: $r('app.media.speed'), title: '倍速' },
  9061. { id: 2, image: $r('app.media.lyric'), title: '歌词' },
  9062. { id: 17, image: $r('app.media.full_4'), title: '横屏模式' },
  9063. { id: 16, image: $r('app.media.hua_zhong_hua'), title: '悬浮歌词' },
  9064. { id: 14, image: $r('app.media.cover_online'), title: '获取封面' },
  9065. { id: 15, image: $r('app.media.rename2'), title: '编辑标签' },
  9066. { id: 5, image: $r('app.media.time_close'), title: '定时关闭' },
  9067. { id: 10, image: $r('app.media.ring_tone'), title: '设为铃声' },
  9068. { id: 11, image: $r('app.media.time_close'), title: '跳过头尾' },
  9069. { id: 12, image: $r('app.media.toubo'), title: '投播' },
  9070. { id: 3, image: $r('app.media.hua_zhong_hua'), title: '详情' },
  9071. { id: 4, image: $r('app.media.share2'), title: '分享' },
  9072. { id: 9, image: $r('app.media.volume_white'), title: '调整音量' },
  9073. // { id: 6, image: $r('app.media.memory'), title: '记忆播放' },
  9074. { id: 13, image: $r('app.media.rectangle'), title: '封面方形' },
  9075. { id: 8, image: $r('app.media.cut_current'), title: '保存播放模式' },
  9076. { id: 7, image: $r('app.media.playlist2'), title: '播放背景随音乐封面' },
  9077. ];
  9078. @State isShowMoreView: boolean = false;
  9079. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  9080. @State isShowTimeCloseMore: boolean = false
  9081. @State isShowDetailMore: boolean = false
  9082. @State isMusicBGCover: boolean = true
  9083. @State isSavePlayMode: boolean = true
  9084. @State isLyricSetting: boolean = false
  9085. @State isJumpSetting: boolean = false
  9086. @State isShowEdit: boolean = false
  9087. @State showPipLyric: boolean = false
  9088. async setRingTone() {
  9089. if (StrUtil.isEmpty(this.videoUrl) || StrUtil.isEmpty(this.name)) {
  9090. return
  9091. }
  9092. // 确定后的逻辑
  9093. let ringtoneTypeList: Array<ringtone.RingtoneType> = ringtone.getSupportedRingtoneTypes();
  9094. LogUtil.info('onecold getSupportedRingtoneTypes : ' + JSON.stringify(ringtoneTypeList));
  9095. let dataTypeList: Array<uniformTypeDescriptor.UniformDataType> =
  9096. ringtone.getSupportedDataTypes(ringtone.RingtoneType.NOTIFICATION);
  9097. LogUtil.info('onecold getSupportedDataTypes: ' + JSON.stringify(dataTypeList));
  9098. //let fileName: string = audioPath.substring(audioPath.lastIndexOf('/') + 1, audioPath.lastIndexOf('.'));
  9099. await ringtone.startRingtoneSetting(getContext(this) as common.UIAbilityContext
  9100. , this.videoUrl, this.name).then(res => {
  9101. LogUtil.info('onecold setFlag :' + res);
  9102. });
  9103. }
  9104. doMore(moreId: number) {
  9105. switch (moreId) {
  9106. case 2: //歌词
  9107. this.isLyricSetting = !this.isLyricSetting;
  9108. this.isShowMoreView = false
  9109. break;
  9110. case 3: //详情
  9111. this.isShowDetailMore = !this.isShowDetailMore;
  9112. break;
  9113. case 4: //分享
  9114. if (this.currentSong !== undefined) {
  9115. Utility.doShareMusic(this.currentSong, getContext(this) as common.UIAbilityContext)
  9116. }
  9117. this.isShowMoreView = false
  9118. break;
  9119. case 5: //定时关闭
  9120. this.isShowTimeCloseMore = !this.isShowTimeCloseMore;
  9121. break;
  9122. case 10: //设为铃声
  9123. this.setRingTone()
  9124. this.isShowMoreView = false
  9125. break;
  9126. case 11: //跳过头尾
  9127. this.isJumpSetting = !this.isJumpSetting;
  9128. break;
  9129. case 13: //倍速
  9130. break;
  9131. case 14: //搜索封面
  9132. if (this.currentSong !== undefined) {
  9133. this.doSearchCover(this.currentSong)
  9134. }
  9135. this.isShowMoreView = false
  9136. break;
  9137. case 15: //编辑标签
  9138. this.setEditStrEmpty()
  9139. this.tempLyricContent = this.lyricContent
  9140. this.isShowEdit = !this.isShowEdit;
  9141. break;
  9142. case 16: //悬浮歌词
  9143. this.showPipLyric = !this.showPipLyric;
  9144. break;
  9145. case 17: //横屏模式
  9146. if (this.isLandscape) {
  9147. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  9148. } else {
  9149. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  9150. }
  9151. this.isShowMoreView = false
  9152. break;
  9153. }
  9154. }
  9155. /**
  9156. * 切换横竖屏
  9157. *
  9158. */
  9159. setOrientation(orientation: number) {
  9160. this.windowClass.setPreferredOrientation(orientation).then(() => {
  9161. Logger.info('setWindowOrientation: ' + orientation + ' Succeeded.');
  9162. }).catch((err: BusinessError) => {
  9163. Logger.info('setWindowOrientation: ' + orientation + ' Failed. Cause: ' + JSON.stringify(err));
  9164. });
  9165. }
  9166. /**
  9167. * 画中画功能(悬浮歌词功能)
  9168. *
  9169. */
  9170. private nodeController: TextNodeController = new TextNodeController('#000000', this.lyricControllerXF);
  9171. pipController?: PiPWindow.PiPController;
  9172. navigationId: string = '';
  9173. @State curState: string = '';
  9174. @State curError: ResourceStr = '';
  9175. @State pipBg: string = '#E8E8E8'
  9176. @State buttonAction: string = '';
  9177. //开启画中画功能
  9178. async startPip() {
  9179. this.nodeController = new TextNodeController(this.pipBg, this.lyricControllerXF);
  9180. if (!this.pipController) {
  9181. await this.createPipController();
  9182. }
  9183. if (!this.pipController) {
  9184. Logger.info(`[${TAG}] pipController create error`);
  9185. return;
  9186. }
  9187. await this.pipController.startPiP();
  9188. }
  9189. async stopPip() {
  9190. if (!this.pipController) {
  9191. Logger.info(`[${TAG}] pipController is not exist`);
  9192. return;
  9193. }
  9194. this.isOpenPip = false
  9195. await this.pipController.stopPiP();
  9196. }
  9197. async createPipController() {
  9198. this.pipController = await PiPWindow.create({
  9199. context: getContext(this),
  9200. componentController: this.xcomponentController,
  9201. navigationId: this.navigationId,
  9202. templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY,
  9203. controlGroups: [PiPWindow.VideoPlayControlGroup.VIDEO_PREVIOUS_NEXT],
  9204. customUIController: this.nodeController,
  9205. });
  9206. this.pipLyWidth = PreferencesUtil.getNumberSync('pipLyWidth', 330)
  9207. this.pipLyHeight = PreferencesUtil.getNumberSync('pipLyHeight', 120)
  9208. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  9209. this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => {
  9210. this.onStateChange(state, reason);
  9211. });
  9212. this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => {
  9213. this.onActionEvent(event, status);
  9214. });
  9215. }
  9216. destroyPipController() {
  9217. if (!this.pipController) {
  9218. return;
  9219. }
  9220. this.pipController.off('stateChange');
  9221. this.pipController.off('controlPanelActionEvent');
  9222. this.pipController = undefined;
  9223. }
  9224. onStateChange(state: PiPWindow.PiPState, reason: string) {
  9225. switch (state) {
  9226. case PiPWindow.PiPState.ABOUT_TO_START:
  9227. this.curState = 'ABOUT_TO_START';
  9228. this.curError = $r('app.string.current_error_hint');
  9229. break;
  9230. case PiPWindow.PiPState.STARTED:
  9231. this.curState = 'STARTED';
  9232. this.curError = $r('app.string.current_error_hint');
  9233. break;
  9234. case PiPWindow.PiPState.ABOUT_TO_STOP:
  9235. this.curState = 'ABOUT_TO_STOP';
  9236. this.curError = $r('app.string.current_error_hint');
  9237. break;
  9238. case PiPWindow.PiPState.STOPPED:
  9239. this.curState = 'STOPPED';
  9240. this.curError = $r('app.string.current_error_hint');
  9241. this.stopPip()
  9242. this.destroyPipController()
  9243. break;
  9244. case PiPWindow.PiPState.ABOUT_TO_RESTORE:
  9245. this.curState = 'ABOUT_TO_RESTORE';
  9246. this.curError = $r('app.string.current_error_hint');
  9247. break;
  9248. case PiPWindow.PiPState.ERROR:
  9249. this.curState = 'ERROR';
  9250. this.curError = reason;
  9251. break;
  9252. default:
  9253. break;
  9254. }
  9255. Logger.info(`[${TAG}] onecold onStateChange: ${this.curState}, reason: ${reason}`);
  9256. }
  9257. onActionEvent(event: PiPWindow.PiPActionEventType, status: number | undefined) {
  9258. LogUtil.info('onecold onActionEvent = ' + event + ' status=' + status)
  9259. switch (event) {
  9260. case 'playbackStateChanged':
  9261. if (status === 0) {
  9262. this.pause();
  9263. } else {
  9264. console.info('onecold startPlayOrResumePlay 9869')
  9265. this.startPlayOrResumePlay();
  9266. }
  9267. break;
  9268. case 'nextVideo':
  9269. // 切换到下一个视频
  9270. this.playNext()
  9271. break;
  9272. case 'previousVideo':
  9273. // 切换到上一个视频
  9274. this.playPrevious()
  9275. break;
  9276. case 'previousVideo':
  9277. // 切换到上一个视频
  9278. this.playPrevious()
  9279. break;
  9280. default:
  9281. }
  9282. this.buttonAction = event + `-status:${status}`;
  9283. Logger.info(`[${TAG}] onActionEvent: ${this.buttonAction} status:${status}}`);
  9284. }
  9285. /**
  9286. * 画中画功能(悬浮歌词功能)结束
  9287. *
  9288. */
  9289. async doSearchCover(item: VideoItem): Promise<string> {
  9290. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  9291. this.isShowMoreView = false;
  9292. this.showTipsDialog();
  9293. return ''; // Return empty string when no API is configured
  9294. }
  9295. if (!item) {
  9296. return ''; // Return empty string if item is undefined
  9297. }
  9298. const artist = item?.artist || ''; // Use empty string if artist is missing
  9299. return this.searchCover(item, item.name, artist); // Await is not needed here as we return the promise directly
  9300. }
  9301. /**
  9302. *api搜索封面
  9303. *item,根据title和artist
  9304. */
  9305. searchCover(item: VideoItem, title: string, artist: string): Promise<string> {
  9306. return NetAxiosUtil.getLyricCover(title, artist, PreferencesUtil.getStringSync('COVER_API', '')).then(async (res) => {
  9307. LogUtil.debug("onecold res =" + res);
  9308. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  9309. if (item.filePath == this.currentSong?.filePath) {
  9310. this.cover = res;
  9311. if (this.currentSong) {
  9312. this.currentSong.pixelMapPath = res;
  9313. }
  9314. }
  9315. // Update pixel map path but always return res regardless of success
  9316. this.table.updatePixelMapPath(item.filePath, res, (success: boolean, error?: string) => {
  9317. if (success) {
  9318. this.doUpdateData();
  9319. console.log("onecold 更新音乐封面成功,数据库已同步");
  9320. } else {
  9321. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  9322. }
  9323. // Note: We don't resolve/reject here because we already returned res
  9324. });
  9325. LogUtil.debug("onecold this.cover =" + this.cover);
  9326. }
  9327. return res; // Always return res regardless of updatePixelMapPath result
  9328. });
  9329. }
  9330. @State jumpTopTime: number = 0
  9331. @State jumpEndTime: number = 0
  9332. @State isOpenJump: boolean = false
  9333. @Builder
  9334. JumpTopEndSheet() {
  9335. Scroll() {
  9336. Column() {
  9337. Column() {
  9338. Text('仅对本播放列表有效')
  9339. .fontSize(16)
  9340. .fontColor($r('app.color.text_color'))
  9341. // 跳过头尾
  9342. Column() {
  9343. Row() {
  9344. Text('跳过片头:')
  9345. .fontSize(16)
  9346. .fontColor($r('app.color.text_color'))
  9347. Text(this.jumpTopTime + 's')
  9348. .fontSize(16)
  9349. .fontColor($r('app.color.text_color'))
  9350. }
  9351. .margin({ bottom: 5 })
  9352. Row() {
  9353. Slider({
  9354. value: this.jumpTopTime,
  9355. min: 0,
  9356. max: 120,
  9357. step: 1,
  9358. style: SliderStyle.OutSet
  9359. })
  9360. .blockColor(this.themeColor)
  9361. .trackColor($r('app.color.speed_text_color'))
  9362. .selectedColor(Color.White)
  9363. .trackThickness(8)
  9364. .onChange((value: number) => {
  9365. this.jumpTopTime = value;
  9366. })
  9367. .width('85%')
  9368. }
  9369. .alignItems(VerticalAlign.Top)
  9370. }
  9371. .margin({ top: 10, bottom: 10 })
  9372. // 跳过头尾
  9373. Column() {
  9374. Row() {
  9375. Text('跳过片尾:')
  9376. .fontSize(16)
  9377. .fontColor($r('app.color.text_color'))
  9378. Text(this.jumpEndTime + 's')
  9379. .fontSize(16)
  9380. .fontColor($r('app.color.text_color'))
  9381. }
  9382. .margin({ bottom: 5 })
  9383. Row() {
  9384. Slider({
  9385. value: this.jumpEndTime,
  9386. min: 0,
  9387. max: 120,
  9388. step: 1,
  9389. style: SliderStyle.OutSet
  9390. })
  9391. .blockColor(this.themeColor)
  9392. .trackColor($r('app.color.speed_text_color'))
  9393. .selectedColor(Color.White)
  9394. .trackThickness(8)
  9395. .onChange((value: number) => {
  9396. this.jumpEndTime = value;
  9397. })
  9398. .width('85%')
  9399. }
  9400. .alignItems(VerticalAlign.Top)
  9401. }
  9402. .margin({ top: 10, bottom: 10 })
  9403. Row() {
  9404. Button('保存设置')
  9405. .fontColor(Color.White)
  9406. .layoutWeight(1)
  9407. .height(40)
  9408. .width(80)
  9409. .backgroundColor(this.themeColor)
  9410. .stateEffect(true)
  9411. .margin({ left: 0, bottom: 20 })
  9412. .onClick(async () => {
  9413. if (!Utility.isNoble()) {
  9414. this.isJumpSetting = false
  9415. this.isShowMoreView = false
  9416. this.showVipDialog()
  9417. return
  9418. }
  9419. if (this.currentSong === undefined) {
  9420. return
  9421. }
  9422. if (this.modeType === 0) {
  9423. let parentPath = FileUtil.getParentPath(this.videoUrl)
  9424. PreferencesUtil.putSync(parentPath + 'isOpenJump', true)
  9425. PreferencesUtil.putSync(parentPath + 'jumpEndTime', this.jumpEndTime)
  9426. PreferencesUtil.putSync(parentPath + 'jumpTopTime', this.jumpTopTime)
  9427. } else if (this.modeType === 1) { //媒体库
  9428. PreferencesUtil.putSync(1 + 'isOpenJump', true)
  9429. PreferencesUtil.putSync(1 + 'jumpEndTime', this.jumpEndTime)
  9430. PreferencesUtil.putSync(1 + 'jumpTopTime', this.jumpTopTime)
  9431. } else if (this.modeType === 2) { //艺术家
  9432. if (this.currentSong?.artist) {
  9433. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'isOpenJump', true)
  9434. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpEndTime', this.jumpEndTime)
  9435. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpTopTime', this.jumpTopTime)
  9436. }
  9437. } else if (this.modeType === 3) { //专辑
  9438. if (this.currentSong?.album) {
  9439. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'isOpenJump', true)
  9440. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpEndTime', this.jumpEndTime)
  9441. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpTopTime', this.jumpTopTime)
  9442. }
  9443. }
  9444. ToastUtil.showShort("保存成功")
  9445. this.isJumpSetting = false
  9446. })
  9447. }
  9448. .margin({
  9449. left: 38,
  9450. right: 38,
  9451. top: 10,
  9452. bottom: 10
  9453. })
  9454. .width(120)
  9455. .height(50)
  9456. }
  9457. }
  9458. }
  9459. .width('100%')
  9460. .height('100%')
  9461. }
  9462. // 应用可以通过onStateChange接口监听组件显示/消失状态,当组件显示时建议不要销毁AVCastPicker的显示;当组件消失时,再根据业务隐藏AVCastPicker。
  9463. private onStateVastChange(state: AVCastPickerState) {
  9464. if (state == AVCastPickerState.STATE_APPEARING) {
  9465. console.log('The picker starts showing.');
  9466. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  9467. console.log('The picker finishes presenting.');
  9468. }
  9469. }
  9470. private showSelectLyric() {
  9471. DialogHelper.showActionSheetDialog({
  9472. title: '温馨提醒:\n1.歌词文件名必须和目标歌曲文件名相同\n2.歌词文件和目标歌曲要同个歌单路径。',
  9473. // sheets: ["本地歌词", "搜索歌词"],
  9474. sheets: [
  9475. { value: "本地歌词", fontColor: $r('app.color.text_color') },
  9476. { value: "搜索歌词", fontColor: $r('app.color.text_color') },
  9477. ],
  9478. maskColor: Color.Transparent,
  9479. backgroundColor: $r('app.color.bg_card'),
  9480. transition: AnimationHelper.transitionInDown(666),
  9481. onAction: (index) => {
  9482. switch (index) {
  9483. case 0:
  9484. this.callFilePickerSelectFileForLyric()
  9485. break;
  9486. case 1:
  9487. if (StrUtil.isNotEmpty(this.videoUrl)) {
  9488. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  9489. this.initLyric(lyricPath);
  9490. }
  9491. break;
  9492. }
  9493. }
  9494. })
  9495. }
  9496. // 拉起picker选择文件管理器
  9497. async callFilePickerSelectFileForLyric(): Promise<void> {
  9498. try {
  9499. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  9500. DocumentSelectOptions.maxSelectNumber = 1
  9501. DocumentSelectOptions.fileSuffixFilters = CommonConstants.LYRIC_FORMAT
  9502. let documentPicker = new picker.DocumentViewPicker();
  9503. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  9504. Logger.info(TAG,
  9505. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  9506. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  9507. this.saveVideoDatasLyric(DocumentSelectResult)
  9508. }
  9509. }).catch((err: BusinessError) => {
  9510. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  9511. });
  9512. } catch (err) {
  9513. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  9514. }
  9515. }
  9516. async saveVideoDatasLyric(uris: string[]) {
  9517. if (ArrayUtil.isEmpty(uris)) {
  9518. return
  9519. }
  9520. let newUris: string[] = [];
  9521. for (let i = 0; i < uris.length; i++) {
  9522. let filePath = getContext(this).filesDir + '/' + Utility.getMediaNameByUri(uris[i])
  9523. Logger.info(TAG, 'filePath uri: ' + filePath);
  9524. newUris.push(filePath)
  9525. let file = fileIo.openSync(uris[i], fileIo.OpenMode.READ_ONLY)
  9526. let file2 = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  9527. fileIo.copyFileSync(file.fd, file2.fd)
  9528. fileIo.closeSync(file);
  9529. fileIo.closeSync(file2);
  9530. this.initLyric(filePath,false,false,true)
  9531. }
  9532. }
  9533. private initDelayPlay(context: object) {
  9534. this.mContext = context;
  9535. }
  9536. startPipLyric() {
  9537. if (this.pipController) {
  9538. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  9539. PiPWindow.PiPControlStatus.PLAY);
  9540. }
  9541. this.isOpenPip = PreferencesUtil.getBooleanSync('isOpenPip', false)
  9542. if (this.isOpenPip) {
  9543. this.startPip()
  9544. } else {
  9545. this.stopPip()
  9546. }
  9547. }
  9548. private startPlayOrResumePlay() {
  9549. this.startPipLyric()
  9550. this.mDestroyPage = false;
  9551. this.animationState = AnimationStatus.Running
  9552. LogUtils.getInstance().LOGI("onecold startPlayOrResumePlay start this.CONTROL_PlayStatus:" + this.CONTROL_PlayStatus)
  9553. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  9554. this.stopProgressTask();
  9555. this.startProgressTask();
  9556. this.play(this.videoUrl.toString());
  9557. }
  9558. if (this.CONTROL_PlayStatus == PlayStatus.PAUSE) {
  9559. this.mIjkMediaPlayer.start();
  9560. this.setProgress()
  9561. this.CONTROL_PlayStatus = PlayStatus.PLAY
  9562. }
  9563. this.setIsPlaying(true)
  9564. this.updateSessionPlayState(true)
  9565. this.watchStatus();
  9566. this.updateLastPlayTimeStr(this.videoUrl)
  9567. }
  9568. updateLastPlayTimeStr(filePath: string) {
  9569. let lastPlayTime = DateUtil.getTodayStr('yyyy-MM-dd HH:mm:ss')
  9570. this.table.updateLastPlayedStrByFilePath(filePath, lastPlayTime, (success: boolean, error?: string) => {
  9571. if (success) {
  9572. this.getHistoryList(false)
  9573. console.log(" onecold 更新最近播放时间成功,数据库已同步");
  9574. } else {
  9575. console.error(" onecold 更新最近播放时间数据库失败原因: " + error);
  9576. }
  9577. });
  9578. }
  9579. private completionNum(num: number): string | number {
  9580. if (num < 10) {
  9581. return '0' + num;
  9582. } else {
  9583. return num;
  9584. }
  9585. }
  9586. private stringForTime(timeMs: number): string {
  9587. let totalSeconds: number | string = (timeMs / 1000);
  9588. let newSeconds: number | string = totalSeconds % 60;
  9589. let minutes: number | string = (totalSeconds / 60) % 60;
  9590. let hours: number | string = totalSeconds / 3600;
  9591. //LogUtils.getInstance().LOGI("stringForTime hours:" + hours + ",minutes:" + minutes + ",seconds:" + newSeconds);
  9592. hours = this.completionNum(Math.floor(Math.floor(hours * 100) / 100));
  9593. minutes = this.completionNum(Math.floor(Math.floor(minutes * 100) / 100));
  9594. newSeconds = Math.floor(Math.floor(newSeconds * 100) / 100)
  9595. if (this.isCurrentTime) {
  9596. if (this.oldSeconds < newSeconds || newSeconds === 0 || this.isSeekTo) {
  9597. this.oldSeconds = newSeconds
  9598. } else {
  9599. newSeconds = this.oldSeconds
  9600. }
  9601. }
  9602. newSeconds = this.completionNum(newSeconds);
  9603. if (hours > 0) {
  9604. return hours + ":" + minutes + ":" + newSeconds;
  9605. } else {
  9606. return minutes + ":" + newSeconds;
  9607. }
  9608. }
  9609. private setProgress() {
  9610. let position = this.mIjkMediaPlayer.getCurrentPosition();
  9611. let duration = this.mIjkMediaPlayer.getDuration();
  9612. let pos = 0;
  9613. if (duration > 0) {
  9614. this.slideEnable = true;
  9615. let curPercent = position / duration;
  9616. pos = curPercent * 100;
  9617. if (pos > this.PROGRESS_MAX_VALUE) {
  9618. this.progressValue = this.PROGRESS_MAX_VALUE
  9619. } else {
  9620. this.progressValue = pos;
  9621. }
  9622. }
  9623. // LogUtils.getInstance()
  9624. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  9625. this.totalTime = this.stringForTime(duration);
  9626. if (position > duration) {
  9627. position = duration;
  9628. }
  9629. this.isCurrentTime = true;
  9630. this.lyricController.updatePosition(position + this.timeOffset * 1000)
  9631. this.lyricControllerXF.updatePosition(position + this.timeOffset * 1000)
  9632. this.lyricControllerSingle.updatePosition(position + this.timeOffset * 1000)
  9633. this.currentTime = this.stringForTime(position);
  9634. this.isCurrentTime = false
  9635. if (this.mIjkMediaPlayer.isPlaying()) {
  9636. this.randomColor =
  9637. `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
  9638. // 判断是否播放到结束时间
  9639. if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
  9640. if (position >= duration - this.jumpEndTime * 1000) {
  9641. this.playNext()
  9642. }
  9643. }
  9644. } else {
  9645. this.randomColor = 'rbg(0,0,0)'
  9646. }
  9647. }
  9648. private startProgressTask() {
  9649. let that = this;
  9650. this.updateProgressTimer = setInterval(() => {
  9651. //LogUtils.getInstance().LOGI("startProgressTask");
  9652. if (!that.mDestroyPage) {
  9653. that.setProgress();
  9654. }
  9655. }, 300);
  9656. }
  9657. private stopProgressTask() {
  9658. LogUtils.getInstance().LOGI("stopProgressTask");
  9659. clearInterval(this.updateProgressTimer);
  9660. }
  9661. private showLoadIng() {
  9662. this.loadingVisible = Visibility.Visible;
  9663. this.replayVisible = Visibility.None;
  9664. }
  9665. private hideLoadIng() {
  9666. this.loadingVisible = Visibility.None;
  9667. this.replayVisible = Visibility.None;
  9668. }
  9669. private showRePlay() {
  9670. this.loadingVisible = Visibility.None;
  9671. this.replayVisible = Visibility.Visible;
  9672. }
  9673. private async play(url: string) {
  9674. let that = this;
  9675. that.showLoadIng();
  9676. //设置XComponent回调的context
  9677. if (!!this.mContext) {
  9678. this.mIjkMediaPlayer.setContext(this.mContext, 'xcomponentId');
  9679. }
  9680. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  9681. this.mIjkMediaPlayer.reset();
  9682. }
  9683. this.CONTROL_PlayStatus = PlayStatus.PLAY;
  9684. //设置debug模式
  9685. this.mIjkMediaPlayer.setDebug(false);
  9686. //初始化配置
  9687. this.mIjkMediaPlayer.native_setup();
  9688. // 初始化配置后需要重新设置音频流音量,否则音量为默认值1.0 针对dsf格式设置最大值1.0
  9689. if(this.volumeSmall){
  9690. if(this.videoUrl.toLowerCase().endsWith('.dsf')){
  9691. this.mIjkMediaPlayer.setVolume('1', '1');
  9692. }else{
  9693. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  9694. }
  9695. }else{
  9696. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  9697. }
  9698. //设置视频源
  9699. this.mIjkMediaPlayer.setDataSource(url);
  9700. //设置视频源http请求头
  9701. let headers = new Map([
  9702. ["user_agent", "Mozilla/5.0 BiliDroid/7.30.0 (bbcallen@gmail.com)"],
  9703. ["referer", "https://www.bilibili.com"]
  9704. ]);
  9705. this.mIjkMediaPlayer.setDataSourceHeader(headers);
  9706. // if(PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN,false)){
  9707. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", "1"); // 启用硬件解码,会导致无法顺序播放
  9708. // }
  9709. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  9710. //使用精确寻帧 例如,拖动播放后,会寻找最近的关键帧进行播放,很有可能关键帧的位置不是拖动后的位置,而是较前的位置.可以设置这个参数来解决问题
  9711. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", "1");
  9712. const fileSize = await this.getFileSize(this.videoUrl);
  9713. let bufferSize = 1 * 1024 ; // 默认缓冲区大小为1MB
  9714. if (fileSize > 3 * 1024 * 1024 * 1024) { // 文件大于3GB
  9715. bufferSize = 25 * 1024 * 1024; // 设置缓冲区大小为25MB
  9716. }
  9717. // 使用软件解码(通常比硬件解码更节省内存)
  9718. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", '0');
  9719. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", '0');
  9720. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", '1024');
  9721. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", '500000');
  9722. //预读数据的缓冲区大小.修复大文件播放前几秒挂掉的bug,太大了会导致倍数播放失效
  9723. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", bufferSize + '');
  9724. //停止预读的最小帧数
  9725. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100");
  9726. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", '1'); ////重连模式,如果中途服务器断开了连接,让它重新连接
  9727. // 设置其他缓冲相关选项
  9728. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100"); // 设置最小缓冲帧数
  9729. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-frames", "1000"); // 设置最大缓冲
  9730. //启动预加载
  9731. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", "1");
  9732. // 设置无缓冲,这是播放器的缓冲区,有数据就播放
  9733. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", "0");
  9734. //跳帧处理,放CPU处理较慢时,进行跳帧处理,保证播放流程,画面和声音同步
  9735. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", "5");
  9736. // 最大缓冲cache是3s, 有时候网络波动,会突然在短时间内收到好几秒的数据
  9737. // 因此需要播放器丢包,才不会累积延时
  9738. // 这个和第三个参数packet-buffering无关。
  9739. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max_cached_duration", "3000");
  9740. // 无限制收流
  9741. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1");
  9742. this.mIjkMediaPlayer.setOptionLong(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1")
  9743. // 屏幕常亮
  9744. this.mIjkMediaPlayer.setScreenOnWhilePlaying(true);
  9745. // 设置超时
  9746. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", "10000000");
  9747. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "connect_timeout", "10000000");
  9748. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "addrinfo_timeout", "10000000");
  9749. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_timeout", "10000000");
  9750. // 变速播放
  9751. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", "1");
  9752. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  9753. let Speed = this.mIjkMediaPlayer.getSpeed()
  9754. LogUtils.getInstance().LOGI('getSpeed--' + Speed)
  9755. //是否开启循环播放
  9756. // this.mIjkMediaPlayer.setLoopCount(this.loop);
  9757. let mOnVideoSizeChangedListener: OnVideoSizeChangedListener = {
  9758. onVideoSizeChanged: (width: number, height: number, sar_num: number, sar_den: number) => {
  9759. if (height === 0) {
  9760. return;
  9761. }
  9762. const va = width / height;
  9763. const vpa = that.videoParentAspectRatio;
  9764. if (vpa > va) {
  9765. that.videoWidth = (width / (height * vpa)) * 100 + '%';
  9766. } else {
  9767. that.videoWidth = '100%';
  9768. }
  9769. if (width && height) {
  9770. that.videoAspectRatio = width / height;
  9771. }
  9772. LogUtils.getInstance()
  9773. .LOGI("setOnVideoSizeChangedListener-->go:" + width + "," + height + "," + sar_num + "," + sar_den);
  9774. that.hideLoadIng();
  9775. }
  9776. }
  9777. this.mIjkMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
  9778. let mOnPreparedListener: OnPreparedListener = {
  9779. onPrepared: async () => {
  9780. LogUtils.getInstance().LOGI("setOnPreparedListener-->go");
  9781. try {
  9782. // this.cover = this.songList[this.curIndex].pixelMapPath
  9783. // this.artist = this.songList[this.curIndex].artist
  9784. // this.videoUrl = this.songList[this.curIndex].filePath
  9785. let isBgCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  9786. if (isBgCover && this.cover !== undefined && StrUtil.isNotEmpty(this.cover)) {
  9787. this.setImageColor2(this.cover)
  9788. } else {
  9789. this.getImageColor();
  9790. }
  9791. //保存碰一碰分享的当前的歌曲
  9792. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  9793. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  9794. await this.initLyric(lyricPath);
  9795. setTimeout(() => {
  9796. this.avSessionController.initAvSession(false);
  9797. this.avSessionController.setAVMetadataMusic(this.songList[this.curIndex], this.duration, this.lyricContent);
  9798. this.setAvSessionListener();
  9799. this.updateSessionPlayState(true)
  9800. this.setCurrentPlayMode()
  9801. }, 500)
  9802. //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9803. let timeoutPlay = 0
  9804. if (StrUtil.isNotEmpty(this.videoUrl) &&
  9805. (this.videoUrl.toLowerCase().endsWith('.rmvb') || this.videoUrl.toLowerCase().endsWith('.flac'))) {
  9806. timeoutPlay = 1000
  9807. }
  9808. //跳过片头片尾关键代码,以下是跳过片头的关键代码
  9809. if (this.modeType === 0) { //文件夹
  9810. let parentPath = FileUtil.getParentPath(this.videoUrl)
  9811. this.jumpTopTime = PreferencesUtil.getNumberSync(parentPath + 'jumpTopTime')
  9812. this.jumpEndTime = PreferencesUtil.getNumberSync(parentPath + 'jumpEndTime')
  9813. this.isOpenJump = PreferencesUtil.getBooleanSync(parentPath + 'isOpenJump', false)
  9814. } else if (this.modeType === 1) { //媒体库
  9815. this.jumpTopTime = PreferencesUtil.getNumberSync(1 + 'jumpTopTime')
  9816. this.jumpEndTime = PreferencesUtil.getNumberSync(1 + 'jumpEndTime')
  9817. this.isOpenJump = PreferencesUtil.getBooleanSync(1 + 'isOpenJump', false)
  9818. } else if (this.modeType === 2) { //艺术家
  9819. if (this.currentSong?.artist) {
  9820. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpTopTime')
  9821. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpEndTime')
  9822. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.artist + 2 + 'isOpenJump', false)
  9823. }
  9824. } else if (this.modeType === 3) { //专辑
  9825. if (this.currentSong?.album) {
  9826. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpTopTime')
  9827. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpEndTime')
  9828. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.album + 3 + 'isOpenJump', false)
  9829. }
  9830. }
  9831. this.duration = this.mIjkMediaPlayer.getDuration()
  9832. if (this.isOpenJump) { //用户是否设置跳过片头片尾
  9833. if (this.mIjkMediaPlayer != null) {
  9834. if (this.jumpTopTime * 1000 <= this.duration) {
  9835. // 调用 seekTo 方法,跳到指定时间
  9836. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9837. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  9838. this.seekTo(this.jumpTopTime * 1000 + ""); // 跳到开头
  9839. }
  9840. }, timeoutPlay)
  9841. } else {
  9842. // 提示用户无法跳过
  9843. ToastUtil.showToast('跳过时间超过视频时长');
  9844. }
  9845. }
  9846. } else {
  9847. this.jumpTopTime = 0
  9848. this.jumpEndTime = 0
  9849. console.error('onecold 最后一首: isFirstStartPlay = ' + this.isFirstStartPlay);
  9850. console.error('onecold 最后一首: isMemoryLastPlay = ' + this.isMemoryLastPlay);
  9851. console.error('onecold 最后一首: PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false) = ' +
  9852. PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false));
  9853. //记忆播放(每一首都会记忆播放)
  9854. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  9855. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9856. if (PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)) {
  9857. this.restorePlaybackPosition() //读取播放记忆功能
  9858. } else if (this.isMemoryLastPlay && this.isFirstStartPlay) {
  9859. console.error('onecold 最后一首:读取播放记忆功能 = ' + this.isFirstStartPlay);
  9860. this.restorePlaybackPosition() //读取播放记忆功能
  9861. }
  9862. this.isFirstStartPlay = false
  9863. }, timeoutPlay)
  9864. } else {
  9865. this.isFirstStartPlay = false
  9866. }
  9867. }
  9868. this.saveLastPlayList()
  9869. } catch (error) {
  9870. let err: BusinessError = error as BusinessError;
  9871. console.error('onecold failed with err: ' + JSON.stringify(err));
  9872. }
  9873. }
  9874. }
  9875. this.mIjkMediaPlayer.setOnPreparedListener(mOnPreparedListener);
  9876. let mOnTimedTextListener: OnTimedTextListener = {
  9877. onTimedText: () => {
  9878. }
  9879. }
  9880. this.mIjkMediaPlayer.setOnTimedTextListener(mOnTimedTextListener)
  9881. let mOnCompletionListener: OnCompletionListener = {
  9882. onCompletion: () => {
  9883. LogUtils.getInstance().LOGI("OnCompletionListener-->go")
  9884. if (this.playType == 0) { //0:连续播放 1:单片重复播放 2:正常播放
  9885. this.playNext()
  9886. } else if (this.playType == 1) { //1:单片重复播放
  9887. this.CONTROL_PlayStatus = PlayStatus.INIT
  9888. console.info('onecold startPlayOrResumePlay 10592')
  9889. that.startPlayOrResumePlay();
  9890. } else if (this.playType == 2) { //2:正常播放,单曲播完
  9891. that.showRePlay();
  9892. that.currentTime = that.stringForTime(this.mIjkMediaPlayer.getDuration());
  9893. that.progressValue = this.PROGRESS_MAX_VALUE;
  9894. that.slideEnable = false;
  9895. that.stop();
  9896. // ToastUtil.showToast('开始重新播放')
  9897. } else if (this.playType == 3) { //3:随机播放
  9898. this.randomPlay()
  9899. }
  9900. }
  9901. }
  9902. this.mIjkMediaPlayer.setOnCompletionListener(mOnCompletionListener);
  9903. let mOnBufferingUpdateListener: OnBufferingUpdateListener = {
  9904. onBufferingUpdate: (percent: number) => {
  9905. LogUtils.getInstance().LOGI("OnBufferingUpdateListener-->go:" + percent);
  9906. let MediaInfo = this.mIjkMediaPlayer.getMediaInfo()
  9907. LogUtils.getInstance().LOGI('getMediaInfo---' + MediaInfo);
  9908. let VideoWidth = this.mIjkMediaPlayer.getVideoWidth()
  9909. LogUtils.getInstance().LOGI('getVideoWidth---' + VideoWidth);
  9910. let VideoHeight = this.mIjkMediaPlayer.getVideoHeight()
  9911. LogUtils.getInstance().LOGI('getVideoHeight---' + VideoHeight);
  9912. let VideoSarNum = this.mIjkMediaPlayer.getVideoSarNum()
  9913. LogUtils.getInstance().LOGI('getVideoSarNum---' + VideoSarNum);
  9914. let VideoSarDen = this.mIjkMediaPlayer.getVideoSarDen()
  9915. LogUtils.getInstance().LOGI('getVideoSarDen---' + VideoSarDen);
  9916. let AudioSessionId = this.mIjkMediaPlayer.getAudioSessionId()
  9917. LogUtils.getInstance().LOGI('getAudioSessionId---' + AudioSessionId);
  9918. let Looping = this.mIjkMediaPlayer.isLooping()
  9919. LogUtils.getInstance().LOGI('isLooping---' + Looping);
  9920. }
  9921. }
  9922. this.mIjkMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
  9923. let mOnSeekCompleteListener: OnSeekCompleteListener = {
  9924. onSeekComplete: () => {
  9925. LogUtils.getInstance().LOGI("OnSeekCompleteListener-->go");
  9926. console.info('onecold startPlayOrResumePlay 10643')
  9927. that.startPlayOrResumePlay();
  9928. }
  9929. }
  9930. this.mIjkMediaPlayer.setOnSeekCompleteListener(mOnSeekCompleteListener);
  9931. let mOnInfoListener: OnInfoListener = {
  9932. onInfo: (what: number, extra: number) => {
  9933. LogUtils.getInstance().LOGI("OnInfoListener-->go:" + what + "===" + extra);
  9934. that.hideLoadIng();
  9935. }
  9936. }
  9937. this.mIjkMediaPlayer.setOnInfoListener(mOnInfoListener);
  9938. let mOnErrorListener: OnErrorListener = {
  9939. onError: (what: number, extra: number) => {
  9940. this.stopProgressTask();
  9941. LogUtils.getInstance().LOGI("OnErrorListener-->go:" + what + "===" + extra + " this.videoUrl=" + this.videoUrl)
  9942. that.hideLoadIng();
  9943. if (StrUtil.isNotEmpty(this.videoUrl) && !FileUtil.accessSync(this.videoUrl)) {
  9944. ToastUtil.showToast(Utility.resourceToString(getContext(), $r('app.string.file_not_exist')))
  9945. } else {
  9946. ToastUtil.showToast(getContext()
  9947. .resourceManager
  9948. .getStringByNameSync("Honey_the_video_is_playing_errant_The_system_is_wandering"))
  9949. }
  9950. }
  9951. }
  9952. this.mIjkMediaPlayer.setOnErrorListener(mOnErrorListener);
  9953. this.mIjkMediaPlayer.setMessageListener();
  9954. this.mIjkMediaPlayer.prepareAsync();
  9955. this.mIjkMediaPlayer.start();
  9956. }
  9957. //保存最后播放的那首歌和已经对应的播放列表
  9958. saveLastPlayList() {
  9959. PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
  9960. PreferencesUtil.putSync('LastMusicList', this.songList)
  9961. }
  9962. // 清空播放记录
  9963. clearVideoHistory() {
  9964. this.table.clearPlayHistory((success: boolean, error?: string) => {
  9965. if (success) {
  9966. this.historyList = [];
  9967. this.updateListData(this.historyList)
  9968. // PreferencesUtil.putSync(LocalMusic.HISTORY_MUSIC, this.historyList)
  9969. ToastUtil.showToast('清空播放记录成功')
  9970. } else {
  9971. console.error(" onecold 清空播放记录数据库失败原因: " + error);
  9972. }
  9973. });
  9974. }
  9975. public async setAvSessionListener() {
  9976. if (!this.avSessionController) {
  9977. return;
  9978. }
  9979. this.avSessionController.getAvSession()?.on('play', this.sessionPlayCallback);
  9980. this.avSessionController.getAvSession()?.on('pause', this.sessionPauseCallback);
  9981. this.avSessionController.getAvSession()?.on('stop', this.sessionStopCallback);
  9982. this.avSessionController.getAvSession()?.on('playNext', this.sessionPlayNextCallback);
  9983. this.avSessionController.getAvSession()?.on('playPrevious', this.sessionPlayPreviousCallback);
  9984. this.avSessionController.getAvSession()?.on('fastForward', this.sessionFastForwardCallback);
  9985. this.avSessionController.getAvSession()?.on('rewind', this.sessionRewindCallback);
  9986. this.avSessionController.getAvSession()?.on('seek', this.sessionSeekCallback);
  9987. this.avSessionController.getAvSession()?.on('setLoopMode', this.sessionSetLoopModeCallback);
  9988. this.avSessionController.getAvSession()?.on('toggleFavorite', this.sessionToggleFavoriteCallback);
  9989. this.avSessionController.getAvSession()?.on('outputDeviceChange', this.sessionOutputDeviceChange)
  9990. }
  9991. setLoopMode() {
  9992. let itype = this.playType + 1
  9993. if (itype >= 4) {
  9994. this.playType = 0
  9995. ToastUtil.showToast('连续播放')
  9996. } else if (itype === 1) {
  9997. this.playType = 1
  9998. ToastUtil.showToast('单曲循环')
  9999. } else if (itype === 2) {
  10000. this.playType = 2
  10001. ToastUtil.showToast('单曲播完')
  10002. } else if (itype === 3) {
  10003. this.playType = 3
  10004. ToastUtil.showToast('随机播放')
  10005. } else if (itype === 0) {
  10006. this.playType = 0
  10007. ToastUtil.showToast('连续播放')
  10008. }
  10009. PreferencesUtil.putSync('musicPlayType', this.playType)
  10010. this.setCurrentPlayMode()
  10011. }
  10012. private sessionSetLoopModeCallback = (mode: number) => {
  10013. if (this.mIjkMediaPlayer != null) {
  10014. ToastUtil.showToast('当前播放模式:' + mode)
  10015. Logger.info('onecold 当前播放模式= ' + mode)
  10016. let hmPlayMode = mode + 1
  10017. if (hmPlayMode >= 4) {
  10018. hmPlayMode = 0
  10019. }
  10020. if (hmPlayMode === 1) {
  10021. this.playType = 1
  10022. ToastUtil.showToast('单曲循环')
  10023. } else if (hmPlayMode === 0) {
  10024. this.playType = 2
  10025. ToastUtil.showToast('单曲播完')
  10026. } else if (hmPlayMode === 3) {
  10027. this.playType = 3
  10028. ToastUtil.showToast('随机播放')
  10029. } else if (hmPlayMode === 2) {
  10030. this.playType = 0
  10031. ToastUtil.showToast('连续播放')
  10032. }
  10033. PreferencesUtil.putSync('musicPlayType', this.playType)
  10034. // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
  10035. let playBackState: avSession.AVPlaybackState = {
  10036. loopMode: hmPlayMode,
  10037. };
  10038. this.avSessionController.getAvSession()?.setAVPlaybackState(playBackState).then(() => {
  10039. console.info(`set setLoopMode AVPlaybackState successfully`);
  10040. }).catch((err: BusinessError) => {
  10041. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  10042. });
  10043. }
  10044. }
  10045. setCurrentPlayMode() {
  10046. if (!this.avSessionController) {
  10047. return;
  10048. }
  10049. let mLoopMode = 0
  10050. switch (this.playType) {
  10051. case 0:
  10052. mLoopMode = avSession.LoopMode.LOOP_MODE_LIST //连续播放
  10053. break;
  10054. case 1:
  10055. mLoopMode = avSession.LoopMode.LOOP_MODE_SINGLE //单曲
  10056. break;
  10057. case 2:
  10058. mLoopMode = avSession.LoopMode.LOOP_MODE_SEQUENCE //正常播放
  10059. break;
  10060. case 3:
  10061. mLoopMode = avSession.LoopMode.LOOP_MODE_SHUFFLE //随机播放
  10062. break;
  10063. }
  10064. // 应用启动时/内部切换循环模式,需要把应用内的当前的循环模式设置给AVSession。
  10065. let playBState: avSession.AVPlaybackState = {
  10066. loopMode: mLoopMode,
  10067. isFavorite: Utility.getIsFav(this.favList, this.currentSong),
  10068. };
  10069. this.avSessionController.getAvSession()?.setAVPlaybackState(playBState).then(() => {
  10070. console.info(`set setLoopMode AVPlaybackState successfully`);
  10071. }).catch((err: BusinessError) => {
  10072. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  10073. });
  10074. }
  10075. private sessionToggleFavoriteCallback = (assetId: string) => {
  10076. if (this.mIjkMediaPlayer != null && this.currentSong) {
  10077. console.info(`on toggleFavorite `);
  10078. // 应用收到收藏命令,进行收藏处理。
  10079. this.isFac = Utility.getIsFav(this.favList, this.currentSong)
  10080. this.doFav(this.currentSong)
  10081. // 应用内完成或者取消收藏,把新的收藏状态设置给AVSession。
  10082. let playbackState: avSession.AVPlaybackState = {
  10083. isFavorite: !this.isFac,
  10084. };
  10085. this.avSessionController.getAvSession()?.setAVPlaybackState(playbackState).then(() => {
  10086. console.info(`SetAVPlaybackState successfully`);
  10087. }).catch((err: BusinessError) => {
  10088. console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  10089. });
  10090. }
  10091. }
  10092. private sessionOutputDeviceChange = async (connectState: avSession.ConnectionState,
  10093. device: avSession.OutputDeviceInfo) => {
  10094. let currentDevice: avSession.DeviceInfo = device?.devices?.[0];
  10095. if (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  10096. connectState === avSession.ConnectionState.STATE_CONNECTED) {
  10097. await this.startCasting();
  10098. } else if ((currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  10099. connectState === avSession.ConnectionState.STATE_DISCONNECTED) ||
  10100. (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_LOCAL &&
  10101. connectState === avSession.ConnectionState.STATE_CONNECTED)) {
  10102. if (device) {
  10103. this.endCasting();
  10104. }
  10105. }
  10106. };
  10107. private async startCasting() {
  10108. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  10109. this.setPlaybackStateChangeListener();
  10110. this.pause();
  10111. this.initQueueItem();
  10112. this.prepare();
  10113. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  10114. refToIsCasting?.set(true);
  10115. this.castSeek = true;
  10116. this.isCastPlaying = true;
  10117. }
  10118. async changeCasting() {
  10119. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  10120. this.initQueueItem();
  10121. this.prepare();
  10122. this.setPlaybackStateChangeListener();
  10123. this.isCastPlaying = true;
  10124. this.castSeek = true;
  10125. }
  10126. public endCasting() {
  10127. this.avSessionController.getAvSession()?.stopCasting();
  10128. this.stopCast();
  10129. this.isCastPlaying = false;
  10130. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  10131. refToIsCasting?.set(false);
  10132. this.pause();
  10133. this.setIsPlaying(false);
  10134. // if (this.curIndex === this.curSource.index) {
  10135. // this.play
  10136. // this.seek(this.currentTime * 1000);
  10137. // this.setIsPlaying(true);
  10138. // } else {
  10139. // this.pauseVideo();
  10140. // this.setIsPlaying(false);
  10141. // }
  10142. }
  10143. public setIsPlaying(isPlayer: boolean) {
  10144. this.isPlaying = isPlayer;
  10145. }
  10146. private setPlaybackStateChangeListener(): void {
  10147. this.castController?.on('playbackStateChange', 'all', this.playbackStateChangeListener);
  10148. this.castController?.on('endOfStream', this.reloadCasting);
  10149. this.castController?.on('playNext', this.playNextCallback);
  10150. this.castController?.on('playPrevious', this.playPreviousCallback);
  10151. }
  10152. private updateSessionPlayState(isPlay: boolean): void {
  10153. // if(!this.isBgPlayOpen)
  10154. // return
  10155. Logger.info(TAG, `updateIsPlay isPlay: ${isPlay}`);
  10156. this.setAVSessionPlayState({
  10157. state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
  10158. position: {
  10159. elapsedTime: this.mIjkMediaPlayer.getCurrentPosition(),
  10160. updateTime: new Date().getTime()
  10161. }
  10162. });
  10163. }
  10164. private setAVSessionPlayState(playbackState: avSession.AVPlaybackState): void {
  10165. this.avSessionController.setAvSessionPlayState(playbackState)
  10166. }
  10167. private positionChange(position: number) {
  10168. this.currentTime2 = position / 1000;
  10169. this.currentStringTime = secondToTime(Math.floor(position / 1000));
  10170. }
  10171. private playDurationChange(duration: number) {
  10172. this.duration = duration;
  10173. this.durationTime = Math.floor(this.duration / 1000);
  10174. this.durationStringTime = secondToTime((this.durationTime));
  10175. }
  10176. private playbackStateChangeListener = (playbackState: avSession.AVPlaybackState) => {
  10177. const duration = playbackState?.extras?.duration;
  10178. if (typeof duration === 'number') {
  10179. this.playDurationChange(duration as number);
  10180. }
  10181. if (typeof playbackState?.position?.elapsedTime !== 'undefined') {
  10182. this.positionChange(playbackState?.position?.elapsedTime);
  10183. }
  10184. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PAUSE ||
  10185. playbackState.state === CommonConstants2.PLAYBACK_STATE_STOP ||
  10186. playbackState.state === CommonConstants2.PLAYBACK_STATE_PREPARE ||
  10187. playbackState.state === CommonConstants2.PLAYBACK_STATE_INITIAL) {
  10188. this.isCastPlaying = false;
  10189. }
  10190. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PLAY) {
  10191. this.isCastPlaying = true;
  10192. }
  10193. };
  10194. private reloadCasting = async () => {
  10195. let item = this.songList[this.curIndex];
  10196. let uri = fileUri.getUriFromPath(item.filePath);
  10197. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  10198. // description.startPosition = 0;
  10199. this.castItem = {
  10200. itemId: this.curIndex,
  10201. description: {
  10202. assetId: item.filePath,
  10203. title: item.name,
  10204. artist: '',
  10205. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  10206. // mediaUri: item.filePath,
  10207. fdSrc: {
  10208. fd: file.fd
  10209. },
  10210. // 该字段大写,音频'AUDIO',视频'VIDEO'
  10211. mediaType: 'VIDEO',
  10212. mediaSize: item.videoSize,
  10213. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  10214. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  10215. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  10216. duration: this.duration,
  10217. // albumCoverUri: 'https://www.example.jpeg',
  10218. // albumTitle: '《ExampleAlbum》',
  10219. appName: this.appName,
  10220. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  10221. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  10222. }
  10223. };
  10224. this.prepare();
  10225. this.isCastPlaying = true;
  10226. };
  10227. public playNextCallback = (): void => {
  10228. this.playNext()
  10229. };
  10230. public playPreviousCallback = (): void => {
  10231. this.playPrevious()
  10232. };
  10233. async prepare() {
  10234. await this.castController?.prepare(this.castItem);
  10235. await this.castController?.start(this.castItem);
  10236. }
  10237. public initQueueItem() {
  10238. let item = this.songList[this.curIndex];
  10239. let time = this.currentTime;
  10240. let uri = fileUri.getUriFromPath(item.filePath);
  10241. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  10242. this.castItem = {
  10243. itemId: this.curIndex,
  10244. description: {
  10245. assetId: item.filePath,
  10246. title: item.name,
  10247. artist: '',
  10248. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  10249. fdSrc: {
  10250. fd: file.fd
  10251. },
  10252. // 该字段大写,音频'AUDIO',视频'VIDEO'
  10253. mediaType: 'AUDIO',
  10254. mediaSize: item.videoSize,
  10255. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  10256. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  10257. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  10258. duration: this.duration,
  10259. // albumCoverUri: 'https://www.example.jpeg',
  10260. // albumTitle: '《ExampleAlbum》',
  10261. appName: this.appName,
  10262. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  10263. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  10264. }
  10265. };
  10266. }
  10267. async stopCast() {
  10268. try {
  10269. this.castController?.off('playbackStateChange');
  10270. this.castController?.off('endOfStream');
  10271. this.castController?.off('playNext');
  10272. this.castController?.off('playPrevious');
  10273. this.castController?.off('error');
  10274. } catch (error) {
  10275. hilog.info(0x0000, TAG, `Failed to setAVCastController. code: ${error.code}, message: ${error.message}`);
  10276. }
  10277. }
  10278. private sessionPlayCallback = (): void => {
  10279. console.info('onecold playOrPause 11050')
  10280. this.playOrPause()
  10281. };
  10282. private sessionPauseCallback = (): void => {
  10283. console.info('onecold playOrPause 11054')
  10284. this.pause()
  10285. };
  10286. private playOrPause() {
  10287. if (!this.debounce()) {
  10288. return;
  10289. }
  10290. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  10291. this.pause();
  10292. } else {
  10293. console.info('onecold startPlayOrResumePlay 11064')
  10294. this.startPlayOrResumePlay();
  10295. this.playChange()
  10296. }
  10297. }
  10298. private sessionPlayNextCallback = (): void => {
  10299. this.playNext()
  10300. };
  10301. private sessionPlayPreviousCallback = (): void => {
  10302. this.playPrevious()
  10303. };
  10304. private sessionStopCallback = (): void => {
  10305. this.stop()
  10306. };
  10307. private sessionFastForwardCallback = (time?: number) => {
  10308. if (!time) {
  10309. return;
  10310. }
  10311. if (this.mIjkMediaPlayer != null) {
  10312. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  10313. let seeTime = curPosition + time * 1000;
  10314. // 限制 seekValue 在合法范围内
  10315. if (seeTime < 0) {
  10316. seeTime = 0;
  10317. } else if (seeTime > this.duration) {
  10318. seeTime = this.duration;
  10319. }
  10320. Logger.info('onecold seeTime= ' + seeTime)
  10321. this.setSeekToActionProgress(seeTime)
  10322. this.seekTo(seeTime + "")
  10323. }
  10324. };
  10325. /**
  10326. * Gesture method onActionUpdate.
  10327. *
  10328. * @param event Gesture event.手势拖动设置快进和后退
  10329. */
  10330. private setSeekToActionProgress(position: number) {
  10331. // let position = this.mIjkMediaPlayer.getCurrentPosition();
  10332. let duration = this.mIjkMediaPlayer.getDuration();
  10333. let pos = 0;
  10334. if (duration > 0) {
  10335. this.slideEnable = true;
  10336. let curPercent = position / duration;
  10337. pos = curPercent * 100;
  10338. if (pos > this.PROGRESS_MAX_VALUE) {
  10339. this.progressValue = this.PROGRESS_MAX_VALUE
  10340. } else {
  10341. this.progressValue = pos;
  10342. }
  10343. }
  10344. // LogUtils.getInstance()
  10345. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  10346. this.totalTime = this.stringForTime(duration);
  10347. if (position > duration) {
  10348. position = duration;
  10349. }
  10350. this.isCurrentTime = true;
  10351. this.currentTime = this.stringForTime(position);
  10352. this.isCurrentTime = false
  10353. }
  10354. private sessionRewindCallback = (time?: number) => {
  10355. if (!time) {
  10356. return;
  10357. }
  10358. if (this.mIjkMediaPlayer != null) {
  10359. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  10360. let seeTime = curPosition - time * 1000;
  10361. // 限制 seekValue 在合法范围内
  10362. if (seeTime < 0) {
  10363. seeTime = 0;
  10364. } else if (seeTime > this.duration) {
  10365. seeTime = this.duration;
  10366. }
  10367. Logger.info('onecold seeTime= ' + seeTime)
  10368. this.setSeekToActionProgress(seeTime)
  10369. this.seekTo(seeTime + "")
  10370. }
  10371. };
  10372. private sessionSeekCallback = (seekTime: number) => {
  10373. if (this.mIjkMediaPlayer != null) {
  10374. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  10375. this.seekTo(seekTime + "")
  10376. }
  10377. };
  10378. private async getFileSize(filePath: string): Promise<number> {
  10379. try {
  10380. const stat = await fs.stat(filePath);
  10381. return stat.size;
  10382. } catch (err) {
  10383. console.error('Failed to get file size: ' + err.message);
  10384. return 0;
  10385. }
  10386. }
  10387. private pause() {
  10388. if (this.mIjkMediaPlayer.isPlaying()) {
  10389. this.savePlaybackPosition();
  10390. this.mIjkMediaPlayer.pause();
  10391. this.setProgress();
  10392. this.mDestroyPage = true;
  10393. this.CONTROL_PlayStatus = PlayStatus.PAUSE;
  10394. this.updateSessionPlayState(false)
  10395. this.playChange()
  10396. if (this.pipController) {
  10397. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  10398. PiPWindow.PiPControlStatus.PAUSE);
  10399. }
  10400. }
  10401. }
  10402. private stop() {
  10403. this.savePlaybackPosition();
  10404. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10405. this.mIjkMediaPlayer.stop();
  10406. this.mIjkMediaPlayer.release();
  10407. this.stopProgressTask();
  10408. this.updateSessionPlayState(false)
  10409. this.playChange()
  10410. this.watchStatus();
  10411. }
  10412. //保持记忆播放功能
  10413. private savePlaybackPosition() {
  10414. if (this.mIjkMediaPlayer != null) {
  10415. const position = this.mIjkMediaPlayer.getCurrentPosition();
  10416. // ToastUtil.showToast('保存记忆播放 = ' + position)
  10417. const duration = this.mIjkMediaPlayer.getDuration();
  10418. const threshold = 5000; // 阈值,单位为毫秒(这里设为5秒)
  10419. // 如果播放位置接近视频末尾,则保存 position 为 0
  10420. const playbackPosition = (duration - position < threshold) ? 0 : position;
  10421. PreferencesUtil.putSync(this.videoUrl, playbackPosition);
  10422. }
  10423. }
  10424. //获取记忆播放功能
  10425. private restorePlaybackPosition() {
  10426. const position: number = PreferencesUtil.getNumberSync(this.videoUrl, 0);
  10427. // ToastUtil.showToast('position = ' + position)
  10428. if (this.mIjkMediaPlayer != null && position > 0) {
  10429. // ToastUtil.showToast('seekTo = ' + position)
  10430. this.seekTo(position + "");
  10431. }
  10432. }
  10433. private seekTo(value: string) {
  10434. if (StrUtil.isNotEmpty(this.videoUrl) && this.videoUrl.toLowerCase().endsWith('.wma')) {
  10435. ToastUtil.showToast('wma格式不支持拖动快进。')
  10436. return
  10437. }
  10438. this.mIjkMediaPlayer.seekTo(value);
  10439. console.info('onecold startPlayOrResumePlay 11227')
  10440. // this.startPlayOrResumePlay()
  10441. // 在这里恢复计时器状态
  10442. this.setProgress()
  10443. // this.startProgressTask();
  10444. }
  10445. // 添加到下一首播放
  10446. private addToNextPlay(song: VideoItem) {
  10447. if (!this.debounce()) {
  10448. return;
  10449. }
  10450. if (this.currentSong) {
  10451. if (this.currentSong === song) {
  10452. ToastUtil.showToast('当前已经在播放这首歌了!')
  10453. return
  10454. }
  10455. }
  10456. // 如果未开始播放或队列为空
  10457. if (this.curIndex === -1 || this.songList.length === 0) {
  10458. this.songList = [song];
  10459. this.curIndex = 0;
  10460. this.doPlay(song)
  10461. return;
  10462. }
  10463. // 插入到当前索引+1的位置
  10464. const insertPos = this.curIndex + 1;
  10465. this.songList.splice(insertPos, 0, song);
  10466. this.songList = [...this.songList]; // 触发状态更新
  10467. this.sonDataSource.pushArrayData(this.songList)
  10468. ToastUtil.showToast('已添加至下一首播放')
  10469. }
  10470. //下一个
  10471. private playNext() {
  10472. if (!this.debounce()) {
  10473. return;
  10474. }
  10475. if (this.playType == 3) { //3:随机播放
  10476. this.randomPlay()
  10477. return;
  10478. }
  10479. if (ArrayUtil.isNotEmpty(this.songList)) {
  10480. if (this.curIndex == this.songList.length - 1) {
  10481. this.curIndex = 0;
  10482. } else {
  10483. this.curIndex++;
  10484. }
  10485. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10486. this.stop();
  10487. this.currentSong = this.songList[this.curIndex]
  10488. this.videoUrl = this.songList[this.curIndex].filePath;
  10489. this.artist = this.songList[this.curIndex].artist
  10490. this.name = this.songList[this.curIndex].name
  10491. //this.cover = this.songList[this.curIndex].pixelMapPath
  10492. this.changeImageAnimation()
  10493. }
  10494. }
  10495. changeImageAnimation() {
  10496. if(this.openSkipSongAnimate){
  10497. // 第一步:淡出动画
  10498. this.getUIContext()?.animateTo({
  10499. duration: 500,
  10500. curve: Curve.EaseOut,
  10501. }, () => {
  10502. this.opacityValueImage = 0.1;
  10503. if(this.isCoverRectangle){
  10504. this.scaleValueImage = 0.88
  10505. }
  10506. });
  10507. // 第二步:切换图片后淡入
  10508. setTimeout(() => {
  10509. this.cover = this.songList[this.curIndex].pixelMapPath
  10510. this.getUIContext()?.animateTo({
  10511. duration: 500,
  10512. curve: Curve.EaseIn,
  10513. }, () => {
  10514. this.opacityValueImage = 1;
  10515. this.scaleValueImage = 1 // 图标恢复到原始大小
  10516. console.info('onecold startPlayOrResumePlay 11313')
  10517. this.startPlayOrResumePlay()
  10518. });
  10519. }, 500);
  10520. }else{
  10521. this.cover = this.songList[this.curIndex].pixelMapPath
  10522. console.info('onecold startPlayOrResumePlay 11319')
  10523. this.startPlayOrResumePlay()
  10524. }
  10525. }
  10526. // 存储已播放的歌曲索引
  10527. private playedIndices: Set<number> = new Set();
  10528. //随机播放
  10529. private randomPlay() {
  10530. // if (!this.debounce()) {
  10531. // return;
  10532. // }
  10533. if (ArrayUtil.isNotEmpty(this.songList)) {
  10534. if (this.songList.length > 3) {
  10535. // 如果所有歌曲都播放过一次,清空已播放索引集合
  10536. if (this.playedIndices.size === this.songList.length) {
  10537. this.playedIndices.clear();
  10538. }
  10539. // 随机选择一个未播放的歌曲索引
  10540. let newIndex: number;
  10541. // 添加超时机制防止无限循环
  10542. let attempt = 0;
  10543. const maxAttempts = 100; // 根据需求调整
  10544. do {
  10545. newIndex = RandomUtil.getRandomNumber(0, this.songList.length - 1);
  10546. attempt++;
  10547. } while (this.playedIndices.has(newIndex) && attempt < maxAttempts);
  10548. if (attempt >= maxAttempts) {
  10549. // 处理无法找到新索引的情况(如随机选择或按顺序播放)
  10550. newIndex = Math.floor(Math.random() * this.songList.length);
  10551. }
  10552. this.curIndex = newIndex;
  10553. this.playedIndices.add(newIndex);
  10554. } else {
  10555. // 当歌曲数量小于或等于3时,直接播放下一首
  10556. if (this.curIndex == this.songList.length - 1) {
  10557. this.curIndex = 0;
  10558. } else {
  10559. this.curIndex++;
  10560. }
  10561. }
  10562. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10563. this.stop();
  10564. this.currentSong = this.songList[this.curIndex];
  10565. this.videoUrl = this.songList[this.curIndex].filePath;
  10566. this.name = this.songList[this.curIndex].name;
  10567. this.artist = this.songList[this.curIndex].artist
  10568. // this.cover = this.songList[this.curIndex].pixelMapPath
  10569. this.changeImageAnimation()
  10570. }
  10571. }
  10572. private playIndex(index: number) {
  10573. if (!this.debounce()) {
  10574. return;
  10575. }
  10576. if (ArrayUtil.isNotEmpty(this.songList)) {
  10577. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10578. this.stop();
  10579. this.currentSong = this.songList[this.curIndex]
  10580. this.videoUrl = this.songList[index].filePath;
  10581. this.name = this.songList[index].name
  10582. this.artist = this.songList[this.curIndex].artist
  10583. this.curIndex = index;
  10584. this.changeImageAnimation()
  10585. }
  10586. }
  10587. //上一个
  10588. private playPrevious() {
  10589. if (!this.debounce()) {
  10590. return;
  10591. }
  10592. if (this.playType == 3) { //3:随机播放的上一首应该应该播放历史记录的第二首
  10593. this.randomModePlayFromHistory()
  10594. return;
  10595. }
  10596. if (this.curIndex == 0) {
  10597. this.curIndex = this.songList.length - 1;
  10598. } else {
  10599. this.curIndex--;
  10600. }
  10601. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10602. this.stop();
  10603. this.currentSong = this.songList[this.curIndex]
  10604. this.videoUrl = this.songList[this.curIndex].filePath;
  10605. this.name = this.songList[this.curIndex].name
  10606. this.artist = this.songList[this.curIndex].artist
  10607. this.changeImageAnimation()
  10608. }
  10609. //随机播放模式下点击上一首: 上一首应该应该播放历史记录的第二首
  10610. private randomModePlayFromHistory() {
  10611. if (this.historyList.length >= 2) {
  10612. // 播放历史记录的第二首
  10613. const prevSong = this.historyList[1];
  10614. this.curIndex = this.songList.findIndex(song => song.filePath === prevSong.filePath);
  10615. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10616. this.stop();
  10617. this.currentSong = prevSong;
  10618. this.videoUrl = prevSong.filePath;
  10619. this.cover = prevSong.pixelMapPath
  10620. this.artist = prevSong.artist
  10621. this.name = prevSong.name;
  10622. console.info('onecold startPlayOrResumePlay 11434')
  10623. this.startPlayOrResumePlay();
  10624. } else {
  10625. // 如果历史记录不足两首,可根据需求处理,这里简单按普通逻辑处理
  10626. if (this.curIndex === 0) {
  10627. this.curIndex = this.songList.length - 1;
  10628. } else {
  10629. this.curIndex--;
  10630. }
  10631. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10632. this.stop();
  10633. this.currentSong = this.songList[this.curIndex];
  10634. this.videoUrl = this.songList[this.curIndex].filePath;
  10635. this.artist = this.songList[this.curIndex].artist
  10636. this.name = this.songList[this.curIndex].name;
  10637. this.changeImageAnimation()
  10638. }
  10639. }
  10640. debounce() {
  10641. const delay = 600;
  10642. let cur = new Date().getTime();
  10643. if (cur - this.last > delay) {
  10644. this.last = cur;
  10645. return true;
  10646. }
  10647. return false;
  10648. }
  10649. /**
  10650. * Sets whether the screen is a constant based on the playback status.
  10651. */
  10652. watchStatus() {
  10653. // let windowClass = GlobalContext.getContext().getObject('windowClass') as window.Window;
  10654. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  10655. this.windowClass.setWindowKeepScreenOn(true);
  10656. } else {
  10657. this.windowClass.setWindowKeepScreenOn(false);
  10658. }
  10659. }
  10660. /**
  10661. * Volume gesture method onActionStart.
  10662. *
  10663. * @param event Gesture event.
  10664. */
  10665. private customDialogComponentIdMM: number = 0
  10666. @Builder
  10667. customDialogComponentMM() {
  10668. Column() {
  10669. Row() {
  10670. Blank()
  10671. Text('验证密码')
  10672. .fontSize(22)
  10673. .fontColor($r('app.color.pri_bg'))
  10674. .margin({ top: 18 })
  10675. Blank()
  10676. Image($r('app.media.close'))
  10677. .fillColor(Color.White)
  10678. .margin({ top: 18, right: 18 })
  10679. .width(20)
  10680. .onClick(() => {
  10681. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  10682. })
  10683. }
  10684. .width('100%') // 使Row占据整个宽度
  10685. .justifyContent(FlexAlign.SpaceBetween); // 在Row中创建空间
  10686. Verify({
  10687. onVerifyCompleted: this.handleVerifyCompleted.bind(this)
  10688. });
  10689. }.height('60%')
  10690. .backgroundColor($r('app.color.index_background'))
  10691. .justifyContent(FlexAlign.SpaceBetween)
  10692. }
  10693. private handleVerifyCompleted(isSuccess: boolean) {
  10694. if (isSuccess) {
  10695. console.log('验证成功');
  10696. // 在这里处理验证成功后的逻辑
  10697. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  10698. this.currentPath = this.lockPath
  10699. this.getSortedFiles(this.currentPath)
  10700. } else {
  10701. // console.log('验证失败');
  10702. ToastUtil.showToast('验证失败')
  10703. }
  10704. }
  10705. private showVerifyDialog() {
  10706. promptAction.openCustomDialog({
  10707. transition: TransitionEffect.asymmetric(
  10708. TransitionEffect.OPACITY.animation({ duration: 888 }).combine(
  10709. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  10710. ,
  10711. TransitionEffect.OPACITY.animation({ delay: 888, duration: 888 }).combine(
  10712. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  10713. ),
  10714. builder: () => {
  10715. this.customDialogComponentMM()
  10716. },
  10717. isModal: true,
  10718. autoCancel: true,
  10719. maskColor: Color.Transparent,
  10720. alignment: DialogAlignment.Bottom,
  10721. onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
  10722. console.info("reason" + JSON.stringify(dismissDialogAction.reason))
  10723. console.log("dialog onWillDismiss")
  10724. if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
  10725. dismissDialogAction.dismiss()
  10726. }
  10727. if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
  10728. dismissDialogAction.dismiss()
  10729. }
  10730. }
  10731. }).then((dialogId: number) => {
  10732. this.customDialogComponentIdMM = dialogId
  10733. })
  10734. }
  10735. //左滑操作 移动文件 重命名 删除等操作
  10736. @Builder
  10737. DeleteButton(item: VideoItem, index: number, filePath: string) {
  10738. Row() {
  10739. //加入收藏
  10740. Button() {
  10741. Image(Utility.getIsFav(this.favList, item) ? $r('app.media.add_fac_light2') : $r('app.media.add_fac'))
  10742. .fillColor(Color.White)
  10743. .width(20)
  10744. }
  10745. .width(40)
  10746. .height(40)
  10747. .type(ButtonType.Circle)
  10748. .backgroundColor(this.themeColor)
  10749. .margin(5)
  10750. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10751. .onClick(() => {
  10752. if (item) {
  10753. this.doFav(item)
  10754. }
  10755. })
  10756. //加入下一首播放
  10757. Button() {
  10758. Image($r('app.media.next_to_play'))
  10759. .fillColor(Color.White)
  10760. .width(20)
  10761. }
  10762. .width(40)
  10763. .height(40)
  10764. .type(ButtonType.Circle)
  10765. .backgroundColor(this.themeColor)
  10766. .margin(5)
  10767. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10768. .onClick(() => {
  10769. this.addToNextPlay(item);
  10770. })
  10771. //复制文件
  10772. Button() {
  10773. Image($r('app.media.copy'))
  10774. .fillColor(Color.White)
  10775. .width(20)
  10776. }
  10777. .width(40)
  10778. .height(40)
  10779. .type(ButtonType.Circle)
  10780. .backgroundColor(this.themeColor)
  10781. .margin(5)
  10782. .id(filePath + 'copy')
  10783. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10784. .onClick(() => {
  10785. this.showCopyDialog(false, item, index, filePath + 'copy');
  10786. })
  10787. //移动文件
  10788. Button() {
  10789. Image($r('app.media.cut'))
  10790. .fillColor(Color.White)
  10791. .width(20)
  10792. }
  10793. .width(40)
  10794. .height(40)
  10795. .type(ButtonType.Circle)
  10796. .backgroundColor(this.themeColor)
  10797. .margin(5)
  10798. .id(filePath)
  10799. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10800. .onClick(() => {
  10801. this.showCutDialog(false, item, index, filePath);
  10802. })
  10803. Button() {
  10804. Image($r('app.media.cut_current'))
  10805. .fillColor(Color.White)
  10806. .width(20)
  10807. }
  10808. .width(40)
  10809. .height(40)
  10810. .type(ButtonType.Circle)
  10811. .backgroundColor(this.themeColor)
  10812. .margin(5)
  10813. .id(filePath + 'current')
  10814. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None :
  10815. (this.isHasDir ? Visibility.Visible : Visibility.None))
  10816. .onClick(() => {
  10817. this.showCutDialog(true, item, index, filePath + 'current');
  10818. })
  10819. //重命名
  10820. Button() {
  10821. Image($r('app.media.rename2'))
  10822. .fillColor(Color.White)
  10823. .width(20)
  10824. }
  10825. .width(40)
  10826. .height(40)
  10827. .type(ButtonType.Circle)
  10828. .backgroundColor(this.themeColor)
  10829. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  10830. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  10831. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  10832. .margin(5)
  10833. .onClick(() => {
  10834. this.showReNameDialog(item, index + '', filePath)
  10835. })
  10836. Button() {
  10837. Image($r('app.media.delete2'))
  10838. .fillColor(Color.White)
  10839. .width(20)
  10840. }
  10841. .width(40)
  10842. .height(40)
  10843. .type(ButtonType.Circle)
  10844. .backgroundColor(this.themeColor)
  10845. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  10846. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  10847. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  10848. .margin(5)
  10849. .onClick(() => {
  10850. this.selectedFiles.push(item)
  10851. this.showWarnIsDelete()
  10852. // this.showWarnIsDeleteFile(item, index + '', filePath)
  10853. })
  10854. Button() {
  10855. Image($r('app.media.share2'))
  10856. .fillColor(Color.White)
  10857. .width(20)
  10858. }
  10859. .width(40)
  10860. .height(40)
  10861. .type(ButtonType.Circle)
  10862. .backgroundColor(this.themeColor)
  10863. .margin(5)
  10864. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10865. .onClick(() => {
  10866. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  10867. })
  10868. }
  10869. }
  10870. /**
  10871. * 穿山甲banner广告
  10872. */
  10873. // private declare bannerAd: CSJNativeExpressAd;
  10874. // @State private status: string = "未加载"
  10875. // @State private isShowAd: boolean = false
  10876. // private declare mAdSlot: AdSlot;
  10877. // private mBiddingAdm = '' //服务端bidding才需要设置
  10878. // private expressLoadAdListener: NativeExpressAdListener = {
  10879. // /**
  10880. // * 加载失败的回调
  10881. // *
  10882. // * @param code
  10883. // * @param message
  10884. // */
  10885. // onError: (code: number, message: string) => {
  10886. // console.error("加载广告失败,code=" + code + ",message=" + message);
  10887. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  10888. // },
  10889. //
  10890. // /**
  10891. // * 广告加载成功的回调,接入方可以在这个回调中进行渲染
  10892. // *
  10893. // * @param ads 返回的广告列表
  10894. // */
  10895. //
  10896. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  10897. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  10898. // if (ads && ads.length > 0) {
  10899. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  10900. // ad.setExpressInteractionListener({
  10901. // /**
  10902. // *广告的点击回调
  10903. // * @param type 广告的交互类型
  10904. // */
  10905. // onAdClicked: (type: number) => {
  10906. // console.log("BannerExpressAdPage==onAdClicked......");
  10907. // },
  10908. //
  10909. // /**
  10910. // * 广告的展示回调 每个广告仅回调一次
  10911. // * @param type 广告的交互类型
  10912. // */
  10913. // onAdShow: (type: number) => {
  10914. // console.log("BannerExpressAdPage==onAdShow......");
  10915. // },
  10916. //
  10917. // /**
  10918. // * 模板渲染失败
  10919. // */
  10920. // onRenderFail: (code: number, msg: string) => {
  10921. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  10922. // },
  10923. //
  10924. // /**
  10925. // * 模板渲染成功
  10926. // * @param width 返回view的宽 单位 vp
  10927. // * @param height 返回view的高 单位 vp
  10928. // */
  10929. // onRenderSuccess: (width: number, height: number) => {
  10930. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  10931. // this.bannerAd = ad;
  10932. // this.status = "广告加载完成待展示";
  10933. //
  10934. // this.showBannerAd()
  10935. // }
  10936. // })
  10937. // //渲染广告
  10938. // ad.setSlideIntervalTime(30 * 1000); //设置轮播时间长
  10939. // this.setDislikeCallback(ad); //设置dislike
  10940. // ad.render(this.getUIContext())
  10941. // this.status = "广告加载中...";
  10942. // });
  10943. // }
  10944. // }
  10945. // }
  10946. //
  10947. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  10948. // ad.setDislikeCallback({
  10949. // /**
  10950. // * dislike show
  10951. // */
  10952. // onShow: () => {
  10953. // console.log("BannerExpressAdPage==dislike......show");
  10954. // },
  10955. //
  10956. // /**
  10957. // * @param position 选择的位置
  10958. // * @param value 选择的内容
  10959. // * @param enforceRemove 是否强制关闭广告
  10960. // */
  10961. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  10962. // this.isShowAd = false;
  10963. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value +
  10964. // ",enforce=" + enforceRemove);
  10965. // },
  10966. //
  10967. // /**
  10968. // * 点击取消
  10969. // */
  10970. // onCancel: () => {
  10971. // console.log("BannerExpressAdPage==dislike......onCancel");
  10972. // }
  10973. //
  10974. // })
  10975. // }
  10976. /**
  10977. * 加载Banner广告
  10978. */
  10979. loadBannerAd(rit: string) {
  10980. // if (Utility.isNoble()) {
  10981. // return
  10982. // }
  10983. // if (!Utility.isPassInstallTime(2)) {
  10984. // return
  10985. // }
  10986. // this.isShowAd = false;
  10987. // let adCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
  10988. // this.mAdSlot = new AdSlotBuilder()
  10989. // .setCodeId(rit)
  10990. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  10991. // .setAdCount(1)
  10992. // .setBidAdm(this.mBiddingAdm)
  10993. // .build()
  10994. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  10995. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  10996. // this.status = "广告加载中..."
  10997. }
  10998. /**
  10999. * 展示Banner广告
  11000. */
  11001. // showBannerAd() {
  11002. // if (!this.bannerAd) {
  11003. // return
  11004. // }
  11005. // this.isShowAd = true
  11006. // this.status = "已展示"
  11007. // }
  11008. /**
  11009. * 穿山甲广告代码结束
  11010. */
  11011. }
  11012. //视频气泡窗口的布局
  11013. @Builder
  11014. function customPopupBuilder(dataBu: BubbleBean) {
  11015. List() {
  11016. LazyForEach(new LazyDataSource(dataBu.data), (item: string, index: number) => {
  11017. ListItem() {
  11018. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  11019. Row() {
  11020. Column() {
  11021. Image(dataBu.imageRes[index])
  11022. .height(28)
  11023. .fillColor(dataBu.color)
  11024. .alignSelf(ItemAlign.Center)
  11025. }
  11026. .width(32)
  11027. Text(item)
  11028. .padding({
  11029. top: 10,
  11030. bottom: 10,
  11031. right: 10,
  11032. left: 10
  11033. })
  11034. .fontColor(dataBu.modeType == index ? dataBu.color : $r('app.color.index_tab_font_color'))
  11035. .textAlign(TextAlign.Start)
  11036. .width("100%")
  11037. }
  11038. }
  11039. .backgroundColor($r('app.color.settings_background_main'))
  11040. .margin({ top: 6, bottom: 6 })
  11041. }
  11042. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  11043. .animation({ duration: 500, curve: Curve.Ease, delay: 100 * index }),
  11044. TransitionEffect.scale({ x: 0, y: 0 })))
  11045. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  11046. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  11047. .onClick(() => {
  11048. dataBu.onItemClick?.(index)
  11049. })
  11050. })
  11051. }
  11052. .width(120)
  11053. .divider({
  11054. strokeWidth: 1,
  11055. color: "#22FFFFFF"
  11056. })
  11057. }
  11058. // Function to calculate a hash for the file list
  11059. function simpleHash(fileList: string[]): string {
  11060. let hash = 0;
  11061. const str = fileList.join(',');
  11062. for (let i = 0; i < str.length; i++) {
  11063. const char = str.charCodeAt(i);
  11064. hash = (hash << 5) - hash + char;
  11065. hash |= 0; // Convert to 32bit integer
  11066. }
  11067. return hash.toString();
  11068. }
  11069. interface MoreItem {
  11070. id: number;
  11071. image: Resource;
  11072. title: string;
  11073. }
  11074. //视频气泡窗口的布局
  11075. @Builder
  11076. function cutPopupBuilder(dataBu: BubbleBean) {
  11077. Column() {
  11078. Text(dataBu.isCopy ? '将文件复制到' : '将文件移动到')
  11079. .padding({
  11080. top: 10,
  11081. bottom: 10,
  11082. right: 10,
  11083. left: 10
  11084. })
  11085. .textAlign(TextAlign.Start)
  11086. .width(160)
  11087. .fontWeight(666)
  11088. .fontSize(16)
  11089. List() {
  11090. ForEach(dataBu.data, (item: string, index: number) => {
  11091. ListItem() {
  11092. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  11093. Row() {
  11094. Column() {
  11095. Image($r('app.media.music_group'))
  11096. .height(28)
  11097. .fillColor(dataBu.color)
  11098. .alignSelf(ItemAlign.Center)
  11099. }
  11100. .width(32)
  11101. Text(item.startsWith('.') ? item.replace(/\./g, '') : item)
  11102. .padding({
  11103. top: 10,
  11104. bottom: 10,
  11105. right: 10,
  11106. left: 10
  11107. })
  11108. .textAlign(TextAlign.Start).width("100%")// .fontColor(Color.Gray)
  11109. .fontSize(15)
  11110. }
  11111. }
  11112. .backgroundColor(Color.Transparent)
  11113. .margin({ top: 7, bottom: 7 })
  11114. }
  11115. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  11116. .animation({ duration: 500 }),
  11117. TransitionEffect.scale({ x: 0, y: 0 })))
  11118. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  11119. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  11120. .onClick(() => {
  11121. dataBu.onItemClick?.(index)
  11122. })
  11123. })
  11124. }
  11125. .width(150)
  11126. .divider({
  11127. strokeWidth: 1,
  11128. color: "#22FFFFFF"
  11129. })
  11130. }
  11131. .height(300)
  11132. .padding({
  11133. bottom: 30
  11134. })
  11135. }
  11136. function getFileDirName(filePath: string,rootPath:string): string{
  11137. if(filePath===rootPath){
  11138. return '首页'
  11139. }
  11140. let result = FileUtil.getFileName(filePath)
  11141. if(StrUtil.isEmpty(result))
  11142. return ''
  11143. if(result.startsWith('.'))
  11144. result = result.replace(/\./g, '')
  11145. return result
  11146. }