LocalMusic.ets 427 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556
  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.High)// 用于重采样后的抗锯齿
  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. if(this.twoFingerType==4){
  2903. this.isGridMusic = false
  2904. this.twoFingerType=3
  2905. }else{
  2906. this.isGridMusic = !this.isGridMusic
  2907. }
  2908. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  2909. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  2910. })
  2911. }
  2912. .width('100%')
  2913. .padding(10)
  2914. .height(50)
  2915. .visibility(this.modeType === 0 || this.modeType === 1 || this.isCanBack ? Visibility.Visible : Visibility.None)
  2916. .border({
  2917. width: { bottom: 1 },
  2918. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2919. })
  2920. }
  2921. .visibility(this.isShowAllBar ? Visibility.Visible : Visibility.None)
  2922. }
  2923. // 第二步:popup构造器定义弹框内容
  2924. @Builder popupBuilder() {
  2925. Column({ space: 2 }) {
  2926. Text('友情提示:双指缩放可以放大缩小列表')
  2927. .fontSize(12)
  2928. .fontWeight(FontWeight.Regular)
  2929. .fontColor($r('app.color.text_color'))
  2930. }
  2931. .justifyContent(FlexAlign.SpaceAround)
  2932. .width(220)
  2933. .height(55)
  2934. .padding(15)
  2935. }
  2936. //搜索功能的实现
  2937. @State searchText: string = ''; // 用户输入内容
  2938. @State filteredList: Array<VideoItem> = []; // 过滤后的结果
  2939. @State isSearchMode: boolean = false
  2940. // 实时搜索逻辑(带防抖)
  2941. private onSearchInput(value: string) {
  2942. this.searchText = value.trim();
  2943. let mSearchList: Array<VideoItem> = []
  2944. switch (this.modeType) {
  2945. case 0:
  2946. mSearchList = this.videoLocalList
  2947. break;
  2948. case 1:
  2949. mSearchList = this.mediaKuList
  2950. break;
  2951. case 2:
  2952. mSearchList = this.artistList
  2953. break;
  2954. case 3:
  2955. mSearchList = this.albumList
  2956. break;
  2957. }
  2958. // 新增条件判断:空输入时显示所有数据
  2959. if (this.searchText === '') {
  2960. this.filteredList = [...mSearchList]; // 创建新数组以触发状态更新
  2961. } else {
  2962. this.filteredList = mSearchList.filter((item: VideoItem) => {
  2963. return item.name.toLowerCase().includes(this.searchText.toLowerCase());
  2964. });
  2965. }
  2966. this.updateListData(this.filteredList);
  2967. // this.isSearchMode = false; // 根据业务需求决定是否启用
  2968. }
  2969. @State dragItem: number = -1
  2970. @State scaleItem: number = -1
  2971. @State neighborItem: number = -1
  2972. @State neighborScale: number = -1
  2973. @State offsetY: number = 0
  2974. private dragRefOffset: number = 0
  2975. private ITEM_INTV: number = 78
  2976. scaleSelect(item: number): number {
  2977. if (this.scaleItem === item) {
  2978. return 1.05
  2979. } else if (this.neighborItem === item) {
  2980. return this.neighborScale
  2981. } else {
  2982. return 1
  2983. }
  2984. }
  2985. itemMove(index: number, newIndex: number): void {
  2986. if (newIndex < 0 || newIndex >= this.videoLocalList.length) {
  2987. return;
  2988. }
  2989. let tmp = this.videoLocalList.splice(index, 1);
  2990. this.videoLocalList.splice(newIndex, 0, tmp[0]);
  2991. this.dataSource.pushArrayData(this.videoLocalList)
  2992. }
  2993. //瀑布流布局 支持双指缩放
  2994. @State columns: number = 2;
  2995. @State waterFlowScale: number = 1;
  2996. @State imageScale: number = 1;
  2997. @State waterFlowOpacity: number = 1;
  2998. @State waterFlowSnapshot: image.PixelMap | undefined = undefined;
  2999. private columnChanged: boolean = false;
  3000. private oldColumn: number = this.columns;
  3001. private pinchTime: number = 0;
  3002. // 根据缩放阈值改变列数,触发WaterFlow重新布局
  3003. changeColumns(scale: number) {
  3004. if (scale > (this.columns / (this.columns - 0.5)) && this.columns > 1) {
  3005. this.columns--;
  3006. this.columnChanged = true;
  3007. } else if (scale < 1 && this.columns < 4) {
  3008. this.columns++;
  3009. this.columnChanged = true;
  3010. }
  3011. }
  3012. @Builder
  3013. getWaterView(){
  3014. Scroll(this.scroller) {
  3015. Column() {
  3016. if(this.isShowCoverHeader()){
  3017. this.coverHeader()
  3018. }else {
  3019. this.listViewTitle()
  3020. }
  3021. WaterFlow({
  3022. scroller:this.waterScroller,
  3023. layoutMode: WaterFlowLayoutMode.SLIDING_WINDOW
  3024. }) {
  3025. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3026. FlowItem() {
  3027. this.MusicWaterCardItem(item,index)
  3028. }
  3029. .width('100%')
  3030. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.9 })
  3031. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3032. {
  3033. preview: MenuPreviewMode.IMAGE,
  3034. previewAnimationOptions: { scale: [0.8, 1.0] },
  3035. })
  3036. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3037. {
  3038. preview: MenuPreviewMode.IMAGE,
  3039. previewAnimationOptions: { scale: [0.8, 1.0] },
  3040. })
  3041. .transition(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }))
  3042. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3043. TransitionEffect.scale({ x: 0, y: 0 }) ))
  3044. .gesture(
  3045. GestureGroup(GestureMode.Exclusive,
  3046. SwipeGesture({ direction: SwipeDirection.Horizontal })
  3047. .onAction((event: GestureEvent) => {
  3048. if (event) {
  3049. // this.sideBarController.openSideBar()
  3050. }
  3051. }),
  3052. TapGesture({ count: 1, fingers: 1 })
  3053. .onAction(async () => {
  3054. })
  3055. )
  3056. )
  3057. }, (item: VideoItem) => item.filePath)
  3058. }
  3059. // .columnsTemplate('repeat(auto-fit, 160)')
  3060. .id('waterflow') // 设置id用于截图
  3061. .columnsTemplate('1fr '.repeat(this.columns)) // 动态生成列模板,如:'1fr 1fr 1fr'表示3列等宽
  3062. .columnsGap(12) // 列间距
  3063. .rowsGap(16) // 行间距
  3064. .cachedCount(6)
  3065. .margin(
  3066. this.isHiCar()?{bottom:this.bottomBarHeight+90}:
  3067. {bottom:this.isShowCoverHeader()? 25:
  3068. this.isCoverOpacity()?this.topBarHeight+this.bottomBarHeight+78
  3069. :this.topBarHeight+this.bottomBarHeight+108})
  3070. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3071. .animation({ duration: 500, curve: Curve.Ease }))
  3072. .scrollBar(BarState.Off)
  3073. // .fadingEdge(true, { fadingEdgeLength: LengthMetrics.vp(38) })
  3074. // 效果:只有向上或者向下滑动到顶部时才会有弹簧回弹效果
  3075. .edgeEffect(EdgeEffect.Spring, { alwaysEnabled: true })
  3076. .width('100%')
  3077. .height('100%')
  3078. .padding(10)
  3079. .opacity(this.waterFlowOpacity)
  3080. .scale({
  3081. x: this.waterFlowScale,
  3082. y: this.waterFlowScale,
  3083. centerX: 0,
  3084. centerY: 0
  3085. })
  3086. .onAppear(() => {
  3087. this.scroller.scrollEdge(Edge.Top)
  3088. })
  3089. .nestedScroll({
  3090. scrollForward: NestedScrollMode.PARENT_FIRST,
  3091. scrollBackward: NestedScrollMode.SELF_FIRST
  3092. })
  3093. .priorityGesture(
  3094. PinchGesture()
  3095. .onActionStart((event: GestureEvent) => {
  3096. // 双指捏合手势识别成功时截图
  3097. this.pinchTime = event.timestamp;
  3098. this.columnChanged = false;
  3099. this.oldColumn = this.columns;
  3100. this.getUIContext().getComponentSnapshot().get('waterflow', (error: Error, pixmap: image.PixelMap) => {
  3101. if (error) {
  3102. console.info('error:' + JSON.stringify(error));
  3103. return;
  3104. }
  3105. this.waterFlowSnapshot = pixmap;
  3106. if ((this.oldColumn === 1 ) && event.scale > 1|| (this.oldColumn === 4 && event.scale < 1)) {
  3107. console.info("onecold onActionStart oldColumn:" + this.oldColumn)
  3108. if (this.oldColumn ===4) {
  3109. this.twoFingerType =3
  3110. this.isGridMusic = true
  3111. }else if (this.oldColumn ===1) {
  3112. this.twoFingerType =1
  3113. this.isGridMusic = false
  3114. }
  3115. return;
  3116. }
  3117. })
  3118. })
  3119. .onActionUpdate((event: GestureEvent) => {
  3120. // 手势更新:处理缩放逻辑和视觉效果
  3121. // 边界限制:防止超出列数范围时继续缩放
  3122. if ((this.oldColumn === 1 && event.scale > 1) || (this.oldColumn === 4 && event.scale < 1)) {
  3123. return;
  3124. }
  3125. // 节流处理:避免过于频繁的更新,提升性能
  3126. if (event.timestamp - this.pinchTime < 10000000) {
  3127. return;
  3128. }
  3129. this.pinchTime = event.timestamp;
  3130. this.waterFlowScale = event.scale;
  3131. this.imageScale = event.scale;
  3132. // 根据缩放比例设置WaterFlow透明度
  3133. this.waterFlowOpacity = (this.waterFlowScale > 1) ? (this.waterFlowScale - 1) : (1 - this.waterFlowScale);
  3134. this.waterFlowOpacity *= 3;
  3135. if (!this.columnChanged) {
  3136. this.changeColumns(event.scale);
  3137. }
  3138. // 列数改变后的缩放比例调整:避免出现空白区域
  3139. if (this.columnChanged) {
  3140. this.waterFlowScale = this.imageScale * this.columns / this.oldColumn;
  3141. // 限制缩放范围,确保视觉效果自然
  3142. if (event.scale < 1) {
  3143. this.waterFlowScale = this.waterFlowScale > 1 ? this.waterFlowScale : 1;
  3144. } else {
  3145. this.waterFlowScale = this.waterFlowScale < 1 ? this.waterFlowScale : 1;
  3146. }
  3147. }
  3148. })
  3149. .onActionEnd((event: GestureEvent) => {
  3150. // 手势结束:执行归位动画并保存状态
  3151. // 执行归位动画:平滑过渡到正常状态
  3152. this.getUIContext()?.animateTo({ duration: 300 }, () => {
  3153. this.waterFlowScale = 1;
  3154. this.waterFlowOpacity = 1;
  3155. })
  3156. // 持久化保存当前列数:下次启动时恢复
  3157. PreferencesUtil.putSync('lastColumns', this.columns);
  3158. })
  3159. )
  3160. //允许拖拽音乐和视频到List或Grid上自动导入视频
  3161. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3162. .onDrop((event?: DragEvent) => {
  3163. try {
  3164. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3165. if (dragData !== undefined) {
  3166. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3167. if (records.length > 0) {
  3168. for (let i = 0; i < records.length; i++) {
  3169. let types = records[i].getTypes();
  3170. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3171. const fileUriUds =
  3172. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3173. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3174. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3175. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3176. this.targetFile = fileUriUds.oriUri;
  3177. this.saveVideoDatas([this.targetFile])
  3178. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3179. }
  3180. }
  3181. }
  3182. } else {
  3183. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3184. }
  3185. } else {
  3186. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3187. }
  3188. } catch (error) {
  3189. const err = error as BusinessError;
  3190. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3191. }
  3192. })
  3193. }
  3194. }
  3195. .scrollBar(BarState.Off)
  3196. }
  3197. //瀑布流卡片布局
  3198. @Builder
  3199. private MusicWaterCardItem(item: VideoItem, index: number) {
  3200. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3201. Stack() {
  3202. Column() {
  3203. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3204. .backgroundImageSize(ImageSize.Auto)
  3205. .borderRadius({
  3206. topLeft: 12,
  3207. topRight : 12,
  3208. bottomLeft: 0,
  3209. bottomRight: 0
  3210. })
  3211. .draggable(false)// 禁止长按手势拖动
  3212. // .autoResize(true) // 重采样,可减少内存占用
  3213. // .interpolation(ImageInterpolation.High)// 用于重采样后的抗锯齿
  3214. .width('100%')
  3215. .height('auto')
  3216. .objectFit(ImageFit.Auto)
  3217. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3218. height: '99%' ,
  3219. dragBar: true,
  3220. onDisappear: () => {
  3221. this.longItemFilePath = '';
  3222. this.tempLyricContent = ''
  3223. },
  3224. showClose: true,
  3225. preferType: SheetType.CENTER ,
  3226. title: { title: '编辑标签' }
  3227. })
  3228. .draggable(false)
  3229. .opacity(this.opacityItem)// 绑定透明度
  3230. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3231. // .animation({ duration: 500, curve: Curve.Ease }))
  3232. .animation({
  3233. duration: 666,
  3234. curve: 'ease-in-out' // 可选动画曲线
  3235. })
  3236. .margin({
  3237. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3238. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3239. })
  3240. Column() {
  3241. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3242. .fontSize(this.columns == 4 ||this.columns==3? 12 : this.columns == 2 ? 15 : 18)
  3243. .maxLines(1)
  3244. .fontWeight(FontWeight.Bold)
  3245. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3246. .animation({
  3247. duration: 555,
  3248. curve: 'Linear',
  3249. })
  3250. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3251. height: '95%',
  3252. dragBar: true,
  3253. showClose: true,
  3254. onDisappear: () => {
  3255. this.longItemFilePathDetail = '';
  3256. },
  3257. blurStyle:BlurStyle.Thin,
  3258. backgroundColor:Color.Transparent,
  3259. preferType: SheetType.CENTER ,
  3260. title: { title: '详情' }
  3261. })
  3262. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3263. $r('app.color.text_color'))
  3264. Column() {
  3265. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  3266. .fontSize(11)
  3267. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 14)
  3268. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3269. .fontColor($r('app.color.text_color'))
  3270. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  3271. .fontSize(11)
  3272. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 14)
  3273. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3274. .fontColor($r('app.color.text_color'))
  3275. Row(){
  3276. Column(){
  3277. Text(item.md5Str?.includes('Lossless')?
  3278. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  3279. .fontSize(this.columns == 4 ||this.columns==3? 8 : this.columns == 2 ? 9 : 11)
  3280. .padding({ top: 3,right:6,left:6,bottom:3 })
  3281. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3282. $r('app.color.text_color'))
  3283. .fontWeight(500)
  3284. .borderRadius(12)
  3285. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  3286. .backgroundColor('#FFC107')
  3287. .visibility(StrUtil.isEmpty(item.md5Str)||this.twoFingerType==1?Visibility.None:Visibility.Visible)
  3288. }
  3289. .margin({ top: 2 ,right:6})
  3290. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  3291. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  3292. Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  3293. .fontSize(this.columns == 4 ||this.columns==3? 10 : this.columns == 2 ? 12 : 13)
  3294. .maxLines(1)
  3295. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3296. .margin({ top: 2})
  3297. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  3298. || item.type == CommonConstants.TYPE_IS_ALBUM
  3299. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3300. .fontWeight(FontWeight.Medium)
  3301. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3302. $r('app.color.text_color'))
  3303. }
  3304. }
  3305. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  3306. }
  3307. .height(this.columns == 4 ||this.columns==3? item.type==CommonConstants.TYPE_IS_DIR?30:40
  3308. : this.columns == 2 ? (item.type==CommonConstants.TYPE_IS_DIR?38:48) :
  3309. (item.type==CommonConstants.TYPE_IS_DIR?48:58))
  3310. .width('100%')
  3311. .justifyContent(FlexAlign.Center)
  3312. .margin({
  3313. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3314. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3315. })
  3316. }
  3317. .width('100%')
  3318. .borderRadius(12)
  3319. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  3320. .backgroundImageSize({ height: '100%', width: '100%' })
  3321. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  3322. .animation({ curve: Curve.Sharp, duration: 300 })
  3323. Checkbox({ name: 'checkbox' + index })
  3324. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  3325. .selectedColor(this.themeColor)
  3326. .shape(CheckBoxShape.CIRCLE)
  3327. .opacity(this.isMultiSelect ? 1 : 0)
  3328. .animation({
  3329. duration: 666,
  3330. curve: 'Smooth' // 可选动画曲线
  3331. })
  3332. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  3333. Visibility.None)
  3334. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  3335. .margin({ left: 20, top: 8, bottom: 8 })
  3336. .width(38)
  3337. .height(38)
  3338. }
  3339. }
  3340. .backgroundColor(Color.Transparent)
  3341. .width('100%')
  3342. .height('auto')
  3343. .padding({top:2})
  3344. .reuseId('card_item')
  3345. .onClick(() => {
  3346. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3347. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3348. this.handleFileSelection(item, !isChecked);
  3349. } else {
  3350. this.doPlay(item, index)
  3351. }
  3352. })
  3353. }
  3354. // Grid布局的开始
  3355. private dragRefOffSetX: number = 0;
  3356. private dragRefOffSetY: number = 0;
  3357. private FIX_VP_X: number = 180;
  3358. private FIX_VP_Y: number = 84;
  3359. isDraggable(index: number): boolean {
  3360. return index >= 0;
  3361. }
  3362. getRowEnd(item: number) {
  3363. if (item.toString() === '0') {
  3364. return 1;
  3365. } else {
  3366. return 0;
  3367. }
  3368. }
  3369. // [Start itemMove_start]
  3370. // itemMoveGrid(index: number, newIndex: number): void {
  3371. // if (!this.isDraggable(newIndex)) {
  3372. // return;
  3373. // }
  3374. // let tmp = this.videoLocalList.splice(index, 1);
  3375. // this.videoLocalList.splice(newIndex, 0, tmp[0]);
  3376. // // this.bigItemIndex = this.videoLocalList.findIndex((item) => item === 0);
  3377. // }
  3378. isInLeft(index: number) {
  3379. return index % 2 == 0;
  3380. }
  3381. down(index: number): void {
  3382. if ([this.videoLocalList.length - 1, this.videoLocalList.length - 2].includes(index)) {
  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. up(index: number): void {
  3390. if (!this.isDraggable(index - 2)) {
  3391. return;
  3392. }
  3393. this.offsetY += this.FIX_VP_Y;
  3394. this.dragRefOffSetY -= this.FIX_VP_Y;
  3395. this.itemMove(index, index - 1);
  3396. }
  3397. left(index: number): void {
  3398. if (this.isInLeft(index)) {
  3399. return;
  3400. }
  3401. if (!this.isDraggable(index - 1)) {
  3402. return;
  3403. }
  3404. this.offsetX += this.FIX_VP_X;
  3405. this.dragRefOffSetX -= this.FIX_VP_X;
  3406. this.itemMove(index, index - 1)
  3407. }
  3408. right(index: number): void {
  3409. if (!this.isInLeft(index)) {
  3410. return;
  3411. }
  3412. if (!this.isDraggable(index + 1)) {
  3413. return;
  3414. }
  3415. this.offsetX -= this.FIX_VP_X;
  3416. this.dragRefOffSetX += this.FIX_VP_X;
  3417. this.itemMove(index, index + 1)
  3418. }
  3419. private scroller: Scroller = new Scroller();
  3420. private waterScroller: Scroller = new Scroller();
  3421. @State startIndex: number = 0
  3422. @State endIndex: number = 0
  3423. @State scaleValue: number = 1
  3424. @State pinchValue: number = 1
  3425. layoutOptionsForHeader: GridLayoutOptions = {
  3426. regularSize: [1, 1], // 只支持[1, 1]
  3427. irregularIndexes: [0], // 索引为0的GridItem占用一行
  3428. };
  3429. @Builder
  3430. getGridView() {
  3431. Grid(this.scroller, this.layoutOptionsForHeader) {
  3432. GridItem() {
  3433. if (this.isShowCoverHeader()) {
  3434. this.coverHeader()
  3435. } else {
  3436. this.listViewTitle()
  3437. }
  3438. }
  3439. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3440. GridItem() {
  3441. Stack({ alignContent: Alignment.Center }) {
  3442. this.MusicItemGrid(item, index)
  3443. }
  3444. }
  3445. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3446. {
  3447. preview: MenuPreviewMode.IMAGE,
  3448. previewAnimationOptions: { scale: [0.8, 1.0] },
  3449. })
  3450. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3451. {
  3452. preview: MenuPreviewMode.IMAGE,
  3453. previewAnimationOptions: { scale: [0.8, 1.0] },
  3454. })
  3455. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3456. TransitionEffect.scale({ x: 0, y: 0 })))
  3457. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3458. .scale({ x: this.scaleItem === index ? 1.02 : 1, y: this.scaleItem === index ? 1.02 : 1 })
  3459. .zIndex(this.dragItem === index ? 1 : 0)
  3460. .translate(this.dragItem === index ? { x: this.offsetX, y: this.offsetY } : { x: 0, y: 0 })
  3461. // .hitTestBehavior(this.isDraggable(this.videoLocalList.indexOf(item)) ? HitTestMode.Default : HitTestMode.None)
  3462. }, (item: VideoItem) => item.filePath)
  3463. }
  3464. .width(this.isShowHeader ? '100%' : '94%')
  3465. .height('100%')
  3466. .editMode(true)
  3467. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3468. .animation({ duration: 500, curve: Curve.Ease }))
  3469. .margin(
  3470. this.isHiCar()?{bottom:this.bottomBarHeight+98}:
  3471. {
  3472. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+30 : this.topBarHeight+90)
  3473. : (this.isShowCoverHeader() ? this.topBarHeight+45 : this.topBarHeight+128)
  3474. })
  3475. .reuseId('grid_item')
  3476. .layoutWeight(1)
  3477. .scrollBar(BarState.Off)
  3478. .supportAnimation(true)
  3479. .cachedCount(this.twoFingerType==1?5:this.twoFingerType==2?4:3)
  3480. // .columnsTemplate('1fr '.repeat(this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM ? 2 : 5))
  3481. .columnsTemplate(
  3482. this.twoFingerType == 3 ? 'repeat(auto-fit, 160)' :
  3483. this.twoFingerType == 2 ? 'repeat(auto-fit, 110)' : 'repeat(auto-fit, 80)'
  3484. )
  3485. .rowsGap(this.isShowDrawer ? 25 : (this.twoFingerType == 3 ? 10 : this.twoFingerType == 2 ? 5 : 1))
  3486. .visibility(this.isGridMusic ? Visibility.Visible : Visibility.None)
  3487. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3488. .gesture(PinchGesture({ fingers: 2 })
  3489. .onActionEnd((event: GestureEvent) => {
  3490. this.setGridTwoFingers()
  3491. })
  3492. .onActionUpdate(e => {
  3493. this.scaleValue = this.pinchValue * e.scale
  3494. })
  3495. .onActionStart(e => {
  3496. }))
  3497. .enableScrollInteraction(true)
  3498. // 滚轴滑动,记录下滑动时的起始位置和终点位置
  3499. .onScrollIndex((start: number, end: number) => {
  3500. this.startIndex = start
  3501. this.endIndex = end
  3502. })
  3503. .onScrollFrameBegin((offset: number) => {
  3504. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  3505. // if (this.isPhoneLan()) {
  3506. // this.setBarHeightHide(offset)
  3507. // } else
  3508. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3509. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3510. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3511. if (this.isScrollHide) {
  3512. this.setBarHeightHide2(offset)
  3513. } else {
  3514. this.setBarHeightNormal()
  3515. }
  3516. } else {
  3517. this.setBarHeightHide(offset)
  3518. }
  3519. return { offsetRemain: offset };
  3520. })
  3521. //允许拖拽音乐和视频到List或Grid上自动导入视频
  3522. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3523. .onDrop((event?: DragEvent) => {
  3524. try {
  3525. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3526. if (dragData !== undefined) {
  3527. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3528. if (records.length > 0) {
  3529. for (let i = 0; i < records.length; i++) {
  3530. let types = records[i].getTypes();
  3531. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3532. const fileUriUds =
  3533. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3534. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3535. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3536. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3537. this.targetFile = fileUriUds.oriUri;
  3538. this.saveVideoDatas([this.targetFile])
  3539. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3540. }
  3541. }
  3542. }
  3543. } else {
  3544. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3545. }
  3546. } else {
  3547. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3548. }
  3549. } catch (error) {
  3550. const err = error as BusinessError;
  3551. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3552. }
  3553. })
  3554. }
  3555. @State targetFile: string = '';
  3556. setGridTwoFingers() {
  3557. this.pinchValue = this.scaleValue;
  3558. Logger.info('this.pinchValue = ' + this.pinchValue);
  3559. if (this.pinchValue >= 1) {
  3560. this.twoFingerType++
  3561. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3562. if(this.twoFingerType >= 4){
  3563. this.twoFingerType = 4//切换成瀑布流
  3564. this.columns = 4
  3565. }
  3566. } else {
  3567. this.twoFingerType--
  3568. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3569. if (this.twoFingerType < 1) {
  3570. this.twoFingerType = 3
  3571. this.isGridMusic = false
  3572. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3573. }
  3574. }
  3575. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3576. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3577. this.pinchValue = 1;
  3578. this.scaleValue = 1;
  3579. }
  3580. @State longItemFilePath: string = ''
  3581. @State tempLyricContent: string = ''
  3582. @Builder
  3583. private MusicItemGrid(item: VideoItem, index: number) {
  3584. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3585. Stack() {
  3586. Column() {
  3587. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3588. .height(this.getGridHeight())
  3589. .width(this.getGridWight())
  3590. .draggable(false)
  3591. .interpolation(ImageInterpolation.High)// 用于重采样后的抗锯齿
  3592. .autoResize(true) // 重采样,可减少内存占用
  3593. .alt($r('app.media.ic_avatar2'))
  3594. .clip(true)
  3595. .borderRadius({
  3596. topLeft: 12,
  3597. topRight: 12,
  3598. bottomLeft: 0,
  3599. bottomRight: 0
  3600. })
  3601. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3602. height: '99%' ,
  3603. dragBar: true,
  3604. onDisappear: () => {
  3605. this.longItemFilePath = '';
  3606. this.tempLyricContent = ''
  3607. },
  3608. showClose: true,
  3609. preferType: SheetType.CENTER ,
  3610. title: { title: '编辑标签' }
  3611. })
  3612. .draggable(false)
  3613. .opacity(this.opacityItem)// 绑定透明度
  3614. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3615. // .animation({ duration: 500, curve: Curve.Ease }))
  3616. .animation({
  3617. duration: 666,
  3618. curve: 'ease-in-out' // 可选动画曲线
  3619. })
  3620. .margin({
  3621. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3622. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3623. })
  3624. Column() {
  3625. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3626. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  3627. .maxLines(1)
  3628. .fontWeight(FontWeight.Bold)
  3629. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3630. .animation({
  3631. duration: 555,
  3632. curve: 'Linear',
  3633. })
  3634. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3635. height: '95%',
  3636. dragBar: true,
  3637. showClose: true,
  3638. onDisappear: () => {
  3639. this.longItemFilePathDetail = '';
  3640. },
  3641. blurStyle:BlurStyle.Thin,
  3642. backgroundColor:Color.Transparent,
  3643. preferType: SheetType.CENTER ,
  3644. title: { title: '详情' }
  3645. })
  3646. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3647. $r('app.color.text_color'))
  3648. Column() {
  3649. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  3650. .fontSize(11)
  3651. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3652. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3653. .fontColor($r('app.color.text_color'))
  3654. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  3655. .fontSize(11)
  3656. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3657. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3658. .fontColor($r('app.color.text_color'))
  3659. Row(){
  3660. Column(){
  3661. Text(item.md5Str?.includes('Lossless')?
  3662. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  3663. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  3664. .padding({ top: 3,right:6,left:6,bottom:3 })
  3665. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3666. $r('app.color.text_color'))
  3667. .fontWeight(500)
  3668. .borderRadius(12)
  3669. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  3670. .backgroundColor('#FFC107')
  3671. .visibility(StrUtil.isEmpty(item.md5Str)||this.twoFingerType==1?Visibility.None:Visibility.Visible)
  3672. }
  3673. .margin({ top: 2 ,right:6})
  3674. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  3675. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  3676. Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  3677. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 13)
  3678. .maxLines(1)
  3679. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3680. .margin({ top: 2})
  3681. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  3682. || item.type == CommonConstants.TYPE_IS_ALBUM
  3683. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3684. .fontWeight(FontWeight.Medium)
  3685. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3686. $r('app.color.text_color'))
  3687. }
  3688. }
  3689. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  3690. }
  3691. .height(this.twoFingerType == 3 ? 60 : this.twoFingerType == 2 ? 48 : 35)
  3692. .width(this.getGridWight())
  3693. .justifyContent(FlexAlign.Center)
  3694. .margin({
  3695. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3696. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3697. })
  3698. }
  3699. .width(this.getGridWight())
  3700. .borderRadius(12)
  3701. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  3702. .backgroundImageSize({ height: '100%', width: '100%' })
  3703. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  3704. .animation({ curve: Curve.Sharp, duration: 300 })
  3705. Checkbox({ name: 'checkbox' + index })
  3706. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  3707. .selectedColor(this.themeColor)
  3708. .shape(CheckBoxShape.CIRCLE)
  3709. .opacity(this.isMultiSelect ? 1 : 0)
  3710. .animation({
  3711. duration: 666,
  3712. curve: 'Smooth' // 可选动画曲线
  3713. })
  3714. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  3715. Visibility.None)
  3716. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  3717. .margin({ left: 20, top: 8, bottom: 8 })
  3718. .width(38)
  3719. .height(38)
  3720. }
  3721. }
  3722. .backgroundColor(Color.Transparent)
  3723. .width('100%')
  3724. .padding({ top: 15 })
  3725. .height(this.getGridAllHeight())
  3726. .onClick(() => {
  3727. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3728. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3729. this.handleFileSelection(item, !isChecked);
  3730. } else {
  3731. this.doPlay(item, index)
  3732. }
  3733. })
  3734. }
  3735. getGridAllHeight() {
  3736. let heightG = 222
  3737. switch (this.twoFingerType) {
  3738. case 1:
  3739. heightG = 118
  3740. break;
  3741. case 2:
  3742. heightG = 168
  3743. break;
  3744. case 3:
  3745. heightG = 222
  3746. break;
  3747. }
  3748. return heightG
  3749. }
  3750. getGridHeight() {
  3751. let heightG = 150
  3752. switch (this.twoFingerType) {
  3753. case 1:
  3754. heightG = 55
  3755. break;
  3756. case 2:
  3757. heightG = 100
  3758. break;
  3759. case 3:
  3760. heightG = 150
  3761. break;
  3762. }
  3763. return heightG
  3764. }
  3765. getGridWight() {
  3766. let wightG = 158
  3767. switch (this.twoFingerType) {
  3768. case 1:
  3769. wightG = 80
  3770. break;
  3771. case 2:
  3772. wightG = 110
  3773. break;
  3774. case 3:
  3775. wightG = 158
  3776. break;
  3777. }
  3778. return wightG
  3779. }
  3780. @State isShowDetail:boolean = false
  3781. // @State isShowDetailGrid:boolean = false
  3782. // @State isShowEditGrid:boolean = false
  3783. @State longItemFilePathDetail:string =''
  3784. @Builder
  3785. MenuBuilder(item: VideoItem, index: number, filePath: string) {
  3786. if(
  3787. ((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  3788. ||(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3789. item.name === LocalMusic.STR_HISTORY_MUSIC)
  3790. ){
  3791. //如果是专辑和艺术家的首页,不能长按
  3792. //如果是我的收藏 最近播放等也不能长按
  3793. }else{
  3794. Scroll() {
  3795. Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
  3796. Menu() {
  3797. MenuItem({
  3798. symbolStartIcon: new SymbolGlyphModifier(Utility.getIsFav(this.favList, item) ?
  3799. $r('sys.symbol.heart_fill') : $r('sys.symbol.heart')),
  3800. content: Utility.getIsFav(this.favList, item) ? '取消收藏' : '收藏'
  3801. })
  3802. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3803. .onClick(() => {
  3804. if (item) {
  3805. this.doFav(item)
  3806. }
  3807. this.longItemFilePath = ''
  3808. })
  3809. MenuItem({
  3810. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.forward_end_fill')),
  3811. content: '下一首播放'
  3812. })
  3813. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3814. .onClick(() => {
  3815. this.addToNextPlay(item);
  3816. this.longItemFilePath = ''
  3817. })
  3818. MenuItem({
  3819. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
  3820. content: '编辑标签'
  3821. })
  3822. .bindSheet($$this.isShowEdit, this.editSheet(item), {
  3823. height: '99%',
  3824. dragBar: true,
  3825. showClose: true,
  3826. preferType: SheetType.CENTER ,
  3827. title: { title: '编辑标签' }
  3828. })
  3829. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3830. .onClick(async() => {
  3831. this.setEditStrEmpty()
  3832. this.tempLyricContent = await this.getLyricContent(item);
  3833. // console.info('onecold 长按this.tempLyricContent' +this.tempLyricContent)
  3834. if(this.isGridMusic||this.twoFingerType==4){
  3835. this.longItemFilePath = item.filePath
  3836. }else{
  3837. this.isShowEdit = !this.isShowEdit;
  3838. }
  3839. })
  3840. MenuItem({
  3841. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.checkmark_square_on_square')),
  3842. content: $r('app.string.select_all')
  3843. })
  3844. .onClick(() => {
  3845. this.isMultiSelect = !this.isMultiSelect
  3846. this.longItemFilePath = ''
  3847. this.selectedFiles.push(item)
  3848. })
  3849. MenuItem({
  3850. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.rename')),
  3851. content: $r('app.string.rename')
  3852. })
  3853. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3854. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3855. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3856. .onClick(() => {
  3857. this.showReNameDialog(item, index + '', filePath)
  3858. this.longItemFilePath = ''
  3859. })
  3860. MenuItem({
  3861. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
  3862. content: $r('app.string.delete')
  3863. })
  3864. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3865. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3866. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3867. .onClick(() => {
  3868. this.selectedFiles.push(item)
  3869. this.showWarnIsDelete()
  3870. this.longItemFilePath = ''
  3871. })
  3872. MenuItem({
  3873. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.info_circle')),
  3874. content: $r('app.string.detail')
  3875. })
  3876. .bindSheet($$this.isShowDetail, this.detailSheet(item), {
  3877. height:'95%',
  3878. dragBar: true,
  3879. showClose: true,
  3880. blurStyle:BlurStyle.Thin,
  3881. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  3882. backgroundColor:Color.Transparent,
  3883. title: { title: '详情信息' }
  3884. })
  3885. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3886. .onClick(() => {
  3887. if(this.isGridMusic||this.twoFingerType==4){
  3888. this.longItemFilePathDetail = item.filePath
  3889. }else{
  3890. this.isShowDetail = !this.isShowDetail
  3891. }
  3892. })
  3893. MenuItem({
  3894. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.share')),
  3895. content: $r('app.string.share')
  3896. })
  3897. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3898. .onClick(() => {
  3899. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  3900. this.longItemFilePath = ''
  3901. })
  3902. }
  3903. .font({ size: 15, weight: FontWeight.Normal })
  3904. }
  3905. .width(180)
  3906. }
  3907. .height('auto')
  3908. }
  3909. }
  3910. private listMaxScrollOffsetY: number = 0
  3911. @State selectedIndex: number = -1
  3912. setlistTwoFingers() {
  3913. this.pinchValue = this.scaleValue;
  3914. Logger.info('this.pinchValue = ' + this.pinchValue);
  3915. if (this.pinchValue >= 1) {
  3916. this.twoFingerType++
  3917. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3918. if (this.twoFingerType > 3) {
  3919. this.twoFingerType = 1
  3920. this.isGridMusic = true
  3921. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3922. }
  3923. } else {
  3924. this.twoFingerType--
  3925. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3926. if (this.twoFingerType < 1) {
  3927. this.twoFingerType = 4
  3928. this.columns = 1
  3929. }
  3930. }
  3931. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3932. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  3933. this.pinchValue = 1;
  3934. this.scaleValue = 1;
  3935. }
  3936. @Builder
  3937. getListView() {
  3938. List({ scroller: this.listScroller }) {
  3939. ListItemGroup({ header: this.coverHeader() }) {
  3940. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3941. ListItem() {
  3942. Column() {
  3943. if (item.type === CommonConstants.TYPE_IS_DIR
  3944. || item.type === CommonConstants.TYPE_IS_ARTIST || item.type === CommonConstants.TYPE_IS_ALBUM) {
  3945. this.DirItem(item, index)
  3946. } else if (item.type === CommonConstants.TYPE_IS_CSJAD) { //如果是穿山甲广告
  3947. } else {
  3948. this.MusicItem(item, index)
  3949. }
  3950. }
  3951. .shadow(this.scaleItem === index ? {
  3952. radius: 70,
  3953. color: '#15000000',
  3954. offsetX: 0,
  3955. offsetY: 0
  3956. } :
  3957. {
  3958. radius: 0,
  3959. color: '#15000000',
  3960. offsetX: 0,
  3961. offsetY: 0
  3962. })
  3963. .animation({ curve: Curve.Sharp, duration: 300 })
  3964. }
  3965. // .transition(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }))
  3966. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  3967. .animation({ duration: 500 }),
  3968. TransitionEffect.scale({ x: 0, y: 0 })))
  3969. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3970. .swipeAction((
  3971. (this.isSwipe&&this.modeType == 0 || this.modeType == 1 || ((this.modeType == 3 || this.modeType == 2) && this.isCanBack))
  3972. && item.type !== CommonConstants.TYPE_IS_CSJAD &&
  3973. !this.isHistory) ? { end: this.DeleteButton(item, index, item.filePath) } : {}) //左滑
  3974. .onClick(() => {
  3975. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3976. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3977. this.handleFileSelection(item, !isChecked);
  3978. } else {
  3979. this.doPlay(item, index)
  3980. }
  3981. })
  3982. //拖动List关键代码开始
  3983. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  3984. .zIndex(this.dragItem === index ? 1 : 0)
  3985. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  3986. .gesture(
  3987. GestureGroup(GestureMode.Sequence,
  3988. LongPressGesture({ repeat: true })
  3989. .onAction((event?: GestureEvent) => {
  3990. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3991. this.scaleItem = index
  3992. })
  3993. })
  3994. .onActionEnd(() => {
  3995. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3996. this.scaleItem = -1
  3997. })
  3998. }),
  3999. PanGesture({ fingers: 1, direction: null, distance: 0 })
  4000. .onActionStart(() => {
  4001. this.dragItem = index // 记录当前拖动项索引
  4002. this.dragRefOffset = 0 // 重置偏移基准
  4003. })
  4004. .onActionUpdate((event: GestureEvent) => {
  4005. this.offsetY = event.offsetY - this.dragRefOffset;
  4006. this.neighborItem = -1;
  4007. let indexA = this.videoLocalList.indexOf(item);
  4008. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  4009. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  4010. let value: number = 0;
  4011. if (this.offsetY < 0) {
  4012. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  4013. this.neighborItem = indexA - 1;
  4014. this.neighborScale = 1 - value / 20;
  4015. } else if (this.offsetY > 0) {
  4016. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  4017. this.neighborItem = indexA + 1;
  4018. this.neighborScale = 1 - value / 20;
  4019. }
  4020. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.videoLocalList.length) {
  4021. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4022. this.offsetY -= this.ITEM_INTV;
  4023. this.dragRefOffset += this.ITEM_INTV;
  4024. this.itemMove(indexA, indexA + 1);
  4025. });
  4026. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  4027. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4028. this.offsetY += this.ITEM_INTV;
  4029. this.dragRefOffset -= this.ITEM_INTV;
  4030. this.itemMove(indexA, indexA - 1);
  4031. });
  4032. }
  4033. let curListOffset = this.listScroller.currentOffset()
  4034. // 获取手指信息
  4035. let fingerInfo = event.fingerList[0]
  4036. let clickPercentY =
  4037. (fingerInfo.globalY - Number(this.listArea.globalPosition.y)) / Number(this.listArea.height)
  4038. if (clickPercentY > 0.8 && !this.listScroller.isAtEnd()) {
  4039. let scrollVelocity = clickPercentY > 0.9 ? 4 : 2
  4040. if (this.listMaxScrollOffsetY - curListOffset.yOffset > scrollVelocity + 5) {
  4041. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset += scrollVelocity })
  4042. }
  4043. } else if (clickPercentY < 0.2 && curListOffset.yOffset >= 0) {
  4044. let scrollVelocity = clickPercentY < 0.1 ? 4 : 2
  4045. if (curListOffset.yOffset > scrollVelocity + 5) {
  4046. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset -= scrollVelocity })
  4047. }
  4048. }
  4049. })
  4050. .onActionEnd((event: GestureEvent) => {
  4051. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4052. this.dragItem = -1
  4053. this.neighborItem = -1
  4054. })
  4055. animateTo({
  4056. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  4057. }, () => {
  4058. this.scaleItem = -1
  4059. })
  4060. })
  4061. )
  4062. .onCancel(() => {
  4063. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  4064. this.dragItem = -1
  4065. this.neighborItem = -1
  4066. })
  4067. animateTo({
  4068. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  4069. }, () => {
  4070. this.scaleItem = -1
  4071. })
  4072. })
  4073. ) //拖动List关键代码结束
  4074. }, (item: VideoItem) => item.filePath)
  4075. }
  4076. }
  4077. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  4078. .gesture(PinchGesture({ fingers: 2 })
  4079. .onActionEnd((event: GestureEvent) => {
  4080. this.setlistTwoFingers()
  4081. })
  4082. .onActionUpdate(e => {
  4083. this.scaleValue = this.pinchValue * e.scale
  4084. })
  4085. .onActionStart(e => {
  4086. }))
  4087. // .divider({ strokeWidth: 1, color: this.isDarkMode? '#333333':'#ffe9f0f0' })
  4088. .margin(
  4089. this.isHiCar()&&(this.windowWidth>1800&&this.windowHeight>=1200)?{bottom:this.bottomBarHeight+98}:
  4090. {
  4091. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+25 : this.topBarHeight+80)
  4092. : (this.isShowCoverHeader() ? this.topBarHeight+35 : this.isHiCarSmall()?this.topBarHeight+90:this.topBarHeight+125)
  4093. })
  4094. .cachedCount(6)
  4095. .reuseId('list_item')
  4096. .borderRadius(20)
  4097. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  4098. TransitionEffect.scale({ x: 0, y: 0 })))
  4099. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  4100. // .animation({ duration: 500, curve: Curve.Ease }))
  4101. .layoutWeight(1)
  4102. .onScrollIndex((start) => {
  4103. this.selectedIndex = start
  4104. })
  4105. .visibility(this.isGridMusic ? Visibility.None : Visibility.Visible)
  4106. .lanes(
  4107. new BreakpointType<number>({
  4108. sm: 1,
  4109. md: 2,
  4110. lg: 2,
  4111. xl: 3,
  4112. xxl: 4
  4113. }).getValue(this.currentBreakpoint),
  4114. new BreakpointType<number>({
  4115. sm: 0,
  4116. md: 12,
  4117. lg: 12,
  4118. xl: 16,
  4119. xxl: 20
  4120. }).getValue(this.currentBreakpoint)
  4121. )
  4122. .onAreaChange((oldValue: Area, newValue: Area) => {
  4123. this.listArea = newValue
  4124. if (this.twoFingerType == 3) {
  4125. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_BIG) - 10
  4126. } else if (this.twoFingerType == 2) {
  4127. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT) - 10
  4128. } else if (this.twoFingerType == 1) {
  4129. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_SMALL) - 10
  4130. }
  4131. })
  4132. .onScrollFrameBegin((offset: number) => {
  4133. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  4134. // if (this.isPhoneLan()) {
  4135. // this.setBarHeightHide(offset)
  4136. // } else
  4137. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  4138. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  4139. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  4140. if (this.isScrollHide) {
  4141. this.setBarHeightHide2(offset)
  4142. } else {
  4143. this.setBarHeightNormal()
  4144. }
  4145. } else {
  4146. this.setBarHeightHide(offset)
  4147. }
  4148. return { offsetRemain: offset };
  4149. })
  4150. //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
  4151. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  4152. .onDrop((event?: DragEvent) => {
  4153. try {
  4154. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  4155. if (dragData !== undefined) {
  4156. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  4157. if (records.length > 0) {
  4158. for (let i = 0; i < records.length; i++) {
  4159. let types = records[i].getTypes();
  4160. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  4161. const fileUriUds =
  4162. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  4163. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  4164. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  4165. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  4166. this.targetFile = fileUriUds.oriUri;
  4167. this.saveVideoDatas([this.targetFile])
  4168. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  4169. }
  4170. }
  4171. }
  4172. } else {
  4173. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  4174. }
  4175. } else {
  4176. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  4177. }
  4178. } catch (error) {
  4179. const err = error as BusinessError;
  4180. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  4181. }
  4182. })
  4183. }
  4184. setBarHeightNormal() {
  4185. this.hideDone = false;
  4186. this.getUIContext().animateTo({
  4187. duration: 300
  4188. }, () => {
  4189. this.bottomBarHeight = 55 + 0;
  4190. this.topBarHeight = 50 + 0;
  4191. this.barOpacity = 1;
  4192. this.barBottomOpacity = 1
  4193. this.currentYOffset = 0;
  4194. this.isHiding = false;
  4195. });
  4196. }
  4197. setBarHeightHide(offset: number) {
  4198. if (offset > 0 && !this.hideDone) {
  4199. this.currentYOffset += offset;
  4200. if (this.currentYOffset <= 100) {
  4201. this.bottomBarHeight = this.bottomBarHeight * (1 - this.currentYOffset / 100);
  4202. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  4203. this.barOpacity = 1 - this.currentYOffset / 100;
  4204. this.barBottomOpacity = 1 - this.currentYOffset / 100;
  4205. } else {
  4206. this.topBarHeight = 0;
  4207. this.bottomBarHeight = 0;
  4208. this.barBottomOpacity = 0
  4209. this.barOpacity = 0;
  4210. this.hideDone = true;
  4211. }
  4212. this.isHiding = true;
  4213. }
  4214. if (offset < 0 && this.isHiding) {
  4215. this.hideDone = false;
  4216. this.getUIContext().animateTo({
  4217. duration: 300
  4218. }, () => {
  4219. this.bottomBarHeight = 55 + 0;
  4220. this.topBarHeight = 50 + 0;
  4221. this.barOpacity = 1;
  4222. this.barBottomOpacity = 1
  4223. this.currentYOffset = 0;
  4224. this.isHiding = false;
  4225. });
  4226. }
  4227. }
  4228. //这个方法没隐藏bottomBar,只隐藏topbar
  4229. setBarHeightHide2(offset: number) {
  4230. if (offset > 0 && !this.hideDone) {
  4231. this.currentYOffset += offset;
  4232. if (this.currentYOffset <= 100) {
  4233. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  4234. this.barOpacity = 1 - this.currentYOffset / 100;
  4235. } else {
  4236. this.topBarHeight = 0;
  4237. this.barOpacity = 0;
  4238. this.hideDone = true;
  4239. }
  4240. this.isHiding = true;
  4241. }
  4242. if (offset < 0 && this.isHiding) {
  4243. this.hideDone = false;
  4244. this.getUIContext().animateTo({
  4245. duration: 300
  4246. }, () => {
  4247. this.topBarHeight = 50 + 0;
  4248. this.barOpacity = 1;
  4249. this.currentYOffset = 0;
  4250. this.isHiding = false;
  4251. });
  4252. }
  4253. }
  4254. private doPlay(item: VideoItem, index?: number, isFromSonPlayList?: boolean) {
  4255. switch (item.type) {
  4256. case CommonConstants.TYPE_IS_DIR:
  4257. // 进入歌单前安全保存当前滚动偏移量,支持列表和网格
  4258. let offsetB = 0
  4259. if(this.twoFingerType==4){
  4260. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4261. let cur = this.waterScroller.currentOffset()
  4262. if (cur && typeof cur.yOffset === 'number') {
  4263. offsetB = cur.yOffset
  4264. }
  4265. }
  4266. this.mScrollMap.set('lastWaterDirScrollOffset', offsetB)
  4267. }else
  4268. if (this.isGridMusic) {
  4269. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4270. let cur = this.scroller.currentOffset()
  4271. if (cur && typeof cur.yOffset === 'number') {
  4272. offsetB = cur.yOffset
  4273. }
  4274. }
  4275. this.mScrollMap.set('lastGridDirScrollOffset', offsetB)
  4276. } else {
  4277. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4278. let cur = this.listScroller.currentOffset()
  4279. if (cur && typeof cur.yOffset === 'number') {
  4280. offsetB = cur.yOffset
  4281. }
  4282. }
  4283. this.mScrollMap.set('lastListDirScrollOffset', offsetB)
  4284. }
  4285. if (item.name === LocalMusic.STR_LOCK_VIDEO) {
  4286. this.showVerifyDialog()
  4287. this.currentTitleName = '私密音频'
  4288. this.currentTitleCover = $r('app.media.ic_avatar5')
  4289. } else if (item.name === LocalMusic.STR_HISTORY_MUSIC) {
  4290. this.titleBarModel.setTitleName('最近播放')
  4291. this.currentTitleCover = $r('app.media.ic_avatar2')
  4292. this.currentTitleName = '最近播放'
  4293. //加载动画效果
  4294. this.updateListData(this.historyList, true)
  4295. // this.videoLocalList = this.historyList
  4296. if (ArrayUtil.isEmpty(this.historyList)) {
  4297. ToastUtil.showToast('最近播放记录空空如也')
  4298. } else {
  4299. this.currentTitleCover = Utility.getFirstCoverFromList(this.historyList)
  4300. }
  4301. this.isHistory = true
  4302. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4303. } else if (item.name === LocalMusic.STR_FAC_VIDEO) {
  4304. this.titleBarModel.setTitleName('我的收藏')
  4305. this.currentTitleName = '我的收藏'
  4306. this.currentTitleCover = $r('app.media.ic_avatar1')
  4307. //加载动画效果
  4308. this.updateListData(this.favList)
  4309. if (ArrayUtil.isEmpty(this.favList)) {
  4310. ToastUtil.showToast('无音乐收藏记录')
  4311. } else {
  4312. this.currentTitleCover = Utility.getFirstCoverFromList(this.favList)
  4313. }
  4314. this.isFavMusic = true
  4315. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4316. } else {
  4317. this.currentTitleName = item.name
  4318. this.currentPath = item.filePath
  4319. this.currentTitleCover = $r('app.media.ic_avatar5')
  4320. this.getSortedFiles(this.currentPath)
  4321. }
  4322. //进入歌单的时候的滚动位置在顶部
  4323. if(this.twoFingerType==4){
  4324. setTimeout(() => {
  4325. this.waterScroller.scrollEdge(Edge.Top)
  4326. this.scroller.scrollEdge(Edge.Top)
  4327. }, 380)
  4328. }else{
  4329. if (this.isGridMusic) {
  4330. this.scroller.scrollEdge(Edge.Top)
  4331. }
  4332. }
  4333. break;
  4334. case CommonConstants.TYPE_IS_ARTIST:
  4335. // 进入艺术家前安全保存当前滚动偏移量,支持列表和网格
  4336. let offsetA = 0
  4337. if(this.twoFingerType==4){
  4338. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4339. let cur = this.waterScroller.currentOffset()
  4340. if (cur && typeof cur.yOffset === 'number') {
  4341. offsetA = cur.yOffset
  4342. }
  4343. }
  4344. this.mScrollMap.set('lastWaterArtistScrollOffset', offsetA)
  4345. }else
  4346. if (this.isGridMusic) {
  4347. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4348. let cur = this.scroller.currentOffset()
  4349. if (cur && typeof cur.yOffset === 'number') {
  4350. offsetA = cur.yOffset
  4351. }
  4352. }
  4353. this.mScrollMap.set('lastGridArtistScrollOffset', offsetA)
  4354. } else {
  4355. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4356. let cur = this.listScroller.currentOffset()
  4357. if (cur && typeof cur.yOffset === 'number') {
  4358. offsetA = cur.yOffset
  4359. }
  4360. }
  4361. this.mScrollMap.set('lastListArtistScrollOffset', offsetA)
  4362. }
  4363. let mList = this.artistMap.get(item.name)
  4364. if (mList !== undefined && ArrayUtil.isNotEmpty(mList)) {
  4365. Utility.doSortListAscending(mList)
  4366. this.isCanBack = true
  4367. this.titleBarModel.setTitleName(item.name)
  4368. this.currentTitleName = '艺术家:' + item.name
  4369. if (item.pixelMapPath) {
  4370. this.currentTitleCover = item.pixelMapPath
  4371. }
  4372. this.updateListData(mList)
  4373. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4374. }
  4375. //进入歌单的时候的滚动位置在顶部
  4376. if(this.twoFingerType==4){
  4377. setTimeout(() => {
  4378. this.waterScroller.scrollEdge(Edge.Top)
  4379. this.scroller.scrollEdge(Edge.Top)
  4380. }, 380)
  4381. }else{
  4382. if (this.isGridMusic) {
  4383. this.scroller.scrollEdge(Edge.Top)
  4384. }
  4385. }
  4386. break;
  4387. case CommonConstants.TYPE_IS_ALBUM:
  4388. // 进入专辑前安全保存当前滚动偏移量,支持列表和网格
  4389. let offset = 0
  4390. if(this.twoFingerType==4){
  4391. if (this.waterScroller && typeof this.waterScroller.currentOffset === 'function') {
  4392. let cur = this.waterScroller.currentOffset()
  4393. if (cur && typeof cur.yOffset === 'number') {
  4394. offset = cur.yOffset
  4395. }
  4396. }
  4397. this.mScrollMap.set('lastWaterAlBumScrollOffset', offset)
  4398. }else
  4399. if (this.isGridMusic) {
  4400. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4401. let cur = this.scroller.currentOffset()
  4402. if (cur && typeof cur.yOffset === 'number') {
  4403. offset = cur.yOffset
  4404. }
  4405. }
  4406. this.mScrollMap.set('lastGridAlBumScrollOffset', offset)
  4407. } else {
  4408. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4409. let cur = this.listScroller.currentOffset()
  4410. if (cur && typeof cur.yOffset === 'number') {
  4411. offset = cur.yOffset
  4412. }
  4413. }
  4414. this.mScrollMap.set('lastListAlBumScrollOffset', offset)
  4415. }
  4416. let albumList = this.albumMap.get(item.name)
  4417. if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
  4418. Utility.doSortListAscending(albumList)
  4419. this.isCanBack = true
  4420. this.titleBarModel.setTitleName(item.name)
  4421. this.currentTitleName = '专辑:' + item.name
  4422. if (item.pixelMapPath) {
  4423. this.currentTitleCover = item.pixelMapPath
  4424. }
  4425. this.updateListData(albumList)
  4426. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4427. this.mScrollMap.set(item.name, this.selectedIndex)
  4428. }
  4429. //进入歌单的时候的滚动位置在顶部
  4430. if(this.twoFingerType==4){
  4431. setTimeout(() => {
  4432. this.waterScroller.scrollEdge(Edge.Top)
  4433. this.scroller.scrollEdge(Edge.Top)
  4434. }, 380)
  4435. }else{
  4436. if (this.isGridMusic) {
  4437. this.scroller.scrollEdge(Edge.Top)
  4438. }
  4439. }
  4440. break;
  4441. case CommonConstants.TYPE_IS_CSJAD:
  4442. return
  4443. break;
  4444. case CommonConstants.TYPE_LOCAL:
  4445. if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
  4446. this.stop();
  4447. }
  4448. if (isFromSonPlayList) { //点击来自右下角的播放列表
  4449. this.currentSong = item
  4450. if (index !== undefined) {
  4451. this.curIndex = index
  4452. }
  4453. } else {
  4454. let globalVideoList = Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL) as VideoItem[];
  4455. this.curIndex = Utility.getCurIndexFromGlobalList(globalVideoList, item.filePath)
  4456. this.songList = globalVideoList
  4457. this.sonDataSource.pushArrayData(this.songList)
  4458. this.currentSong = globalVideoList[this.curIndex]
  4459. }
  4460. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  4461. this.videoUrl = this.currentSong.filePath
  4462. this.name = this.currentSong.name
  4463. this.cover = this.currentSong.pixelMapPath
  4464. this.artist = this.currentSong.artist
  4465. LogUtil.info('this.currentSong.duration =' + this.currentSong.duration)
  4466. LogUtil.info('this.currentSong.sampleRate =' + this.currentSong.sampleRate)
  4467. LogUtil.info('this.currentSongmimeType =' + this.currentSong.mimeType)
  4468. console.info('onecold startPlayOrResumePlay 4547')
  4469. this.startPlayOrResumePlay()
  4470. break;
  4471. }
  4472. }
  4473. @Builder
  4474. PlayController() {
  4475. Column() {
  4476. Line().width('100%').height(1).backgroundColor($r('app.color.index_background'))
  4477. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4478. Row() {
  4479. if(this.isHiCar()){
  4480. this.playConRigth()
  4481. Column(){
  4482. this.centerName()
  4483. }.layoutWeight(1)
  4484. .onClick(()=>{
  4485. this.showPlayerView()
  4486. })
  4487. this.playConLeft(false)
  4488. }else{
  4489. this.playConLeft()
  4490. this.playConRigth()
  4491. }
  4492. }
  4493. .width('100%')
  4494. .height(this.bottomBarHeight)
  4495. .justifyContent(FlexAlign.Center)
  4496. .hitTestBehavior(HitTestMode.Transparent)
  4497. .backgroundColor(this.isCustomizeBg ? Color.Transparent : $r('app.color.bottom_control_background'))
  4498. .bindContentCover($$this.isShowPlay, this.MusicPlayBuilder(), {
  4499. // modalTransition: ModalTransition.DEFAULT,
  4500. transition: AnimationHelper.transitionInDown(666),
  4501. backgroundColor: 'rgba(0, 0, 0, 0.9)',
  4502. })
  4503. .padding({
  4504. left: 16,
  4505. right: 16
  4506. })
  4507. Line()
  4508. .width('100%')
  4509. .height(25)
  4510. .backgroundColor($r('app.color.bottom_control_background'))// .visibility(this.isPhoneLan()?Visibility.None:this.isCustomizeBg?Visibility.Hidden:Visibility.Visible)
  4511. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4512. }
  4513. .clickEffect({ level: ClickEffectLevel.HEAVY })
  4514. }
  4515. @State isFrontWhite: boolean = false
  4516. @Builder
  4517. centerName() {
  4518. Column() {
  4519. Text(this.currentSong?.name)
  4520. .fontSize(16)
  4521. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4522. .maxLines(1)
  4523. .fontColor($r('app.color.text_color'))
  4524. .fontWeight(500);
  4525. Row() {
  4526. Text(this.currentSong?.artist)
  4527. .margin({ top: 2 })
  4528. .fontSize(13)
  4529. .textAlign(TextAlign.Start)
  4530. .maxLines(1)
  4531. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4532. .fontColor($r('app.color.text_color'));
  4533. }
  4534. .visibility(this.currentSong?.artist? Visibility.Visible:Visibility.None)
  4535. }
  4536. .alignItems(HorizontalAlign.Center)
  4537. }
  4538. @Builder
  4539. playConLeft(isLeft: boolean = true) {
  4540. Row() {
  4541. RotatingCover({ songLabel: this.currentSong?.pixelMapPath });
  4542. Column() {
  4543. Text(this.currentSong?.name)
  4544. .fontSize(16)
  4545. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4546. .maxLines(1)
  4547. .fontColor($r('app.color.text_color'))
  4548. .fontWeight(500);
  4549. Row() {
  4550. Text(this.currentSong?.artist)
  4551. .margin({ top: 2 })
  4552. .fontSize(13)
  4553. .textAlign(TextAlign.Start)
  4554. .maxLines(1)
  4555. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  4556. .fontColor($r('app.color.text_color'));
  4557. }
  4558. .visibility(this.currentSong?.artist? Visibility.Visible:Visibility.None)
  4559. }
  4560. .alignItems(isLeft?HorizontalAlign.Start:HorizontalAlign.End)
  4561. .margin({ right: isLeft?22:10 })
  4562. .visibility(isLeft? Visibility.Visible:Visibility.None)
  4563. }
  4564. .padding({ right: 18 })
  4565. .layoutWeight(isLeft?1:0)
  4566. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4567. .onClick(() => {
  4568. this.showPlayerView()
  4569. })
  4570. }
  4571. //打开播放页
  4572. showPlayerView() {
  4573. if (ArrayUtil.isNotEmpty(this.songList)) {
  4574. this.isShowPlay = true;
  4575. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc';
  4576. this.initLyric(lyricPath);
  4577. this.startAutoHide();
  4578. } else {
  4579. ToastUtil.showToast('当前播放列表为空,请先导入音乐。');
  4580. }
  4581. }
  4582. @Builder
  4583. playConRigth() {
  4584. Row() {
  4585. Image($r('app.media.hm_previous'))
  4586. .height(28)
  4587. .width(28)
  4588. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4589. .margin({ left: 8, right: 16 })
  4590. .fillColor(this.themeColor)
  4591. .displayPriority(2)
  4592. .onClick(() => {
  4593. if (ArrayUtil.isNotEmpty(this.songList)) {
  4594. this.playPrevious()
  4595. } else {
  4596. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4597. }
  4598. })
  4599. //播放进度条
  4600. Stack() {
  4601. Progress({
  4602. value: Math.floor(this.progressValue),
  4603. type: ProgressType.Ring,
  4604. })
  4605. .color(this.themeColor)// 进度条前景色为灰色
  4606. .backgroundColor($r('app.color.index_background'))
  4607. .height(40)
  4608. .aspectRatio(CommonConstants.ASPECT_RATIO)
  4609. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
  4610. .height(38)
  4611. .width(38)
  4612. .displayPriority(3)
  4613. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4614. .fillColor(this.themeColor)
  4615. .onClick(() => {
  4616. if (ArrayUtil.isNotEmpty(this.songList)) {
  4617. console.info('onecold playOrPause 4642')
  4618. this.playOrPause()
  4619. } else {
  4620. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4621. }
  4622. })
  4623. }
  4624. Image($r('app.media.hm_next'))
  4625. .height(28)
  4626. .width(28)
  4627. .margin({
  4628. right: 16,
  4629. left: 16
  4630. })
  4631. .fillColor(this.themeColor)
  4632. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4633. .displayPriority(2)
  4634. .onClick(() => {
  4635. if (ArrayUtil.isNotEmpty(this.songList)) {
  4636. this.playNext()
  4637. } else {
  4638. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4639. }
  4640. })
  4641. Image($r('app.media.hm_playlist'))
  4642. .height(28)
  4643. .width(28)
  4644. .displayPriority(1)
  4645. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4646. .fillColor(this.themeColor)
  4647. .bindSheet($$this.isShowSheet, this.PlayListSheet(), {
  4648. height: '95%',
  4649. dragBar: true,
  4650. showClose: true,
  4651. blurStyle: BlurStyle.Thin,
  4652. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  4653. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  4654. title: {
  4655. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  4656. + `(${this.songList.length}首)`
  4657. }
  4658. })
  4659. .onClick(() => {
  4660. if (ArrayUtil.isNotEmpty(this.songList)) {
  4661. this.isShowSheet = !this.isShowSheet;
  4662. this.isFrontWhite = false
  4663. LogUtil.info('onecold scrollToIndex = ' + this.curIndex)
  4664. this.scrollIndex()
  4665. } else {
  4666. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4667. }
  4668. })
  4669. }
  4670. }
  4671. scrollIndex(){
  4672. if(this.curIndex>500)//条数太大的时候 滚动非常卡 导致闪退,先改为不滚
  4673. return
  4674. try {
  4675. setTimeout(() => {
  4676. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  4677. this.playListScroller.scrollToIndex(this.curIndex,true, ScrollAlign.CENTER)
  4678. })
  4679. }, 123)
  4680. }catch (error) {
  4681. console.error(`onecold scrollIndex出错: ${error}`);
  4682. }
  4683. }
  4684. //播放列表布局
  4685. @Builder
  4686. PlayListSheet() {
  4687. Column() {
  4688. this.PlayList()
  4689. }
  4690. .width('100%')
  4691. .height('100%')
  4692. }
  4693. @State titleStr: string = ''
  4694. @State ablumStr: string = ''
  4695. @State artistStr: string = ''
  4696. @State lyricConStr: string = ''
  4697. @State currentEditItem: string = ''
  4698. @State yearStr: string = ''
  4699. @State trackStr: string = ''
  4700. @State genreStr: string = ''
  4701. @State imagePathStr: string = ''
  4702. @State albumArtistStr: string = ''
  4703. @State composerStr: string = ''
  4704. @State lyricistStr: string = ''
  4705. @State commentStr: string = ''
  4706. @State discStr: string = ''
  4707. doUpdateData() {
  4708. setTimeout(() => {
  4709. if (this.modeType === 0) {
  4710. this.deleteCache(this.currentPath)
  4711. this.getSortedFiles(this.currentPath)
  4712. }
  4713. workerInstance.postMessage({ code: 2, data: this.context });
  4714. workerInstance.postMessage({ code: 3, data: this.context });
  4715. workerInstance.postMessage({ code: 4, data: this.context });
  4716. }, 999)
  4717. }
  4718. //编辑信息
  4719. async doEdit(item: VideoItem) {
  4720. if (!item) {
  4721. return
  4722. }
  4723. if (StrUtil.isEmpty(this.titleStr)) {
  4724. ToastUtil.showToast('标题不能为空')
  4725. return
  4726. }
  4727. // let doChangeLyric = false
  4728. // if(item.filePath==this.currentSong?.filePath){
  4729. // if(this.lyricConStr !== this.lyricContent){
  4730. // doChangeLyric = true
  4731. // }
  4732. // }else if(this.lyricConStr !== this.tempLyricContent){
  4733. // doChangeLyric = true
  4734. // }
  4735. //用户更改了封面,那就内嵌下封面
  4736. if(StrUtil.isNotEmpty(this.imagePathStr)){
  4737. const resultCover:boolean = await changeMusicCover(this.context,
  4738. item.filePath,this.imagePathStr,true);
  4739. this.imagePathStr = ''
  4740. if(resultCover){
  4741. ToastUtil.showToast('内嵌封面成功')
  4742. }
  4743. }
  4744. const metadata:FFMpegTags = {
  4745. title: this.titleStr,
  4746. artist: this.artistStr,
  4747. album: this.ablumStr,
  4748. // LYRICS:this.lyricConStr,
  4749. // USLT:this.lyricConStr,
  4750. TYER:this.yearStr,
  4751. genre:this.genreStr,
  4752. track:this.trackStr,
  4753. album_artist:this.albumArtistStr,
  4754. TPE2:this.albumArtistStr,//ID3v2 中通常没有专门的 "专辑艺术家" 字段,但有些软件会使用 TPE2 来表示专辑艺
  4755. COMPOSER:this.composerStr,
  4756. lyricist:this.lyricistStr,
  4757. TEXT:this.lyricistStr,//ID3v2 使用 TEXT 字段来表示作词者
  4758. comment:this.commentStr,
  4759. // comm:this.commentStr,//ID3v2:使用 COMM(Comment)字段。
  4760. disc:this.discStr,
  4761. };
  4762. //内嵌下标签的值,设置overwrite为true会直接修改原文件
  4763. const result:boolean = await repairAudioMetadata(
  4764. item.filePath,
  4765. this.lyricConStr,
  4766. metadata,
  4767. true
  4768. );
  4769. if (result) {
  4770. this.table.updateMediaInfo(item.filePath, this.titleStr, this.artistStr, this.ablumStr,this.lyricConStr,
  4771. this.yearStr,this.genreStr,this.trackStr,this.albumArtistStr,this.composerStr, this.lyricistStr,this.commentStr,this.discStr,
  4772. (success: boolean, error?: string) => {
  4773. // this.isShowEdit = false
  4774. if (success) {
  4775. console.log(" onecold 编辑信息成功,数据库已同步");
  4776. ToastUtil.showToast('内嵌音乐标签成功')
  4777. this.isShowMoreView = false
  4778. this.name = this.titleStr
  4779. if (item.filePath == this.currentSong?.filePath) {
  4780. this.currentSong.name = this.titleStr
  4781. this.artist = this.artistStr
  4782. this.currentSong.artist = this.artistStr
  4783. this.currentSong.album = this.ablumStr
  4784. this.currentSong.year = this.yearStr
  4785. this.currentSong.genre = this.genreStr
  4786. this.currentSong.track = this.trackStr
  4787. this.currentSong.lyricContent = this.lyricConStr
  4788. this.initLyric(item.filePath)
  4789. this.currentSong.ALBUMARTIST = this.albumArtistStr
  4790. this.currentSong.COMPOSER = this.composerStr
  4791. this.currentSong.LYRICIST = this.lyricistStr
  4792. this.currentSong.COMMENT = this.commentStr
  4793. }
  4794. this.doUpdateData()
  4795. } else {
  4796. // ToastUtil.showToast('保存失败' + error?.toString())
  4797. console.error(" onecold 编辑信息数据库失败原因: " + error);
  4798. }
  4799. });
  4800. console.log(' onecold 元数据标签更新成功,');
  4801. } else {
  4802. ToastUtil.showToast('内嵌音乐标签失败')
  4803. console.log('onecold 内嵌音乐标签失败');
  4804. }
  4805. this.longItemFilePath = ''
  4806. this.tempLyricContent = ''
  4807. this.isShowEdit = false
  4808. }
  4809. updateLyricToDB() {
  4810. }
  4811. @Builder
  4812. editSheet(item: VideoItem) {
  4813. Scroll() {
  4814. Column() {
  4815. this.editDetail(item)
  4816. }
  4817. }
  4818. .width('100%')
  4819. .height('100%')
  4820. }
  4821. @Builder
  4822. editDetail(item: VideoItem) {
  4823. Column() {
  4824. if (item) {
  4825. Row() {
  4826. Stack() {
  4827. Image(StrUtil.isNotEmpty(this.imagePathStr)?this.imagePathStr.startsWith('http')?
  4828. this.imagePathStr:fileUri.getUriFromPath(this.imagePathStr):
  4829. StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.add_image2') :
  4830. item.pixelMapPath)
  4831. .fillColor(this.themeColor)
  4832. .height(88)
  4833. .width(88)
  4834. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
  4835. .borderRadius(12)
  4836. .clip(true)
  4837. .opacity(this.opacityItem)// 绑定透明度
  4838. .margin({ left: 25 })
  4839. }
  4840. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.6})
  4841. .onClick(async () => {
  4842. const imagePath:string | undefined = await this.goSelectImage(item);
  4843. if (imagePath) {
  4844. //用户更改过图片
  4845. this.imagePathStr = imagePath
  4846. }
  4847. })
  4848. .width('28%')
  4849. Row() {
  4850. Column() {
  4851. Text(item.name)
  4852. .fontSize(17)
  4853. .maxLines(1)
  4854. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4855. .animation({
  4856. duration: 555,
  4857. curve: 'Linear',
  4858. })
  4859. .fontColor(this.themeColor)
  4860. .margin({ left: 8 })
  4861. Row() {
  4862. Text(item.artist)
  4863. .fontSize(14)
  4864. .maxLines(1)
  4865. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4866. .padding({ top: 8 })
  4867. .fontColor(this.themeColor)
  4868. .margin({ left: 8 })
  4869. }
  4870. }
  4871. .height('100%')
  4872. .width(100)
  4873. .layoutWeight(1)
  4874. .visibility(this.isDarkMode ? Visibility.None : Visibility.Visible)
  4875. .justifyContent(FlexAlign.Center)
  4876. .alignItems(HorizontalAlign.Start)
  4877. Column() {
  4878. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  4879. Row(){
  4880. SymbolGlyph($r('sys.symbol.picture'))
  4881. .fontSize(18)
  4882. .fontColor([Color.White])
  4883. Text('获取封面')
  4884. .margin({ left: 4 })
  4885. .fontSize(11)
  4886. .fontColor(Color.White)
  4887. .fontWeight(480)
  4888. .textAlign(TextAlign.Center)
  4889. }
  4890. .justifyContent(FlexAlign.Center)
  4891. }
  4892. .height(38)
  4893. .width(100)
  4894. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4895. .backgroundColor(this.themeColor)
  4896. .stateEffect(true)
  4897. .margin({ right: 35 })
  4898. .onClick(async () => {
  4899. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  4900. this.showTipsDialog();
  4901. return; // Return empty string when no API is configured
  4902. }
  4903. const imagePath:string | undefined = await this.doSearchCover(item);
  4904. console.info('onecold imagePath = '+imagePath)
  4905. if (StrUtil.isNotEmpty(imagePath)) {
  4906. //用户更改过图片
  4907. this.imagePathStr = imagePath
  4908. ToastUtil.showToast('获取封面成功')
  4909. }else{
  4910. ToastUtil.showToast('获取封面失败,请重试')
  4911. }
  4912. })
  4913. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  4914. Row(){
  4915. SymbolGlyph($r('sys.symbol.input_mode'))
  4916. .fontSize(18)
  4917. .fontColor([Color.White])
  4918. Text('获取歌词')
  4919. .margin({ left: 4 })
  4920. .fontSize(11)
  4921. .fontColor(Color.White)
  4922. .fontWeight(480)
  4923. .textAlign(TextAlign.Center)
  4924. }
  4925. .justifyContent(FlexAlign.Center)
  4926. }
  4927. .height(38)
  4928. .width(100)
  4929. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  4930. .backgroundColor(this.themeColor)
  4931. .stateEffect(true)
  4932. .margin({ top: 9, right: 35 })
  4933. .onClick(async () => {
  4934. //判断有没有设置api
  4935. let apiUrl = PreferencesUtil.getStringSync('LRC_API', '')
  4936. if (StrUtil.isEmpty(apiUrl)) {
  4937. this.isLyricSetting = false
  4938. this.showTipsDialog()
  4939. return
  4940. }
  4941. let artist = item.artist
  4942. let title = item.name
  4943. if(!artist)
  4944. artist = ''
  4945. if(!title)
  4946. title = ''
  4947. let res: string | undefined = await getApiLyric(apiUrl,title, artist, false);
  4948. if (res && StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  4949. this.lyricConStr = res;
  4950. ToastUtil.showToast('获取歌词成功')
  4951. }else{
  4952. ToastUtil.showToast('获取歌词失败,请重试')
  4953. }
  4954. })
  4955. }
  4956. .justifyContent(FlexAlign.Start)
  4957. }
  4958. .height('100%')
  4959. .justifyContent(FlexAlign.Start)
  4960. .layoutWeight(1)
  4961. }
  4962. .width('100%')
  4963. .height(98)
  4964. Row() {
  4965. Text('标题:')
  4966. .fontSize(14)
  4967. .fontColor($r('app.color.text_color'))
  4968. .margin({ left: 22 })
  4969. TextInput({ text: item.name })
  4970. .height(40)
  4971. .maxLines(1)
  4972. .fontSize(14)
  4973. .layoutWeight(1)
  4974. .fontColor($r('app.color.text_color'))
  4975. .margin({ right: 20, left: 10 })
  4976. .onChange((val: string) => {
  4977. this.titleStr = val
  4978. })
  4979. }
  4980. .width('100%')
  4981. .margin({ top: 10, bottom: 10 })
  4982. .justifyContent(FlexAlign.Start)
  4983. Row() {
  4984. Text('艺术家:')
  4985. .fontSize(14)
  4986. .fontColor($r('app.color.text_color'))
  4987. .margin({ left: 22 })
  4988. TextInput({ text: item.artist })
  4989. .height(40)
  4990. .maxLines(1)
  4991. .fontSize(14)
  4992. .layoutWeight(1)
  4993. .fontColor($r('app.color.text_color'))
  4994. .margin({ right: 20, left: 10 })
  4995. .onChange((val: string) => {
  4996. this.artistStr = val
  4997. })
  4998. }
  4999. .width('100%')
  5000. .margin({ top: 10, bottom: 10 })
  5001. .justifyContent(FlexAlign.Start)
  5002. Row() {
  5003. Text('专辑名:')
  5004. .fontSize(14)
  5005. .fontColor($r('app.color.text_color'))
  5006. .margin({ left: 22 })
  5007. TextInput({ text: item.album })
  5008. .height(40)
  5009. .maxLines(1)
  5010. .fontSize(14)
  5011. .layoutWeight(1)
  5012. .fontColor($r('app.color.text_color'))
  5013. .margin({ right: 20, left: 10 })
  5014. .onChange((val: string) => {
  5015. this.ablumStr = val
  5016. })
  5017. }
  5018. .width('100%')
  5019. .margin({ top: 10, bottom: 10 })
  5020. .justifyContent(FlexAlign.Start)
  5021. Row() {
  5022. Column(){
  5023. Column(){
  5024. Text('歌词:')
  5025. .fontSize(14)
  5026. .fontColor($r('app.color.text_color'))
  5027. .margin({ top:9,left: 22 })
  5028. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5029. SymbolGlyph($r('sys.symbol.trash_fill'))
  5030. .fontSize(25)
  5031. .alignSelf(ItemAlign.Center)
  5032. .margin({ left: 22,top:25})
  5033. }
  5034. .backgroundColor(Color.Transparent)
  5035. .visibility(StrUtil.isEmpty(this.tempLyricContent)&&StrUtil.isEmpty(this.lyricConStr)?
  5036. Visibility.None:Visibility.Visible)
  5037. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5038. .onClick(()=>{
  5039. this.lyricConStr = ''
  5040. this.lyricContent = ''
  5041. this.tempLyricContent = ''
  5042. })
  5043. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  5044. SymbolGlyph($r('sys.symbol.plus'))
  5045. .fontSize(25)
  5046. .alignSelf(ItemAlign.Center)
  5047. .margin({ left: 22,top:25})
  5048. }
  5049. .backgroundColor(Color.Transparent)
  5050. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5051. .onClick( ()=>{
  5052. this.callFilePickerSelectFileForLyric()
  5053. })
  5054. }
  5055. .layoutWeight(1)
  5056. }
  5057. TextArea({ text: StrUtil.isNotEmpty(this.lyricConStr)?this.lyricConStr:
  5058. this.tempLyricContent })
  5059. .type(TextAreaType.NORMAL)
  5060. .height(StrUtil.isEmpty(this.lyricConStr)&&StrUtil.isEmpty(this.tempLyricContent)?100:'auto')
  5061. .fontSize(14)
  5062. .layoutWeight(1)
  5063. .fontColor($r('app.color.text_color'))
  5064. .margin({ right: 20, left: 10 })
  5065. .onChange((val: string) => {
  5066. this.lyricConStr = val
  5067. })
  5068. }
  5069. .width('100%')
  5070. .height(StrUtil.isEmpty(this.lyricConStr)&&StrUtil.isEmpty(this.tempLyricContent)?100:'auto')
  5071. .margin({ top: 10, bottom: 10 })
  5072. .justifyContent(FlexAlign.Start)
  5073. Row() {
  5074. Text('年份:')
  5075. .fontSize(14)
  5076. .fontColor($r('app.color.text_color'))
  5077. .margin({ left: 22 })
  5078. TextInput({ text: item.year })
  5079. .height(40)
  5080. .maxLines(1)
  5081. .fontSize(14)
  5082. .type(InputType.Number)
  5083. .layoutWeight(1)
  5084. .fontColor($r('app.color.text_color'))
  5085. .margin({ right: 20, left: 10 })
  5086. .onChange((val: string) => {
  5087. this.yearStr = val
  5088. })
  5089. }
  5090. .width('100%')
  5091. .margin({ top: 10, bottom: 10 })
  5092. .justifyContent(FlexAlign.Start)
  5093. Row() {
  5094. Text('音轨号:')
  5095. .fontSize(14)
  5096. .fontColor($r('app.color.text_color'))
  5097. .margin({ left: 22 })
  5098. TextInput({ text:item.track=='未知'?'': item.track })
  5099. .height(40)
  5100. .maxLines(1)
  5101. .fontSize(14)
  5102. .type(InputType.Number)
  5103. .layoutWeight(1)
  5104. .fontColor($r('app.color.text_color'))
  5105. .margin({ right: 20, left: 10 })
  5106. .onChange((val: string) => {
  5107. this.trackStr = val
  5108. })
  5109. }
  5110. .width('100%')
  5111. .margin({ top: 10, bottom: 10 })
  5112. .justifyContent(FlexAlign.Start)
  5113. Row() {
  5114. Text('碟号:')
  5115. .fontSize(14)
  5116. .fontColor($r('app.color.text_color'))
  5117. .margin({ left: 22 })
  5118. TextInput({ text:item.disc })
  5119. .height(40)
  5120. .maxLines(1)
  5121. .fontSize(14)
  5122. .type(InputType.Number)
  5123. .layoutWeight(1)
  5124. .fontColor($r('app.color.text_color'))
  5125. .margin({ right: 20, left: 10 })
  5126. .onChange((val: string) => {
  5127. this.discStr = val
  5128. })
  5129. }
  5130. .width('100%')
  5131. .margin({ top: 10, bottom: 10 })
  5132. .justifyContent(FlexAlign.Start)
  5133. Row() {
  5134. Text('风格:')
  5135. .fontSize(14)
  5136. .fontColor($r('app.color.text_color'))
  5137. .margin({ left: 22 })
  5138. TextInput({ text: item.genre })
  5139. .height(40)
  5140. .maxLines(1)
  5141. .fontSize(14)
  5142. .layoutWeight(1)
  5143. .fontColor($r('app.color.text_color'))
  5144. .margin({ right: 20, left: 10 })
  5145. .onChange((val: string) => {
  5146. this.genreStr = val
  5147. })
  5148. }
  5149. .width('100%')
  5150. .margin({ top: 10, bottom: 10 })
  5151. .justifyContent(FlexAlign.Start)
  5152. Row() {
  5153. Text('专辑艺术家:')
  5154. .fontSize(14)
  5155. .fontColor($r('app.color.text_color'))
  5156. .margin({ left: 22 })
  5157. TextInput({ text: item.ALBUMARTIST })
  5158. .height(40)
  5159. .maxLines(1)
  5160. .fontSize(14)
  5161. .layoutWeight(1)
  5162. .fontColor($r('app.color.text_color'))
  5163. .margin({ right: 20, left: 10 })
  5164. .onChange((val: string) => {
  5165. this.albumArtistStr = val
  5166. })
  5167. }
  5168. .width('100%')
  5169. .margin({ top: 10, bottom: 10 })
  5170. .justifyContent(FlexAlign.Start)
  5171. Row() {
  5172. Text('作曲:')
  5173. .fontSize(14)
  5174. .fontColor($r('app.color.text_color'))
  5175. .margin({ left: 22 })
  5176. TextInput({ text: item.COMPOSER })
  5177. .height(40)
  5178. .maxLines(1)
  5179. .fontSize(14)
  5180. .layoutWeight(1)
  5181. .fontColor($r('app.color.text_color'))
  5182. .margin({ right: 20, left: 10 })
  5183. .onChange((val: string) => {
  5184. this.composerStr = val
  5185. })
  5186. }
  5187. .width('100%')
  5188. .margin({ top: 10, bottom: 10 })
  5189. .justifyContent(FlexAlign.Start)
  5190. Row() {
  5191. Text('作词:')
  5192. .fontSize(14)
  5193. .fontColor($r('app.color.text_color'))
  5194. .margin({ left: 22 })
  5195. TextInput({ text: item.LYRICIST })
  5196. .height(40)
  5197. .maxLines(1)
  5198. .fontSize(14)
  5199. .layoutWeight(1)
  5200. .fontColor($r('app.color.text_color'))
  5201. .margin({ right: 20, left: 10 })
  5202. .onChange((val: string) => {
  5203. this.lyricistStr = val
  5204. })
  5205. }
  5206. .width('100%')
  5207. .margin({ top: 10, bottom: 10 })
  5208. .justifyContent(FlexAlign.Start)
  5209. Row() {
  5210. Text('注释:')
  5211. .fontSize(14)
  5212. .fontColor($r('app.color.text_color'))
  5213. .margin({ left: 22 })
  5214. TextInput({ text: item.COMMENT })
  5215. .height(40)
  5216. .maxLines(1)
  5217. .fontSize(14)
  5218. .layoutWeight(1)
  5219. .fontColor($r('app.color.text_color'))
  5220. .margin({ right: 20, left: 10 })
  5221. .onChange((val: string) => {
  5222. this.commentStr = val
  5223. })
  5224. }
  5225. .width('100%')
  5226. .margin({ top: 10, bottom: 10 })
  5227. .justifyContent(FlexAlign.Start)
  5228. Row() {
  5229. Button('保存')
  5230. .fontColor(Color.White)
  5231. .layoutWeight(1)
  5232. .height(50)
  5233. .width(100)
  5234. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5235. .backgroundColor(this.themeColor)
  5236. .stateEffect(true)
  5237. .margin({ right: 20, bottom: 20 })
  5238. .onClick(async () => {
  5239. this.doEdit(item)
  5240. })
  5241. Button('取消')
  5242. .fontColor(Color.White)
  5243. .layoutWeight(1)
  5244. .height(50)
  5245. .width(100)
  5246. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  5247. .backgroundColor(this.themeColor)
  5248. .stateEffect(true)
  5249. .margin({ left: 20, bottom: 20 })
  5250. .onClick(async () => {
  5251. if(this.isGridMusic){
  5252. this.longItemFilePath =''
  5253. }else{
  5254. this.isShowEdit = false
  5255. }
  5256. this.setEditStrEmpty()
  5257. if(this.isShowPlay){
  5258. this.isShowEdit = false
  5259. }
  5260. })
  5261. }
  5262. .margin({
  5263. left: 38,
  5264. right: 38,
  5265. top: 10,
  5266. bottom: 10
  5267. })
  5268. .width(250)
  5269. .height(60)
  5270. }
  5271. }
  5272. .margin({ bottom: 20 })
  5273. }
  5274. setEditStrEmpty(){
  5275. this.imagePathStr = ''
  5276. this.lyricConStr = ''
  5277. this.artistStr = ''
  5278. this.titleStr = ''
  5279. this.ablumStr = ''
  5280. this.genreStr = ''
  5281. this.yearStr = ''
  5282. this.trackStr = ''
  5283. this.albumArtistStr = ''
  5284. this.composerStr = ''
  5285. this.lyricistStr = ''
  5286. this.commentStr = ''
  5287. this.discStr = ''
  5288. }
  5289. @Builder
  5290. detailSheet(item:VideoItem) {
  5291. Scroll() {
  5292. Column() {
  5293. this.songDetail(item)
  5294. }
  5295. }
  5296. .width('100%')
  5297. .height('100%')
  5298. }
  5299. @Builder
  5300. songDetail(currentItem:VideoItem) {
  5301. Column() {
  5302. if (currentItem) {
  5303. Row() {
  5304. Stack() {
  5305. Image(StrUtil.isEmpty(currentItem.pixelMapPath) ? $r('app.media.music_red') :
  5306. currentItem.pixelMapPath)
  5307. .fillColor(this.themeColor)
  5308. .height(80)
  5309. .width(80)
  5310. .borderRadius(10)
  5311. .opacity(this.opacityItem)// 绑定透明度
  5312. .margin({ left: 22 })
  5313. }
  5314. Column() {
  5315. Column() {
  5316. Text(currentItem.name)
  5317. .fontSize(16)
  5318. .maxLines(1)
  5319. .animation({
  5320. duration: 555,
  5321. curve: 'Linear',
  5322. })
  5323. .fontColor($r('app.color.text_color'))
  5324. .margin({ left: 15 })
  5325. }
  5326. .height('100%')
  5327. .width('100%')
  5328. .justifyContent(FlexAlign.Center)
  5329. .alignItems(HorizontalAlign.Start)
  5330. }
  5331. .height('100%')
  5332. }
  5333. .width('100%')
  5334. .height(90)
  5335. .justifyContent(FlexAlign.SpaceBetween)
  5336. Row() {
  5337. Text('艺术家:')
  5338. .fontSize(14)
  5339. .fontColor($r('app.color.text_color'))
  5340. .margin({ left: 22 })
  5341. Text(currentItem?.artist ? currentItem.artist : '未知歌手')
  5342. .fontSize(14)
  5343. .fontColor($r('app.color.text_color'))
  5344. .margin({ left: 10 })
  5345. .layoutWeight(1)
  5346. }
  5347. .width('100%')
  5348. .margin({ top: 10, bottom: 10 })
  5349. .justifyContent(FlexAlign.Start)
  5350. Row() {
  5351. Text('专辑名:')
  5352. .fontSize(14)
  5353. .fontColor($r('app.color.text_color'))
  5354. .margin({ left: 22 })
  5355. Text(currentItem?.album ?currentItem.album : '未知专辑')
  5356. .fontSize(14)
  5357. .margin({ left: 10 })
  5358. .fontColor($r('app.color.text_color'))
  5359. .layoutWeight(1)
  5360. }
  5361. .width('100%')
  5362. .margin({ top: 10, bottom: 10 })
  5363. .justifyContent(FlexAlign.Start)
  5364. Row() {
  5365. Text('时长:')
  5366. .fontSize(14)
  5367. .fontColor($r('app.color.text_color'))
  5368. .margin({ left: 22 })
  5369. Text(StrUtil.isEmpty(currentItem.duration)?
  5370. (this.isShowDetailMore?this.totalTime:'未知'):currentItem.duration)
  5371. .fontSize(14)
  5372. .margin({ left: 10 })
  5373. .fontColor($r('app.color.text_color'))
  5374. .layoutWeight(1)
  5375. }
  5376. .width('100%')
  5377. .margin({ top: 10, bottom: 10 })
  5378. .justifyContent(FlexAlign.Start)
  5379. Row() {
  5380. Text('采样率:')
  5381. .fontSize(14)
  5382. .fontColor($r('app.color.text_color'))
  5383. .margin({ left: 22 })
  5384. Text(Utility.convertToKHz(currentItem.sampleRate))
  5385. .fontSize(14)
  5386. .margin({ left: 10 })
  5387. .fontColor($r('app.color.text_color'))
  5388. .layoutWeight(1)
  5389. }
  5390. .width('100%')
  5391. .margin({ top: 10, bottom: 10 })
  5392. .justifyContent(FlexAlign.Start)
  5393. Row() {
  5394. Text('比特率:')
  5395. .fontSize(14)
  5396. .fontColor($r('app.color.text_color'))
  5397. .margin({ left: 22 })
  5398. Text(currentItem.bit_rate)
  5399. .fontSize(14)
  5400. .margin({ left: 10 })
  5401. .fontColor($r('app.color.text_color'))
  5402. .layoutWeight(1)
  5403. }
  5404. .width('100%')
  5405. .margin({ top: 10, bottom: 10 })
  5406. .justifyContent(FlexAlign.Start)
  5407. Row() {
  5408. Text('位深:')
  5409. .fontSize(14)
  5410. .fontColor($r('app.color.text_color'))
  5411. .margin({ left: 22 })
  5412. Text(`${currentItem.bits_per_raw_sample} bits`)
  5413. .fontSize(14)
  5414. .margin({ left: 10 })
  5415. .fontColor($r('app.color.text_color'))
  5416. .layoutWeight(1)
  5417. }
  5418. .width('100%')
  5419. .margin({ top: 10, bottom: 10 })
  5420. .justifyContent(FlexAlign.Start)
  5421. Row() {
  5422. Text('声道:')
  5423. .fontSize(14)
  5424. .fontColor($r('app.color.text_color'))
  5425. .margin({ left: 22 })
  5426. Text(`${currentItem.channels}`)
  5427. .fontSize(14)
  5428. .margin({ left: 10 })
  5429. .fontColor($r('app.color.text_color'))
  5430. .layoutWeight(1)
  5431. }
  5432. .width('100%')
  5433. .margin({ top: 10, bottom: 10 })
  5434. .justifyContent(FlexAlign.Start)
  5435. Row() {
  5436. Text('声道布局:')
  5437. .fontSize(14)
  5438. .fontColor($r('app.color.text_color'))
  5439. .margin({ left: 22 })
  5440. Text(`${currentItem.channel_layout}`)
  5441. .fontSize(14)
  5442. .margin({ left: 10 })
  5443. .fontColor($r('app.color.text_color'))
  5444. .layoutWeight(1)
  5445. }
  5446. .width('100%')
  5447. .margin({ top: 10, bottom: 10 })
  5448. .justifyContent(FlexAlign.Start)
  5449. Row() {
  5450. Text('起始播放点:')
  5451. .fontSize(14)
  5452. .fontColor($r('app.color.text_color'))
  5453. .margin({ left: 22 })
  5454. Text(`${currentItem.start_time}`)
  5455. .fontSize(14)
  5456. .margin({ left: 10 })
  5457. .fontColor($r('app.color.text_color'))
  5458. .layoutWeight(1)
  5459. }
  5460. .width('100%')
  5461. .margin({ top: 10, bottom: 10 })
  5462. .justifyContent(FlexAlign.Start)
  5463. Row() {
  5464. Text('风格:')
  5465. .fontSize(14)
  5466. .fontColor($r('app.color.text_color'))
  5467. .margin({ left: 22 })
  5468. Text(currentItem.genre)
  5469. .fontSize(14)
  5470. .margin({ left: 10 })
  5471. .fontColor($r('app.color.text_color'))
  5472. .layoutWeight(1)
  5473. }
  5474. .width('100%')
  5475. .margin({ top: 10, bottom: 10 })
  5476. .justifyContent(FlexAlign.Start)
  5477. Row() {
  5478. Text('发行时间:')
  5479. .fontSize(14)
  5480. .fontColor($r('app.color.text_color'))
  5481. .margin({ left: 22 })
  5482. Text(currentItem.year)
  5483. .fontSize(14)
  5484. .margin({ left: 10 })
  5485. .fontColor($r('app.color.text_color'))
  5486. .layoutWeight(1)
  5487. }
  5488. .width('100%')
  5489. .margin({ top: 10, bottom: 10 })
  5490. .justifyContent(FlexAlign.Start)
  5491. Row() {
  5492. Text('质量评分:')
  5493. .fontSize(14)
  5494. .fontColor($r('app.color.text_color'))
  5495. .margin({ left: 22 })
  5496. Text(currentItem.probe_score+"")
  5497. .fontSize(14)
  5498. .margin({ left: 10 })
  5499. .fontColor($r('app.color.text_color'))
  5500. .layoutWeight(1)
  5501. }
  5502. .width('100%')
  5503. .margin({ top: 10, bottom: 10 })
  5504. .justifyContent(FlexAlign.Start)
  5505. Row() {
  5506. Text('音轨号:')
  5507. .fontSize(14)
  5508. .fontColor($r('app.color.text_color'))
  5509. .margin({ left: 22 })
  5510. Text(currentItem.track)
  5511. .fontSize(14)
  5512. .margin({ left: 10 })
  5513. .fontColor($r('app.color.text_color'))
  5514. .layoutWeight(1)
  5515. }
  5516. .width('100%')
  5517. .margin({ top: 10, bottom: 10 })
  5518. .justifyContent(FlexAlign.Start)
  5519. Row() {
  5520. Text('碟号:')
  5521. .fontSize(14)
  5522. .fontColor($r('app.color.text_color'))
  5523. .margin({ left: 22 })
  5524. Text(currentItem.disc)
  5525. .fontSize(14)
  5526. .margin({ left: 10 })
  5527. .fontColor($r('app.color.text_color'))
  5528. .layoutWeight(1)
  5529. }
  5530. .width('100%')
  5531. .margin({ top: 10, bottom: 10 })
  5532. .justifyContent(FlexAlign.Start)
  5533. Row() {
  5534. Text('专辑艺术家:')
  5535. .fontSize(14)
  5536. .fontColor($r('app.color.text_color'))
  5537. .margin({ left: 22 })
  5538. Text(currentItem.ALBUMARTIST)
  5539. .fontSize(14)
  5540. .margin({ left: 10 })
  5541. .fontColor($r('app.color.text_color'))
  5542. .layoutWeight(1)
  5543. }
  5544. .width('100%')
  5545. .margin({ top: 10, bottom: 10 })
  5546. .justifyContent(FlexAlign.Start)
  5547. Row() {
  5548. Text('作曲家:')
  5549. .fontSize(14)
  5550. .fontColor($r('app.color.text_color'))
  5551. .margin({ left: 22 })
  5552. Text(currentItem.COMPOSER)
  5553. .fontSize(14)
  5554. .margin({ left: 10 })
  5555. .fontColor($r('app.color.text_color'))
  5556. .layoutWeight(1)
  5557. }
  5558. .width('100%')
  5559. .margin({ top: 10, bottom: 10 })
  5560. .justifyContent(FlexAlign.Start)
  5561. Row() {
  5562. Text('作词家:')
  5563. .fontSize(14)
  5564. .fontColor($r('app.color.text_color'))
  5565. .margin({ left: 22 })
  5566. Text(currentItem.LYRICIST)
  5567. .fontSize(14)
  5568. .margin({ left: 10 })
  5569. .fontColor($r('app.color.text_color'))
  5570. .layoutWeight(1)
  5571. }
  5572. .width('100%')
  5573. .margin({ top: 10, bottom: 10 })
  5574. .justifyContent(FlexAlign.Start)
  5575. Row() {
  5576. Text('注释:')
  5577. .fontSize(14)
  5578. .fontColor($r('app.color.text_color'))
  5579. .margin({ left: 22 })
  5580. Text(currentItem.COMMENT)
  5581. .fontSize(14)
  5582. .margin({ left: 10 })
  5583. .fontColor($r('app.color.text_color'))
  5584. .layoutWeight(1)
  5585. }
  5586. .width('100%')
  5587. .margin({ top: 10, bottom: 10 })
  5588. .justifyContent(FlexAlign.Start)
  5589. Row() {
  5590. Text('格式:')
  5591. .fontSize(14)
  5592. .fontColor($r('app.color.text_color'))
  5593. .margin({ left: 22 })
  5594. Text(Utility.formatMimeType(currentItem.mimeType))
  5595. .fontSize(14)
  5596. .margin({ left: 10 })
  5597. .fontColor($r('app.color.text_color'))
  5598. .layoutWeight(1)
  5599. }
  5600. .width('100%')
  5601. .margin({ top: 10, bottom: 10 })
  5602. .justifyContent(FlexAlign.Start)
  5603. Row() {
  5604. Text('播放次数:')
  5605. .fontSize(14)
  5606. .fontColor($r('app.color.text_color'))
  5607. .margin({ left: 22 })
  5608. Text(currentItem.playCount?.toString())
  5609. .fontSize(14)
  5610. .margin({ left: 10 })
  5611. .fontColor($r('app.color.text_color'))
  5612. .layoutWeight(1)
  5613. }
  5614. .width('100%')
  5615. .margin({ top: 10, bottom: 10 })
  5616. .justifyContent(FlexAlign.Start)
  5617. Row() {
  5618. Text('流数量:')
  5619. .fontSize(14)
  5620. .fontColor($r('app.color.text_color'))
  5621. .margin({ left: 22 })
  5622. Text(currentItem.nb_streams?.toString())
  5623. .fontSize(14)
  5624. .margin({ left: 10 })
  5625. .fontColor($r('app.color.text_color'))
  5626. .layoutWeight(1)
  5627. }
  5628. .width('100%')
  5629. .margin({ top: 10, bottom: 10 })
  5630. .justifyContent(FlexAlign.Start)
  5631. Row() {
  5632. Text('文件大小:')
  5633. .fontSize(14)
  5634. .fontColor($r('app.color.text_color'))
  5635. .margin({ left: 22 })
  5636. Text(currentItem.size)
  5637. .fontSize(14)
  5638. .margin({ left: 10 })
  5639. .fontColor($r('app.color.text_color'))
  5640. .layoutWeight(1)
  5641. }
  5642. .width('100%')
  5643. .margin({ top: 10, bottom: 10 })
  5644. .justifyContent(FlexAlign.Start)
  5645. Row() {
  5646. Text('文件名:')
  5647. .fontSize(14)
  5648. .fontColor($r('app.color.text_color'))
  5649. .margin({ left: 22 })
  5650. Text(currentItem.fileName)
  5651. .fontSize(14)
  5652. .margin({ left: 10 })
  5653. .fontColor($r('app.color.text_color'))
  5654. .layoutWeight(1)
  5655. }
  5656. .width('100%')
  5657. .margin({ top: 10, bottom: 10 })
  5658. .justifyContent(FlexAlign.Start)
  5659. Row() {
  5660. Text('修改时间:')
  5661. .fontSize(14)
  5662. .fontColor($r('app.color.text_color'))
  5663. .margin({ left: 22 })
  5664. Text(currentItem.cTime)
  5665. .fontSize(14)
  5666. .margin({ left: 10 })
  5667. .fontColor($r('app.color.text_color'))
  5668. .layoutWeight(1)
  5669. }
  5670. .width('100%')
  5671. .margin({ top: 10, bottom: 10 })
  5672. .justifyContent(FlexAlign.Start)
  5673. Row() {
  5674. Text('存放目录:')
  5675. .fontSize(14)
  5676. .fontColor($r('app.color.text_color'))
  5677. .margin({ left: 22 })
  5678. Text(currentItem.filePath)
  5679. .fontSize(12)
  5680. .margin({ left: 10 })
  5681. .fontColor($r('app.color.text_color'))
  5682. .layoutWeight(1)
  5683. }
  5684. .margin({ top: 10, bottom: 10 })
  5685. .width('100%')
  5686. .justifyContent(FlexAlign.Start)
  5687. Row() {
  5688. Text('内嵌歌词:')
  5689. .fontSize(14)
  5690. .fontColor($r('app.color.text_color'))
  5691. .margin({ left: 22 })
  5692. Text(currentItem.lyricContent)
  5693. .fontSize(12)
  5694. .copyOption(CopyOptions.InApp)
  5695. .margin({ left: 10 })
  5696. .fontColor($r('app.color.text_color'))
  5697. .layoutWeight(1)
  5698. }
  5699. .margin({ top: 10, bottom: 10 })
  5700. .width('100%')
  5701. .justifyContent(FlexAlign.Start)
  5702. }
  5703. }
  5704. .margin({ bottom: 20 })
  5705. }
  5706. //定时关闭布局
  5707. @Builder
  5708. TimeCloseSheet() {
  5709. Scroll() {
  5710. Column() {
  5711. this.TimeClose()
  5712. }
  5713. }
  5714. .width('100%')
  5715. .height('100%')
  5716. }
  5717. //倒计时关闭音乐,退出App功能实现。
  5718. @State selectedMinutes: number = 0 // 0表示未开启
  5719. @State remainingSeconds: number = 0
  5720. // 预设时间选项
  5721. private presetTimes: number[] = [0, 5, 15, 30, 45, 60, -1]
  5722. private formatTime(seconds: number): string {
  5723. const mins = Math.floor(seconds / 60)
  5724. const secs = seconds % 60
  5725. return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
  5726. }
  5727. // 开始倒计时
  5728. private handleTimeSelect(minutes: number) {
  5729. if (minutes === this.selectedMinutes) {
  5730. this.stopCountdown();
  5731. this.selectedMinutes = 0;
  5732. return;
  5733. }
  5734. this.selectedMinutes = minutes;
  5735. this.remainingSeconds = minutes * 60;
  5736. this.startCountdown(); // 新增调用
  5737. }
  5738. @Builder
  5739. TimeClose() {
  5740. Column() {
  5741. // 倒计时显示区域
  5742. Text(this.selectedMinutes > 0 ?
  5743. `剩余时间:${this.formatTime(this.remainingSeconds)}` :
  5744. "定时关闭未开启")
  5745. .fontSize(17)
  5746. .fontColor($r('app.color.text_color'))
  5747. .margin({ top: 2, bottom: 8 });
  5748. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  5749. ForEach(this.presetTimes, (minutes: number, index: number) => {
  5750. // 单行时间选项容器
  5751. Row() {
  5752. // 文字描述区域
  5753. Text(this.getDisplayText(minutes))
  5754. .fontSize(15)
  5755. .fontColor(minutes === this.selectedMinutes ? this.themeColor :
  5756. $r('app.color.text_color'))// 选中态颜色变化
  5757. .textAlign(TextAlign.Start)
  5758. .layoutWeight(1); // 占据剩余空间
  5759. // 复选框样式的选择器
  5760. Row() {
  5761. if (minutes === this.selectedMinutes) {
  5762. // 选中状态 - 带勾号的圆形复选框
  5763. Row() {
  5764. // 使用系统内置的勾号图标
  5765. Image($r('sys.media.ohos_ic_public_ok'))
  5766. .width(14)
  5767. .height(14)
  5768. .fillColor(Color.White)
  5769. }
  5770. .width(24)
  5771. .height(24)
  5772. .borderRadius(12)
  5773. .backgroundColor(this.themeColor)
  5774. .justifyContent(FlexAlign.Center)
  5775. .alignItems(VerticalAlign.Center)
  5776. } else {
  5777. // 未选中状态的圆形边框
  5778. Row()
  5779. .width(24)
  5780. .height(24)
  5781. .borderRadius(12)
  5782. .border({
  5783. width: 2,
  5784. color: $r('app.color.text_color'),
  5785. style: BorderStyle.Solid
  5786. })
  5787. .backgroundColor(Color.Transparent)
  5788. }
  5789. }
  5790. .width(24)
  5791. .height(24)
  5792. .margin({ left: 20 })
  5793. .justifyContent(FlexAlign.Center)
  5794. .alignItems(VerticalAlign.Center)
  5795. }
  5796. .width('100%')
  5797. .padding({
  5798. top: 18,
  5799. bottom: 18,
  5800. left: 18,
  5801. right: 18
  5802. })
  5803. .backgroundColor(minutes === this.selectedMinutes ? $r('app.color.timeColor_bg') :
  5804. $r('app.color.bottom_control_background')) // 选中背景高亮
  5805. .borderRadius(12)
  5806. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  5807. .margin({ bottom: 18 })
  5808. .onClick(() => this.handleSelect(minutes)); // 点击整行触发选择
  5809. });
  5810. }
  5811. .width('100%')
  5812. .padding(16)
  5813. }
  5814. }
  5815. // 获取显示文本
  5816. private getDisplayText(minutes: number): string {
  5817. if (minutes === -1) {
  5818. return Utility.resourceToString(getContext(this), $r('app.string.customize'));
  5819. }
  5820. return minutes === 0 ? Utility.resourceToString(getContext(this), $r('app.string.close')) :
  5821. `${minutes}` + Utility.resourceToString(getContext(this), $r('app.string.minute_after'));
  5822. }
  5823. // 处理选择事件
  5824. private handleSelect(minutes: number): void {
  5825. if (minutes === -1) { // 自定义
  5826. // 弹出自定义时间对话框
  5827. DialogHelper.showTextInputDialog({
  5828. title: '自定义时间',
  5829. maskColor: Color.Transparent,
  5830. inputType: InputType.Number,
  5831. text: '',
  5832. onChange: (text) => {
  5833. console.error("onChange: " + text);
  5834. },
  5835. onAction: (action, dialogId, content) => {
  5836. if (action == DialogAction.TWO) {
  5837. const customMinutes = Number(content);
  5838. if (customMinutes > 0) {
  5839. this.handleTimeSelect(customMinutes); // 设置自定义时间
  5840. ToastUtil.showToast("设置成功," + customMinutes + "分钟后定时关闭");
  5841. }
  5842. }
  5843. }
  5844. });
  5845. } else {
  5846. this.handleTimeSelect(minutes); // 统一调用选择处理方法
  5847. }
  5848. }
  5849. // 添加定时器引用
  5850. private timerId: number = -1;
  5851. // 启动/重置倒计时
  5852. private startCountdown() {
  5853. // 清除旧定时器
  5854. if (this.timerId !== -1) {
  5855. clearInterval(this.timerId);
  5856. }
  5857. // 创建新定时器
  5858. if (this.selectedMinutes > 0) {
  5859. this.timerId = setInterval(() => {
  5860. if (this.remainingSeconds === 15) {
  5861. this.showConfirmationDialog();
  5862. }
  5863. if (this.remainingSeconds > 0) {
  5864. this.remainingSeconds -= 1;
  5865. } else {
  5866. this.stopCountdown();
  5867. this.handleTimeout();
  5868. }
  5869. }, 1000);
  5870. }
  5871. }
  5872. // 15倒计时后再次提示显示确认是否关闭App对话框
  5873. private showConfirmationDialog() {
  5874. DialogHelper.showAlertDialog({
  5875. backgroundColor: $r('app.color.btn_green'),
  5876. title: '确认关闭',
  5877. maskColor: Color.Transparent,
  5878. content: "马上到达定时关闭时间,您是否确定要退出应用?",
  5879. borderStyle: BorderStyle.Dashed,
  5880. primaryButton: '暂不关闭',
  5881. secondaryButton: '确定',
  5882. onAction: (action) => {
  5883. if (action == DialogAction.ONE) { //暂不关闭,取消定时
  5884. this.stopCountdown();
  5885. this.selectedMinutes = 0
  5886. } else if (action == DialogAction.TWO) {
  5887. }
  5888. }
  5889. })
  5890. }
  5891. // 停止倒计时
  5892. private stopCountdown() {
  5893. if (this.timerId !== -1) {
  5894. clearInterval(this.timerId);
  5895. this.timerId = -1;
  5896. }
  5897. }
  5898. // 超时处理
  5899. private handleTimeout() {
  5900. // 执行播放器关闭逻辑
  5901. this.selectedMinutes = 0;
  5902. ToastUtil.showToast(" 定时关闭已完成");
  5903. this.stop(); // 假设存在的播放器实例
  5904. //退出APP
  5905. const mContext = getContext(this) as common.UIAbilityContext
  5906. mContext.terminateSelf();
  5907. AvSessionController.getInstance(true).unregisterSessionListener()
  5908. }
  5909. //倒计时关闭音乐,退出App功能实现结束。
  5910. //播放列表的拖动List 重新排序
  5911. @State sonDataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.songList)
  5912. //左滑操作 移动文件 重命名 删除等操作
  5913. @Builder
  5914. sonButton(item: VideoItem, index: number, filePath: string) {
  5915. Row() {
  5916. //加入下一首播放
  5917. Button() {
  5918. Image($r('app.media.next_to_play'))
  5919. .fillColor(Color.White)
  5920. .width(20)
  5921. }
  5922. .width(40)
  5923. .height(40)
  5924. .type(ButtonType.Circle)
  5925. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5926. .backgroundColor(this.themeColor)
  5927. .margin(5)
  5928. .onClick(() => {
  5929. this.addToNextPlay(item);
  5930. })
  5931. Button() {
  5932. Image($r('app.media.close'))
  5933. .fillColor(Color.White)
  5934. .width(20)
  5935. }
  5936. .width(40)
  5937. .height(40)
  5938. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5939. .type(ButtonType.Circle)
  5940. .backgroundColor(this.themeColor)
  5941. .margin(5)
  5942. .onClick(() => {
  5943. this.songList.splice(Number(index), 1)
  5944. this.sonDataSource.pushArrayData(this.songList)
  5945. })
  5946. Button() {
  5947. Image($r('app.media.share2'))
  5948. .fillColor(Color.White)
  5949. .width(20)
  5950. }
  5951. .width(40)
  5952. .height(40)
  5953. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5954. .type(ButtonType.Circle)
  5955. .backgroundColor(this.themeColor)
  5956. .margin(5)
  5957. .onClick(() => {
  5958. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  5959. })
  5960. }
  5961. }
  5962. itemMoveSon(index: number, newIndex: number): void {
  5963. if (newIndex < 0 || newIndex >= this.songList.length) {
  5964. return;
  5965. }
  5966. let tmp = this.songList.splice(index, 1);
  5967. this.songList.splice(newIndex, 0, tmp[0]);
  5968. this.sonDataSource.pushArrayData(this.songList)
  5969. this.curIndex = Utility.getIndexFromList(this.songList, this.videoUrl)
  5970. }
  5971. @Builder
  5972. PlayList() {
  5973. List({ scroller: this.playListScroller }) {
  5974. LazyForEach(this.sonDataSource, (item: VideoItem, index: number) => {
  5975. ListItem() {
  5976. this.MusicItemSon(item, index)
  5977. }
  5978. .swipeAction({ end: this.sonButton(item, index, item.filePath) }) //左滑
  5979. .animation({
  5980. duration: 666,
  5981. curve: 'ease-in-out' // 可选动画曲线
  5982. })
  5983. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 600 }),
  5984. TransitionEffect.scale({ x: 0, y: 0 })))
  5985. .clickEffect({ level: ClickEffectLevel.MIDDLE })
  5986. //拖动List关键代码开始
  5987. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  5988. .zIndex(this.dragItem === index ? 1 : 0)
  5989. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  5990. .gesture(
  5991. GestureGroup(GestureMode.Sequence,
  5992. LongPressGesture({ repeat: true })
  5993. .onAction((event?: GestureEvent) => {
  5994. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5995. this.scaleItem = index
  5996. })
  5997. })
  5998. .onActionEnd(() => {
  5999. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  6000. this.scaleItem = -1
  6001. })
  6002. }),
  6003. PanGesture({ fingers: 1, direction: null, distance: 0 })
  6004. .onActionStart(() => {
  6005. this.dragItem = index // 记录当前拖动项索引
  6006. this.dragRefOffset = 0 // 重置偏移基准
  6007. })
  6008. .onActionUpdate((event: GestureEvent) => {
  6009. this.offsetY = event.offsetY - this.dragRefOffset;
  6010. this.neighborItem = -1;
  6011. let indexA = this.songList.indexOf(item);
  6012. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  6013. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  6014. let value: number = 0;
  6015. if (this.offsetY < 0) {
  6016. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  6017. this.neighborItem = indexA - 1;
  6018. this.neighborScale = 1 - value / 20;
  6019. } else if (this.offsetY > 0) {
  6020. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  6021. this.neighborItem = indexA + 1;
  6022. this.neighborScale = 1 - value / 20;
  6023. }
  6024. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.songList.length) {
  6025. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6026. this.offsetY -= this.ITEM_INTV;
  6027. this.dragRefOffset += this.ITEM_INTV;
  6028. this.itemMoveSon(indexA, indexA + 1);
  6029. });
  6030. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  6031. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6032. this.offsetY += this.ITEM_INTV;
  6033. this.dragRefOffset -= this.ITEM_INTV;
  6034. this.itemMoveSon(indexA, indexA - 1);
  6035. });
  6036. }
  6037. })
  6038. .onActionEnd((event: GestureEvent) => {
  6039. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6040. this.dragItem = -1
  6041. this.neighborItem = -1
  6042. })
  6043. animateTo({
  6044. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  6045. }, () => {
  6046. this.scaleItem = -1
  6047. })
  6048. })
  6049. )
  6050. .onCancel(() => {
  6051. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  6052. this.dragItem = -1
  6053. this.neighborItem = -1
  6054. })
  6055. animateTo({
  6056. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  6057. }, () => {
  6058. this.scaleItem = -1
  6059. })
  6060. })
  6061. ) //拖动List关键代码结束
  6062. .onClick(() => {
  6063. this.doPlay(item, index, true)
  6064. })
  6065. }, (item: VideoItem) => item.filePath)
  6066. }
  6067. .width('100%')
  6068. .height('100%')
  6069. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  6070. // .animation({ duration: 500, curve: Curve.Ease }))
  6071. .cachedCount(10)
  6072. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  6073. .gesture(PinchGesture({ fingers: 2 })
  6074. .onActionEnd((event: GestureEvent) => {
  6075. this.setSonListTwoFingers()
  6076. })
  6077. .onActionUpdate(e => {
  6078. this.scaleValue = this.pinchValue * e.scale
  6079. })
  6080. .onActionStart(e => {
  6081. }))
  6082. .padding({
  6083. bottom: 0
  6084. })
  6085. }
  6086. setSonListTwoFingers() {
  6087. this.pinchValue = this.scaleValue;
  6088. Logger.info('this.pinchValue = ' + this.pinchValue);
  6089. if (this.pinchValue >= 1) {
  6090. this.sonTwoFingerType++
  6091. Logger.info('this.twoFingerType1 = ' + this.sonTwoFingerType);
  6092. if (this.sonTwoFingerType > 3) {
  6093. this.sonTwoFingerType = 1
  6094. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  6095. }
  6096. } else {
  6097. this.sonTwoFingerType--
  6098. Logger.info('this.twoFingerType2 = ' + this.sonTwoFingerType);
  6099. if (this.sonTwoFingerType < 1) {
  6100. this.sonTwoFingerType = 1
  6101. }
  6102. }
  6103. PreferencesUtil.put('sonTwoFingerType', this.sonTwoFingerType)
  6104. this.pinchValue = 1;
  6105. this.scaleValue = 1;
  6106. }
  6107. @State sonTwoFingerType:number = 3
  6108. @Builder
  6109. private MusicItemSon(item: VideoItem, index?: number) {
  6110. Button({ type: ButtonType.Normal, stateEffect: true }) {
  6111. Row() {
  6112. Stack() {
  6113. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  6114. .height(this.sonTwoFingerType == 3||this.sonTwoFingerType==4 ? 55 : this.sonTwoFingerType == 2 ? 48 : 40)
  6115. .width(this.sonTwoFingerType == 3||this.sonTwoFingerType==4 ? 55 : this.sonTwoFingerType == 2 ? 48 : 40)
  6116. .alt($r('app.media.music_red'))
  6117. .fillColor(this.themeColor)
  6118. .borderRadius('100%')
  6119. .clip(true)
  6120. .interpolation(ImageInterpolation.High)// 用于重采样后的抗锯齿
  6121. .draggable(false)// 禁止长按手势拖动
  6122. .autoResize(true) // 重采样,可减少内存占用
  6123. .margin({ left: 20 })
  6124. }
  6125. .width('15%')
  6126. Column() {
  6127. Column() {
  6128. Text(item.name)
  6129. .fontSize(this.sonTwoFingerType == 1 ? 12 : this.sonTwoFingerType == 2 ? 15 : 18)
  6130. .fontColor(this.curIndex === index ? this.themeColor :
  6131. this.isFrontWhite ? Color.White : $r('app.color.text_color'))
  6132. .maxLines(1)
  6133. .margin({ left: this.sonTwoFingerType == 3 ? 18 : 10 })
  6134. Row() {
  6135. Column(){
  6136. Text(item.md5Str?.includes('Lossless')?
  6137. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  6138. .fontSize(this.sonTwoFingerType == 1 ? 8 : this.sonTwoFingerType == 2 ? 9 : 11)
  6139. .padding({ top: 3,right:6,left:6,bottom:3 })
  6140. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  6141. $r('app.color.text_color'))
  6142. .fontWeight(500)
  6143. .borderRadius(12)
  6144. .margin({ left: this.sonTwoFingerType == 3 ? 12 : 10 })
  6145. .backgroundColor('#FFC107')
  6146. }
  6147. .padding({ top: 8 })
  6148. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  6149. .fontSize(this.sonTwoFingerType == 1 ? 11 : this.sonTwoFingerType == 2 ? 12 : 14)
  6150. .padding({ top: 8 })
  6151. .fontColor(this.curIndex === index ? this.themeColor :
  6152. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  6153. .margin({ left: this.sonTwoFingerType == 3 ? 5 : 3 })
  6154. Blank()
  6155. Text(item.size)
  6156. .fontSize(this.sonTwoFingerType == 1 ? 11 : this.sonTwoFingerType == 2 ? 12 : 14)
  6157. .padding({ top: 8 })
  6158. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  6159. .fontColor(this.curIndex === index ? $r('app.color.title_bar_bg_text') :
  6160. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  6161. .margin({ left: 10 })
  6162. }
  6163. }
  6164. .height('100%')
  6165. .width('100%')
  6166. .justifyContent(FlexAlign.Center)
  6167. .alignItems(HorizontalAlign.Start)
  6168. }
  6169. .height('100%')
  6170. .width('65%')
  6171. Column() {
  6172. ImageAnimator()
  6173. .images(this.imagesF)// 动画数组
  6174. .duration(1000)// 持续
  6175. .state(this.animationState)// 动画状态
  6176. .fillMode(FillMode.Forwards)
  6177. .width(18)
  6178. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  6179. Visibility.None)
  6180. .height(18)
  6181. .iterations(-1) // 播放次数
  6182. }
  6183. .width('20%')
  6184. }
  6185. }
  6186. .backgroundColor(Color.Transparent)
  6187. .width('100%')
  6188. .reuseId('son_item')
  6189. .height(this.sonTwoFingerType == 3 ? ITEM_HEIGHT_BIG : this.sonTwoFingerType == 2 ? ITEM_HEIGHT+10 : ITEM_HEIGHT_SMALL+10)
  6190. .shadow(this.scaleItem === index ? {
  6191. radius: 70,
  6192. color: '#15000000',
  6193. offsetX: 0,
  6194. offsetY: 0
  6195. } :
  6196. {
  6197. radius: 0,
  6198. color: '#15000000',
  6199. offsetX: 0,
  6200. offsetY: 0
  6201. })
  6202. .animation({ curve: Curve.Sharp, duration: 300 })
  6203. }
  6204. @Builder
  6205. MusicPlayBuilder() {
  6206. Column() {
  6207. this.IjkMusicPlayerView()
  6208. }
  6209. .height('100%')
  6210. .width('100%')
  6211. .onDisAppear(() => {
  6212. this.translateY = 0;
  6213. })
  6214. .translate({ y: this.translateY })
  6215. .gesture(
  6216. PanGesture(this.panOption)
  6217. .onActionUpdate((event?: GestureEvent) => {
  6218. if (event) {
  6219. // 只允许向下滑动,向上滑动时限制为0
  6220. this.translateY = Math.max(0, event.offsetY);
  6221. }
  6222. })
  6223. .onActionEnd((event?: GestureEvent) => {
  6224. // 使用更低的阈值和滑动速度判断
  6225. const minDistance = 100; // 最小滑动距离 100vp
  6226. const minVelocity = 500; // 最小滑动速度
  6227. // 获取滑动速度(如果可用)
  6228. const velocity = event?.velocityY || 0;
  6229. // 判断是否应该关闭:距离足够 或者 速度足够快
  6230. const shouldClose = this.translateY > minDistance || velocity > minVelocity;
  6231. if (shouldClose) {
  6232. // 添加关闭动画
  6233. this.getUIContext().animateTo({
  6234. duration: 300,
  6235. curve: Curve.Smooth
  6236. }, () => {
  6237. this.isShowPlay = false;
  6238. this.translateY = 0;
  6239. })
  6240. } else {
  6241. // 回弹动画
  6242. this.getUIContext().animateTo({
  6243. duration: 300,
  6244. curve: Curve.Smooth
  6245. }, () => {
  6246. this.translateY = 0;
  6247. })
  6248. }
  6249. })
  6250. )
  6251. }
  6252. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD; //一多界面适配
  6253. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  6254. HeightBreakpoint.HEIGHT_LG;
  6255. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  6256. @State topBarHeight: number = 50
  6257. @State barOpacity: number = 1
  6258. @State barBottomOpacity: number = 1
  6259. private hideDone: boolean = false;
  6260. @State currentYOffset: number = 0;
  6261. @State bottomBarHeight: number = 60;
  6262. private isHiding: boolean = false;
  6263. //是否是Pura X外屏,或者小屏幕
  6264. isPuraWP() {
  6265. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  6266. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  6267. }
  6268. //是否是Pura X外屏,或者小屏幕,手机横屏
  6269. /**
  6270. * 是否是Pura X外屏,或者小屏幕,手机横屏
  6271. * @returns
  6272. */
  6273. isCoverOpacity() {
  6274. if (this.isPuraWP()) {
  6275. return true
  6276. }
  6277. if (this.isPhoneLan()) {
  6278. return true
  6279. }
  6280. if (deviceInfo.marketName.includes('Pura X')
  6281. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  6282. return true
  6283. }
  6284. return false
  6285. }
  6286. //是不是手机横屏
  6287. isPhoneLan() {
  6288. // LogUtil.info('twocold this.currentHeightBreakpoint = '+this.currentHeightBreakpoint)
  6289. // LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
  6290. LogUtil.info('hicar isPhoneLan width= ' + this.windowWidth);
  6291. LogUtil.info('hicar isPhoneLan height= ' + this.windowHeight);
  6292. LogUtil.info(`twocold hicarWindow size: ${this.windowWidth}x${this.windowHeight}, this.isHiCarStatus: ${this.isHiCarStatus}`);
  6293. LogUtil.info(`twocold hicar Window size: ${this.windowWidth}x${this.windowHeight}, isHiCarSmall: ${this.isHiCarSmall()}`);
  6294. if (this.isHiCarKuanBianPing()) {
  6295. return true
  6296. }
  6297. if (this.isHiCar()) {
  6298. return false
  6299. }
  6300. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  6301. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_SM
  6302. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_MD&&this.isLandscape) { //如果是手机横屏,返回true
  6303. return true
  6304. }
  6305. return false
  6306. }
  6307. //是不是1920x720的hicar的屏幕分辨率
  6308. isHiCarKuanBianPing(){
  6309. if(!this.isHiCar()){
  6310. return false
  6311. }
  6312. const hiCarAspectRatios: HiCarAspectRatio[] = [
  6313. { ratio: 1920 / 720, name: "1920x720" },
  6314. ];
  6315. const currentRatio: number = this.windowWidth / this.windowHeight;
  6316. const RATIO_TOLERANCE: number = 0.22; // 宽高比容差
  6317. LogUtil.info('twocold isHiCarKuanBianPing currentRatio = ' + currentRatio)
  6318. for (const hiCarRatio of hiCarAspectRatios) {
  6319. LogUtil.info('twocold isHiCarKuanBianPing hiCarRatio= ' + hiCarRatio.ratio)
  6320. LogUtil.info('twocold isHiCarKuanBianPing Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  6321. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  6322. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  6323. //宽扁平的尺寸设置列表展示
  6324. this.twoFingerType ==3
  6325. this.isGridMusic = false
  6326. return true;
  6327. }
  6328. }
  6329. return false;
  6330. }
  6331. //是不是hicar的屏幕分辨率
  6332. isHiCarSmall() {
  6333. if(!this.isHiCar()){
  6334. return false
  6335. }
  6336. if(this.windowWidth>1800&&this.windowHeight>=1200)//大屏幕可以Grid
  6337. {
  6338. this.columns = 6
  6339. return false
  6340. }
  6341. const hiCarAspectRatios: HiCarAspectRatio[] = [
  6342. { ratio: 800 / 480, name: "800x480" },
  6343. { ratio: 1280 / 720, name: "1280x720" },
  6344. { ratio: 1920 / 1080, name: "1920x1080" },
  6345. ];
  6346. const currentRatio: number = this.windowWidth / this.windowHeight;
  6347. const RATIO_TOLERANCE: number = 0.22; // 宽高比容差
  6348. LogUtil.info('twocold isHiCarSmall currentRatio = ' + currentRatio)
  6349. for (const hiCarRatio of hiCarAspectRatios) {
  6350. LogUtil.info('twocold isHiCarSmall hiCarRatio= ' + hiCarRatio.ratio)
  6351. LogUtil.info('twocold isHiCarSmall Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  6352. LogUtil.info('twocold isHiCarSmall isHiCarStatus= ' + this.isHiCarStatus);
  6353. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  6354. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  6355. return true;
  6356. }
  6357. }
  6358. return false;
  6359. }
  6360. isHiCar() {
  6361. return this.isHiCarStatus&&this.curDisplayIsHiCar;
  6362. }
  6363. //是不是正常的手机竖屏
  6364. isPhonePortrait() {
  6365. // LogUtil.info('twocold this.currentHeightBreakpoint = ' + this.currentHeightBreakpoint)
  6366. // LogUtil.info('twocold this.currentWidthBreakpoint = ' + this.currentWidthBreakpoint)
  6367. // LogUtil.info('Heanup 当前设备类型:' + DeviceUtil.getDeviceType())
  6368. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  6369. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG
  6370. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_SM) { //如果是手机横屏,返回false
  6371. return true
  6372. }
  6373. return false
  6374. }
  6375. @State showSpeedDialog: boolean = false
  6376. @State longPressSpeed: number = 3 //长按默认倍数
  6377. @Builder
  6378. SpeedDialog() {
  6379. Stack() {
  6380. Column() {
  6381. Text('已切换至' + this.longPressSpeed + '倍速播放')
  6382. .fontColor(Color.White)
  6383. .visibility(Visibility.Hidden)
  6384. }
  6385. .backgroundColor(Color.Black)
  6386. .borderRadius(20)
  6387. .padding({
  6388. top: 10,
  6389. right: 20,
  6390. left: 15,
  6391. bottom: 20
  6392. })
  6393. .opacity(0.6)
  6394. Text('已切换至' + this.longPressSpeed + '倍速播放')
  6395. .fontColor(Color.White)
  6396. }
  6397. .transition(TransitionEffect.OPACITY.animation({ duration: 500, curve: Curve.Ease }))
  6398. .zIndex(5)
  6399. .margin({ top: 80 })
  6400. }
  6401. @Builder
  6402. IjkMusicPlayerView() {
  6403. Column() {
  6404. Column() {
  6405. Column() {
  6406. //播放标题
  6407. Column() {
  6408. this.PlayTitle()
  6409. }
  6410. .position({ x: 0, y: this.isCoverOpacity() ? 15 : 40 })
  6411. .width('100%')
  6412. .margin({ top: 0 })
  6413. .height(PlayConstants.HEIGHT)
  6414. .visibility(DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1 ?
  6415. Visibility.Visible : this.isShowPlayPageBack ? Visibility.Visible : Visibility.None)
  6416. if (this.showSpeedDialog) {
  6417. this.SpeedDialog()
  6418. }
  6419. Stack() {
  6420. //手势拖动快进
  6421. Column()
  6422. .width(CommonConstants.FULL_PERCENT)
  6423. .height('100%')
  6424. .gesture(
  6425. GestureGroup(GestureMode.Parallel,
  6426. // 长按屏幕倍数播放
  6427. LongPressGesture({ repeat: true })
  6428. .onAction(() => {
  6429. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6430. this.showSpeedDialog = true;
  6431. this.mIjkMediaPlayer.setSpeed(this.longPressSpeed + 'f');
  6432. }
  6433. })
  6434. .onActionEnd(() => {
  6435. this.showSpeedDialog = false;
  6436. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  6437. }),
  6438. //双击屏幕暂停或者播放
  6439. TapGesture({ count: 2 })
  6440. .onAction((event: GestureEvent) => {
  6441. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6442. ToastUtil.showToast('已暂停')
  6443. }
  6444. console.info('onecold playOrPause 6693')
  6445. this.playOrPause()
  6446. })
  6447. )
  6448. )
  6449. }
  6450. .height('65%')
  6451. Swiper() {
  6452. this.CoverInfo()
  6453. this.PlayerLyrics()
  6454. }
  6455. .onChange((index: number) => {
  6456. this.currentSwiperIndex = index
  6457. })
  6458. .indicator(false)
  6459. // .indicator(this.currentBreakpoint === BreakpointTypeEnum.SM ?
  6460. // new DotIndicator()
  6461. // .top(this.isCoverOpacity()?0:10)
  6462. //
  6463. // .selectedColor($r('app.color.select_swiper'))
  6464. // .color($r('app.color.slider_track')):false
  6465. // )
  6466. .displayCount(new BreakpointType({
  6467. sm: 1,
  6468. md: 2,
  6469. lg: 2,
  6470. xl: 2,
  6471. xxl: 2
  6472. }).getValue(this.currentBreakpoint))
  6473. .clip(false)
  6474. .loop(false)
  6475. .autoPlay(false)
  6476. // .interval(8000)
  6477. .position({ x: 0, y: this.isCoverOpacity() ? 30 : 40 })
  6478. .height('100%')
  6479. .hitTestBehavior(HitTestMode.Transparent)
  6480. Image($r('app.media.icon_replay'))
  6481. .objectFit(ImageFit.Auto)
  6482. .width('120px')
  6483. .height('120px')
  6484. .position({ x: '45.1%', y: '47.5%' })// .visibility(this.replayVisible)
  6485. .border({ width: 0 })
  6486. .visibility(Visibility.None)
  6487. .borderStyle(BorderStyle.Dashed)// .hitTestBehavior(HitTestMode.Transparent)
  6488. .onClick(() => {
  6489. console.info('onecold startPlayOrResumePlay 6744')
  6490. this.startPlayOrResumePlay();
  6491. })
  6492. }
  6493. .width(CommonConstants.FULL_PERCENT)
  6494. .height(CommonConstants.FULL_PERCENT)
  6495. .justifyContent(FlexAlign.End)
  6496. }
  6497. .justifyContent(FlexAlign.End)
  6498. .margin({ bottom: 8 })
  6499. }
  6500. // .backgroundImage(this.imageLabelBg)
  6501. .backgroundImage(this.isPuraWP() && this.currentSwiperIndex === 0 ?
  6502. (StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover) : this.imageLabelBg)
  6503. .backgroundImageSize(this.isPuraWP() ? { width: '100%' } : { height: '150%', width: '100%' })
  6504. // .backgroundImagePosition(Alignment.Center)
  6505. .animation({
  6506. duration: 666,
  6507. curve: 'ease-in-out' // 可选动画曲线
  6508. })
  6509. .backgroundBlurStyle(this.isPuraWP() && this.currentSwiperIndex === 0 ? BlurStyle.NONE :
  6510. BlurStyle.BACKGROUND_ULTRA_THICK)
  6511. .hitTestBehavior(HitTestMode.Transparent)
  6512. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  6513. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  6514. .backgroundBrightness({ rate: this.isPuraWP() ? 0.1 : 0, lightUpDegree: -0.1 })
  6515. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
  6516. .onClick(() => {
  6517. // this.startAutoHide()
  6518. if(this.isHiCar())
  6519. return
  6520. if(this.is_auto_hide_progress){
  6521. this.is_auto_hide_progress = false
  6522. }
  6523. this.startAutoHide()
  6524. })
  6525. }
  6526. @State progressValue: number = 0;
  6527. @State currentTime: string = "00:00";
  6528. @State totalTime: string = "00:00";
  6529. @State loadingVisible: Visibility = Visibility.None;
  6530. @State replayVisible: Visibility = Visibility.None;
  6531. @State slideEnable: boolean = false;
  6532. @State aspRatio: number = 0.5;
  6533. @State mContext: object | undefined = undefined;
  6534. // private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
  6535. @State mFirst: boolean = true;
  6536. @State mDestroyPage: boolean = false;
  6537. @State playSpeed: number = 1;
  6538. @State oldSeconds: number = 0;
  6539. @State isSeekTo: boolean = false;
  6540. @State isCurrentTime: boolean = false;
  6541. @State videoWidth: string = '100%';
  6542. @State videoHeight: string = '100%';
  6543. @State initAspectRatio: number = 1;
  6544. @State videoAspectRatio: number = this.initAspectRatio;
  6545. private videoUrl: string = '';
  6546. private last: number = 0;
  6547. @State videoParentAspectRatio: number = this.initAspectRatio;
  6548. private mIjkMediaPlayer = IjkMediaPlayer.getInstance();
  6549. @State CONTROL_PlayStatus: number = PlayStatus.INIT;
  6550. @State PROGRESS_MAX_VALUE: number = 100;
  6551. @State updateProgressTimer: number = 0;
  6552. @State isHide: boolean = false; //是否因此播放器的按钮,默认是进入横屏模式隐藏,点击视频的时候显示
  6553. @State name: string = '';
  6554. // @State loop: boolean = false;
  6555. @State playType: number = 0; //0:连续播放 1:单片重复播放 2:正常播放 3:随机播放
  6556. @State multiple: string = '1.0X';
  6557. xcomponentController: XComponentController = new XComponentController()
  6558. private panOptionBright: PanGestureOptions =
  6559. new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down });
  6560. private panOptionVolume: PanGestureOptions =
  6561. new PanGestureOptions({ direction: PanDirection.Vertical | PanDirection.Up | PanDirection.Down });
  6562. private panOptionSeekTo: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Horizontal });
  6563. //手势的音量控制和亮度控制
  6564. private positionX: number = PlayConstants.POSITION_X;
  6565. private positionY: number = PlayConstants.POSITION_Y;
  6566. private windowClass: window.Window = globalThis.windowClass
  6567. @State volume: number = 0.5;
  6568. @State volumeSmall: boolean = false
  6569. @State volumeShow: boolean = PlayConstants.VOLUME_SHOW;
  6570. @State bright: number = PlayConstants.BRIGHT;
  6571. @State brightShow: boolean = PlayConstants.BRIGHT_SHOW;
  6572. @State seekToShow: boolean = PlayConstants.BRIGHT_SHOW;
  6573. @State screenWidth: number = 0
  6574. @State screenHeight: number = 0
  6575. @State statusBarHeight: number = 0
  6576. @State isYesFull: boolean = false
  6577. private seekValue: number = 0
  6578. @State isVideoLock: boolean = false; // Whether the video playback is locked
  6579. eventHub = getContext().eventHub;
  6580. //投播组件
  6581. private avSessionController: AvSessionController = AvSessionController.getInstance(false);
  6582. private castController: avSession.AVCastController | undefined = undefined;
  6583. @State isCastPlaying: boolean = false;
  6584. @State currentTime2: number = 0;
  6585. @State currentStringTime: string = '00:00';
  6586. @State duration: number = 0;
  6587. @State isReady: boolean = false;
  6588. @State durationTime: number = 0;
  6589. @State durationStringTime: string = '00:00';
  6590. @StorageLink('isPlaying') @Watch('animationRoFun') isPlaying: boolean = false;
  6591. // @State isPlaying: boolean = false;
  6592. private castSeek: boolean = false;
  6593. private castItem: avSession.AVQueueItem | undefined = undefined;
  6594. // @State isBgPlayOpen:boolean = true //是否启用后台播放
  6595. @State imageLabel: PixelMap | Resource = CommonConstants.musicBgList[0];
  6596. @State imageLabelBg: PixelMap | Resource = CommonConstants.musicBgList[0];
  6597. @State rotateAngle2: number = -9
  6598. @StorageLink('imageColor') imageColor: string = 'rgba(0, 0, 2, 1.00)';
  6599. @State cover: string | undefined = '';
  6600. @State artist: string | undefined = ''
  6601. // 1.初始化controller
  6602. private lyricController: LyricController = new LyricController()
  6603. private lyricControllerXF: LyricController = new LyricController() //悬浮歌词控制器
  6604. private lyricControllerSingle: LyricController = new LyricController() //播放页单行歌词控制器
  6605. private parser = new LyricParser()
  6606. @State randomColor: string = 'rgb(0,0,0)'
  6607. @State randomShakenX: number = 0
  6608. @State randomShakenY: number = 0
  6609. @State lyricTextSize: number = 24
  6610. @State lyricContent: string = ''
  6611. @State isDebug: boolean = false
  6612. @State isHightLightCenter: boolean = true
  6613. /**
  6614. * 初始化歌词加载与展示逻辑
  6615. * @param lyricPath 歌词文件路径(支持普通.lrc和加密.lrcc)
  6616. * @param isOnLineAndToast 是否弹出Toast提示(可选)获取在线歌词为true
  6617. * @param isApi2 是否使用API2获取歌词(可选)
  6618. *
  6619. * 主要流程:
  6620. * 1. 设置歌词显示样式(字号、颜色、行距、对齐、动画等)。
  6621. * 2. 优先尝试本地读取歌词文件(支持加密和普通两种后缀)。
  6622. * 3. 若本地无歌词且满足条件(调试模式或会员且安装时间超过2天),则联网获取歌词。
  6623. * 4. 获取到歌词后,解析并设置到lyricController,并保存到本地。
  6624. * 5. 本地有歌词时,读取文件内容(自动检测编码,支持解密),解析后设置到lyricController。
  6625. * 6. 解析失败或读取失败时,清空歌词显示。
  6626. *
  6627. * 注意事项:
  6628. * - 仅会员且安装时间超过2天才可联网获取歌词(调试模式isDebug=true时跳过限制)。
  6629. * - 支持加密歌词文件(.lrcc),自动检测并解密。
  6630. * - 歌词内容解析后通过lyricController驱动UI渲染。
  6631. */
  6632. async initLyric(lyricPath: string, isOnLineAndToast?: boolean, isApi2?: boolean, isLocal?: boolean) {
  6633. if (StrUtil.isEmpty(lyricPath)) {
  6634. return
  6635. }
  6636. this.initPipLyricSetting()
  6637. this.lyricControllerSingle
  6638. .setTextSize(15)
  6639. .setCacheSize(4)
  6640. .setTextColor("#FFFFFF")
  6641. .setHighlightColor("#FFFFFF")
  6642. .setHighlightScale(1.2)
  6643. .setEmptyHint("")
  6644. .setAlignMode('center')
  6645. .setAnimationDuration(500)
  6646. .setSingleLine(true)
  6647. this.lyricContent = ''
  6648. this.lyricController
  6649. .setTextSize(this.currentLyricSize)
  6650. .setCacheSize(4)
  6651. .setTextColor("#DDDDDD")
  6652. .setHighlightColor("#FFFFFF")
  6653. .setEmptyHint("")
  6654. .setAnimationDuration(1000)
  6655. this.currentLyricAlignMode = PreferencesUtil.getNumberSync('LyricAlignMode', 1)
  6656. this.blurDegree = PreferencesUtil.getNumberSync('setBlurDegree', 3)
  6657. this.setBlurDegree(this.blurDegree, false)
  6658. this.setLyricAlignMode(this.currentLyricAlignMode, false)
  6659. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSize', 18), false)
  6660. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSize', 1.23), false)
  6661. this.lyricController.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpace', 10))
  6662. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColor', '#FFFFFF'), false)
  6663. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColor', '#FFFFFF'), false)
  6664. this.isHightLightCenter = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, true)
  6665. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  6666. this.lyricTextWeight = PreferencesUtil.getNumberSync('lyricTextWeight', 400)
  6667. this.lyricController.setTextWeight(this.lyricTextWeight)
  6668. this.showSingleLyric = false
  6669. this.timeOffset = 0
  6670. this.lyricController.setLyric(null)
  6671. this.lyricControllerSingle.setLyric(null)
  6672. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc'
  6673. console.log("onecold lyricPath =" + lyricPath)
  6674. let neiqianLrc = ''
  6675. let lyContent = this.currentSong?.lyricContent
  6676. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  6677. neiqianLrc = lyContent
  6678. }
  6679. if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast&&!isLocal&&!isLocal) {
  6680. console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
  6681. //赋值给this.lyricContent,播控中心才可以显示歌词
  6682. this.lyricContent = neiqianLrc
  6683. // 将文件内容按行分割成字符串数组
  6684. let lines = neiqianLrc.split('\n').map(line => line.trim());
  6685. // 3.解析歌词
  6686. let lyric = this.parser.parse(lines);
  6687. // 4.设置歌词
  6688. this.lyricController.setLyric(lyric);
  6689. this.lyricControllerXF.setLyric(lyric)
  6690. this.lyricControllerSingle.setLyric(lyric)
  6691. return
  6692. }
  6693. if (isOnLineAndToast || ((!FileUtil.accessSync(lyricPath) && !FileUtil.accessSync(jiaMilyricPath))
  6694. && !Utility.isVideoByExtension(this.videoUrl))) {
  6695. if (this.currentSong !== undefined) {
  6696. // ToastUtil.showShort('正在为你搜索在线歌词!')
  6697. //判断是不是赞助会员,是会员的话才开启歌词功能
  6698. // if (!this.isDebug) {
  6699. // if (!Utility.isNoble()) {
  6700. // LogUtil.debug("onecold 不是赞助会员")
  6701. // return
  6702. // }
  6703. // if(!Utility.isPassInstallTime(33)){
  6704. // LogUtil.debug("onecold not pass time")
  6705. // // LogUtil.debug("onecold 用户安装app没超过12天" )
  6706. // return
  6707. // }
  6708. // }
  6709. let artist = this.currentSong?.artist
  6710. if (artist === undefined) {
  6711. artist = ''
  6712. }
  6713. if (isApi2 === undefined) {
  6714. isApi2 = false
  6715. }
  6716. NetAxiosUtil.getLyric(this.name, artist, isApi2).then((res) => {
  6717. // LogUtil.debug("onecold res =" + res)
  6718. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  6719. if (StrUtil.isNotEmpty(res)) {
  6720. this.lyricContent = res
  6721. let lines = res.split('\n').map(line => line.trim());
  6722. // 3.解析歌词
  6723. let lyric = this.parser.parse(lines);
  6724. // 4.设置歌词
  6725. this.lyricController.setLyric(lyric);
  6726. this.lyricControllerXF.setLyric(lyric)
  6727. this.lyricControllerSingle.setLyric(lyric)
  6728. this.showSingleLyric = true
  6729. // 4.保存歌词文件lyric到本地
  6730. //2025年8月28日歌词不再加密下载
  6731. this.saveDataToFile(res, lyricPath, false)
  6732. } else {
  6733. this.lyricController.setLyric(null)
  6734. this.lyricControllerXF.setLyric(null)
  6735. this.lyricControllerSingle.setLyric(null)
  6736. if (isOnLineAndToast) {
  6737. ToastUtil.showShort('未获取到歌词!')
  6738. }
  6739. }
  6740. } else {
  6741. this.lyricController.setLyric(null)
  6742. this.lyricControllerXF.setLyric(null)
  6743. this.lyricControllerSingle.setLyric(null)
  6744. if (isOnLineAndToast) {
  6745. ToastUtil.showShort('未获取到歌词!')
  6746. }
  6747. }
  6748. })
  6749. } else {
  6750. this.lyricController.setLyric(null)
  6751. this.lyricControllerXF.setLyric(null)
  6752. this.lyricControllerSingle.setLyric(null)
  6753. if (isOnLineAndToast) {
  6754. ToastUtil.showShort('未获取到歌词!')
  6755. }
  6756. }
  6757. return
  6758. }
  6759. try {
  6760. let isJiaMi = false;
  6761. let realLyricPath = lyricPath
  6762. if (FileUtil.accessSync(jiaMilyricPath)) {
  6763. isJiaMi = true
  6764. realLyricPath = jiaMilyricPath
  6765. console.info("onecold 找到加密本地歌词 ");
  6766. } else {
  6767. isJiaMi = false
  6768. realLyricPath = lyricPath
  6769. console.info("onecold 找到本地歌词 ");
  6770. }
  6771. // 3.读取文件内容并指定编码为 UTF-8
  6772. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  6773. const stat = await fileIo.stat(file.fd);
  6774. const arrayBuffer = new ArrayBuffer(stat.size);
  6775. fs.read(file.fd, arrayBuffer)
  6776. .then((readLen: number) => {
  6777. console.info("read file data succeed");
  6778. // let buf = buffer.from(arrayBuffer, 0, readLen);
  6779. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  6780. // 检查 buf 是否为空
  6781. if (buf.length === 0) {
  6782. throw new Error("Buffer is empty after reading the file");
  6783. }
  6784. try {
  6785. // 检测文件编码
  6786. // let detectedEncoding = chardet.detect(buf);
  6787. // console.info("onecoldT Detected encoding: " + detectedEncoding);
  6788. let detectedEncoding = this.detect(arrayBuffer)
  6789. console.info("onecoldT Detected encoding: " + detectedEncoding);
  6790. // 使用检测到的编码解码,解决中文乱码问题
  6791. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  6792. console.info("onecoldT Detected textDecoder: " + textDecoder);
  6793. let fileContent = textDecoder.decode(buf);
  6794. console.info(`onecoldT The content of file1: ${fileContent}`);
  6795. //解密
  6796. if (isJiaMi) {
  6797. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent))
  6798. }
  6799. console.info(`onecold The content of file2: ${fileContent}`);
  6800. this.lyricContent = fileContent
  6801. if(isLocal){//编辑标签选择本地歌词需要赋值给this.lyricConStr
  6802. this.lyricConStr = fileContent
  6803. }
  6804. // 将文件内容按行分割成字符串数组
  6805. let lines = fileContent.split('\n').map(line => line.trim());
  6806. console.info(`onecold The content of file: ${fileContent}`);
  6807. // 3.解析歌词
  6808. let lyric = this.parser.parse(lines);
  6809. // 4.设置歌词
  6810. this.lyricController.setLyric(lyric);
  6811. this.lyricControllerXF.setLyric(lyric)
  6812. this.lyricControllerSingle.setLyric(lyric)
  6813. this.showSingleLyric = true
  6814. console.info(`The content of file: ${fileContent}`);
  6815. } catch (chardetError) {
  6816. console.error("chardet.detect failed with error: " + chardetError.message);
  6817. this.lyricController.setLyric(null);
  6818. this.lyricControllerXF.setLyric(null)
  6819. this.lyricControllerSingle.setLyric(null)
  6820. }
  6821. })
  6822. .catch((err: BusinessError) => {
  6823. this.lyricController.setLyric(null)
  6824. this.lyricControllerXF.setLyric(null)
  6825. this.lyricControllerSingle.setLyric(null)
  6826. console.error("read file data failed with error message: " + err.message + ", error code: " + err.code);
  6827. })
  6828. .catch((err: Error) => {
  6829. this.lyricController.setLyric(null)
  6830. this.lyricControllerXF.setLyric(null)
  6831. this.lyricControllerSingle.setLyric(null)
  6832. console.error("read file 2 data failed with error message: " + err.message);
  6833. })
  6834. .finally(() => {
  6835. fs.closeSync(file);
  6836. });
  6837. } catch (error) {
  6838. this.lyricController.setLyric(null)
  6839. this.lyricControllerSingle.setLyric(null)
  6840. this.lyricControllerXF.setLyric(null)
  6841. Logger.error(TAG, 'init Lyric failed with err: ' + JSON.stringify(error));
  6842. }
  6843. }
  6844. detect(data: ArrayBuffer): string {
  6845. //创建检测对象
  6846. let detector: UniversalDetector = new UniversalDetector();
  6847. // 传入检测数据并实时判断编码格式
  6848. detector.handleData(data, 0, data.byteLength);
  6849. // 标记检测数据 读取结束
  6850. detector.dataEnd();
  6851. // 获取检测结果
  6852. let detected: string = detector.getDetectedCharset();
  6853. // 释放资源
  6854. detector.reset();
  6855. return detected;
  6856. }
  6857. //初始化悬浮歌词的自定义设置
  6858. initPipLyricSetting() {
  6859. this.lyricControllerXF
  6860. .setTextSize(this.currentLyricSize)
  6861. .setCacheSize(4)
  6862. .setTextColor("#DDDDDD")
  6863. .setHighlightColor("#FFFFFF")// .setLineSpace(18)
  6864. .setEmptyHint("")
  6865. .setAnimationDuration(1000)
  6866. this.currentLyricAlignModePip = PreferencesUtil.getNumberSync('LyricAlignModePip', 0)
  6867. this.blurDegreePip = PreferencesUtil.getNumberSync('setBlurDegreePip', 3)
  6868. this.setBlurDegree(this.blurDegreePip, true)
  6869. this.setLyricAlignMode(this.currentLyricAlignModePip, true)
  6870. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSizePip', 18), true)
  6871. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSizePip', 1.23), true)
  6872. this.lyricControllerXF.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpacePip', 10))
  6873. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColorPip', '#FFFFFF'), true)
  6874. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColorPip', '#FFFFFF'), true)
  6875. this.lyricControllerXF.setHightLightCenter(true)
  6876. this.lyricTextWeightPip = PreferencesUtil.getNumberSync('lyricTextWeightPip', 400)
  6877. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  6878. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  6879. this.pipBgIndex = PreferencesUtil.getNumberSync('pipBgIndex', 0)
  6880. if (this.pipBgIndex === 0) {
  6881. if (this.cover) {
  6882. this.pipBg = this.cover
  6883. } else {
  6884. this.pipBg = this.imageColor
  6885. }
  6886. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  6887. }
  6888. }
  6889. //根据item返回歌词内容
  6890. async getLyricContent(item: VideoItem): Promise<string> {
  6891. let neiqianLrc = ''
  6892. let lyContent = item?.lyricContent
  6893. if(lyContent&&StrUtil.isNotEmpty(lyContent)){
  6894. neiqianLrc = lyContent
  6895. return neiqianLrc
  6896. }
  6897. try {
  6898. //取数据库里面的歌词lyContent
  6899. const lyricContent = await this.table.getLyricContentByFilePath(item.filePath);
  6900. if (lyricContent&&StrUtil.isNotEmpty(lyricContent)) {
  6901. console.log("onecold Lyrics:", lyricContent);
  6902. neiqianLrc = lyricContent
  6903. return neiqianLrc
  6904. }
  6905. } catch (error) {
  6906. console.error("Error fetching lyrics:", error);
  6907. }
  6908. try {
  6909. let filePath = item.filePath;
  6910. let lyricPath = filePath.substring(0, filePath.lastIndexOf('.')) + '.lrc';
  6911. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc';
  6912. let isJiaMi = false;
  6913. let realLyricPath = lyricPath;
  6914. if (FileUtil.accessSync(jiaMilyricPath)) {
  6915. isJiaMi = true;
  6916. realLyricPath = jiaMilyricPath;
  6917. console.info("onecold 找到加密本地歌词");
  6918. } else {
  6919. console.info("onecold 找到本地歌词");
  6920. }
  6921. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  6922. const stat = await fileIo.stat(file.fd);
  6923. const arrayBuffer = new ArrayBuffer(stat.size);
  6924. const readLen = await fs.read(file.fd, arrayBuffer);
  6925. console.info("read file data succeed");
  6926. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  6927. if (buf.length === 0) {
  6928. throw new Error("Buffer is empty after reading the file");
  6929. }
  6930. // let detectedEncoding = chardet.detect(buf);
  6931. let detectedEncoding = this.detect(arrayBuffer)
  6932. console.info("Detected encoding: " + detectedEncoding);
  6933. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  6934. let fileContent = textDecoder.decode(buf);
  6935. console.info(`onecold The content of file1: ${fileContent}`);
  6936. if (isJiaMi) {
  6937. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent));
  6938. }
  6939. console.info(`onecold The content of file2: ${fileContent}`);
  6940. fs.closeSync(file);
  6941. return fileContent;
  6942. } catch (error) {
  6943. console.error('init Lyric failed with err: ' + JSON.stringify(error));
  6944. return '';
  6945. }
  6946. }
  6947. async saveDataToFile(content: string, filePath: string, isJiaMi?: boolean) {
  6948. if (StrUtil.isEmpty(filePath)) {
  6949. return
  6950. }
  6951. try {
  6952. //将content进行加密
  6953. // let jiaMilyricPath = filePath.substring(0,filePath.lastIndexOf('.'))+'.lrcc'
  6954. let lyricContent = ''
  6955. if (isJiaMi) {
  6956. lyricContent = Base64Util.encodeToStrSync(StrUtil.strToUint8Array(content))
  6957. } else {
  6958. lyricContent = content
  6959. }
  6960. const file = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  6961. // 清空文件内容
  6962. await fileIo.truncate(file.fd, 0);
  6963. await fileIo.write(file.fd, lyricContent);
  6964. await fileIo.close(file);
  6965. console.log('onecold lyric file Data saved successfully.');
  6966. } catch (error) {
  6967. console.error('onecold lyric file Failed to save data:', error);
  6968. }
  6969. }
  6970. /**
  6971. * Get largest proportion color of an image.
  6972. */
  6973. getImageColor() {
  6974. if (!this.context) {
  6975. return;
  6976. }
  6977. let bg = Utility.getMusisBg()
  6978. this.imageLabel = bg
  6979. ColorConversion.setSysBarLightBackground(true);
  6980. this.context.resourceManager.getMediaContent(bg)
  6981. .then((value: Uint8Array) => {
  6982. let buffer = value.buffer as ArrayBuffer;
  6983. image.createImageSource(buffer).createPixelMap().then((pixelMap) => {
  6984. effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
  6985. if (error) {
  6986. Logger.error('Failed to create color picker.');
  6987. } else {
  6988. let color = colorPicker.getLargestProportionColor();
  6989. let colorArr = ColorConversion.dealColor(color.red, color.green, color.blue);
  6990. this.imageColor = `rgba(${colorArr[0]}, ${colorArr[1]}, ${colorArr[2]}, 1)`;
  6991. }
  6992. })
  6993. let headFilter = effectKit.createEffect(pixelMap);
  6994. if (headFilter !== null) {
  6995. headFilter.blur(15);
  6996. headFilter.getEffectPixelMap().then((value) => {
  6997. this.imageLabelBg = value;
  6998. })
  6999. }
  7000. })
  7001. .catch((error: BusinessError) => {
  7002. Logger.error(`${error.code} + ${error.message}`)
  7003. })
  7004. })
  7005. .catch((error: BusinessError) => {
  7006. Logger.error(`${error.code} + ${error.message}`)
  7007. })
  7008. }
  7009. setImageColor(cover: string) {
  7010. if (!this.context) {
  7011. return;
  7012. }
  7013. if (cover === undefined) {
  7014. return;
  7015. }
  7016. imagePathToPixelMap(cover).then((value) => {
  7017. let headFilter = effectKit.createEffect(value);
  7018. if (headFilter !== null) {
  7019. headFilter.blur(15);
  7020. headFilter.getEffectPixelMap().then((value) => {
  7021. this.imageLabelBg = value;
  7022. })
  7023. }
  7024. }).catch((error: BusinessError) => {
  7025. Logger.error(`${error.code} + ${error.message}`)
  7026. })
  7027. }
  7028. setImageColor2(cover: string) {
  7029. if (!this.context) {
  7030. return;
  7031. }
  7032. if (cover === undefined) {
  7033. return;
  7034. }
  7035. LogUtils.getInstance().LOGI("setImageColor2--> cover ==" + cover);
  7036. ImageUtils.getImageDealData(getContext(this), cover, this.videoUrl).then((data) => {
  7037. this.imageColor = data.imageColor;
  7038. if (data.blurPixelMap) {
  7039. this.imageLabelBg = data.blurPixelMap;
  7040. }
  7041. })
  7042. }
  7043. // 定义开始旋转的方法
  7044. // 定时器用于一百毫秒执行一次旋转角度
  7045. @State timer: number = 0
  7046. @State rotateAngle: number = 0
  7047. //封面旋转动画
  7048. animationRoFun() {
  7049. if (this.isPlaying && !this.isCoverRectangle) {
  7050. this.timer = setInterval(() => {
  7051. this.rotateAngle += 1
  7052. }, 100)
  7053. this.startRotation()
  7054. } else {
  7055. clearInterval(this.timer)
  7056. this.stopRotation()
  7057. }
  7058. }
  7059. // 定义开始旋转的方法
  7060. startRotation() {
  7061. if (this.isPlaying) {
  7062. animateTo({
  7063. duration: 777,
  7064. iterations: 1,
  7065. curve: Curve.Linear
  7066. }, () => {
  7067. this.rotateAngle2 = -9
  7068. })
  7069. }
  7070. }
  7071. // 回调,暂停和播放按钮回调,下一首和上一首
  7072. playChange() {
  7073. // if(this.isCoverRectangle){
  7074. // return
  7075. // }
  7076. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  7077. this.setIsPlaying(true)
  7078. this.animationState = AnimationStatus.Running
  7079. } else {
  7080. this.setIsPlaying(false)
  7081. this.animationState = AnimationStatus.Paused
  7082. }
  7083. }
  7084. // 定义停止旋转的方法
  7085. stopRotation() {
  7086. if (this.isCoverRectangle) {
  7087. this.rotateAngle = 0
  7088. } else {
  7089. //唱针以左上角为点选择逆时针40度
  7090. animateTo({
  7091. duration: 1000,
  7092. curve: Curve.Linear,
  7093. iterations: 1,
  7094. }, () => {
  7095. this.rotateAngle2 = -45;
  7096. });
  7097. }
  7098. }
  7099. @Builder
  7100. private LyricsTopItem() {
  7101. Row() {
  7102. Stack() {
  7103. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  7104. .height(55)
  7105. .width(55)
  7106. .alt(this.imageLabel)
  7107. .borderRadius(8)
  7108. .clickEffect({ level: ClickEffectLevel.HEAVY })
  7109. .margin({ left: this.currentLyricAlignMode === 0 ? 28 : -15 })
  7110. }
  7111. .width('18%')
  7112. Column() {
  7113. Column() {
  7114. Text(this.name)
  7115. .fontSize(16)
  7116. .maxLines(1)
  7117. .fontWeight(FontWeight.Bolder)
  7118. .fontColor(this.currentLyricColor)
  7119. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  7120. Row() {
  7121. Text(this.currentSong?.artist !== undefined ? this.currentSong?.artist : '')
  7122. .fontSize(13)
  7123. .fontWeight(FontWeight.Bold)
  7124. .padding({ top: 8 })
  7125. .fontColor(this.currentLyricColor)
  7126. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  7127. Blank()
  7128. }
  7129. }
  7130. .height('100%')
  7131. .width('100%')
  7132. .justifyContent(FlexAlign.Center)
  7133. .alignItems(HorizontalAlign.Start)
  7134. }
  7135. .height('100%')
  7136. .width('65%')
  7137. Column() {
  7138. Image($r('app.media.lyric'))
  7139. .width(28)
  7140. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7141. .margin({ right: 30 })
  7142. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7143. .onClick(() => {
  7144. this.isLyricSetting = !this.isLyricSetting;
  7145. })
  7146. .bindSheet($$this.isLyricSetting, this.lyricSettingSheet(false), {
  7147. height: '95%',
  7148. dragBar: true,
  7149. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7150. showClose: true,
  7151. blurStyle: BlurStyle.Thin,
  7152. backgroundColor: Color.Transparent,
  7153. // title: { title: $r('app.string.lyric_setting') }
  7154. })
  7155. }
  7156. .width('18%')
  7157. }
  7158. .width('82%')
  7159. .height(58)
  7160. .justifyContent(FlexAlign.SpaceBetween)
  7161. }
  7162. //歌词显示
  7163. @Builder
  7164. PlayerLyrics() {
  7165. Column() {
  7166. Column() {
  7167. this.LyricsTopItem()
  7168. }
  7169. .height(this.isPuraWP() ? 15 : 58)
  7170. .visibility(this.currentBreakpoint !== BreakpointTypeEnum.SM ?
  7171. Visibility.None : Visibility.Visible)
  7172. .margin({ left: 6, top: this.isPuraWP() ? 5 : 38 })
  7173. .width("100%")
  7174. Column() {
  7175. LyricView2({
  7176. controller: this.lyricController,
  7177. enableSeek: true,
  7178. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  7179. seekLineColor: "#80ffffff", // 滑动定位线颜色
  7180. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  7181. onSeekAction: (position: number) => { // 滑动歌词触发seek定位回调
  7182. if (!this.isPlaying) {
  7183. console.info('onecold startPlayOrResumePlay 7527')
  7184. this.startPlayOrResumePlay()
  7185. }
  7186. else {
  7187. this.isSeekTo = true;
  7188. this.mDestroyPage = false;
  7189. this.showLoadIng();
  7190. this.seekTo(position + "");
  7191. this.isSeekTo = false;
  7192. }
  7193. return true
  7194. }
  7195. })
  7196. .width("100%")
  7197. .layoutWeight(1)
  7198. .margin({ left: this.currentLyricAlignMode === 0 ? 0 : 50, top: 2, bottom: this.isPhoneLan()||this.isHiCarKuanBianPing() ? 40 : 10 })
  7199. if (this.isPhoneLan()) {
  7200. Column() {
  7201. this.playProgressView()
  7202. // this.playCenterView()
  7203. }
  7204. .margin({ bottom: 30, right: this.currentLyricAlignMode == 0 ? 0 : 30 })
  7205. }
  7206. }
  7207. .position({
  7208. top: this.currentBreakpoint !== BreakpointTypeEnum.SM ? (this.isPhoneLan() ? 0 : 45) :
  7209. (this.isPuraWP() ? 58 : 99)
  7210. })
  7211. .justifyContent(FlexAlign.Center)
  7212. .height(this.isCoverOpacity() ? this.isPhoneLan()?'95%':'90%' : '82%')
  7213. }
  7214. }
  7215. @Builder
  7216. SingleLyricView() {
  7217. Column() {
  7218. Column() {
  7219. LyricView2({
  7220. controller: this.lyricControllerSingle,
  7221. enableSeek: false,
  7222. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  7223. seekLineColor: "#80ffffff", // 滑动定位线颜色
  7224. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  7225. })
  7226. }
  7227. .height(66)
  7228. .margin({ bottom: 20 })
  7229. }
  7230. }
  7231. //播放器的底部控制中心,上一首,暂停,下一首,播放进度条等
  7232. @Builder
  7233. BottomControl() {
  7234. Column() {
  7235. this.TopPlayProgressView()
  7236. //播放 暂停,下一首,上一首
  7237. this.playCenterView()
  7238. //播放进度条
  7239. this.BottomView()
  7240. }
  7241. .position({ bottom: this.isHiCarSmall()?50:(this.isCoverOpacity() ? 55 : 70) }) // 将 固定在底部
  7242. }
  7243. //播放控制上一首 下一首 暂停和播放
  7244. @Builder
  7245. playCenterView(){
  7246. Row() {
  7247. Row({ space: 20 }) {
  7248. Button({type:ButtonType.Circle,stateEffect:true}){
  7249. //更多功能
  7250. Image($r('app.media.menu'))
  7251. .width(24)
  7252. .clickEffect({level:ClickEffectLevel.MIDDLE})
  7253. .bindSheet($$this.isShowMoreView, this.PlayMoreSheet(), {
  7254. height: this.isCoverOpacity() ? '95%' : '93%',
  7255. preferType: this.currentBreakpoint!==BreakpointTypeEnum.SM?SheetType.CENTER:SheetType.BOTTOM,
  7256. dragBar: true,
  7257. showClose: true,
  7258. blurStyle: BlurStyle.Thin,
  7259. backgroundColor: Color.Transparent,
  7260. })
  7261. }
  7262. .margin({ left: 5 })
  7263. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7264. .backgroundColor(Color.Transparent)
  7265. .onClick(() => {
  7266. this.isShowMoreView = !this.isShowMoreView;
  7267. })
  7268. Button({type:ButtonType.Circle,stateEffect:true}){
  7269. Image($r('app.media.ic_previous'))
  7270. .width(33)
  7271. .clickEffect({level:ClickEffectLevel.HEAVY})
  7272. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7273. }
  7274. .onClick(async () => {
  7275. this.playPrevious()
  7276. })
  7277. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7278. .backgroundColor(Color.Transparent)
  7279. .margin({ left: 5 })
  7280. }
  7281. Button({type:ButtonType.Circle,stateEffect:true}){
  7282. Column() {
  7283. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ?
  7284. (this.isCircleBtn?$r('app.media.hm_pause'):$r('app.media.ic_public_play'))
  7285. : (this.isCircleBtn?$r('app.media.hm_play2'):$r('app.media.ic_public_pause')))
  7286. .width(this.isPhoneLan()?45:55)
  7287. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7288. .fillColor(Color.White)
  7289. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7290. .onClick(async () => {
  7291. console.info('onecold playOrPause 7651')
  7292. this.playOrPause()
  7293. })
  7294. }
  7295. }
  7296. .backgroundColor(Color.Transparent)
  7297. .layoutWeight(1)
  7298. // .margin({ left: 38, right: 38 })
  7299. Row({ space: 20 }) {
  7300. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7301. Image($r('app.media.ic_next'))
  7302. .width(33)
  7303. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7304. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7305. .onClick(() => {
  7306. this.playNext();
  7307. })
  7308. }
  7309. .backgroundColor(Color.Transparent)
  7310. .margin({ right: 5 })
  7311. .width(33)
  7312. if(this.isPhoneLan()){
  7313. this.fullButton()
  7314. }else{
  7315. Button({type:ButtonType.Circle,stateEffect:true}){
  7316. //添加或取消收藏
  7317. SymbolGlyph(Utility.getIsFav(this.favList,this.currentSong)?
  7318. $r('sys.symbol.heart_fill'):$r('sys.symbol.heart'))
  7319. .fontSize(23)
  7320. .fontColor([Color.White])
  7321. .alignSelf(ItemAlign.Center)
  7322. // .width(24)
  7323. .clickEffect({level:ClickEffectLevel.MIDDLE})
  7324. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7325. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7326. .onClick(async () => {
  7327. if(this.currentSong){
  7328. this.doFav(this.currentSong)
  7329. }
  7330. })
  7331. }
  7332. .backgroundColor(Color.Transparent)
  7333. .width(24)
  7334. }
  7335. }
  7336. // .margin({ left: 5 })
  7337. }
  7338. .width('95%')
  7339. .margin({ bottom:this.isCoverOpacity()?0:20 })
  7340. .justifyContent(FlexAlign.SpaceEvenly)
  7341. }
  7342. @Builder
  7343. TopPlayProgressView(){
  7344. Row() {
  7345. Column(){
  7346. Row(){
  7347. Slider({
  7348. value: this.progressValue,
  7349. min: 0,
  7350. max: this.PROGRESS_MAX_VALUE,
  7351. step: 1,
  7352. style: SliderStyle.InSet
  7353. })
  7354. .height(20)
  7355. .blockColor('rgba(255,255,255,1)')
  7356. .trackColor('rgba(255,255,255,0.3)')
  7357. .selectedColor(Color.White)
  7358. .trackThickness(4)
  7359. .layoutWeight(1)
  7360. .showSteps(false)
  7361. .showTips(true)
  7362. .alignSelf(ItemAlign.Center)
  7363. .enabled(this.slideEnable)
  7364. .onChange((value: number, mode: SliderChangeMode) => {
  7365. // if (mode == 2) {
  7366. this.isSeekTo = true;
  7367. this.mDestroyPage = false;
  7368. this.showLoadIng();
  7369. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  7370. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  7371. this.seekTo(seekValue + "");
  7372. // this.setProgress()
  7373. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  7374. this.isSeekTo = false;
  7375. // }
  7376. })
  7377. }
  7378. .padding({ right: 7,left:20 })
  7379. Row(){
  7380. Text(this.currentTime)
  7381. .fontSize(10)
  7382. .fontColor(Color.White)
  7383. Blank()
  7384. .layoutWeight(1)
  7385. Text(this.totalTime)
  7386. .fontSize(10)
  7387. .fontColor(Color.White)
  7388. }
  7389. .justifyContent(FlexAlign.Start)
  7390. .padding({ right: 18,left:36 })
  7391. }
  7392. }
  7393. //x5的竖屏模式需要99%
  7394. .width(this.isLandscape?'80%':'93%')
  7395. .justifyContent(FlexAlign.Center)
  7396. .margin({bottom:6})
  7397. .animation({
  7398. duration: 666,
  7399. curve: 'ease-in-out' // 可选动画曲线
  7400. })
  7401. }
  7402. //播放进度条
  7403. @Builder
  7404. BottomView(){
  7405. Row() {
  7406. Button({type:ButtonType.Circle,stateEffect:true}){
  7407. Column() {
  7408. if (this.playType === 0) {
  7409. Image($r('app.media.loop'))
  7410. .width(27)
  7411. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7412. } else if (this.playType === 1) {
  7413. Image($r('app.media.single'))
  7414. .width(27)
  7415. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7416. } else if (this.playType === 2) {
  7417. Image($r('app.media.normal_play'))
  7418. .width(27)
  7419. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7420. } else if (this.playType === 3) {
  7421. Image($r('app.media.random'))
  7422. .width(27)
  7423. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7424. }
  7425. }
  7426. }
  7427. .layoutWeight(1)
  7428. .margin({ left: 5 })
  7429. .backgroundColor(Color.Transparent)
  7430. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7431. .onClick(async () => {
  7432. this.setLoopMode()
  7433. })
  7434. this.fullButton()
  7435. Button({type:ButtonType.Circle,stateEffect:true}){
  7436. Column() {
  7437. Image($r('app.media.lyric'))
  7438. .width(26)
  7439. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7440. }
  7441. }
  7442. .layoutWeight(1)
  7443. .backgroundColor(Color.Transparent)
  7444. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7445. .onClick(async () => {
  7446. this.isLyricSetting = !this.isLyricSetting;
  7447. })
  7448. //播放列表
  7449. Button({type:ButtonType.Circle,stateEffect:true}){
  7450. Image($r('app.media.hm_playlist'))
  7451. .width(24)
  7452. .fillColor(Color.White)
  7453. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7454. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  7455. height: '95%',
  7456. dragBar: true,
  7457. showClose: true,
  7458. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7459. blurStyle: BlurStyle.Thin,
  7460. backgroundColor: this.isPlayListBgGrass?Color.Transparent:$r('app.color.silvery'),
  7461. title: {
  7462. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  7463. + `(${this.songList.length}首)`
  7464. }
  7465. })
  7466. }
  7467. .layoutWeight(1)
  7468. .backgroundColor(Color.Transparent)
  7469. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7470. .onClick(() => {
  7471. this.isShowSheetView = !this.isShowSheetView;
  7472. if(this.isPlayListBgGrass){
  7473. this.isFrontWhite = true
  7474. }else{
  7475. this.isFrontWhite = false
  7476. }
  7477. this.scrollIndex()
  7478. })
  7479. }
  7480. .width(this.isLandscape?'88%':'95%')
  7481. .justifyContent(FlexAlign.SpaceAround)
  7482. .height(30)
  7483. .margin({top:3})
  7484. .animation({
  7485. duration: 666,
  7486. curve: 'ease-in-out' // 可选动画曲线
  7487. })
  7488. }
  7489. @Builder
  7490. fullButton(){
  7491. Button({type:ButtonType.Circle,stateEffect:true}){
  7492. Column() {
  7493. Image($r('app.media.full_4'))
  7494. .width(25)
  7495. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7496. }
  7497. }
  7498. .layoutWeight(1)
  7499. .backgroundColor(Color.Transparent)
  7500. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  7501. .onClick(async () => {
  7502. if (this.isLandscape) {
  7503. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  7504. } else {
  7505. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  7506. }
  7507. })
  7508. }
  7509. //旧版本播放进度条
  7510. @Builder
  7511. playProgressView() {
  7512. Row() {
  7513. Button({ type: ButtonType.Circle, stateEffect: true }) {
  7514. Column() {
  7515. if (this.playType === 0) {
  7516. Image($r('app.media.loop'))
  7517. .width($r('app.float.control_image_width'))
  7518. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7519. } else if (this.playType === 1) {
  7520. Image($r('app.media.single'))
  7521. .width($r('app.float.control_image_width'))
  7522. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7523. } else if (this.playType === 2) {
  7524. Image($r('app.media.normal_play'))
  7525. .width($r('app.float.control_image_width'))
  7526. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7527. } else if (this.playType === 3) {
  7528. Image($r('app.media.random'))
  7529. .width($r('app.float.control_image_width'))
  7530. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7531. }
  7532. }
  7533. }
  7534. .visibility(this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  7535. .animation({
  7536. duration: 666,
  7537. curve: 'ease-in-out' // 可选动画曲线
  7538. })
  7539. .backgroundColor(Color.Transparent)
  7540. .margin({ right: 10 })
  7541. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7542. .onClick(async () => {
  7543. this.setLoopMode()
  7544. })
  7545. Text(this.currentTime)
  7546. .fontSize($r('app.float.slider_font_size'))
  7547. .fontColor(Color.White)
  7548. .margin(3)
  7549. Slider({
  7550. value: this.progressValue,
  7551. min: 0,
  7552. max: this.PROGRESS_MAX_VALUE,
  7553. step: 1,
  7554. style: SliderStyle.OutSet
  7555. })
  7556. .width('600px')
  7557. .blockColor('rgba(255,255,255,1)')
  7558. .trackColor('rgba(255,255,255,0.3)')
  7559. .selectedColor(Color.White)
  7560. .trackThickness(PlayConstants.PROGRESS_TRACK_THICKNESS)
  7561. .layoutWeight(1)
  7562. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  7563. .showSteps(false)
  7564. .showTips(true)
  7565. .enabled(this.slideEnable)
  7566. .onChange((value: number, mode: SliderChangeMode) => {
  7567. // if (mode == 2) {
  7568. this.isSeekTo = true;
  7569. this.mDestroyPage = false;
  7570. this.showLoadIng();
  7571. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  7572. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  7573. this.seekTo(seekValue + "");
  7574. // this.setProgress()
  7575. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  7576. this.isSeekTo = false;
  7577. // }
  7578. })
  7579. Text(this.totalTime)
  7580. .fontSize($r('app.float.slider_font_size'))
  7581. .fontColor(Color.White)
  7582. .margin(3)
  7583. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  7584. //播放列表
  7585. Button({ type: ButtonType.Circle, stateEffect: true }) {
  7586. Image($r('app.media.hm_playlist'))
  7587. .width($r('app.float.control_image_width'))
  7588. .fillColor(Color.White)
  7589. .aspectRatio(CommonConstants.ASPECT_RATIO)
  7590. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  7591. height: '95%',
  7592. dragBar: true,
  7593. showClose: true,
  7594. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7595. blurStyle: BlurStyle.Thin,
  7596. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  7597. title: {
  7598. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  7599. + `(${this.songList.length}首)`
  7600. }
  7601. })
  7602. }
  7603. .visibility( this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  7604. .animation({
  7605. duration: 666,
  7606. curve: 'ease-in-out' // 可选动画曲线
  7607. })
  7608. .backgroundColor(Color.Transparent)
  7609. .margin({ right: 20, left: 10 })
  7610. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7611. .onClick(() => {
  7612. this.isShowSheetView = !this.isShowSheetView;
  7613. if (this.isPlayListBgGrass) {
  7614. this.isFrontWhite = true
  7615. } else {
  7616. this.isFrontWhite = false
  7617. }
  7618. this.scrollIndex()
  7619. })
  7620. }
  7621. //x5的竖屏模式需要99%
  7622. .width(this.isPhonePortrait() ? '93.4%'
  7623. : this.currentHeightBreakpoint == 1 && this.currentWidthBreakpoint == 2 ? '99%' : '82%')
  7624. .height(this.isPhoneLan() ? 25 : 33)
  7625. .animation({
  7626. duration: 666,
  7627. curve: 'ease-in-out' // 可选动画曲线
  7628. })
  7629. }
  7630. isBigScreen() {
  7631. if (this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_LG) {
  7632. return true
  7633. }
  7634. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  7635. && this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  7636. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG) {
  7637. return false
  7638. } else {
  7639. return true
  7640. }
  7641. return false
  7642. }
  7643. @State is_auto_hide_progress: boolean = false //手机横屏自动隐藏播放进退条,点击屏幕可以显示,倒计时4秒后又自动隐藏
  7644. @State isCoverRectangle: boolean = false
  7645. @State isCoverTop: boolean = true
  7646. // 添加控制缩放的状态变量
  7647. @State scaleValueImage: number = 1
  7648. @Builder
  7649. CoverInfo() {
  7650. Column() {
  7651. //如果是方形,判断是不是封面在顶部,如果不是顶部,显示musicNameInfo, 如果是圆形显示musicNameInfo
  7652. if (this.isCoverRectangle) {
  7653. if (!this.isCoverTop) {
  7654. this.musicNameInfo(false)
  7655. }
  7656. } else {
  7657. this.musicNameInfo(false)
  7658. }
  7659. Stack() {
  7660. // 唱片旋转效果
  7661. Image($r('app.media.ic_music_disc'))
  7662. .width(245)
  7663. .height(245)
  7664. .margin({ right: 20, left: 20 ,top:this.isCoverRectangle||this.isLandscape?0:43})
  7665. .aspectRatio(1)
  7666. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  7667. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  7668. .borderRadius('100%')
  7669. .align(Alignment.Center)
  7670. .clip(true)// .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
  7671. .rotate({
  7672. angle: this.rotateAngle,
  7673. centerX: "50%",
  7674. centerY: "50%",
  7675. })
  7676. .animation({
  7677. duration: 100,
  7678. curve: Curve.Linear
  7679. })
  7680. .shadow({
  7681. radius: 30,
  7682. color: this.randomColor
  7683. })
  7684. Column() {
  7685. if (this.isCoverTop && !this.isCoverOpacity() && this.isCoverRectangle) {
  7686. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  7687. .height(this.isHiCar()?(px2vp(this.windowHeight)*0.46):'auto')
  7688. .width(this.isHiCar()?'auto':this.isBigScreen() ? '72%' : this.isCoverTopBig ? '100%' : '88%')
  7689. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  7690. .alt(this.imageLabel)
  7691. .margin({ right: 8, left: 8, top: 8 })
  7692. .aspectRatio(1)
  7693. .opacity(this.opacityValueImage)
  7694. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7695. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  7696. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  7697. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  7698. .align(Alignment.Center)//
  7699. .clip(true)
  7700. .rotate({
  7701. x: 0,
  7702. y: 0,
  7703. z: 1,
  7704. angle: this.rotateAngle
  7705. })
  7706. .onClick(() => {
  7707. this.getImageColor()
  7708. })
  7709. this.musicNameInfo(false)
  7710. } else {
  7711. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  7712. .height(this.isHiCarSmall()?(this.isHiCarKuanBianPing()?140:px2vp(this.windowHeight)*0.38):
  7713. (this.isCoverOpacity() ? (px2vp(this.windowHeight)*0.62) : this.isCoverRectangle ? 320 : 162))
  7714. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  7715. .alt(this.imageLabel)
  7716. .margin({ right: 20, left: 20,top:this.isCoverRectangle||this.isLandscape?0:43 })
  7717. .aspectRatio(1)
  7718. .opacity(this.opacityValueImage)
  7719. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7720. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  7721. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  7722. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  7723. .align(Alignment.Center)//
  7724. .clip(true)
  7725. .rotate({
  7726. x: 0,
  7727. y: 0,
  7728. z: 1,
  7729. angle: this.rotateAngle
  7730. })
  7731. .onClick(() => {
  7732. this.getImageColor()
  7733. })
  7734. if (this.isPhoneLan()) {
  7735. Text(this.name)
  7736. .fontSize(18)
  7737. .fontWeight(FontWeight.Bold)
  7738. .margin({ top: 13 })
  7739. .textOverflow({ overflow: TextOverflow.Ellipsis })
  7740. .maxLines(1)
  7741. .width('99%')
  7742. .textAlign(TextAlign.Center)
  7743. .fontColor(Color.White)
  7744. }
  7745. }
  7746. }
  7747. // 唱针以左上角为点选择逆时针40度
  7748. Image($r('app.media.ic_music_cover_hand'))
  7749. .height(130)
  7750. .margin({ bottom: 220, top: 0 })
  7751. .align(Alignment.Top)
  7752. .rotate({ angle: this.rotateAngle2, centerX: 0, centerY: 0 })
  7753. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  7754. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  7755. Column({ space: 8 }) {
  7756. Text(this.name)
  7757. .fontSize(this.isPuraWP() ? 24 : (this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22))
  7758. .fontWeight(FontWeight.Bold)
  7759. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7760. .maxLines(1)
  7761. .width('48%')
  7762. .textAlign(TextAlign.Center)
  7763. .fontColor(Color.White)
  7764. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  7765. Text(this.artist)
  7766. .fontSize(this.isPuraWP() ? 18 : (this.isCoverOpacity() ? 12 : 15))
  7767. .fontColor(Color.White)
  7768. .fontWeight(FontWeight.Bold)
  7769. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  7770. }
  7771. .justifyContent(FlexAlign.Start)
  7772. .zIndex(1)
  7773. .visibility(this.isCoverOpacity() ? Visibility.Visible : Visibility.None)
  7774. }
  7775. .margin({
  7776. bottom: this.isCoverOpacity() || this.isCoverRectangle ?
  7777. (this.isPhonePortrait() && this.isShowSingleLineLyric ? 20 : 55) : 0,
  7778. top: this.isCoverOpacity() ? 0 : 20
  7779. })
  7780. if (this.isPhonePortrait() && this.isShowSingleLineLyric) {
  7781. this.SingleLyricView()
  7782. }
  7783. if (this.isPhoneLan()) {
  7784. Column() {
  7785. this.playCenterView()
  7786. // this.playProgressView()
  7787. }
  7788. .position({ left: 28, bottom: 38 })
  7789. } else {
  7790. this.BottomControl()
  7791. }
  7792. }
  7793. .width(CommonConstants.FULL_PERCENT)
  7794. .clip(true)
  7795. }
  7796. @Builder
  7797. private musicNameInfo(isHidden: boolean) {
  7798. Column({ space: 8 }) {
  7799. Text(this.name)
  7800. .fontSize(this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22)
  7801. .fontWeight(FontWeight.Bold)
  7802. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7803. .maxLines(1)
  7804. .width('99%')
  7805. .textAlign(TextAlign.Center)
  7806. .fontColor(Color.White)
  7807. Text(this.artist + ' ' + this.currentSong?.album)
  7808. .fontSize(this.isCoverOpacity() ? 12 : 15)
  7809. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7810. .fontColor(Color.White)
  7811. .textAlign(TextAlign.Center)
  7812. .visibility(StrUtil.isEmpty(this.artist)?Visibility.None:Visibility.Visible)
  7813. .width('99%')
  7814. .maxLines(1)
  7815. }
  7816. .margin({ top: this.isCoverOpacity() ? 20 : isHidden ? 40 : 20 })
  7817. .zIndex(1)
  7818. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  7819. .visibility(this.isCoverOpacity() || isHidden ? Visibility.None : Visibility.Visible)
  7820. }
  7821. @Builder
  7822. private PlayTitle() {
  7823. Row() {
  7824. Row() {
  7825. Image($r('app.media.ic_back_down'))
  7826. .width($r('app.float.title_image_size'))// .aspectRatio(CommonConstants.ASPECT_RATIO)
  7827. .hitTestBehavior(HitTestMode.Transparent)
  7828. Text(this.name + ' ' + this.artist)
  7829. .fontColor(Color.White)
  7830. .fontSize($r('app.float.title_font_size'))
  7831. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  7832. .maxLines(1)
  7833. .visibility(Visibility.None)
  7834. .margin({ left: 2, right: 30 })
  7835. }
  7836. .layoutWeight(1)
  7837. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7838. .visibility(this.isHide ? Visibility.Hidden : Visibility.Visible)
  7839. .onClick(() => {
  7840. this.isShowPlay = false;
  7841. })
  7842. Column() {
  7843. AVCastPicker({
  7844. normalColor: Color.White,
  7845. onStateChange: this.onStateVastChange
  7846. })
  7847. .width(24)
  7848. .height(24)
  7849. }
  7850. .visibility(this.isHide ? Visibility.Hidden : Visibility.None)
  7851. }
  7852. .width(PlayConstants.ROW_WIDTH)
  7853. }
  7854. @Builder
  7855. lyricSettingSheet(isPip: boolean) {
  7856. Scroll() {
  7857. this.lyricSetting(isPip)
  7858. }
  7859. .width('100%')
  7860. .height('100%')
  7861. }
  7862. @Builder
  7863. lyricSetting(isPip: boolean) {
  7864. Column() {
  7865. // 时间调节模块
  7866. if (!isPip) {
  7867. this.BuildTimeControls()
  7868. }
  7869. // 字号控制模块
  7870. this.BuildFontControls(isPip)
  7871. }
  7872. }
  7873. // 歌词时间偏移状态
  7874. @State timeOffset: number = 0.0
  7875. @State currentLyricColor: string = '#FFFFFF'
  7876. @State currentLyricColorPip: string = '#FFFFFF'
  7877. @State currentHighLightLyricColor: string = '#FF4081'
  7878. @State currentHighLightLyricColorPip: string = '#FF4081'
  7879. // 歌词字号状态
  7880. @State currentLyricSize: number = 20
  7881. @State currentLyricSizePip: number = 20
  7882. // 高亮歌词放大倍数
  7883. @State currentHightLyricSize: number = 1.2
  7884. @State currentHightLyricSizePip: number = 1.2
  7885. @State currentLyricLineSpace: number = 10
  7886. @State currentLyricLineSpacePip: number = 10
  7887. @State currentLyricAlignMode: number = 1
  7888. @State currentLyricAlignModePip: number = 1
  7889. @State blurDegree: number = 2
  7890. @State blurDegreePip: number = 2
  7891. @State isShowSelectColor: boolean = false
  7892. @State isShowHLSelectColor: boolean = false
  7893. @State isShowPipBgSelectColor: boolean = false
  7894. @State pipLyWidth: number = 330
  7895. @State pipLyHeight: number = 120
  7896. // 构建颜色选择器
  7897. @Builder
  7898. SelectColor(isHighColor: boolean, isPip: boolean, isBGPip?: boolean) {
  7899. Row({ space: 10 }) {
  7900. HSBColorPicker({
  7901. color: '#FFFFFF',
  7902. radius: 8,
  7903. layout: HSBColorPickerLayout.COLUMN,
  7904. predefine: ['#8b27f4', '#73f9fc', '#fffe55', '#f5cee3', '#eb4827', '#e93bf4', '#3e68f4', '#c5e6d3', '#e4e4e4',
  7905. '#fa7105'],
  7906. onChange: (value: string) => isHighColor ? this.changeLyricHightLightColor(value, isPip) :
  7907. this.changeLyricColor(value, isPip, isBGPip)
  7908. })
  7909. .height(250)
  7910. .layoutWeight(1)
  7911. .padding(25)
  7912. }
  7913. .width('66%')
  7914. }
  7915. @State isOpenPip: boolean = false
  7916. @State pipBgIndex: number = 0
  7917. // 构建字号控制器
  7918. @Builder
  7919. BuildFontControls(isPip: boolean) {
  7920. Column() {
  7921. if (isPip) {
  7922. Column() {
  7923. Row() {
  7924. Text('悬浮歌词')
  7925. .margin({ left: 18 })
  7926. .fontSize(15)
  7927. .fontColor(Color.White)
  7928. .fontWeight(480)
  7929. .layoutWeight(1)
  7930. Toggle({ type: ToggleType.Switch, isOn: this.isOpenPip })
  7931. .selectedColor(this.themeColor)
  7932. .switchPointColor(Color.White)
  7933. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7934. .margin({ right: 18 })
  7935. .onChange((checked: boolean) => {
  7936. this.isOpenPip = checked;
  7937. if (this.isOpenPip) {
  7938. this.startPip()
  7939. } else {
  7940. this.stopPip()
  7941. }
  7942. PreferencesUtil.put('isOpenPip', this.isOpenPip)
  7943. })
  7944. .width(50)
  7945. .height(30);
  7946. }
  7947. .height(55)
  7948. }
  7949. .backgroundColor(Color.Transparent)
  7950. .borderRadius(15)
  7951. .margin({
  7952. left: 30,
  7953. right: 30,
  7954. top: 0,
  7955. bottom: 20
  7956. })
  7957. .padding(0)
  7958. .border({
  7959. color: Color.White,
  7960. width: 1.8
  7961. })
  7962. }else{
  7963. Column() {
  7964. Row() {
  7965. Text('单行歌词')
  7966. .margin({ left: 18 })
  7967. .fontSize(15)
  7968. .fontColor(Color.White)
  7969. .fontWeight(480)
  7970. .layoutWeight(1)
  7971. Toggle({ type: ToggleType.Switch, isOn: this.isShowSingleLineLyric })
  7972. .selectedColor(this.themeColor)
  7973. .switchPointColor(Color.White)
  7974. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7975. .margin({ right: 18 })
  7976. .onChange((checked: boolean) => {
  7977. this.isShowSingleLineLyric = checked;
  7978. PreferencesUtil.put(SettingPage.IS_SHOW_SLLYRIC, this.isShowSingleLineLyric)
  7979. })
  7980. .width(50)
  7981. .height(30);
  7982. }
  7983. .height(55)
  7984. }
  7985. .backgroundColor(Color.Transparent)
  7986. .borderRadius(15)
  7987. .margin({
  7988. left: 30,
  7989. right: 30,
  7990. top: 10,
  7991. bottom: 10
  7992. })
  7993. .padding(0)
  7994. .border({
  7995. color: Color.White,
  7996. width: 1.8
  7997. })
  7998. }
  7999. Row() {
  8000. Text(`歌词居中:`)
  8001. .fontSize(14)
  8002. .fontColor(Color.White)
  8003. .margin({ left: 2 })
  8004. Row() {
  8005. ForEach(['居中', '居左'], (size: string, index: number) => {
  8006. Button(size)
  8007. .width(60)
  8008. .height(28)
  8009. .fontSize(12)
  8010. .fontColor('#FFFFFF')
  8011. .backgroundColor((!isPip && this.currentLyricAlignMode === index) ||
  8012. (isPip && this.currentLyricAlignModePip === index) ? this.themeColor : Color.Transparent)
  8013. .border({
  8014. color: (!isPip && this.currentLyricAlignMode === index) ||
  8015. (isPip && this.currentLyricAlignModePip === index) ?
  8016. '#007DFF' : '#DDDDDD',
  8017. width: 1.8
  8018. })
  8019. .onClick(() => {
  8020. this.setLyricAlignMode(index, isPip)
  8021. })
  8022. .margin({ left: 10, right: 8 })
  8023. })
  8024. }
  8025. .width('76%')
  8026. Blank()
  8027. }
  8028. .margin({
  8029. top: 10,
  8030. bottom: 10,
  8031. right: 20,
  8032. left: 20
  8033. })
  8034. if (isPip) {
  8035. Row() {
  8036. Text(`悬浮背景:`)
  8037. .fontSize(14)
  8038. .fontColor(Color.White)
  8039. Select([
  8040. { value: CommonConstants.PIP_LYRIC_BG[0] },
  8041. { value: CommonConstants.PIP_LYRIC_BG[1] }])
  8042. .font({ size: 13, weight: FontWeight.Medium })
  8043. .fontColor(Color.White)
  8044. .margin({ left: 10 })
  8045. .selected(this.pipBgIndex)
  8046. .value(CommonConstants.PIP_LYRIC_BG[this.pipBgIndex])
  8047. .onSelect(async (_index: number, text?: string | undefined) => {
  8048. this.pipBgIndex = _index
  8049. PreferencesUtil.put('pipBgIndex', this.pipBgIndex)
  8050. if (this.pipBgIndex === 0) {
  8051. if (this.cover) {
  8052. this.pipBg = this.cover
  8053. } else {
  8054. this.pipBg = this.imageColor
  8055. }
  8056. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  8057. } else {
  8058. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  8059. }
  8060. })
  8061. Column() {
  8062. }
  8063. .backgroundColor(this.pipBg)
  8064. .margin({ left: 10, right: 10 })
  8065. .borderRadius(20)
  8066. .height(28)
  8067. .width(28)
  8068. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8069. Row() {
  8070. SymbolGlyph($r('sys.symbol.paintbrush'))
  8071. .fontColor([Color.White])
  8072. .effectStrategy(1)
  8073. Text(`选择颜色`)
  8074. .fontSize(13)
  8075. .margin({ left: 10 })
  8076. .fontColor(Color.White)
  8077. }
  8078. }
  8079. .visibility(this.pipBgIndex === 1 ? Visibility.Visible : Visibility.None)
  8080. .backgroundColor(Color.Transparent)
  8081. .border({
  8082. color: '#FFFFFF',
  8083. radius: 20,
  8084. width: 1.8
  8085. })
  8086. .height(36)
  8087. .width(110)
  8088. .onClick(() => {
  8089. this.isShowPipBgSelectColor = !this.isShowPipBgSelectColor
  8090. })
  8091. .bindPopup(this.isShowPipBgSelectColor, {
  8092. builder: this.SelectColor(false, isPip, true),
  8093. placement: Placement.Top,
  8094. mask: { color: '#33000000' },
  8095. enableArrow: false, //是否显示箭头
  8096. showInSubWindow: false,
  8097. onStateChange: (e) => {
  8098. if (!e.isVisible) {
  8099. this.isShowPipBgSelectColor = false
  8100. }
  8101. }
  8102. })
  8103. }
  8104. .width('76%')
  8105. .margin({ bottom: 5, right: 45, left: 20 })
  8106. }
  8107. if (!isPip) {
  8108. Row() {
  8109. Text(`高亮居中:`)
  8110. .fontSize(14)
  8111. .fontColor(Color.White)
  8112. Column() {
  8113. Toggle({ type: ToggleType.Switch, isOn: this.isHightLightCenter })
  8114. .selectedColor(this.themeColor)
  8115. .switchPointColor(Color.White)
  8116. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8117. .onChange((checked: boolean) => {
  8118. this.isHightLightCenter = checked;
  8119. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isHightLightCenter)
  8120. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  8121. })
  8122. .width(50)
  8123. .height(30)
  8124. .alignSelf(ItemAlign.Start)
  8125. .margin({ left: 12 })
  8126. Blank()
  8127. }
  8128. .width('76%')
  8129. }
  8130. .margin({
  8131. left: 20,
  8132. right: 15,
  8133. top: 10,
  8134. bottom: 10
  8135. })
  8136. }
  8137. Row() {
  8138. Text(`歌词颜色:`)
  8139. .fontSize(14)
  8140. .fontColor(Color.White)
  8141. Text(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  8142. .fontSize(15)
  8143. .fontColor(Color.White)
  8144. .margin({ left: 12, right: 12 })
  8145. Column() {
  8146. }
  8147. .backgroundColor(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  8148. .margin({ right: 12 })
  8149. .borderRadius(20)
  8150. .height(28)
  8151. .width(28)
  8152. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8153. Row() {
  8154. SymbolGlyph($r('sys.symbol.paintbrush'))
  8155. .fontColor([Color.White])
  8156. .effectStrategy(1)
  8157. Text(`选择颜色`)
  8158. .fontSize(13)
  8159. .margin({ left: 10 })
  8160. .fontColor(Color.White)
  8161. }
  8162. }
  8163. .backgroundColor(Color.Transparent)
  8164. .border({
  8165. color: '#FFFFFF',
  8166. radius: 20,
  8167. width: 1.8
  8168. })
  8169. .height(36)
  8170. .width(110)
  8171. .onClick(() => {
  8172. this.isShowSelectColor = !this.isShowSelectColor
  8173. })
  8174. .bindPopup(this.isShowSelectColor, {
  8175. builder: this.SelectColor(false, isPip),
  8176. placement: Placement.Top,
  8177. mask: { color: '#33000000' },
  8178. enableArrow: false, //是否显示箭头
  8179. showInSubWindow: false,
  8180. onStateChange: (e) => {
  8181. if (!e.isVisible) {
  8182. this.isShowSelectColor = false
  8183. }
  8184. }
  8185. })
  8186. }
  8187. .width('76%')
  8188. .margin({
  8189. top: 10,
  8190. bottom: 10,
  8191. right: 45,
  8192. left: 20
  8193. })
  8194. Row() {
  8195. Text(`高亮颜色:`)
  8196. .fontSize(14)
  8197. .fontColor(Color.White)
  8198. Text(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  8199. .fontSize(15)
  8200. .fontColor(Color.White)
  8201. .margin({ left: 12, right: 12 })
  8202. Column() {
  8203. }
  8204. .backgroundColor(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  8205. .margin({ right: 12 })
  8206. .borderRadius(20)
  8207. .height(28)
  8208. .width(28)
  8209. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8210. Row() {
  8211. SymbolGlyph($r('sys.symbol.paintbrush'))
  8212. .fontColor([Color.White])
  8213. .effectStrategy(1)
  8214. Text(`选择颜色`)
  8215. .fontSize(13)
  8216. .margin({ left: 10 })
  8217. .fontColor(Color.White)
  8218. }
  8219. }
  8220. .backgroundColor(Color.Transparent)
  8221. .border({
  8222. color: '#FFFFFF',
  8223. radius: 20,
  8224. width: 1.8
  8225. })
  8226. .height(36)
  8227. .width(110)
  8228. .onClick(() => {
  8229. this.isShowHLSelectColor = !this.isShowHLSelectColor
  8230. })
  8231. .bindPopup(this.isShowHLSelectColor, {
  8232. builder: this.SelectColor(true, isPip),
  8233. placement: Placement.Top,
  8234. mask: { color: '#33000000' },
  8235. enableArrow: false, //是否显示箭头
  8236. showInSubWindow: false,
  8237. onStateChange: (e) => {
  8238. if (!e.isVisible) {
  8239. this.isShowHLSelectColor = false
  8240. }
  8241. }
  8242. })
  8243. }
  8244. .width('76%')
  8245. .margin({
  8246. top: 10,
  8247. bottom: 10,
  8248. right: 45,
  8249. left: 20
  8250. })
  8251. if (isPip) {
  8252. Row() {
  8253. Text(`显示宽度:`)
  8254. .fontSize(14)
  8255. .fontColor(Color.White)
  8256. Slider({
  8257. value: this.pipLyWidth,
  8258. min: 10,
  8259. max: 800,
  8260. step: 1,
  8261. style: SliderStyle.OutSet
  8262. })
  8263. .blockColor(this.themeColor)
  8264. .trackColor($r('app.color.speed_text_color'))
  8265. .selectedColor(Color.White)
  8266. .trackThickness(6)
  8267. .onChange((value: number) => {
  8268. this.pipLyWidth = value
  8269. if (this.pipController) {
  8270. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8271. PreferencesUtil.putSync('pipLyWidth', this.pipLyWidth)
  8272. }
  8273. })
  8274. .width('76%')
  8275. }
  8276. .margin({
  8277. left: 20,
  8278. right: 15,
  8279. top: 5,
  8280. bottom: 5
  8281. })
  8282. Row() {
  8283. Text(`显示高度:`)
  8284. .fontSize(14)
  8285. .fontColor(Color.White)
  8286. Slider({
  8287. value: this.pipLyHeight,
  8288. min: 10,
  8289. max: 1000,
  8290. step: 1,
  8291. style: SliderStyle.OutSet
  8292. })
  8293. .blockColor(this.themeColor)
  8294. .trackColor($r('app.color.speed_text_color'))
  8295. .selectedColor(Color.White)
  8296. .trackThickness(6)
  8297. .onChange((value: number) => {
  8298. this.pipLyHeight = value
  8299. if (this.pipController) {
  8300. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8301. PreferencesUtil.putSync('pipLyHeight', this.pipLyHeight)
  8302. }
  8303. })
  8304. .width('76%')
  8305. }
  8306. .margin({
  8307. left: 20,
  8308. right: 15,
  8309. top: 5,
  8310. bottom: 5
  8311. })
  8312. }
  8313. Row() {
  8314. Text(`歌词字号:`)
  8315. .fontSize(14)
  8316. .fontColor(Color.White)
  8317. Slider({
  8318. value: isPip ? this.currentLyricSizePip : this.currentLyricSize,
  8319. min: 12,
  8320. max: 30,
  8321. step: 0.1,
  8322. style: SliderStyle.OutSet
  8323. })
  8324. .blockColor(this.themeColor)
  8325. .trackColor($r('app.color.speed_text_color'))
  8326. .selectedColor(Color.White)
  8327. .trackThickness(6)
  8328. .onChange((value: number) => {
  8329. this.setLyricTextSize(value, isPip)
  8330. })
  8331. .width('76%')
  8332. }
  8333. .margin({
  8334. left: 20,
  8335. right: 15,
  8336. top: 5,
  8337. bottom: 5
  8338. })
  8339. Row() {
  8340. Text(`高亮倍数:`)
  8341. .fontSize(14)
  8342. .fontColor(Color.White)
  8343. Slider({
  8344. value: isPip ? this.currentHightLyricSizePip : this.currentHightLyricSize,
  8345. min: 1,
  8346. max: 2,
  8347. step: 0.1,
  8348. style: SliderStyle.OutSet
  8349. })
  8350. .blockColor(this.themeColor)
  8351. .trackColor($r('app.color.speed_text_color'))
  8352. .selectedColor(Color.White)
  8353. .trackThickness(6)
  8354. .onChange((value: number) => {
  8355. this.setHighLyricTextSize(value, isPip)
  8356. })
  8357. .width('76%')
  8358. }
  8359. .margin({
  8360. left: 20,
  8361. right: 15,
  8362. top: 5,
  8363. bottom: 5
  8364. })
  8365. Row() {
  8366. Text(`歌词间隙:`)
  8367. .fontSize(14)
  8368. .fontColor(Color.White)
  8369. Slider({
  8370. value: isPip ? this.currentLyricLineSpacePip : this.currentLyricLineSpace,
  8371. min: 0,
  8372. max: 100,
  8373. step: 1,
  8374. style: SliderStyle.OutSet
  8375. })
  8376. .blockColor(this.themeColor)
  8377. .trackColor($r('app.color.speed_text_color'))
  8378. .selectedColor(Color.White)
  8379. .trackThickness(6)
  8380. .onChange((value: number) => {
  8381. this.setLyricLineSpace(value, isPip)
  8382. })
  8383. .width('76%')
  8384. }
  8385. .margin({
  8386. left: 20,
  8387. right: 15,
  8388. top: 5,
  8389. bottom: 5
  8390. })
  8391. //取值间隔为100,默认为400,取值越大,字体越粗
  8392. Row() {
  8393. Text(`歌词字重:`)
  8394. .fontSize(14)
  8395. .fontColor(Color.White)
  8396. Slider({
  8397. value: isPip ? this.lyricTextWeightPip : this.lyricTextWeight,
  8398. min: 100,
  8399. max: 900,
  8400. step: 100,
  8401. style: SliderStyle.OutSet
  8402. })
  8403. .blockColor(this.themeColor)
  8404. .trackColor($r('app.color.speed_text_color'))
  8405. .selectedColor(Color.White)
  8406. .trackThickness(6)
  8407. .onChange((value: number) => {
  8408. if (isPip) {
  8409. this.lyricTextWeightPip = value
  8410. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  8411. PreferencesUtil.putSync('lyricTextWeightPip', this.lyricTextWeightPip)
  8412. } else {
  8413. this.lyricTextWeight = value
  8414. this.lyricController.setTextWeight(this.lyricTextWeight)
  8415. PreferencesUtil.putSync('lyricTextWeight', this.lyricTextWeight)
  8416. }
  8417. })
  8418. .width('76%')
  8419. }
  8420. .margin({
  8421. left: 20,
  8422. right: 15,
  8423. top: 5,
  8424. bottom: 5
  8425. })
  8426. if (!isPip) {
  8427. Row() {
  8428. Text(`歌词模糊:`)
  8429. .fontSize(14)
  8430. .fontColor(Color.White)
  8431. Slider({
  8432. value: isPip ? this.blurDegreePip : this.blurDegree,
  8433. min: 0,
  8434. max: 5,
  8435. step: 0.1,
  8436. style: SliderStyle.OutSet
  8437. })
  8438. .blockColor(this.themeColor)
  8439. .trackColor($r('app.color.speed_text_color'))
  8440. .selectedColor(Color.White)
  8441. .trackThickness(6)
  8442. .onChange((value: number) => {
  8443. this.setBlurDegree(value, isPip)
  8444. })
  8445. .width('76%')
  8446. }
  8447. .margin({
  8448. left: 20,
  8449. right: 15,
  8450. top: 5,
  8451. bottom: 15
  8452. })
  8453. }
  8454. Row() {
  8455. this.pushLyricButton($r('app.media.cut_current'), 0, '本地歌词')
  8456. this.pushLyricButton($r('app.media.white_search'), 1, '获取歌词')
  8457. }
  8458. .justifyContent(FlexAlign.Center)
  8459. .margin({ top: 3, bottom: 10 })
  8460. }
  8461. }
  8462. private setBlurDegree(index: number, isPip: boolean) {
  8463. if (isPip) {
  8464. this.blurDegreePip = index
  8465. this.lyricControllerXF.setBlurDegree(this.blurDegreePip)
  8466. PreferencesUtil.putSync('setBlurDegreePip', this.blurDegreePip)
  8467. } else {
  8468. this.blurDegree = index
  8469. this.lyricController.setBlurDegree(this.blurDegree)
  8470. PreferencesUtil.putSync('setBlurDegree', this.blurDegree)
  8471. }
  8472. }
  8473. private setLyricAlignMode(index: number, isPip: boolean) {
  8474. if (isPip) {
  8475. this.currentLyricAlignModePip = index
  8476. if (this.currentLyricAlignModePip === 1) {
  8477. this.lyricControllerXF.setAlignMode("left")
  8478. } else {
  8479. this.lyricControllerXF.setAlignMode("center")
  8480. }
  8481. PreferencesUtil.putSync('LyricAlignModePip', this.currentLyricAlignModePip)
  8482. } else {
  8483. this.currentLyricAlignMode = index
  8484. if (this.currentLyricAlignMode === 1) {
  8485. this.lyricController.setAlignMode("left")
  8486. } else {
  8487. this.lyricController.setAlignMode("center")
  8488. }
  8489. PreferencesUtil.putSync('LyricAlignMode', this.currentLyricAlignMode)
  8490. }
  8491. }
  8492. private setLyricTextSize(index: number, isPip: boolean) {
  8493. if (isPip) {
  8494. this.currentLyricSizePip = index
  8495. this.lyricControllerXF.setTextSize(this.currentLyricSizePip)
  8496. PreferencesUtil.putSync('LyricTextSizePip', this.currentLyricSizePip)
  8497. } else {
  8498. this.currentLyricSize = index
  8499. this.lyricController.setTextSize(this.currentLyricSize)
  8500. PreferencesUtil.putSync('LyricTextSize', this.currentLyricSize)
  8501. }
  8502. }
  8503. private setHighLyricTextSize(scale: number, isPip: boolean) {
  8504. if (isPip) {
  8505. this.currentHightLyricSizePip = scale
  8506. this.lyricControllerXF
  8507. .setHighlightScale(this.currentHightLyricSizePip)
  8508. PreferencesUtil.putSync('HighLyricTextSizePip', scale)
  8509. } else {
  8510. this.currentHightLyricSize = scale
  8511. this.lyricController
  8512. .setHighlightScale(this.currentHightLyricSize)
  8513. PreferencesUtil.putSync('HighLyricTextSize', scale)
  8514. }
  8515. }
  8516. private setLyricLineSpace(index: number, isPip: boolean) {
  8517. if (isPip) {
  8518. this.currentLyricLineSpacePip = index
  8519. this.lyricControllerXF.setLineSpace(this.currentLyricLineSpacePip)
  8520. PreferencesUtil.putSync('LyricLineSpacePip', this.currentLyricLineSpacePip)
  8521. } else {
  8522. this.currentLyricLineSpace = index
  8523. this.lyricController.setLineSpace(this.currentLyricLineSpace)
  8524. PreferencesUtil.putSync('LyricLineSpace', this.currentLyricLineSpace)
  8525. }
  8526. }
  8527. private changeLyricColor(color: string, isPip: boolean, isBG?: boolean) {
  8528. LogUtil.info('onecold isBG = ' + isBG)
  8529. if (isBG) { //如果是设置悬浮背景
  8530. this.pipBg = color
  8531. PreferencesUtil.putSync('BGColorPip', this.pipBg)
  8532. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  8533. return
  8534. }
  8535. if (isPip) {
  8536. this.currentLyricColorPip = color
  8537. this.lyricControllerXF
  8538. .setTextColor(this.currentLyricColorPip)
  8539. PreferencesUtil.putSync('LyricColorPip', this.currentLyricColorPip)
  8540. } else {
  8541. this.currentLyricColor = color
  8542. this.lyricController
  8543. .setTextColor(this.currentLyricColor)
  8544. PreferencesUtil.putSync('LyricColor', this.currentLyricColor)
  8545. }
  8546. }
  8547. private changeLyricHightLightColor(color: string, isPip: boolean) {
  8548. if (isPip) {
  8549. this.currentHighLightLyricColorPip = color
  8550. this.lyricControllerXF
  8551. .setHighlightColor(this.currentHighLightLyricColorPip)
  8552. PreferencesUtil.putSync('LyricHighLightColorPip', this.currentHighLightLyricColorPip)
  8553. } else {
  8554. this.currentHighLightLyricColor = color
  8555. this.lyricController
  8556. .setHighlightColor(this.currentHighLightLyricColor)
  8557. PreferencesUtil.putSync('LyricHighLightColor', this.currentHighLightLyricColor)
  8558. }
  8559. }
  8560. // 构建时间控制器
  8561. @Builder
  8562. BuildTimeControls() {
  8563. Column() {
  8564. // 时间显示
  8565. Text(this.getTimeText())
  8566. .fontSize(18)
  8567. .fontColor(Color.White)
  8568. .margin({ bottom: 10 })
  8569. Row() {
  8570. this.PrecisionTimeButton($r('app.media.ic_previous'), -0.5, ' -0.5s ')
  8571. this.PrecisionTimeButton($r('app.media.loop'), 0, '重置')
  8572. this.PrecisionTimeButton($r('app.media.ic_next'), 0.5, ' +0.5s ')
  8573. }
  8574. .justifyContent(FlexAlign.Center)
  8575. }
  8576. .margin({ top: 12, bottom: 8 })
  8577. }
  8578. // 精度按钮组件
  8579. @Builder
  8580. PrecisionTimeButton(icon: Resource, step: number, label: string) {
  8581. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8582. Column() {
  8583. Image(icon)
  8584. .width(28)
  8585. .margin({ bottom: 5 })
  8586. .opacity(this.isButtonDisabled(step) ? 0.5 : 1)
  8587. Text(label)
  8588. .fontSize(12)
  8589. .fontColor('#FFFFFF')
  8590. }
  8591. }
  8592. .backgroundColor(Color.Transparent)
  8593. .enabled(!this.isButtonDisabled(step))
  8594. .onClick(() => this.handlePrecisionAdjust(step))
  8595. .padding(5)
  8596. .width(66)
  8597. .height(66)
  8598. .margin({ left: 18, right: 18 })
  8599. .border({
  8600. color: '#FFFFFF',
  8601. width: 1.8
  8602. })
  8603. }
  8604. private handlePrecisionAdjust(step: number) {
  8605. if (step === 0) {
  8606. this.timeOffset = 0
  8607. return
  8608. }
  8609. // 精度处理:保留1位小数
  8610. const newOffset = Number((this.timeOffset + step).toFixed(5))
  8611. // 边界保护(±15.0秒)
  8612. if (newOffset < -30.0 || newOffset > 30.0) {
  8613. // this.triggerEdgeFeedback(newOffset) // 触发边界反馈
  8614. return
  8615. }
  8616. // 状态更新
  8617. this.timeOffset = newOffset
  8618. }
  8619. // 按钮禁用逻辑
  8620. private isButtonDisabled(step: number): boolean {
  8621. const futureOffset = this.timeOffset + step
  8622. return (futureOffset < -30.0) || (futureOffset > 30.0)
  8623. }
  8624. // 时间显示文本升级
  8625. private getTimeText(): string {
  8626. const absValue = Math.abs(this.timeOffset)
  8627. return this.timeOffset === 0
  8628. ? '歌词时间已重置'
  8629. : `歌词已${this.timeOffset < 0 ? '延后' : '提前'} ${absValue.toFixed(1)} 秒`
  8630. }
  8631. // 导入 本地歌词 搜索歌词
  8632. @Builder
  8633. pushLyricButton(icon: Resource, step: number, label: string) {
  8634. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8635. Row() {
  8636. Image(icon)
  8637. .width(14)
  8638. .margin({ left: 13 })
  8639. Text(label)
  8640. .fontSize(12)
  8641. .margin({ left: 6 })
  8642. .fontColor('#FFFFFF')
  8643. }
  8644. }
  8645. .onClick(() => {
  8646. switch (step) {
  8647. case 0:
  8648. this.callFilePickerSelectFileForLyric()
  8649. break;
  8650. case 1:
  8651. //判断有没有设置api
  8652. if (PreferencesUtil.getStringSync('LRC_API', '') === '') {
  8653. this.isLyricSetting = false
  8654. this.showTipsDialog()
  8655. return
  8656. }
  8657. if (StrUtil.isNotEmpty(this.videoUrl)) {
  8658. ToastUtil.showToast('正在获取')
  8659. this.isLyricSetting = false
  8660. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  8661. this.initLyric(lyricPath, true);
  8662. }
  8663. break;
  8664. }
  8665. })
  8666. .padding(5)
  8667. .width(110)
  8668. .backgroundColor(Color.Transparent)
  8669. .height(40)
  8670. .margin({ left: 6, right: 6 })
  8671. .border({
  8672. color: '#FFFFFF',
  8673. radius: 20,
  8674. width: 1.8
  8675. })
  8676. }
  8677. showVipDialog() {
  8678. DialogHelper.showCustomContentDialog({
  8679. dialogId: 'vip',
  8680. title: "友情提示",
  8681. autoCancel: false, //点击遮障层时,不关闭弹窗
  8682. backCancel: true, //点击返回键,不关闭弹窗
  8683. contentBuilder: () => {
  8684. this.customVipBuilder("该功能需开通会员,非常感谢您的支持!")
  8685. },
  8686. buttons: [],
  8687. })
  8688. }
  8689. //去赞助的自定义内容
  8690. @Builder
  8691. customVipBuilder(content: string) {
  8692. Column() {
  8693. Text(content)
  8694. .fontColor(Color.Gray)
  8695. .fontSize(16)
  8696. .alignSelf(ItemAlign.Start)
  8697. .margin({ bottom: 15 })
  8698. .fontSize(16)
  8699. Row() {
  8700. Button('取消')
  8701. .fontColor(Color.White)
  8702. .backgroundColor(this.themeColor)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  8703. .height(50)
  8704. .layoutWeight(1)
  8705. .stateEffect(true)
  8706. .margin({ right: 6 })
  8707. .onClick(() => {
  8708. DialogHelper.closeDialog('vip'); //关闭弹框
  8709. })
  8710. Button('开通')
  8711. .fontColor(Color.White)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  8712. .layoutWeight(1)
  8713. .height(50)
  8714. .backgroundColor(this.themeColor)
  8715. .stateEffect(true)
  8716. .margin({ left: 6 })
  8717. .onClick(() => {
  8718. DialogHelper.closeDialog('vip'); //关闭弹框
  8719. this.isShowPlay = false
  8720. this.mType = 1 //跳转到用户中心
  8721. // router.pushUrl({
  8722. // url: 'pages/VipPage'
  8723. // }, router.RouterMode.Single);
  8724. })
  8725. }
  8726. }
  8727. .width("100%")
  8728. .padding(10)
  8729. }
  8730. showTipsDialog() {
  8731. DialogHelper.showCustomContentDialog({
  8732. dialogId: 'tips',
  8733. title: "友情提示",
  8734. autoCancel: false, //点击遮障层时,不关闭弹窗
  8735. backCancel: true, //点击返回键,不关闭弹窗
  8736. contentBuilder: () => {
  8737. this.customTipsBuilder("请到设置界面配置API服务器地址!")
  8738. },
  8739. buttons: [],
  8740. })
  8741. }
  8742. @Builder
  8743. customTipsBuilder(content: string) {
  8744. Column() {
  8745. Text(content)
  8746. .fontColor(Color.Gray)
  8747. .fontSize(16)
  8748. .alignSelf(ItemAlign.Start)
  8749. .margin({ bottom: 15 })
  8750. .fontSize(16)
  8751. Row() {
  8752. Button('取消')
  8753. .fontColor(Color.White)
  8754. .backgroundColor(this.themeColor)
  8755. .height(50)
  8756. .layoutWeight(1)
  8757. .stateEffect(true)
  8758. .margin({ right: 6 })
  8759. .onClick(() => {
  8760. DialogHelper.closeDialog('tips'); //关闭弹框
  8761. })
  8762. Button('跳转')
  8763. .fontColor(Color.White)//
  8764. .layoutWeight(1)
  8765. .height(50)
  8766. .backgroundColor(this.themeColor)
  8767. .stateEffect(true)
  8768. .margin({ left: 6 })
  8769. .onClick(() => {
  8770. DialogHelper.closeDialog('tips'); //关闭弹框
  8771. this.isShowEdit = false
  8772. this.longItemFilePath = ''
  8773. // if(this.isGridMusic&&!this.isShowPlay){
  8774. // this.longItemFilePath== ''
  8775. // }else{
  8776. // this.isShowEdit = false
  8777. // }
  8778. this.isShowMoreView = false;
  8779. this.isShowPlay = false
  8780. this.mType = 4
  8781. // router.pushUrl({
  8782. // url: 'pages/SettingPage'
  8783. // }, router.RouterMode.Single);
  8784. })
  8785. }
  8786. }
  8787. .width("100%")
  8788. .padding(10)
  8789. }
  8790. @Builder
  8791. PlayMoreSheet() {
  8792. Column() {
  8793. this.MoreList()
  8794. }
  8795. .width('100%')
  8796. .height('100%')
  8797. }
  8798. @Builder
  8799. MoreList() {
  8800. Scroll() {
  8801. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  8802. ForEach(this.moreItems, (more: MoreItem, index: number) => {
  8803. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  8804. Row() {
  8805. if (more.id === 3&&this.currentSong) {
  8806. Image(more.image)
  8807. .width(24)
  8808. .height(24)
  8809. .margin({ left: 10, right: 10 })
  8810. Text(more.title)
  8811. .fontSize(16)
  8812. .fontColor(Color.White)
  8813. .bindSheet($$this.isShowDetailMore, this.detailSheet(this.currentSong), {
  8814. height: this.isCoverOpacity() ? '95%' : '95%',
  8815. dragBar: true,
  8816. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8817. showClose: true,
  8818. blurStyle: BlurStyle.Thin,
  8819. backgroundColor: Color.Transparent,
  8820. title: { title: '歌曲信息' }
  8821. })
  8822. } else if (more.id === 15 && this.currentSong) { //编辑标签
  8823. Image(more.image)
  8824. .width(24)
  8825. .height(24)
  8826. .margin({ left: 10, right: 10 })
  8827. Text(more.title)
  8828. .fontSize(16)
  8829. .fontColor(Color.White)
  8830. .bindSheet($$this.isShowEdit, this.editSheet(this.currentSong), {
  8831. height: '99%',
  8832. dragBar: true,
  8833. showClose: true,
  8834. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8835. // blurStyle:BlurStyle.Thin,
  8836. // backgroundColor:Color.Transparent,
  8837. title: { title: '编辑标签' }
  8838. })
  8839. } else if (more.id === 5) { //定时关闭
  8840. Image(more.image)
  8841. .width(24)
  8842. .height(24)
  8843. .margin({ left: 10, right: 10 })
  8844. Text(more.title)
  8845. .fontSize(16)
  8846. .fontColor(Color.White)
  8847. .onClick(() => {
  8848. this.doMore(more.id)
  8849. })
  8850. .bindSheet($$this.isShowTimeCloseMore, this.TimeCloseSheet(), {
  8851. height: this.isCoverOpacity() ? '95%' : '95%',
  8852. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8853. dragBar: true,
  8854. showClose: true,
  8855. title: { title: $r('app.string.time_close') }
  8856. })
  8857. } else if (more.id === 2) { //歌词设置
  8858. Image(more.image)
  8859. .width(24)
  8860. .height(24)
  8861. .margin({ left: 10, right: 10 })
  8862. Text(more.title)
  8863. .fontSize(16)
  8864. .fontColor(Color.White)
  8865. } else if (more.id === 16) { //悬浮歌词设置
  8866. Image(more.image)
  8867. .width(24)
  8868. .height(24)
  8869. .margin({ left: 10, right: 10 })
  8870. Text(more.title)
  8871. .fontSize(16)
  8872. .fontColor(Color.White)
  8873. .bindSheet($$this.showPipLyric, this.lyricSettingSheet(true), {
  8874. height: this.isCoverOpacity() ? '95%' : '95%',
  8875. dragBar: true,
  8876. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8877. showClose: true,
  8878. blurStyle: BlurStyle.Thin,
  8879. backgroundColor: Color.Transparent,
  8880. title: { title: '悬浮歌词' }
  8881. })
  8882. } else if (more.id === 11) {
  8883. Image(more.image)
  8884. .width(24)
  8885. .height(24)
  8886. .margin({ left: 10, right: 10 })
  8887. Text(more.title)
  8888. .fontSize(16)
  8889. .fontColor(Color.White)
  8890. .bindSheet($$this.isJumpSetting, this.JumpTopEndSheet(), {
  8891. height: this.isCoverOpacity() ? '95%' : '60%',
  8892. dragBar: true,
  8893. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  8894. showClose: true,
  8895. blurStyle: BlurStyle.Thin,
  8896. backgroundColor: Color.Transparent,
  8897. title: { title: '跳过头尾' }
  8898. })
  8899. } else if (more.id === 12) { //投播
  8900. AVCastPicker({
  8901. customPicker: (): void => this.TPImageBuilder(more),
  8902. onStateChange: (state) => {
  8903. if (state == AVCastPickerState.STATE_APPEARING) {
  8904. console.log(' The picker starts showing.');
  8905. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  8906. console.log(' The picker finishes presenting.');
  8907. }
  8908. },
  8909. pickerStyle: AVCastPickerStyle.STYLE_PANEL,
  8910. sessionType: 'video'
  8911. })
  8912. .id('AVCastPicker')
  8913. } else {
  8914. Image(more.image)
  8915. .width(24)
  8916. .height(24)
  8917. .margin({ left: 10, right: 10 })
  8918. .onClick(() => {
  8919. this.doMore(more.id)
  8920. })
  8921. Text(more.id == 17 ? (this.isLandscape ? '竖屏模式' : '横屏模式') : more.title)
  8922. .fontSize(16)
  8923. .fontColor(Color.White)
  8924. .onClick(() => {
  8925. this.doMore(more.id)
  8926. })
  8927. Select([//倍速
  8928. { value: '0.25x' },
  8929. { value: '0.5x' },
  8930. { value: '0.75x' },
  8931. { value: '1x' },
  8932. { value: '1.25x' },
  8933. { value: '1.5x' },
  8934. { value: '1.75x' },
  8935. { value: '2x' },
  8936. { value: '3x' }])
  8937. .font({ size: 16, weight: FontWeight.Medium })
  8938. .fontColor($r('sys.color.white'))
  8939. .margin({ left: 25 })
  8940. .visibility(more.id === 1 ? Visibility.Visible : Visibility.None)
  8941. .selected(CommonConstants.video_speed_list.indexOf(this.playSpeed))
  8942. .value(Utility.optimizedFormat(this.playSpeed))
  8943. .onSelect(async (_index: number, text?: string | undefined) => {
  8944. let speed = parseFloat(text?.replace('x', '') || '1');
  8945. if (!CommonConstants.video_speed_list.includes(speed)) {
  8946. speed = 1;
  8947. }
  8948. this.playSpeed = speed
  8949. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  8950. })
  8951. Slider({
  8952. value: this.volume,
  8953. min: 0,
  8954. max: 1,
  8955. step: 0.1,
  8956. style: SliderStyle.OutSet
  8957. })
  8958. .margin({ left: 18, right: 8 })
  8959. .blockColor(this.themeColor)
  8960. .trackColor($r('app.color.speed_text_color'))
  8961. .selectedColor(Color.White)
  8962. .trackThickness(9)
  8963. .visibility(more.id === 9 ? Visibility.Visible : Visibility.None)
  8964. .onChange((value: number) => {
  8965. this.volume = value;
  8966. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  8967. PreferencesUtil.putSync('DefalutVolume',this.volume)
  8968. })
  8969. .layoutWeight(1)
  8970. Blank()
  8971. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  8972. .selectedColor(this.themeColor)
  8973. .switchPointColor(Color.White)
  8974. .margin({ right: 15 })
  8975. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8976. .visibility(more.id == 6 ? Visibility.Visible : Visibility.None)
  8977. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8978. if (more.id == 6) {
  8979. this.isMusicMemoryPlay = checked;
  8980. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  8981. if (this.isMusicMemoryPlay) {
  8982. ToastUtil.showToast('记忆播放已开启')
  8983. } else {
  8984. ToastUtil.showToast('记忆播放已关闭')
  8985. }
  8986. }
  8987. })
  8988. .width(48)
  8989. .height(24);
  8990. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  8991. .selectedColor(this.themeColor)
  8992. .switchPointColor(Color.White)
  8993. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8994. .margin({ right: 15 })
  8995. .visibility(more.id == 7 ? Visibility.Visible : Visibility.None)
  8996. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8997. if (more.id == 7) {
  8998. this.isMusicBGCover = checked;
  8999. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  9000. if (this.isMusicBGCover) {
  9001. ToastUtil.showToast('播放背景随音乐封面已开启')
  9002. } else {
  9003. ToastUtil.showToast('播放背景随音乐封面已关闭')
  9004. }
  9005. }
  9006. })
  9007. .width(48)
  9008. .height(24);
  9009. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  9010. .selectedColor(this.themeColor)
  9011. .switchPointColor(Color.White)
  9012. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  9013. .margin({ right: 15 })
  9014. .visibility(more.id == 8 ? Visibility.Visible : Visibility.None)
  9015. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  9016. if (more.id == 8) {
  9017. this.isSavePlayMode = checked;
  9018. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  9019. if (this.isSavePlayMode) {
  9020. ToastUtil.showToast('保存播放模式已开启')
  9021. } else {
  9022. ToastUtil.showToast('保存播放模式已关闭')
  9023. }
  9024. }
  9025. })
  9026. .width(48)
  9027. .height(24);
  9028. Toggle({ type: ToggleType.Switch, isOn: this.isCoverRectangle })
  9029. .selectedColor(this.themeColor)
  9030. .switchPointColor(Color.White)
  9031. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  9032. .margin({ right: 15 })
  9033. .visibility(more.id == 13 ? Visibility.Visible : Visibility.None)
  9034. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  9035. if (more.id == 13) {
  9036. this.isCoverRectangle = checked;
  9037. PreferencesUtil.put(SettingPage.IS_COVER_RECTANGLE, this.isCoverRectangle)
  9038. if (this.isCoverRectangle) {
  9039. ToastUtil.showToast('封面方形已开启')
  9040. this.animationRoFun()
  9041. } else {
  9042. ToastUtil.showToast('封面圆形已开启')
  9043. this.animationRoFun()
  9044. }
  9045. }
  9046. })
  9047. .width(48)
  9048. .height(24);
  9049. }
  9050. }
  9051. .width('100%')
  9052. .height(45)
  9053. .padding(15)
  9054. .backgroundColor(Color.Transparent)
  9055. .borderRadius(12)
  9056. .margin({ bottom: 6 })
  9057. }
  9058. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.9 })
  9059. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  9060. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  9061. .backgroundColor(Color.Transparent)
  9062. .onClick(() => {
  9063. this.doMore(more.id)
  9064. })
  9065. });
  9066. }
  9067. .width('100%')
  9068. .padding(16)
  9069. }.margin({ bottom: 18 })
  9070. }
  9071. @Builder
  9072. TPImageBuilder(more: MoreItem): void {
  9073. Row() {
  9074. Image($r('app.media.tuoping'))
  9075. .width(22)
  9076. .height(22)
  9077. .margin({ left: 10, right: 10 })
  9078. Text(more.title)
  9079. .fontSize(16)
  9080. .fontColor(Color.White)
  9081. }
  9082. .width('100%')
  9083. .layoutWeight(1)
  9084. .alignItems(VerticalAlign.Center)
  9085. .justifyContent(FlexAlign.Start)
  9086. }
  9087. private moreItems: MoreItem[] = [
  9088. { id: 1, image: $r('app.media.speed'), title: '倍速' },
  9089. { id: 2, image: $r('app.media.lyric'), title: '歌词' },
  9090. { id: 17, image: $r('app.media.full_4'), title: '横屏模式' },
  9091. { id: 16, image: $r('app.media.hua_zhong_hua'), title: '悬浮歌词' },
  9092. { id: 14, image: $r('app.media.cover_online'), title: '获取封面' },
  9093. { id: 15, image: $r('app.media.rename2'), title: '编辑标签' },
  9094. { id: 5, image: $r('app.media.time_close'), title: '定时关闭' },
  9095. { id: 10, image: $r('app.media.ring_tone'), title: '设为铃声' },
  9096. { id: 11, image: $r('app.media.time_close'), title: '跳过头尾' },
  9097. { id: 12, image: $r('app.media.toubo'), title: '投播' },
  9098. { id: 3, image: $r('app.media.hua_zhong_hua'), title: '详情' },
  9099. { id: 4, image: $r('app.media.share2'), title: '分享' },
  9100. { id: 9, image: $r('app.media.volume_white'), title: '调整音量' },
  9101. // { id: 6, image: $r('app.media.memory'), title: '记忆播放' },
  9102. { id: 13, image: $r('app.media.rectangle'), title: '封面方形' },
  9103. { id: 8, image: $r('app.media.cut_current'), title: '保存播放模式' },
  9104. { id: 7, image: $r('app.media.playlist2'), title: '播放背景随音乐封面' },
  9105. ];
  9106. @State isShowMoreView: boolean = false;
  9107. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  9108. @State isShowTimeCloseMore: boolean = false
  9109. @State isShowDetailMore: boolean = false
  9110. @State isMusicBGCover: boolean = true
  9111. @State isSavePlayMode: boolean = true
  9112. @State isLyricSetting: boolean = false
  9113. @State isJumpSetting: boolean = false
  9114. @State isShowEdit: boolean = false
  9115. @State showPipLyric: boolean = false
  9116. async setRingTone() {
  9117. if (StrUtil.isEmpty(this.videoUrl) || StrUtil.isEmpty(this.name)) {
  9118. return
  9119. }
  9120. // 确定后的逻辑
  9121. let ringtoneTypeList: Array<ringtone.RingtoneType> = ringtone.getSupportedRingtoneTypes();
  9122. LogUtil.info('onecold getSupportedRingtoneTypes : ' + JSON.stringify(ringtoneTypeList));
  9123. let dataTypeList: Array<uniformTypeDescriptor.UniformDataType> =
  9124. ringtone.getSupportedDataTypes(ringtone.RingtoneType.NOTIFICATION);
  9125. LogUtil.info('onecold getSupportedDataTypes: ' + JSON.stringify(dataTypeList));
  9126. //let fileName: string = audioPath.substring(audioPath.lastIndexOf('/') + 1, audioPath.lastIndexOf('.'));
  9127. await ringtone.startRingtoneSetting(getContext(this) as common.UIAbilityContext
  9128. , this.videoUrl, this.name).then(res => {
  9129. LogUtil.info('onecold setFlag :' + res);
  9130. });
  9131. }
  9132. doMore(moreId: number) {
  9133. switch (moreId) {
  9134. case 2: //歌词
  9135. this.isLyricSetting = !this.isLyricSetting;
  9136. this.isShowMoreView = false
  9137. break;
  9138. case 3: //详情
  9139. this.isShowDetailMore = !this.isShowDetailMore;
  9140. break;
  9141. case 4: //分享
  9142. if (this.currentSong !== undefined) {
  9143. Utility.doShareMusic(this.currentSong, getContext(this) as common.UIAbilityContext)
  9144. }
  9145. this.isShowMoreView = false
  9146. break;
  9147. case 5: //定时关闭
  9148. this.isShowTimeCloseMore = !this.isShowTimeCloseMore;
  9149. break;
  9150. case 10: //设为铃声
  9151. this.setRingTone()
  9152. this.isShowMoreView = false
  9153. break;
  9154. case 11: //跳过头尾
  9155. this.isJumpSetting = !this.isJumpSetting;
  9156. break;
  9157. case 13: //倍速
  9158. break;
  9159. case 14: //搜索封面
  9160. if (this.currentSong !== undefined) {
  9161. this.doSearchCover(this.currentSong)
  9162. }
  9163. this.isShowMoreView = false
  9164. break;
  9165. case 15: //编辑标签
  9166. this.setEditStrEmpty()
  9167. this.tempLyricContent = this.lyricContent
  9168. this.isShowEdit = !this.isShowEdit;
  9169. break;
  9170. case 16: //悬浮歌词
  9171. this.showPipLyric = !this.showPipLyric;
  9172. break;
  9173. case 17: //横屏模式
  9174. if (this.isLandscape) {
  9175. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  9176. } else {
  9177. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  9178. }
  9179. this.isShowMoreView = false
  9180. break;
  9181. }
  9182. }
  9183. /**
  9184. * 切换横竖屏
  9185. *
  9186. */
  9187. setOrientation(orientation: number) {
  9188. this.windowClass.setPreferredOrientation(orientation).then(() => {
  9189. Logger.info('setWindowOrientation: ' + orientation + ' Succeeded.');
  9190. }).catch((err: BusinessError) => {
  9191. Logger.info('setWindowOrientation: ' + orientation + ' Failed. Cause: ' + JSON.stringify(err));
  9192. });
  9193. }
  9194. /**
  9195. * 画中画功能(悬浮歌词功能)
  9196. *
  9197. */
  9198. private nodeController: TextNodeController = new TextNodeController('#000000', this.lyricControllerXF);
  9199. pipController?: PiPWindow.PiPController;
  9200. navigationId: string = '';
  9201. @State curState: string = '';
  9202. @State curError: ResourceStr = '';
  9203. @State pipBg: string = '#E8E8E8'
  9204. @State buttonAction: string = '';
  9205. //开启画中画功能
  9206. async startPip() {
  9207. this.nodeController = new TextNodeController(this.pipBg, this.lyricControllerXF);
  9208. if (!this.pipController) {
  9209. await this.createPipController();
  9210. }
  9211. if (!this.pipController) {
  9212. Logger.info(`[${TAG}] pipController create error`);
  9213. return;
  9214. }
  9215. await this.pipController.startPiP();
  9216. }
  9217. async stopPip() {
  9218. if (!this.pipController) {
  9219. Logger.info(`[${TAG}] pipController is not exist`);
  9220. return;
  9221. }
  9222. this.isOpenPip = false
  9223. await this.pipController.stopPiP();
  9224. }
  9225. async createPipController() {
  9226. this.pipController = await PiPWindow.create({
  9227. context: getContext(this),
  9228. componentController: this.xcomponentController,
  9229. navigationId: this.navigationId,
  9230. templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY,
  9231. controlGroups: [PiPWindow.VideoPlayControlGroup.VIDEO_PREVIOUS_NEXT],
  9232. customUIController: this.nodeController,
  9233. });
  9234. this.pipLyWidth = PreferencesUtil.getNumberSync('pipLyWidth', 330)
  9235. this.pipLyHeight = PreferencesUtil.getNumberSync('pipLyHeight', 120)
  9236. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  9237. this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => {
  9238. this.onStateChange(state, reason);
  9239. });
  9240. this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => {
  9241. this.onActionEvent(event, status);
  9242. });
  9243. }
  9244. destroyPipController() {
  9245. if (!this.pipController) {
  9246. return;
  9247. }
  9248. this.pipController.off('stateChange');
  9249. this.pipController.off('controlPanelActionEvent');
  9250. this.pipController = undefined;
  9251. }
  9252. onStateChange(state: PiPWindow.PiPState, reason: string) {
  9253. switch (state) {
  9254. case PiPWindow.PiPState.ABOUT_TO_START:
  9255. this.curState = 'ABOUT_TO_START';
  9256. this.curError = $r('app.string.current_error_hint');
  9257. break;
  9258. case PiPWindow.PiPState.STARTED:
  9259. this.curState = 'STARTED';
  9260. this.curError = $r('app.string.current_error_hint');
  9261. break;
  9262. case PiPWindow.PiPState.ABOUT_TO_STOP:
  9263. this.curState = 'ABOUT_TO_STOP';
  9264. this.curError = $r('app.string.current_error_hint');
  9265. break;
  9266. case PiPWindow.PiPState.STOPPED:
  9267. this.curState = 'STOPPED';
  9268. this.curError = $r('app.string.current_error_hint');
  9269. this.stopPip()
  9270. this.destroyPipController()
  9271. break;
  9272. case PiPWindow.PiPState.ABOUT_TO_RESTORE:
  9273. this.curState = 'ABOUT_TO_RESTORE';
  9274. this.curError = $r('app.string.current_error_hint');
  9275. break;
  9276. case PiPWindow.PiPState.ERROR:
  9277. this.curState = 'ERROR';
  9278. this.curError = reason;
  9279. break;
  9280. default:
  9281. break;
  9282. }
  9283. Logger.info(`[${TAG}] onecold onStateChange: ${this.curState}, reason: ${reason}`);
  9284. }
  9285. onActionEvent(event: PiPWindow.PiPActionEventType, status: number | undefined) {
  9286. LogUtil.info('onecold onActionEvent = ' + event + ' status=' + status)
  9287. switch (event) {
  9288. case 'playbackStateChanged':
  9289. if (status === 0) {
  9290. this.pause();
  9291. } else {
  9292. console.info('onecold startPlayOrResumePlay 9869')
  9293. this.startPlayOrResumePlay();
  9294. }
  9295. break;
  9296. case 'nextVideo':
  9297. // 切换到下一个视频
  9298. this.playNext()
  9299. break;
  9300. case 'previousVideo':
  9301. // 切换到上一个视频
  9302. this.playPrevious()
  9303. break;
  9304. case 'previousVideo':
  9305. // 切换到上一个视频
  9306. this.playPrevious()
  9307. break;
  9308. default:
  9309. }
  9310. this.buttonAction = event + `-status:${status}`;
  9311. Logger.info(`[${TAG}] onActionEvent: ${this.buttonAction} status:${status}}`);
  9312. }
  9313. /**
  9314. * 画中画功能(悬浮歌词功能)结束
  9315. *
  9316. */
  9317. async doSearchCover(item: VideoItem): Promise<string> {
  9318. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  9319. this.isShowMoreView = false;
  9320. this.showTipsDialog();
  9321. return ''; // Return empty string when no API is configured
  9322. }
  9323. if (!item) {
  9324. return ''; // Return empty string if item is undefined
  9325. }
  9326. const artist = item?.artist || ''; // Use empty string if artist is missing
  9327. return this.searchCover(item, item.name, artist); // Await is not needed here as we return the promise directly
  9328. }
  9329. /**
  9330. *api搜索封面
  9331. *item,根据title和artist
  9332. */
  9333. searchCover(item: VideoItem, title: string, artist: string): Promise<string> {
  9334. return NetAxiosUtil.getLyricCover(title, artist, PreferencesUtil.getStringSync('COVER_API', '')).then(async (res) => {
  9335. LogUtil.debug("onecold res =" + res);
  9336. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  9337. if (item.filePath == this.currentSong?.filePath) {
  9338. this.cover = res;
  9339. if (this.currentSong) {
  9340. this.currentSong.pixelMapPath = res;
  9341. }
  9342. }
  9343. // Update pixel map path but always return res regardless of success
  9344. this.table.updatePixelMapPath(item.filePath, res, (success: boolean, error?: string) => {
  9345. if (success) {
  9346. this.doUpdateData();
  9347. console.log("onecold 更新音乐封面成功,数据库已同步");
  9348. } else {
  9349. console.error("onecold 更新音乐封面数据库失败原因: " + error);
  9350. }
  9351. // Note: We don't resolve/reject here because we already returned res
  9352. });
  9353. LogUtil.debug("onecold this.cover =" + this.cover);
  9354. }
  9355. return res; // Always return res regardless of updatePixelMapPath result
  9356. });
  9357. }
  9358. @State jumpTopTime: number = 0
  9359. @State jumpEndTime: number = 0
  9360. @State isOpenJump: boolean = false
  9361. @Builder
  9362. JumpTopEndSheet() {
  9363. Scroll() {
  9364. Column() {
  9365. Column() {
  9366. Text('仅对本播放列表有效')
  9367. .fontSize(16)
  9368. .fontColor($r('app.color.text_color'))
  9369. // 跳过头尾
  9370. Column() {
  9371. Row() {
  9372. Text('跳过片头:')
  9373. .fontSize(16)
  9374. .fontColor($r('app.color.text_color'))
  9375. Text(this.jumpTopTime + 's')
  9376. .fontSize(16)
  9377. .fontColor($r('app.color.text_color'))
  9378. }
  9379. .margin({ bottom: 5 })
  9380. Row() {
  9381. Slider({
  9382. value: this.jumpTopTime,
  9383. min: 0,
  9384. max: 120,
  9385. step: 1,
  9386. style: SliderStyle.OutSet
  9387. })
  9388. .blockColor(this.themeColor)
  9389. .trackColor($r('app.color.speed_text_color'))
  9390. .selectedColor(Color.White)
  9391. .trackThickness(8)
  9392. .onChange((value: number) => {
  9393. this.jumpTopTime = value;
  9394. })
  9395. .width('85%')
  9396. }
  9397. .alignItems(VerticalAlign.Top)
  9398. }
  9399. .margin({ top: 10, bottom: 10 })
  9400. // 跳过头尾
  9401. Column() {
  9402. Row() {
  9403. Text('跳过片尾:')
  9404. .fontSize(16)
  9405. .fontColor($r('app.color.text_color'))
  9406. Text(this.jumpEndTime + 's')
  9407. .fontSize(16)
  9408. .fontColor($r('app.color.text_color'))
  9409. }
  9410. .margin({ bottom: 5 })
  9411. Row() {
  9412. Slider({
  9413. value: this.jumpEndTime,
  9414. min: 0,
  9415. max: 120,
  9416. step: 1,
  9417. style: SliderStyle.OutSet
  9418. })
  9419. .blockColor(this.themeColor)
  9420. .trackColor($r('app.color.speed_text_color'))
  9421. .selectedColor(Color.White)
  9422. .trackThickness(8)
  9423. .onChange((value: number) => {
  9424. this.jumpEndTime = value;
  9425. })
  9426. .width('85%')
  9427. }
  9428. .alignItems(VerticalAlign.Top)
  9429. }
  9430. .margin({ top: 10, bottom: 10 })
  9431. Row() {
  9432. Button('保存设置')
  9433. .fontColor(Color.White)
  9434. .layoutWeight(1)
  9435. .height(40)
  9436. .width(80)
  9437. .backgroundColor(this.themeColor)
  9438. .stateEffect(true)
  9439. .margin({ left: 0, bottom: 20 })
  9440. .onClick(async () => {
  9441. if (!Utility.isNoble()) {
  9442. this.isJumpSetting = false
  9443. this.isShowMoreView = false
  9444. this.showVipDialog()
  9445. return
  9446. }
  9447. if (this.currentSong === undefined) {
  9448. return
  9449. }
  9450. if (this.modeType === 0) {
  9451. let parentPath = FileUtil.getParentPath(this.videoUrl)
  9452. PreferencesUtil.putSync(parentPath + 'isOpenJump', true)
  9453. PreferencesUtil.putSync(parentPath + 'jumpEndTime', this.jumpEndTime)
  9454. PreferencesUtil.putSync(parentPath + 'jumpTopTime', this.jumpTopTime)
  9455. } else if (this.modeType === 1) { //媒体库
  9456. PreferencesUtil.putSync(1 + 'isOpenJump', true)
  9457. PreferencesUtil.putSync(1 + 'jumpEndTime', this.jumpEndTime)
  9458. PreferencesUtil.putSync(1 + 'jumpTopTime', this.jumpTopTime)
  9459. } else if (this.modeType === 2) { //艺术家
  9460. if (this.currentSong?.artist) {
  9461. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'isOpenJump', true)
  9462. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpEndTime', this.jumpEndTime)
  9463. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpTopTime', this.jumpTopTime)
  9464. }
  9465. } else if (this.modeType === 3) { //专辑
  9466. if (this.currentSong?.album) {
  9467. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'isOpenJump', true)
  9468. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpEndTime', this.jumpEndTime)
  9469. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpTopTime', this.jumpTopTime)
  9470. }
  9471. }
  9472. ToastUtil.showShort("保存成功")
  9473. this.isJumpSetting = false
  9474. })
  9475. }
  9476. .margin({
  9477. left: 38,
  9478. right: 38,
  9479. top: 10,
  9480. bottom: 10
  9481. })
  9482. .width(120)
  9483. .height(50)
  9484. }
  9485. }
  9486. }
  9487. .width('100%')
  9488. .height('100%')
  9489. }
  9490. // 应用可以通过onStateChange接口监听组件显示/消失状态,当组件显示时建议不要销毁AVCastPicker的显示;当组件消失时,再根据业务隐藏AVCastPicker。
  9491. private onStateVastChange(state: AVCastPickerState) {
  9492. if (state == AVCastPickerState.STATE_APPEARING) {
  9493. console.log('The picker starts showing.');
  9494. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  9495. console.log('The picker finishes presenting.');
  9496. }
  9497. }
  9498. private showSelectLyric() {
  9499. DialogHelper.showActionSheetDialog({
  9500. title: '温馨提醒:\n1.歌词文件名必须和目标歌曲文件名相同\n2.歌词文件和目标歌曲要同个歌单路径。',
  9501. // sheets: ["本地歌词", "搜索歌词"],
  9502. sheets: [
  9503. { value: "本地歌词", fontColor: $r('app.color.text_color') },
  9504. { value: "搜索歌词", fontColor: $r('app.color.text_color') },
  9505. ],
  9506. maskColor: Color.Transparent,
  9507. backgroundColor: $r('app.color.bg_card'),
  9508. transition: AnimationHelper.transitionInDown(666),
  9509. onAction: (index) => {
  9510. switch (index) {
  9511. case 0:
  9512. this.callFilePickerSelectFileForLyric()
  9513. break;
  9514. case 1:
  9515. if (StrUtil.isNotEmpty(this.videoUrl)) {
  9516. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  9517. this.initLyric(lyricPath);
  9518. }
  9519. break;
  9520. }
  9521. }
  9522. })
  9523. }
  9524. // 拉起picker选择文件管理器
  9525. async callFilePickerSelectFileForLyric(): Promise<void> {
  9526. try {
  9527. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  9528. DocumentSelectOptions.maxSelectNumber = 1
  9529. DocumentSelectOptions.fileSuffixFilters = CommonConstants.LYRIC_FORMAT
  9530. let documentPicker = new picker.DocumentViewPicker();
  9531. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  9532. Logger.info(TAG,
  9533. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  9534. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  9535. this.saveVideoDatasLyric(DocumentSelectResult)
  9536. }
  9537. }).catch((err: BusinessError) => {
  9538. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  9539. });
  9540. } catch (err) {
  9541. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  9542. }
  9543. }
  9544. async saveVideoDatasLyric(uris: string[]) {
  9545. if (ArrayUtil.isEmpty(uris)) {
  9546. return
  9547. }
  9548. let newUris: string[] = [];
  9549. for (let i = 0; i < uris.length; i++) {
  9550. let filePath = getContext(this).filesDir + '/' + Utility.getMediaNameByUri(uris[i])
  9551. Logger.info(TAG, 'filePath uri: ' + filePath);
  9552. newUris.push(filePath)
  9553. let file = fileIo.openSync(uris[i], fileIo.OpenMode.READ_ONLY)
  9554. let file2 = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  9555. fileIo.copyFileSync(file.fd, file2.fd)
  9556. fileIo.closeSync(file);
  9557. fileIo.closeSync(file2);
  9558. this.initLyric(filePath,false,false,true)
  9559. }
  9560. }
  9561. private initDelayPlay(context: object) {
  9562. this.mContext = context;
  9563. }
  9564. startPipLyric() {
  9565. if (this.pipController) {
  9566. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  9567. PiPWindow.PiPControlStatus.PLAY);
  9568. }
  9569. this.isOpenPip = PreferencesUtil.getBooleanSync('isOpenPip', false)
  9570. if (this.isOpenPip) {
  9571. this.startPip()
  9572. } else {
  9573. this.stopPip()
  9574. }
  9575. }
  9576. private startPlayOrResumePlay() {
  9577. this.startPipLyric()
  9578. this.mDestroyPage = false;
  9579. this.animationState = AnimationStatus.Running
  9580. LogUtils.getInstance().LOGI("onecold startPlayOrResumePlay start this.CONTROL_PlayStatus:" + this.CONTROL_PlayStatus)
  9581. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  9582. this.stopProgressTask();
  9583. this.startProgressTask();
  9584. this.play(this.videoUrl.toString());
  9585. }
  9586. if (this.CONTROL_PlayStatus == PlayStatus.PAUSE) {
  9587. this.mIjkMediaPlayer.start();
  9588. this.setProgress()
  9589. this.CONTROL_PlayStatus = PlayStatus.PLAY
  9590. }
  9591. this.setIsPlaying(true)
  9592. this.updateSessionPlayState(true)
  9593. this.watchStatus();
  9594. this.updateLastPlayTimeStr(this.videoUrl)
  9595. }
  9596. updateLastPlayTimeStr(filePath: string) {
  9597. let lastPlayTime = DateUtil.getTodayStr('yyyy-MM-dd HH:mm:ss')
  9598. this.table.updateLastPlayedStrByFilePath(filePath, lastPlayTime, (success: boolean, error?: string) => {
  9599. if (success) {
  9600. this.getHistoryList(false)
  9601. console.log(" onecold 更新最近播放时间成功,数据库已同步");
  9602. } else {
  9603. console.error(" onecold 更新最近播放时间数据库失败原因: " + error);
  9604. }
  9605. });
  9606. }
  9607. private completionNum(num: number): string | number {
  9608. if (num < 10) {
  9609. return '0' + num;
  9610. } else {
  9611. return num;
  9612. }
  9613. }
  9614. private stringForTime(timeMs: number): string {
  9615. let totalSeconds: number | string = (timeMs / 1000);
  9616. let newSeconds: number | string = totalSeconds % 60;
  9617. let minutes: number | string = (totalSeconds / 60) % 60;
  9618. let hours: number | string = totalSeconds / 3600;
  9619. //LogUtils.getInstance().LOGI("stringForTime hours:" + hours + ",minutes:" + minutes + ",seconds:" + newSeconds);
  9620. hours = this.completionNum(Math.floor(Math.floor(hours * 100) / 100));
  9621. minutes = this.completionNum(Math.floor(Math.floor(minutes * 100) / 100));
  9622. newSeconds = Math.floor(Math.floor(newSeconds * 100) / 100)
  9623. if (this.isCurrentTime) {
  9624. if (this.oldSeconds < newSeconds || newSeconds === 0 || this.isSeekTo) {
  9625. this.oldSeconds = newSeconds
  9626. } else {
  9627. newSeconds = this.oldSeconds
  9628. }
  9629. }
  9630. newSeconds = this.completionNum(newSeconds);
  9631. if (hours > 0) {
  9632. return hours + ":" + minutes + ":" + newSeconds;
  9633. } else {
  9634. return minutes + ":" + newSeconds;
  9635. }
  9636. }
  9637. private setProgress() {
  9638. let position = this.mIjkMediaPlayer.getCurrentPosition();
  9639. let duration = this.mIjkMediaPlayer.getDuration();
  9640. let pos = 0;
  9641. if (duration > 0) {
  9642. this.slideEnable = true;
  9643. let curPercent = position / duration;
  9644. pos = curPercent * 100;
  9645. if (pos > this.PROGRESS_MAX_VALUE) {
  9646. this.progressValue = this.PROGRESS_MAX_VALUE
  9647. } else {
  9648. this.progressValue = pos;
  9649. }
  9650. }
  9651. // LogUtils.getInstance()
  9652. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  9653. this.totalTime = this.stringForTime(duration);
  9654. if (position > duration) {
  9655. position = duration;
  9656. }
  9657. this.isCurrentTime = true;
  9658. this.lyricController.updatePosition(position + this.timeOffset * 1000)
  9659. this.lyricControllerXF.updatePosition(position + this.timeOffset * 1000)
  9660. this.lyricControllerSingle.updatePosition(position + this.timeOffset * 1000)
  9661. this.currentTime = this.stringForTime(position);
  9662. this.isCurrentTime = false
  9663. if (this.mIjkMediaPlayer.isPlaying()) {
  9664. this.randomColor =
  9665. `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
  9666. // 判断是否播放到结束时间
  9667. if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
  9668. if (position >= duration - this.jumpEndTime * 1000) {
  9669. this.playNext()
  9670. }
  9671. }
  9672. } else {
  9673. this.randomColor = 'rbg(0,0,0)'
  9674. }
  9675. }
  9676. private startProgressTask() {
  9677. let that = this;
  9678. this.updateProgressTimer = setInterval(() => {
  9679. //LogUtils.getInstance().LOGI("startProgressTask");
  9680. if (!that.mDestroyPage) {
  9681. that.setProgress();
  9682. }
  9683. }, 300);
  9684. }
  9685. private stopProgressTask() {
  9686. LogUtils.getInstance().LOGI("stopProgressTask");
  9687. clearInterval(this.updateProgressTimer);
  9688. }
  9689. private showLoadIng() {
  9690. this.loadingVisible = Visibility.Visible;
  9691. this.replayVisible = Visibility.None;
  9692. }
  9693. private hideLoadIng() {
  9694. this.loadingVisible = Visibility.None;
  9695. this.replayVisible = Visibility.None;
  9696. }
  9697. private showRePlay() {
  9698. this.loadingVisible = Visibility.None;
  9699. this.replayVisible = Visibility.Visible;
  9700. }
  9701. private async play(url: string) {
  9702. let that = this;
  9703. that.showLoadIng();
  9704. //设置XComponent回调的context
  9705. if (!!this.mContext) {
  9706. this.mIjkMediaPlayer.setContext(this.mContext, 'xcomponentId');
  9707. }
  9708. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  9709. this.mIjkMediaPlayer.reset();
  9710. }
  9711. this.CONTROL_PlayStatus = PlayStatus.PLAY;
  9712. //设置debug模式
  9713. this.mIjkMediaPlayer.setDebug(false);
  9714. //初始化配置
  9715. this.mIjkMediaPlayer.native_setup();
  9716. // 初始化配置后需要重新设置音频流音量,否则音量为默认值1.0 针对dsf格式设置最大值1.0
  9717. if(this.volumeSmall){
  9718. if(this.videoUrl.toLowerCase().endsWith('.dsf')){
  9719. this.mIjkMediaPlayer.setVolume('1', '1');
  9720. }else{
  9721. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  9722. }
  9723. }else{
  9724. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  9725. }
  9726. //设置视频源
  9727. this.mIjkMediaPlayer.setDataSource(url);
  9728. //设置视频源http请求头
  9729. let headers = new Map([
  9730. ["user_agent", "Mozilla/5.0 BiliDroid/7.30.0 (bbcallen@gmail.com)"],
  9731. ["referer", "https://www.bilibili.com"]
  9732. ]);
  9733. this.mIjkMediaPlayer.setDataSourceHeader(headers);
  9734. // if(PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN,false)){
  9735. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", "1"); // 启用硬件解码,会导致无法顺序播放
  9736. // }
  9737. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  9738. //使用精确寻帧 例如,拖动播放后,会寻找最近的关键帧进行播放,很有可能关键帧的位置不是拖动后的位置,而是较前的位置.可以设置这个参数来解决问题
  9739. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", "1");
  9740. const fileSize = await this.getFileSize(this.videoUrl);
  9741. let bufferSize = 1 * 1024 ; // 默认缓冲区大小为1MB
  9742. if (fileSize > 3 * 1024 * 1024 * 1024) { // 文件大于3GB
  9743. bufferSize = 25 * 1024 * 1024; // 设置缓冲区大小为25MB
  9744. }
  9745. // 使用软件解码(通常比硬件解码更节省内存)
  9746. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", '0');
  9747. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", '0');
  9748. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", '1024');
  9749. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", '500000');
  9750. //预读数据的缓冲区大小.修复大文件播放前几秒挂掉的bug,太大了会导致倍数播放失效
  9751. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", bufferSize + '');
  9752. //停止预读的最小帧数
  9753. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100");
  9754. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", '1'); ////重连模式,如果中途服务器断开了连接,让它重新连接
  9755. // 设置其他缓冲相关选项
  9756. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100"); // 设置最小缓冲帧数
  9757. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-frames", "1000"); // 设置最大缓冲
  9758. //启动预加载
  9759. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", "1");
  9760. // 设置无缓冲,这是播放器的缓冲区,有数据就播放
  9761. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", "0");
  9762. //跳帧处理,放CPU处理较慢时,进行跳帧处理,保证播放流程,画面和声音同步
  9763. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", "5");
  9764. // 最大缓冲cache是3s, 有时候网络波动,会突然在短时间内收到好几秒的数据
  9765. // 因此需要播放器丢包,才不会累积延时
  9766. // 这个和第三个参数packet-buffering无关。
  9767. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max_cached_duration", "3000");
  9768. // 无限制收流
  9769. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1");
  9770. this.mIjkMediaPlayer.setOptionLong(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1")
  9771. // 屏幕常亮
  9772. this.mIjkMediaPlayer.setScreenOnWhilePlaying(true);
  9773. // 设置超时
  9774. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", "10000000");
  9775. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "connect_timeout", "10000000");
  9776. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "addrinfo_timeout", "10000000");
  9777. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_timeout", "10000000");
  9778. // 变速播放
  9779. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", "1");
  9780. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  9781. let Speed = this.mIjkMediaPlayer.getSpeed()
  9782. LogUtils.getInstance().LOGI('getSpeed--' + Speed)
  9783. //是否开启循环播放
  9784. // this.mIjkMediaPlayer.setLoopCount(this.loop);
  9785. let mOnVideoSizeChangedListener: OnVideoSizeChangedListener = {
  9786. onVideoSizeChanged: (width: number, height: number, sar_num: number, sar_den: number) => {
  9787. if (height === 0) {
  9788. return;
  9789. }
  9790. const va = width / height;
  9791. const vpa = that.videoParentAspectRatio;
  9792. if (vpa > va) {
  9793. that.videoWidth = (width / (height * vpa)) * 100 + '%';
  9794. } else {
  9795. that.videoWidth = '100%';
  9796. }
  9797. if (width && height) {
  9798. that.videoAspectRatio = width / height;
  9799. }
  9800. LogUtils.getInstance()
  9801. .LOGI("setOnVideoSizeChangedListener-->go:" + width + "," + height + "," + sar_num + "," + sar_den);
  9802. that.hideLoadIng();
  9803. }
  9804. }
  9805. this.mIjkMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
  9806. let mOnPreparedListener: OnPreparedListener = {
  9807. onPrepared: async () => {
  9808. LogUtils.getInstance().LOGI("setOnPreparedListener-->go");
  9809. try {
  9810. // this.cover = this.songList[this.curIndex].pixelMapPath
  9811. // this.artist = this.songList[this.curIndex].artist
  9812. // this.videoUrl = this.songList[this.curIndex].filePath
  9813. let isBgCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  9814. if (isBgCover && this.cover !== undefined && StrUtil.isNotEmpty(this.cover)) {
  9815. this.setImageColor2(this.cover)
  9816. } else {
  9817. this.getImageColor();
  9818. }
  9819. //保存碰一碰分享的当前的歌曲
  9820. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  9821. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  9822. await this.initLyric(lyricPath);
  9823. setTimeout(() => {
  9824. this.avSessionController.initAvSession(false);
  9825. this.avSessionController.setAVMetadataMusic(this.songList[this.curIndex], this.duration, this.lyricContent);
  9826. this.setAvSessionListener();
  9827. this.updateSessionPlayState(true)
  9828. this.setCurrentPlayMode()
  9829. }, 500)
  9830. //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9831. let timeoutPlay = 0
  9832. if (StrUtil.isNotEmpty(this.videoUrl) &&
  9833. (this.videoUrl.toLowerCase().endsWith('.rmvb') || this.videoUrl.toLowerCase().endsWith('.flac'))) {
  9834. timeoutPlay = 1000
  9835. }
  9836. //跳过片头片尾关键代码,以下是跳过片头的关键代码
  9837. if (this.modeType === 0) { //文件夹
  9838. let parentPath = FileUtil.getParentPath(this.videoUrl)
  9839. this.jumpTopTime = PreferencesUtil.getNumberSync(parentPath + 'jumpTopTime')
  9840. this.jumpEndTime = PreferencesUtil.getNumberSync(parentPath + 'jumpEndTime')
  9841. this.isOpenJump = PreferencesUtil.getBooleanSync(parentPath + 'isOpenJump', false)
  9842. } else if (this.modeType === 1) { //媒体库
  9843. this.jumpTopTime = PreferencesUtil.getNumberSync(1 + 'jumpTopTime')
  9844. this.jumpEndTime = PreferencesUtil.getNumberSync(1 + 'jumpEndTime')
  9845. this.isOpenJump = PreferencesUtil.getBooleanSync(1 + 'isOpenJump', false)
  9846. } else if (this.modeType === 2) { //艺术家
  9847. if (this.currentSong?.artist) {
  9848. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpTopTime')
  9849. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpEndTime')
  9850. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.artist + 2 + 'isOpenJump', false)
  9851. }
  9852. } else if (this.modeType === 3) { //专辑
  9853. if (this.currentSong?.album) {
  9854. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpTopTime')
  9855. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpEndTime')
  9856. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.album + 3 + 'isOpenJump', false)
  9857. }
  9858. }
  9859. this.duration = this.mIjkMediaPlayer.getDuration()
  9860. if (this.isOpenJump) { //用户是否设置跳过片头片尾
  9861. if (this.mIjkMediaPlayer != null) {
  9862. let jumpTopTimeMs = this.jumpTopTime*1000;
  9863. if (jumpTopTimeMs <= this.duration) {
  9864. // 调用 seekTo 方法,跳到指定时间
  9865. if(PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY,true)){
  9866. console.log('onecold jumpTopTime = '+jumpTopTimeMs);
  9867. const position:number = PreferencesUtil.getNumberSync(this.videoUrl, 0);
  9868. console.log('onecold position = '+position);
  9869. if (position > jumpTopTimeMs) {
  9870. jumpTopTimeMs = position
  9871. }
  9872. }
  9873. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9874. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  9875. this.seekTo(this.jumpTopTime * 1000 + ""); // 跳到开头
  9876. }
  9877. }, timeoutPlay)
  9878. } else {
  9879. // 提示用户无法跳过
  9880. ToastUtil.showToast('跳过时间超过视频时长');
  9881. }
  9882. }
  9883. } else {
  9884. this.jumpTopTime = 0
  9885. this.jumpEndTime = 0
  9886. console.error('onecold 最后一首: isFirstStartPlay = ' + this.isFirstStartPlay);
  9887. console.error('onecold 最后一首: isMemoryLastPlay = ' + this.isMemoryLastPlay);
  9888. console.error('onecold 最后一首: PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false) = ' +
  9889. PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false));
  9890. //记忆播放(每一首都会记忆播放)
  9891. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  9892. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  9893. if (PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)) {
  9894. this.restorePlaybackPosition() //读取播放记忆功能
  9895. } else if (this.isMemoryLastPlay && this.isFirstStartPlay) {
  9896. console.error('onecold 最后一首:读取播放记忆功能 = ' + this.isFirstStartPlay);
  9897. this.restorePlaybackPosition() //读取播放记忆功能
  9898. }
  9899. this.isFirstStartPlay = false
  9900. }, timeoutPlay)
  9901. } else {
  9902. this.isFirstStartPlay = false
  9903. }
  9904. }
  9905. this.saveLastPlayList()
  9906. } catch (error) {
  9907. let err: BusinessError = error as BusinessError;
  9908. console.error('onecold failed with err: ' + JSON.stringify(err));
  9909. }
  9910. }
  9911. }
  9912. this.mIjkMediaPlayer.setOnPreparedListener(mOnPreparedListener);
  9913. let mOnTimedTextListener: OnTimedTextListener = {
  9914. onTimedText: () => {
  9915. }
  9916. }
  9917. this.mIjkMediaPlayer.setOnTimedTextListener(mOnTimedTextListener)
  9918. let mOnCompletionListener: OnCompletionListener = {
  9919. onCompletion: () => {
  9920. LogUtils.getInstance().LOGI("OnCompletionListener-->go")
  9921. if (this.playType == 0) { //0:连续播放 1:单片重复播放 2:正常播放
  9922. this.playNext()
  9923. } else if (this.playType == 1) { //1:单片重复播放
  9924. this.CONTROL_PlayStatus = PlayStatus.INIT
  9925. console.info('onecold startPlayOrResumePlay 10592')
  9926. that.startPlayOrResumePlay();
  9927. } else if (this.playType == 2) { //2:正常播放,单曲播完
  9928. that.showRePlay();
  9929. that.currentTime = that.stringForTime(this.mIjkMediaPlayer.getDuration());
  9930. that.progressValue = this.PROGRESS_MAX_VALUE;
  9931. that.slideEnable = false;
  9932. that.stop();
  9933. // ToastUtil.showToast('开始重新播放')
  9934. } else if (this.playType == 3) { //3:随机播放
  9935. this.randomPlay()
  9936. }
  9937. }
  9938. }
  9939. this.mIjkMediaPlayer.setOnCompletionListener(mOnCompletionListener);
  9940. let mOnBufferingUpdateListener: OnBufferingUpdateListener = {
  9941. onBufferingUpdate: (percent: number) => {
  9942. LogUtils.getInstance().LOGI("OnBufferingUpdateListener-->go:" + percent);
  9943. let MediaInfo = this.mIjkMediaPlayer.getMediaInfo()
  9944. LogUtils.getInstance().LOGI('getMediaInfo---' + MediaInfo);
  9945. let VideoWidth = this.mIjkMediaPlayer.getVideoWidth()
  9946. LogUtils.getInstance().LOGI('getVideoWidth---' + VideoWidth);
  9947. let VideoHeight = this.mIjkMediaPlayer.getVideoHeight()
  9948. LogUtils.getInstance().LOGI('getVideoHeight---' + VideoHeight);
  9949. let VideoSarNum = this.mIjkMediaPlayer.getVideoSarNum()
  9950. LogUtils.getInstance().LOGI('getVideoSarNum---' + VideoSarNum);
  9951. let VideoSarDen = this.mIjkMediaPlayer.getVideoSarDen()
  9952. LogUtils.getInstance().LOGI('getVideoSarDen---' + VideoSarDen);
  9953. let AudioSessionId = this.mIjkMediaPlayer.getAudioSessionId()
  9954. LogUtils.getInstance().LOGI('getAudioSessionId---' + AudioSessionId);
  9955. let Looping = this.mIjkMediaPlayer.isLooping()
  9956. LogUtils.getInstance().LOGI('isLooping---' + Looping);
  9957. }
  9958. }
  9959. this.mIjkMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
  9960. let mOnSeekCompleteListener: OnSeekCompleteListener = {
  9961. onSeekComplete: () => {
  9962. LogUtils.getInstance().LOGI("OnSeekCompleteListener-->go");
  9963. console.info('onecold startPlayOrResumePlay 10643')
  9964. that.startPlayOrResumePlay();
  9965. }
  9966. }
  9967. this.mIjkMediaPlayer.setOnSeekCompleteListener(mOnSeekCompleteListener);
  9968. let mOnInfoListener: OnInfoListener = {
  9969. onInfo: (what: number, extra: number) => {
  9970. LogUtils.getInstance().LOGI("OnInfoListener-->go:" + what + "===" + extra);
  9971. that.hideLoadIng();
  9972. }
  9973. }
  9974. this.mIjkMediaPlayer.setOnInfoListener(mOnInfoListener);
  9975. let mOnErrorListener: OnErrorListener = {
  9976. onError: (what: number, extra: number) => {
  9977. this.stopProgressTask();
  9978. LogUtils.getInstance().LOGI("OnErrorListener-->go:" + what + "===" + extra + " this.videoUrl=" + this.videoUrl)
  9979. that.hideLoadIng();
  9980. if (StrUtil.isNotEmpty(this.videoUrl) && !FileUtil.accessSync(this.videoUrl)) {
  9981. ToastUtil.showToast(Utility.resourceToString(getContext(), $r('app.string.file_not_exist')))
  9982. } else {
  9983. ToastUtil.showToast(getContext()
  9984. .resourceManager
  9985. .getStringByNameSync("Honey_the_video_is_playing_errant_The_system_is_wandering"))
  9986. }
  9987. }
  9988. }
  9989. this.mIjkMediaPlayer.setOnErrorListener(mOnErrorListener);
  9990. this.mIjkMediaPlayer.setMessageListener();
  9991. this.mIjkMediaPlayer.prepareAsync();
  9992. this.mIjkMediaPlayer.start();
  9993. }
  9994. //保存最后播放的那首歌和已经对应的播放列表
  9995. saveLastPlayList() {
  9996. PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
  9997. PreferencesUtil.putSync('LastMusicList', this.songList)
  9998. }
  9999. // 清空播放记录
  10000. clearVideoHistory() {
  10001. this.table.clearPlayHistory((success: boolean, error?: string) => {
  10002. if (success) {
  10003. this.historyList = [];
  10004. this.updateListData(this.historyList)
  10005. // PreferencesUtil.putSync(LocalMusic.HISTORY_MUSIC, this.historyList)
  10006. ToastUtil.showToast('清空播放记录成功')
  10007. } else {
  10008. console.error(" onecold 清空播放记录数据库失败原因: " + error);
  10009. }
  10010. });
  10011. }
  10012. public async setAvSessionListener() {
  10013. if (!this.avSessionController) {
  10014. return;
  10015. }
  10016. this.avSessionController.getAvSession()?.on('play', this.sessionPlayCallback);
  10017. this.avSessionController.getAvSession()?.on('pause', this.sessionPauseCallback);
  10018. this.avSessionController.getAvSession()?.on('stop', this.sessionStopCallback);
  10019. this.avSessionController.getAvSession()?.on('playNext', this.sessionPlayNextCallback);
  10020. this.avSessionController.getAvSession()?.on('playPrevious', this.sessionPlayPreviousCallback);
  10021. this.avSessionController.getAvSession()?.on('fastForward', this.sessionFastForwardCallback);
  10022. this.avSessionController.getAvSession()?.on('rewind', this.sessionRewindCallback);
  10023. this.avSessionController.getAvSession()?.on('seek', this.sessionSeekCallback);
  10024. this.avSessionController.getAvSession()?.on('setLoopMode', this.sessionSetLoopModeCallback);
  10025. this.avSessionController.getAvSession()?.on('toggleFavorite', this.sessionToggleFavoriteCallback);
  10026. this.avSessionController.getAvSession()?.on('outputDeviceChange', this.sessionOutputDeviceChange)
  10027. }
  10028. setLoopMode() {
  10029. let itype = this.playType + 1
  10030. if (itype >= 4) {
  10031. this.playType = 0
  10032. ToastUtil.showToast('连续播放')
  10033. } else if (itype === 1) {
  10034. this.playType = 1
  10035. ToastUtil.showToast('单曲循环')
  10036. } else if (itype === 2) {
  10037. this.playType = 2
  10038. ToastUtil.showToast('单曲播完')
  10039. } else if (itype === 3) {
  10040. this.playType = 3
  10041. ToastUtil.showToast('随机播放')
  10042. } else if (itype === 0) {
  10043. this.playType = 0
  10044. ToastUtil.showToast('连续播放')
  10045. }
  10046. PreferencesUtil.putSync('musicPlayType', this.playType)
  10047. this.setCurrentPlayMode()
  10048. }
  10049. private sessionSetLoopModeCallback = (mode: number) => {
  10050. if (this.mIjkMediaPlayer != null) {
  10051. ToastUtil.showToast('当前播放模式:' + mode)
  10052. Logger.info('onecold 当前播放模式= ' + mode)
  10053. let hmPlayMode = mode + 1
  10054. if (hmPlayMode >= 4) {
  10055. hmPlayMode = 0
  10056. }
  10057. if (hmPlayMode === 1) {
  10058. this.playType = 1
  10059. ToastUtil.showToast('单曲循环')
  10060. } else if (hmPlayMode === 0) {
  10061. this.playType = 2
  10062. ToastUtil.showToast('单曲播完')
  10063. } else if (hmPlayMode === 3) {
  10064. this.playType = 3
  10065. ToastUtil.showToast('随机播放')
  10066. } else if (hmPlayMode === 2) {
  10067. this.playType = 0
  10068. ToastUtil.showToast('连续播放')
  10069. }
  10070. PreferencesUtil.putSync('musicPlayType', this.playType)
  10071. // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
  10072. let playBackState: avSession.AVPlaybackState = {
  10073. loopMode: hmPlayMode,
  10074. };
  10075. this.avSessionController.getAvSession()?.setAVPlaybackState(playBackState).then(() => {
  10076. console.info(`set setLoopMode AVPlaybackState successfully`);
  10077. }).catch((err: BusinessError) => {
  10078. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  10079. });
  10080. }
  10081. }
  10082. setCurrentPlayMode() {
  10083. if (!this.avSessionController) {
  10084. return;
  10085. }
  10086. let mLoopMode = 0
  10087. switch (this.playType) {
  10088. case 0:
  10089. mLoopMode = avSession.LoopMode.LOOP_MODE_LIST //连续播放
  10090. break;
  10091. case 1:
  10092. mLoopMode = avSession.LoopMode.LOOP_MODE_SINGLE //单曲
  10093. break;
  10094. case 2:
  10095. mLoopMode = avSession.LoopMode.LOOP_MODE_SEQUENCE //正常播放
  10096. break;
  10097. case 3:
  10098. mLoopMode = avSession.LoopMode.LOOP_MODE_SHUFFLE //随机播放
  10099. break;
  10100. }
  10101. // 应用启动时/内部切换循环模式,需要把应用内的当前的循环模式设置给AVSession。
  10102. let playBState: avSession.AVPlaybackState = {
  10103. loopMode: mLoopMode,
  10104. isFavorite: Utility.getIsFav(this.favList, this.currentSong),
  10105. };
  10106. this.avSessionController.getAvSession()?.setAVPlaybackState(playBState).then(() => {
  10107. console.info(`set setLoopMode AVPlaybackState successfully`);
  10108. }).catch((err: BusinessError) => {
  10109. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  10110. });
  10111. }
  10112. private sessionToggleFavoriteCallback = (assetId: string) => {
  10113. if (this.mIjkMediaPlayer != null && this.currentSong) {
  10114. console.info(`on toggleFavorite `);
  10115. // 应用收到收藏命令,进行收藏处理。
  10116. this.isFac = Utility.getIsFav(this.favList, this.currentSong)
  10117. this.doFav(this.currentSong)
  10118. // 应用内完成或者取消收藏,把新的收藏状态设置给AVSession。
  10119. let playbackState: avSession.AVPlaybackState = {
  10120. isFavorite: !this.isFac,
  10121. };
  10122. this.avSessionController.getAvSession()?.setAVPlaybackState(playbackState).then(() => {
  10123. console.info(`SetAVPlaybackState successfully`);
  10124. }).catch((err: BusinessError) => {
  10125. console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  10126. });
  10127. }
  10128. }
  10129. private sessionOutputDeviceChange = async (connectState: avSession.ConnectionState,
  10130. device: avSession.OutputDeviceInfo) => {
  10131. let currentDevice: avSession.DeviceInfo = device?.devices?.[0];
  10132. if (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  10133. connectState === avSession.ConnectionState.STATE_CONNECTED) {
  10134. await this.startCasting();
  10135. } else if ((currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  10136. connectState === avSession.ConnectionState.STATE_DISCONNECTED) ||
  10137. (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_LOCAL &&
  10138. connectState === avSession.ConnectionState.STATE_CONNECTED)) {
  10139. if (device) {
  10140. this.endCasting();
  10141. }
  10142. }
  10143. };
  10144. private async startCasting() {
  10145. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  10146. this.setPlaybackStateChangeListener();
  10147. this.pause();
  10148. this.initQueueItem();
  10149. this.prepare();
  10150. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  10151. refToIsCasting?.set(true);
  10152. this.castSeek = true;
  10153. this.isCastPlaying = true;
  10154. }
  10155. async changeCasting() {
  10156. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  10157. this.initQueueItem();
  10158. this.prepare();
  10159. this.setPlaybackStateChangeListener();
  10160. this.isCastPlaying = true;
  10161. this.castSeek = true;
  10162. }
  10163. public endCasting() {
  10164. this.avSessionController.getAvSession()?.stopCasting();
  10165. this.stopCast();
  10166. this.isCastPlaying = false;
  10167. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  10168. refToIsCasting?.set(false);
  10169. this.pause();
  10170. this.setIsPlaying(false);
  10171. // if (this.curIndex === this.curSource.index) {
  10172. // this.play
  10173. // this.seek(this.currentTime * 1000);
  10174. // this.setIsPlaying(true);
  10175. // } else {
  10176. // this.pauseVideo();
  10177. // this.setIsPlaying(false);
  10178. // }
  10179. }
  10180. public setIsPlaying(isPlayer: boolean) {
  10181. this.isPlaying = isPlayer;
  10182. }
  10183. private setPlaybackStateChangeListener(): void {
  10184. this.castController?.on('playbackStateChange', 'all', this.playbackStateChangeListener);
  10185. this.castController?.on('endOfStream', this.reloadCasting);
  10186. this.castController?.on('playNext', this.playNextCallback);
  10187. this.castController?.on('playPrevious', this.playPreviousCallback);
  10188. }
  10189. private updateSessionPlayState(isPlay: boolean): void {
  10190. // if(!this.isBgPlayOpen)
  10191. // return
  10192. Logger.info(TAG, `updateIsPlay isPlay: ${isPlay}`);
  10193. this.setAVSessionPlayState({
  10194. state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
  10195. position: {
  10196. elapsedTime: this.mIjkMediaPlayer.getCurrentPosition(),
  10197. updateTime: new Date().getTime()
  10198. }
  10199. });
  10200. }
  10201. private setAVSessionPlayState(playbackState: avSession.AVPlaybackState): void {
  10202. this.avSessionController.setAvSessionPlayState(playbackState)
  10203. }
  10204. private positionChange(position: number) {
  10205. this.currentTime2 = position / 1000;
  10206. this.currentStringTime = secondToTime(Math.floor(position / 1000));
  10207. }
  10208. private playDurationChange(duration: number) {
  10209. this.duration = duration;
  10210. this.durationTime = Math.floor(this.duration / 1000);
  10211. this.durationStringTime = secondToTime((this.durationTime));
  10212. }
  10213. private playbackStateChangeListener = (playbackState: avSession.AVPlaybackState) => {
  10214. const duration = playbackState?.extras?.duration;
  10215. if (typeof duration === 'number') {
  10216. this.playDurationChange(duration as number);
  10217. }
  10218. if (typeof playbackState?.position?.elapsedTime !== 'undefined') {
  10219. this.positionChange(playbackState?.position?.elapsedTime);
  10220. }
  10221. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PAUSE ||
  10222. playbackState.state === CommonConstants2.PLAYBACK_STATE_STOP ||
  10223. playbackState.state === CommonConstants2.PLAYBACK_STATE_PREPARE ||
  10224. playbackState.state === CommonConstants2.PLAYBACK_STATE_INITIAL) {
  10225. this.isCastPlaying = false;
  10226. }
  10227. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PLAY) {
  10228. this.isCastPlaying = true;
  10229. }
  10230. };
  10231. private reloadCasting = async () => {
  10232. let item = this.songList[this.curIndex];
  10233. let uri = fileUri.getUriFromPath(item.filePath);
  10234. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  10235. // description.startPosition = 0;
  10236. this.castItem = {
  10237. itemId: this.curIndex,
  10238. description: {
  10239. assetId: item.filePath,
  10240. title: item.name,
  10241. artist: '',
  10242. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  10243. // mediaUri: item.filePath,
  10244. fdSrc: {
  10245. fd: file.fd
  10246. },
  10247. // 该字段大写,音频'AUDIO',视频'VIDEO'
  10248. mediaType: 'VIDEO',
  10249. mediaSize: item.videoSize,
  10250. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  10251. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  10252. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  10253. duration: this.duration,
  10254. // albumCoverUri: 'https://www.example.jpeg',
  10255. // albumTitle: '《ExampleAlbum》',
  10256. appName: this.appName,
  10257. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  10258. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  10259. }
  10260. };
  10261. this.prepare();
  10262. this.isCastPlaying = true;
  10263. };
  10264. public playNextCallback = (): void => {
  10265. this.playNext()
  10266. };
  10267. public playPreviousCallback = (): void => {
  10268. this.playPrevious()
  10269. };
  10270. async prepare() {
  10271. await this.castController?.prepare(this.castItem);
  10272. await this.castController?.start(this.castItem);
  10273. }
  10274. public initQueueItem() {
  10275. let item = this.songList[this.curIndex];
  10276. let time = this.currentTime;
  10277. let uri = fileUri.getUriFromPath(item.filePath);
  10278. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  10279. this.castItem = {
  10280. itemId: this.curIndex,
  10281. description: {
  10282. assetId: item.filePath,
  10283. title: item.name,
  10284. artist: '',
  10285. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  10286. fdSrc: {
  10287. fd: file.fd
  10288. },
  10289. // 该字段大写,音频'AUDIO',视频'VIDEO'
  10290. mediaType: 'AUDIO',
  10291. mediaSize: item.videoSize,
  10292. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  10293. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  10294. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  10295. duration: this.duration,
  10296. // albumCoverUri: 'https://www.example.jpeg',
  10297. // albumTitle: '《ExampleAlbum》',
  10298. appName: this.appName,
  10299. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  10300. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  10301. }
  10302. };
  10303. }
  10304. async stopCast() {
  10305. try {
  10306. this.castController?.off('playbackStateChange');
  10307. this.castController?.off('endOfStream');
  10308. this.castController?.off('playNext');
  10309. this.castController?.off('playPrevious');
  10310. this.castController?.off('error');
  10311. } catch (error) {
  10312. hilog.info(0x0000, TAG, `Failed to setAVCastController. code: ${error.code}, message: ${error.message}`);
  10313. }
  10314. }
  10315. private sessionPlayCallback = (): void => {
  10316. console.info('onecold playOrPause 11050')
  10317. this.playOrPause()
  10318. };
  10319. private sessionPauseCallback = (): void => {
  10320. console.info('onecold playOrPause 11054')
  10321. this.pause()
  10322. };
  10323. private playOrPause() {
  10324. if (!this.debounce()) {
  10325. return;
  10326. }
  10327. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  10328. this.pause();
  10329. } else {
  10330. console.info('onecold startPlayOrResumePlay 11064')
  10331. this.startPlayOrResumePlay();
  10332. this.playChange()
  10333. }
  10334. }
  10335. private sessionPlayNextCallback = (): void => {
  10336. this.playNext()
  10337. };
  10338. private sessionPlayPreviousCallback = (): void => {
  10339. this.playPrevious()
  10340. };
  10341. private sessionStopCallback = (): void => {
  10342. this.stop()
  10343. };
  10344. private sessionFastForwardCallback = (time?: number) => {
  10345. if (!time) {
  10346. return;
  10347. }
  10348. if (this.mIjkMediaPlayer != null) {
  10349. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  10350. let seeTime = curPosition + time * 1000;
  10351. // 限制 seekValue 在合法范围内
  10352. if (seeTime < 0) {
  10353. seeTime = 0;
  10354. } else if (seeTime > this.duration) {
  10355. seeTime = this.duration;
  10356. }
  10357. Logger.info('onecold seeTime= ' + seeTime)
  10358. this.setSeekToActionProgress(seeTime)
  10359. this.seekTo(seeTime + "")
  10360. }
  10361. };
  10362. /**
  10363. * Gesture method onActionUpdate.
  10364. *
  10365. * @param event Gesture event.手势拖动设置快进和后退
  10366. */
  10367. private setSeekToActionProgress(position: number) {
  10368. // let position = this.mIjkMediaPlayer.getCurrentPosition();
  10369. let duration = this.mIjkMediaPlayer.getDuration();
  10370. let pos = 0;
  10371. if (duration > 0) {
  10372. this.slideEnable = true;
  10373. let curPercent = position / duration;
  10374. pos = curPercent * 100;
  10375. if (pos > this.PROGRESS_MAX_VALUE) {
  10376. this.progressValue = this.PROGRESS_MAX_VALUE
  10377. } else {
  10378. this.progressValue = pos;
  10379. }
  10380. }
  10381. // LogUtils.getInstance()
  10382. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  10383. this.totalTime = this.stringForTime(duration);
  10384. if (position > duration) {
  10385. position = duration;
  10386. }
  10387. this.isCurrentTime = true;
  10388. this.currentTime = this.stringForTime(position);
  10389. this.isCurrentTime = false
  10390. }
  10391. private sessionRewindCallback = (time?: number) => {
  10392. if (!time) {
  10393. return;
  10394. }
  10395. if (this.mIjkMediaPlayer != null) {
  10396. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  10397. let seeTime = curPosition - time * 1000;
  10398. // 限制 seekValue 在合法范围内
  10399. if (seeTime < 0) {
  10400. seeTime = 0;
  10401. } else if (seeTime > this.duration) {
  10402. seeTime = this.duration;
  10403. }
  10404. Logger.info('onecold seeTime= ' + seeTime)
  10405. this.setSeekToActionProgress(seeTime)
  10406. this.seekTo(seeTime + "")
  10407. }
  10408. };
  10409. private sessionSeekCallback = (seekTime: number) => {
  10410. if (this.mIjkMediaPlayer != null) {
  10411. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  10412. this.seekTo(seekTime + "")
  10413. }
  10414. };
  10415. private async getFileSize(filePath: string): Promise<number> {
  10416. try {
  10417. const stat = await fs.stat(filePath);
  10418. return stat.size;
  10419. } catch (err) {
  10420. console.error('Failed to get file size: ' + err.message);
  10421. return 0;
  10422. }
  10423. }
  10424. private pause() {
  10425. if (this.mIjkMediaPlayer.isPlaying()) {
  10426. this.savePlaybackPosition();
  10427. this.mIjkMediaPlayer.pause();
  10428. this.setProgress();
  10429. this.mDestroyPage = true;
  10430. this.CONTROL_PlayStatus = PlayStatus.PAUSE;
  10431. this.updateSessionPlayState(false)
  10432. this.playChange()
  10433. if (this.pipController) {
  10434. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  10435. PiPWindow.PiPControlStatus.PAUSE);
  10436. }
  10437. }
  10438. }
  10439. private stop() {
  10440. this.savePlaybackPosition();
  10441. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10442. this.mIjkMediaPlayer.stop();
  10443. this.mIjkMediaPlayer.release();
  10444. this.stopProgressTask();
  10445. this.updateSessionPlayState(false)
  10446. this.playChange()
  10447. this.watchStatus();
  10448. }
  10449. //保持记忆播放功能
  10450. private savePlaybackPosition() {
  10451. if (this.mIjkMediaPlayer != null) {
  10452. const position = this.mIjkMediaPlayer.getCurrentPosition();
  10453. // ToastUtil.showToast('保存记忆播放 = ' + position)
  10454. const duration = this.mIjkMediaPlayer.getDuration();
  10455. const threshold = 5000; // 阈值,单位为毫秒(这里设为5秒)
  10456. // 如果播放位置接近视频末尾,则保存 position 为 0
  10457. const playbackPosition = (duration - position < threshold) ? 0 : position;
  10458. PreferencesUtil.putSync(this.videoUrl, playbackPosition);
  10459. }
  10460. }
  10461. //获取记忆播放功能
  10462. private restorePlaybackPosition() {
  10463. const position: number = PreferencesUtil.getNumberSync(this.videoUrl, 0);
  10464. // ToastUtil.showToast('position = ' + position)
  10465. if (this.mIjkMediaPlayer != null && position > 0) {
  10466. // ToastUtil.showToast('seekTo = ' + position)
  10467. this.seekTo(position + "");
  10468. }
  10469. }
  10470. private seekTo(value: string) {
  10471. if (StrUtil.isNotEmpty(this.videoUrl) && this.videoUrl.toLowerCase().endsWith('.wma')) {
  10472. ToastUtil.showToast('wma格式不支持拖动快进。')
  10473. return
  10474. }
  10475. this.isSeekTo = true
  10476. this.mIjkMediaPlayer.seekTo(value);
  10477. console.info('onecold startPlayOrResumePlay 11227')
  10478. // this.startPlayOrResumePlay()
  10479. // 在这里恢复计时器状态
  10480. this.setProgress()
  10481. this.isSeekTo = false
  10482. }
  10483. // 添加到下一首播放
  10484. private addToNextPlay(song: VideoItem) {
  10485. if (!this.debounce()) {
  10486. return;
  10487. }
  10488. if (this.currentSong) {
  10489. if (this.currentSong === song) {
  10490. ToastUtil.showToast('当前已经在播放这首歌了!')
  10491. return
  10492. }
  10493. }
  10494. // 如果未开始播放或队列为空
  10495. if (this.curIndex === -1 || this.songList.length === 0) {
  10496. this.songList = [song];
  10497. this.curIndex = 0;
  10498. this.doPlay(song)
  10499. return;
  10500. }
  10501. // 插入到当前索引+1的位置
  10502. const insertPos = this.curIndex + 1;
  10503. this.songList.splice(insertPos, 0, song);
  10504. this.songList = [...this.songList]; // 触发状态更新
  10505. this.sonDataSource.pushArrayData(this.songList)
  10506. ToastUtil.showToast('已添加至下一首播放')
  10507. }
  10508. //下一个
  10509. private playNext() {
  10510. if (!this.debounce()) {
  10511. return;
  10512. }
  10513. if (this.playType == 3) { //3:随机播放
  10514. this.randomPlay()
  10515. return;
  10516. }
  10517. if (ArrayUtil.isNotEmpty(this.songList)) {
  10518. if (this.curIndex == this.songList.length - 1) {
  10519. this.curIndex = 0;
  10520. } else {
  10521. this.curIndex++;
  10522. }
  10523. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10524. this.stop();
  10525. this.currentSong = this.songList[this.curIndex]
  10526. this.videoUrl = this.songList[this.curIndex].filePath;
  10527. this.artist = this.songList[this.curIndex].artist
  10528. this.name = this.songList[this.curIndex].name
  10529. //this.cover = this.songList[this.curIndex].pixelMapPath
  10530. this.changeImageAnimation()
  10531. }
  10532. }
  10533. changeImageAnimation() {
  10534. if(this.openSkipSongAnimate){
  10535. // 第一步:淡出动画
  10536. this.getUIContext()?.animateTo({
  10537. duration: 500,
  10538. curve: Curve.EaseOut,
  10539. }, () => {
  10540. this.opacityValueImage = 0.1;
  10541. if(this.isCoverRectangle){
  10542. this.scaleValueImage = 0.88
  10543. }
  10544. });
  10545. // 第二步:切换图片后淡入
  10546. setTimeout(() => {
  10547. this.cover = this.songList[this.curIndex].pixelMapPath
  10548. this.getUIContext()?.animateTo({
  10549. duration: 500,
  10550. curve: Curve.EaseIn,
  10551. }, () => {
  10552. this.opacityValueImage = 1;
  10553. this.scaleValueImage = 1 // 图标恢复到原始大小
  10554. console.info('onecold startPlayOrResumePlay 11313')
  10555. this.startPlayOrResumePlay()
  10556. });
  10557. }, 500);
  10558. }else{
  10559. this.cover = this.songList[this.curIndex].pixelMapPath
  10560. console.info('onecold startPlayOrResumePlay 11319')
  10561. this.startPlayOrResumePlay()
  10562. }
  10563. }
  10564. // 存储已播放的歌曲索引
  10565. private playedIndices: Set<number> = new Set();
  10566. //随机播放
  10567. private randomPlay() {
  10568. // if (!this.debounce()) {
  10569. // return;
  10570. // }
  10571. if (ArrayUtil.isNotEmpty(this.songList)) {
  10572. if (this.songList.length > 3) {
  10573. // 如果所有歌曲都播放过一次,清空已播放索引集合
  10574. if (this.playedIndices.size === this.songList.length) {
  10575. this.playedIndices.clear();
  10576. }
  10577. // 随机选择一个未播放的歌曲索引
  10578. let newIndex: number;
  10579. // 添加超时机制防止无限循环
  10580. let attempt = 0;
  10581. const maxAttempts = 100; // 根据需求调整
  10582. do {
  10583. newIndex = RandomUtil.getRandomNumber(0, this.songList.length - 1);
  10584. attempt++;
  10585. } while (this.playedIndices.has(newIndex) && attempt < maxAttempts);
  10586. if (attempt >= maxAttempts) {
  10587. // 处理无法找到新索引的情况(如随机选择或按顺序播放)
  10588. newIndex = Math.floor(Math.random() * this.songList.length);
  10589. }
  10590. this.curIndex = newIndex;
  10591. this.playedIndices.add(newIndex);
  10592. } else {
  10593. // 当歌曲数量小于或等于3时,直接播放下一首
  10594. if (this.curIndex == this.songList.length - 1) {
  10595. this.curIndex = 0;
  10596. } else {
  10597. this.curIndex++;
  10598. }
  10599. }
  10600. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10601. this.stop();
  10602. this.currentSong = this.songList[this.curIndex];
  10603. this.videoUrl = this.songList[this.curIndex].filePath;
  10604. this.name = this.songList[this.curIndex].name;
  10605. this.artist = this.songList[this.curIndex].artist
  10606. // this.cover = this.songList[this.curIndex].pixelMapPath
  10607. this.changeImageAnimation()
  10608. }
  10609. }
  10610. private playIndex(index: number) {
  10611. if (!this.debounce()) {
  10612. return;
  10613. }
  10614. if (ArrayUtil.isNotEmpty(this.songList)) {
  10615. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10616. this.stop();
  10617. this.currentSong = this.songList[this.curIndex]
  10618. this.videoUrl = this.songList[index].filePath;
  10619. this.name = this.songList[index].name
  10620. this.artist = this.songList[this.curIndex].artist
  10621. this.curIndex = index;
  10622. this.changeImageAnimation()
  10623. }
  10624. }
  10625. //上一个
  10626. private playPrevious() {
  10627. if (!this.debounce()) {
  10628. return;
  10629. }
  10630. if (this.playType == 3) { //3:随机播放的上一首应该应该播放历史记录的第二首
  10631. this.randomModePlayFromHistory()
  10632. return;
  10633. }
  10634. if (this.curIndex == 0) {
  10635. this.curIndex = this.songList.length - 1;
  10636. } else {
  10637. this.curIndex--;
  10638. }
  10639. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10640. this.stop();
  10641. this.currentSong = this.songList[this.curIndex]
  10642. this.videoUrl = this.songList[this.curIndex].filePath;
  10643. this.name = this.songList[this.curIndex].name
  10644. this.artist = this.songList[this.curIndex].artist
  10645. this.changeImageAnimation()
  10646. }
  10647. //随机播放模式下点击上一首: 上一首应该应该播放历史记录的第二首
  10648. private randomModePlayFromHistory() {
  10649. if (this.historyList.length >= 2) {
  10650. // 播放历史记录的第二首
  10651. const prevSong = this.historyList[1];
  10652. this.curIndex = this.songList.findIndex(song => song.filePath === prevSong.filePath);
  10653. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10654. this.stop();
  10655. this.currentSong = prevSong;
  10656. this.videoUrl = prevSong.filePath;
  10657. this.cover = prevSong.pixelMapPath
  10658. this.artist = prevSong.artist
  10659. this.name = prevSong.name;
  10660. console.info('onecold startPlayOrResumePlay 11434')
  10661. this.startPlayOrResumePlay();
  10662. } else {
  10663. // 如果历史记录不足两首,可根据需求处理,这里简单按普通逻辑处理
  10664. if (this.curIndex === 0) {
  10665. this.curIndex = this.songList.length - 1;
  10666. } else {
  10667. this.curIndex--;
  10668. }
  10669. this.CONTROL_PlayStatus = PlayStatus.INIT;
  10670. this.stop();
  10671. this.currentSong = this.songList[this.curIndex];
  10672. this.videoUrl = this.songList[this.curIndex].filePath;
  10673. this.artist = this.songList[this.curIndex].artist
  10674. this.name = this.songList[this.curIndex].name;
  10675. this.changeImageAnimation()
  10676. }
  10677. }
  10678. debounce() {
  10679. const delay = 600;
  10680. let cur = new Date().getTime();
  10681. if (cur - this.last > delay) {
  10682. this.last = cur;
  10683. return true;
  10684. }
  10685. return false;
  10686. }
  10687. /**
  10688. * Sets whether the screen is a constant based on the playback status.
  10689. */
  10690. watchStatus() {
  10691. // let windowClass = GlobalContext.getContext().getObject('windowClass') as window.Window;
  10692. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  10693. this.windowClass.setWindowKeepScreenOn(true);
  10694. } else {
  10695. this.windowClass.setWindowKeepScreenOn(false);
  10696. }
  10697. }
  10698. /**
  10699. * Volume gesture method onActionStart.
  10700. *
  10701. * @param event Gesture event.
  10702. */
  10703. private customDialogComponentIdMM: number = 0
  10704. @Builder
  10705. customDialogComponentMM() {
  10706. Column() {
  10707. Row() {
  10708. Blank()
  10709. Text('验证密码')
  10710. .fontSize(22)
  10711. .fontColor($r('app.color.pri_bg'))
  10712. .margin({ top: 18 })
  10713. Blank()
  10714. Image($r('app.media.close'))
  10715. .fillColor(Color.White)
  10716. .margin({ top: 18, right: 18 })
  10717. .width(20)
  10718. .onClick(() => {
  10719. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  10720. })
  10721. }
  10722. .width('100%') // 使Row占据整个宽度
  10723. .justifyContent(FlexAlign.SpaceBetween); // 在Row中创建空间
  10724. Verify({
  10725. onVerifyCompleted: this.handleVerifyCompleted.bind(this)
  10726. });
  10727. }.height('60%')
  10728. .backgroundColor($r('app.color.index_background'))
  10729. .justifyContent(FlexAlign.SpaceBetween)
  10730. }
  10731. private handleVerifyCompleted(isSuccess: boolean) {
  10732. if (isSuccess) {
  10733. console.log('验证成功');
  10734. // 在这里处理验证成功后的逻辑
  10735. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  10736. this.currentPath = this.lockPath
  10737. this.getSortedFiles(this.currentPath)
  10738. } else {
  10739. // console.log('验证失败');
  10740. ToastUtil.showToast('验证失败')
  10741. }
  10742. }
  10743. private showVerifyDialog() {
  10744. promptAction.openCustomDialog({
  10745. transition: TransitionEffect.asymmetric(
  10746. TransitionEffect.OPACITY.animation({ duration: 888 }).combine(
  10747. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  10748. ,
  10749. TransitionEffect.OPACITY.animation({ delay: 888, duration: 888 }).combine(
  10750. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  10751. ),
  10752. builder: () => {
  10753. this.customDialogComponentMM()
  10754. },
  10755. isModal: true,
  10756. autoCancel: true,
  10757. maskColor: Color.Transparent,
  10758. alignment: DialogAlignment.Bottom,
  10759. onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
  10760. console.info("reason" + JSON.stringify(dismissDialogAction.reason))
  10761. console.log("dialog onWillDismiss")
  10762. if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
  10763. dismissDialogAction.dismiss()
  10764. }
  10765. if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
  10766. dismissDialogAction.dismiss()
  10767. }
  10768. }
  10769. }).then((dialogId: number) => {
  10770. this.customDialogComponentIdMM = dialogId
  10771. })
  10772. }
  10773. //左滑操作 移动文件 重命名 删除等操作
  10774. @Builder
  10775. DeleteButton(item: VideoItem, index: number, filePath: string) {
  10776. Row() {
  10777. //加入收藏
  10778. Button() {
  10779. Image(Utility.getIsFav(this.favList, item) ? $r('app.media.add_fac_light2') : $r('app.media.add_fac'))
  10780. .fillColor(Color.White)
  10781. .width(20)
  10782. }
  10783. .width(40)
  10784. .height(40)
  10785. .type(ButtonType.Circle)
  10786. .backgroundColor(this.themeColor)
  10787. .margin(5)
  10788. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10789. .onClick(() => {
  10790. if (item) {
  10791. this.doFav(item)
  10792. }
  10793. })
  10794. //加入下一首播放
  10795. Button() {
  10796. Image($r('app.media.next_to_play'))
  10797. .fillColor(Color.White)
  10798. .width(20)
  10799. }
  10800. .width(40)
  10801. .height(40)
  10802. .type(ButtonType.Circle)
  10803. .backgroundColor(this.themeColor)
  10804. .margin(5)
  10805. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10806. .onClick(() => {
  10807. this.addToNextPlay(item);
  10808. })
  10809. //复制文件
  10810. Button() {
  10811. Image($r('app.media.copy'))
  10812. .fillColor(Color.White)
  10813. .width(20)
  10814. }
  10815. .width(40)
  10816. .height(40)
  10817. .type(ButtonType.Circle)
  10818. .backgroundColor(this.themeColor)
  10819. .margin(5)
  10820. .id(filePath + 'copy')
  10821. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10822. .onClick(() => {
  10823. this.showCopyDialog(false, item, index, filePath + 'copy');
  10824. })
  10825. //移动文件
  10826. Button() {
  10827. Image($r('app.media.cut'))
  10828. .fillColor(Color.White)
  10829. .width(20)
  10830. }
  10831. .width(40)
  10832. .height(40)
  10833. .type(ButtonType.Circle)
  10834. .backgroundColor(this.themeColor)
  10835. .margin(5)
  10836. .id(filePath)
  10837. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10838. .onClick(() => {
  10839. this.showCutDialog(false, item, index, filePath);
  10840. })
  10841. Button() {
  10842. Image($r('app.media.cut_current'))
  10843. .fillColor(Color.White)
  10844. .width(20)
  10845. }
  10846. .width(40)
  10847. .height(40)
  10848. .type(ButtonType.Circle)
  10849. .backgroundColor(this.themeColor)
  10850. .margin(5)
  10851. .id(filePath + 'current')
  10852. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None :
  10853. (this.isHasDir ? Visibility.Visible : Visibility.None))
  10854. .onClick(() => {
  10855. this.showCutDialog(true, item, index, filePath + 'current');
  10856. })
  10857. //重命名
  10858. Button() {
  10859. Image($r('app.media.rename2'))
  10860. .fillColor(Color.White)
  10861. .width(20)
  10862. }
  10863. .width(40)
  10864. .height(40)
  10865. .type(ButtonType.Circle)
  10866. .backgroundColor(this.themeColor)
  10867. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  10868. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  10869. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  10870. .margin(5)
  10871. .onClick(() => {
  10872. this.showReNameDialog(item, index + '', filePath)
  10873. })
  10874. Button() {
  10875. Image($r('app.media.delete2'))
  10876. .fillColor(Color.White)
  10877. .width(20)
  10878. }
  10879. .width(40)
  10880. .height(40)
  10881. .type(ButtonType.Circle)
  10882. .backgroundColor(this.themeColor)
  10883. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  10884. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  10885. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  10886. .margin(5)
  10887. .onClick(() => {
  10888. this.selectedFiles.push(item)
  10889. this.showWarnIsDelete()
  10890. // this.showWarnIsDeleteFile(item, index + '', filePath)
  10891. })
  10892. Button() {
  10893. Image($r('app.media.share2'))
  10894. .fillColor(Color.White)
  10895. .width(20)
  10896. }
  10897. .width(40)
  10898. .height(40)
  10899. .type(ButtonType.Circle)
  10900. .backgroundColor(this.themeColor)
  10901. .margin(5)
  10902. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  10903. .onClick(() => {
  10904. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  10905. })
  10906. }
  10907. }
  10908. /**
  10909. * 穿山甲banner广告
  10910. */
  10911. // private declare bannerAd: CSJNativeExpressAd;
  10912. // @State private status: string = "未加载"
  10913. // @State private isShowAd: boolean = false
  10914. // private declare mAdSlot: AdSlot;
  10915. // private mBiddingAdm = '' //服务端bidding才需要设置
  10916. // private expressLoadAdListener: NativeExpressAdListener = {
  10917. // /**
  10918. // * 加载失败的回调
  10919. // *
  10920. // * @param code
  10921. // * @param message
  10922. // */
  10923. // onError: (code: number, message: string) => {
  10924. // console.error("加载广告失败,code=" + code + ",message=" + message);
  10925. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  10926. // },
  10927. //
  10928. // /**
  10929. // * 广告加载成功的回调,接入方可以在这个回调中进行渲染
  10930. // *
  10931. // * @param ads 返回的广告列表
  10932. // */
  10933. //
  10934. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  10935. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  10936. // if (ads && ads.length > 0) {
  10937. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  10938. // ad.setExpressInteractionListener({
  10939. // /**
  10940. // *广告的点击回调
  10941. // * @param type 广告的交互类型
  10942. // */
  10943. // onAdClicked: (type: number) => {
  10944. // console.log("BannerExpressAdPage==onAdClicked......");
  10945. // },
  10946. //
  10947. // /**
  10948. // * 广告的展示回调 每个广告仅回调一次
  10949. // * @param type 广告的交互类型
  10950. // */
  10951. // onAdShow: (type: number) => {
  10952. // console.log("BannerExpressAdPage==onAdShow......");
  10953. // },
  10954. //
  10955. // /**
  10956. // * 模板渲染失败
  10957. // */
  10958. // onRenderFail: (code: number, msg: string) => {
  10959. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  10960. // },
  10961. //
  10962. // /**
  10963. // * 模板渲染成功
  10964. // * @param width 返回view的宽 单位 vp
  10965. // * @param height 返回view的高 单位 vp
  10966. // */
  10967. // onRenderSuccess: (width: number, height: number) => {
  10968. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  10969. // this.bannerAd = ad;
  10970. // this.status = "广告加载完成待展示";
  10971. //
  10972. // this.showBannerAd()
  10973. // }
  10974. // })
  10975. // //渲染广告
  10976. // ad.setSlideIntervalTime(30 * 1000); //设置轮播时间长
  10977. // this.setDislikeCallback(ad); //设置dislike
  10978. // ad.render(this.getUIContext())
  10979. // this.status = "广告加载中...";
  10980. // });
  10981. // }
  10982. // }
  10983. // }
  10984. //
  10985. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  10986. // ad.setDislikeCallback({
  10987. // /**
  10988. // * dislike show
  10989. // */
  10990. // onShow: () => {
  10991. // console.log("BannerExpressAdPage==dislike......show");
  10992. // },
  10993. //
  10994. // /**
  10995. // * @param position 选择的位置
  10996. // * @param value 选择的内容
  10997. // * @param enforceRemove 是否强制关闭广告
  10998. // */
  10999. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  11000. // this.isShowAd = false;
  11001. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value +
  11002. // ",enforce=" + enforceRemove);
  11003. // },
  11004. //
  11005. // /**
  11006. // * 点击取消
  11007. // */
  11008. // onCancel: () => {
  11009. // console.log("BannerExpressAdPage==dislike......onCancel");
  11010. // }
  11011. //
  11012. // })
  11013. // }
  11014. /**
  11015. * 加载Banner广告
  11016. */
  11017. loadBannerAd(rit: string) {
  11018. // if (Utility.isNoble()) {
  11019. // return
  11020. // }
  11021. // if (!Utility.isPassInstallTime(2)) {
  11022. // return
  11023. // }
  11024. // this.isShowAd = false;
  11025. // let adCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
  11026. // this.mAdSlot = new AdSlotBuilder()
  11027. // .setCodeId(rit)
  11028. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  11029. // .setAdCount(1)
  11030. // .setBidAdm(this.mBiddingAdm)
  11031. // .build()
  11032. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  11033. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  11034. // this.status = "广告加载中..."
  11035. }
  11036. /**
  11037. * 展示Banner广告
  11038. */
  11039. // showBannerAd() {
  11040. // if (!this.bannerAd) {
  11041. // return
  11042. // }
  11043. // this.isShowAd = true
  11044. // this.status = "已展示"
  11045. // }
  11046. /**
  11047. * 穿山甲广告代码结束
  11048. */
  11049. }
  11050. //视频气泡窗口的布局
  11051. @Builder
  11052. function customPopupBuilder(dataBu: BubbleBean) {
  11053. List() {
  11054. LazyForEach(new LazyDataSource(dataBu.data), (item: string, index: number) => {
  11055. ListItem() {
  11056. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  11057. Row() {
  11058. Column() {
  11059. Image(dataBu.imageRes[index])
  11060. .height(28)
  11061. .fillColor(dataBu.color)
  11062. .alignSelf(ItemAlign.Center)
  11063. }
  11064. .width(32)
  11065. Text(item)
  11066. .padding({
  11067. top: 10,
  11068. bottom: 10,
  11069. right: 10,
  11070. left: 10
  11071. })
  11072. .fontColor(dataBu.modeType == index ? dataBu.color : $r('app.color.index_tab_font_color'))
  11073. .textAlign(TextAlign.Start)
  11074. .width("100%")
  11075. }
  11076. }
  11077. .backgroundColor($r('app.color.settings_background_main'))
  11078. .margin({ top: 6, bottom: 6 })
  11079. }
  11080. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  11081. .animation({ duration: 500, curve: Curve.Ease, delay: 100 * index }),
  11082. TransitionEffect.scale({ x: 0, y: 0 })))
  11083. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  11084. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  11085. .onClick(() => {
  11086. dataBu.onItemClick?.(index)
  11087. })
  11088. })
  11089. }
  11090. .width(120)
  11091. .divider({
  11092. strokeWidth: 1,
  11093. color: "#22FFFFFF"
  11094. })
  11095. }
  11096. // Function to calculate a hash for the file list
  11097. function simpleHash(fileList: string[]): string {
  11098. let hash = 0;
  11099. const str = fileList.join(',');
  11100. for (let i = 0; i < str.length; i++) {
  11101. const char = str.charCodeAt(i);
  11102. hash = (hash << 5) - hash + char;
  11103. hash |= 0; // Convert to 32bit integer
  11104. }
  11105. return hash.toString();
  11106. }
  11107. interface MoreItem {
  11108. id: number;
  11109. image: Resource;
  11110. title: string;
  11111. }
  11112. //视频气泡窗口的布局
  11113. @Builder
  11114. function cutPopupBuilder(dataBu: BubbleBean) {
  11115. Column() {
  11116. Text(dataBu.isCopy ? '将文件复制到' : '将文件移动到')
  11117. .padding({
  11118. top: 10,
  11119. bottom: 10,
  11120. right: 10,
  11121. left: 10
  11122. })
  11123. .textAlign(TextAlign.Start)
  11124. .width(160)
  11125. .fontWeight(666)
  11126. .fontSize(16)
  11127. List() {
  11128. ForEach(dataBu.data, (item: string, index: number) => {
  11129. ListItem() {
  11130. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  11131. Row() {
  11132. Column() {
  11133. Image($r('app.media.music_group'))
  11134. .height(28)
  11135. .fillColor(dataBu.color)
  11136. .alignSelf(ItemAlign.Center)
  11137. }
  11138. .width(32)
  11139. Text(item.startsWith('.') ? item.replace(/\./g, '') : item)
  11140. .padding({
  11141. top: 10,
  11142. bottom: 10,
  11143. right: 10,
  11144. left: 10
  11145. })
  11146. .textAlign(TextAlign.Start).width("100%")// .fontColor(Color.Gray)
  11147. .fontSize(15)
  11148. }
  11149. }
  11150. .backgroundColor(Color.Transparent)
  11151. .margin({ top: 7, bottom: 7 })
  11152. }
  11153. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  11154. .animation({ duration: 500 }),
  11155. TransitionEffect.scale({ x: 0, y: 0 })))
  11156. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  11157. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  11158. .onClick(() => {
  11159. dataBu.onItemClick?.(index)
  11160. })
  11161. })
  11162. }
  11163. .width(150)
  11164. .divider({
  11165. strokeWidth: 1,
  11166. color: "#22FFFFFF"
  11167. })
  11168. }
  11169. .height(300)
  11170. .padding({
  11171. bottom: 30
  11172. })
  11173. }
  11174. function getFileDirName(filePath: string,rootPath:string): string{
  11175. if(filePath===rootPath){
  11176. return '首页'
  11177. }
  11178. let result = FileUtil.getFileName(filePath)
  11179. if(StrUtil.isEmpty(result))
  11180. return ''
  11181. if(result.startsWith('.'))
  11182. result = result.replace(/\./g, '')
  11183. return result
  11184. }