LocalMusic.ets 388 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446
  1. import TitleBar from './TitleBar'
  2. import { curves, display, PiPWindow, promptAction, router, SymbolGlyphModifier, window } from '@kit.ArkUI';
  3. import { VideoItem } from '../viewmodel/VideoItem';
  4. import {
  5. AppUtil,
  6. ArrayUtil,
  7. Base64Util,
  8. DateUtil,
  9. DeviceUtil,
  10. DisplayUtil,
  11. FileUtil,
  12. ImageUtil,
  13. LogUtil,
  14. MD5,
  15. PreferencesUtil,
  16. RandomUtil,
  17. StrUtil,
  18. ToastUtil
  19. } from '@pura/harmony-utils';
  20. import { unifiedDataChannel, uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
  21. import { CommonConstants } from '../common/constants/CommonConstants';
  22. import Logger from '../common/util/Logger';
  23. import { photoAccessHelper } from '@kit.MediaLibraryKit';
  24. import { Utility } from '../common/util/Utility';
  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 {
  40. // DeviceChangeReason,
  41. IjkMediaPlayer,
  42. InterruptEvent,
  43. InterruptHintType,
  44. LogUtils,
  45. OnBufferingUpdateListener,
  46. OnCompletionListener,
  47. OnErrorListener,
  48. OnInfoListener,
  49. OnPreparedListener,
  50. OnSeekCompleteListener,
  51. OnTimedTextListener,
  52. OnVideoSizeChangedListener
  53. } from '@ohos/ijkplayer';
  54. import { PlayStatus } from '../common/PlayStatus';
  55. import fs from '@ohos.file.fs';
  56. import { image } from '@kit.ImageKit';
  57. import { AVCastPicker, AVCastPickerState, AVCastPickerStyle, avSession } from '@kit.AVSessionKit';
  58. import { UniversalDetector } from '@ohos/juniversalchardet';
  59. import { SettingPage } from '../pages/SettingPage';
  60. import { secondToTime } from '../common/util/CommUtils';
  61. import { CommonConstants2 } from '../common/util/CommonConstants2';
  62. import { hilog } from '@kit.PerformanceAnalysisKit';
  63. import { LazyDataSource } from '../common/util/LazyDataSource';
  64. import MediaTable from '../common/util/MediaTable';
  65. import NetAxiosUtil from '../common/util/NetAxiosUtil';
  66. import ImageUtils from '../common/util/ImageUtils';
  67. import { ringtone } from '@kit.RingtoneKit';
  68. import { BreakpointType, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
  69. import { resourceManager } from '@kit.LocalizationKit';
  70. import { deviceInfo } from '@kit.BasicServicesKit';
  71. import { HSBColorPicker, HSBColorPickerLayout } from '@keke/color-picker'
  72. import app from '@system.app';
  73. import { TextNodeController } from './PipLyricTextBuilder';
  74. import { IndexerView } from './IndexerView';
  75. import { KeyCode } from '@kit.InputKit';
  76. import { KnockController } from '../controller/KnockController';
  77. // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
  78. const TAG = 'LocalMusic';
  79. const DEFAULT_INDEX =
  80. ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  81. 'X', 'Y', 'Z']
  82. //排序类型
  83. function getTypeOrder(type: number) {
  84. switch (type) {
  85. case CommonConstants.TYPE_IS_DIR:
  86. return 1; // First
  87. case CommonConstants.TYPE_IS_CSJAD:
  88. return 2; // Middle
  89. case CommonConstants.TYPE_LOCAL:
  90. return 3; // Last
  91. default:
  92. return 4; // Unknown types, if any, go last
  93. }
  94. }
  95. const workerInstance = new worker.ThreadWorker("entry/ets/workers/Worker.ets");
  96. // 定义接口
  97. interface HiCarAspectRatio {
  98. ratio: number;
  99. name: string;
  100. }
  101. interface GeneratedObjectLiteralInterface_1 {
  102. assetId: string;
  103. title: string;
  104. artist: string;
  105. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  106. mediaUri: string;
  107. // 该字段大写,音频'AUDIO',视频'VIDEO'
  108. mediaType: string;
  109. mediaSize: number;
  110. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  111. startPosition: number;
  112. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  113. duration: number;
  114. albumCoverUri: string;
  115. albumTitle: string;
  116. appName: string;
  117. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  118. drmScheme: string;
  119. }
  120. const ITEM_HEIGHT_SMALL: number = 48; // 列表项小高度
  121. const ITEM_HEIGHT: number = 58; // 列表项中高度
  122. const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
  123. //功能强大的音乐播放器
  124. @Preview
  125. @Component
  126. export struct LocalMusic {
  127. @State opacityValueImage: number = 1;
  128. @State tipPopup:boolean = false
  129. @Consume mType: number;
  130. @StorageProp('themeColor') themeColor: string =
  131. PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  132. themeMode: number = 0;
  133. @State titleName: string = '首页'
  134. @State textStr: string = ''
  135. // static readonly STR_MUSIC_VIDEO: string = 'Audios';
  136. // private download_path: string = '';
  137. @Consume rootPath: string //音频根目录
  138. @Consume currentPath: string
  139. static readonly STR_LOCK_VIDEO: string = '.私密音频';
  140. static readonly STR_FAC_VIDEO: string = '.我的收藏';
  141. @State lockPath: string = ''
  142. @State favPath: string = ''
  143. static readonly STR_HISTORY_MUSIC: string = '.最近播放';
  144. @State historyPath: string = ''
  145. @State historyList: Array<VideoItem> = []
  146. @Consume isHistory: boolean
  147. static readonly HISTORY_MUSIC: string = 'music_historyList';
  148. private table: MediaTable = new MediaTable(getContext(this))
  149. @State isZero: boolean = false
  150. @State fileList: Array<string> = []
  151. @State dirList: Array<VideoItem> = []
  152. @Consume videoLocalList: Array<VideoItem>
  153. @State dataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.videoLocalList)
  154. @State mediaKuList: Array<VideoItem> = []; //媒体库文件
  155. @State artistList: Array<VideoItem> = []; //艺术家文件
  156. @State artistMap: Map<string, VideoItem[]> = new Map(); //艺术家Map
  157. @State albumList: Array<VideoItem> = []; //专辑文件
  158. @State albumMap: Map<string, VideoItem[]> = new Map(); //专辑Map
  159. private mScrollMap: Map<string, number> = new Map(); // 艺术家、专辑名->滚动index
  160. @State imageOpacities: number[] = [];
  161. @Consume isCanBack: boolean
  162. @Consume @Watch('onModeChange') modeType: number; // 0首页,1媒体库,2艺术家,3专辑
  163. @State showSingleLyric: boolean = false
  164. @State sortType: number = 4 //默认排序方式
  165. @State isShowSimi: boolean = false //是否显示私密音频
  166. @State isShowFAV: boolean = true //是否显示我的收藏
  167. @State isShowTitleBar: boolean = true //是否显示分类导航条
  168. @State isShowAllBar: boolean = true //是否显示播放全部条
  169. @State isShowHistory: boolean = true //是否显示最近播放
  170. @State isCustomizeBg: boolean = false //自定义背景界面
  171. @State isGridMusic: boolean = false //是否网格布局
  172. @State isCircleBtn: boolean = false //是否圆形播放按钮
  173. @State twoFingerType: number = 3 //双支放大缩小的类型
  174. @State isScrollHide: boolean = false //是否滚动隐藏
  175. @State isSameTimePlay: boolean = false //是否和其他app同时播放
  176. @State isStartAutoPlay: boolean = false //启动后自动播放
  177. @State isShowPlayPageBack: boolean = false //是否显示播放页返回键
  178. @State isShowHeader: boolean = true
  179. @State isPlayListBgGrass: boolean = true //是否播放列表玻璃透明效果
  180. @State isShowSingleLineLyric: boolean = false //是否显示播放页返回键
  181. @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
  182. @State isCoverTopBig: boolean = false //顶部大封面部分手机显示会和播放控制页重叠
  183. @State isSwipe: boolean = false //listItem的左滑开关
  184. @State openSkipSongAnimate: boolean = true//切歌动画效果
  185. @State customizeBgPath: string | undefined = '';
  186. @State isDarkMode: boolean = false
  187. @State lyricTextWeight: number = 400
  188. @State lyricTextWeightPip: number = 400
  189. @State currentSwiperIndex: number = 0
  190. @State blurValue: number = 0 //背景模糊
  191. @State bgBrightness: number = 0 //背景亮度
  192. private listScroller: ListScroller = new ListScroller()
  193. private playListScroller: Scroller = new Scroller()
  194. @StorageProp('isLandscape') isLandscape: boolean = false;
  195. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  196. @StorageProp('windowWidth') windowWidth: number = 0;
  197. @StorageProp('windowHeight') windowHeight: number = 0;
  198. @StorageProp('isHiCarStatus') isHiCarStatus: boolean = false;
  199. @StorageProp('curDisplayIsHiCar') curDisplayIsHiCar: boolean = false;
  200. private UNKONWN:string = '';
  201. private listArea: Area = {
  202. width: 0,
  203. height: 0,
  204. position: {},
  205. globalPosition: {}
  206. }
  207. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  208. ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET;
  209. onColorModeChange() {
  210. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  211. if (this.isCustomizeBg) {
  212. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  213. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  214. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  215. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  216. } else {
  217. if (!this.isDarkMode) {
  218. this.titleBarModel.setTitleBarBackground(this.themeColor)
  219. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  220. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  221. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  222. } else {
  223. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  224. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  225. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  226. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  227. }
  228. }
  229. }
  230. onModeChange() {
  231. this.isFavMusic = false
  232. if (this.modeType === 2 || this.modeType === 3) {
  233. this.titleBarModel.setRightIcon(null)
  234. } else {
  235. this.titleBarModel.setRightIcon(($r('app.media.add')))
  236. }
  237. LogUtil.info('onecold onModeChange = ' + this.modeType)
  238. switch (this.modeType) {
  239. case 0:
  240. this.getSortedFiles(this.currentPath)
  241. break
  242. case 1:
  243. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  244. this.updateListData(this.mediaKuList)
  245. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  246. break
  247. case 2:
  248. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  249. this.updateListData(this.artistList)
  250. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  251. break
  252. case 3:
  253. this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
  254. this.updateListData(this.albumList)
  255. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  256. break
  257. }
  258. }
  259. @StorageLink('currentSong') currentSong: VideoItem | undefined = undefined;
  260. // @StorageLink('isPlay') isPlay: boolean = false;
  261. @StorageLink('isShowPlay') isShowPlay: boolean = false;
  262. @StorageLink('songList') songList: Array<VideoItem> = [];
  263. @State translateY: number = 0;
  264. @State isShowSheet: boolean = false;
  265. @State isShowSheetView: boolean = false;
  266. @State isShowTimeCloseView: boolean = false;
  267. private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Vertical });
  268. @StorageLink('currIndex') curIndex: number = 0;
  269. @Consume isShowDrawer: boolean;
  270. @Consume offsetX: number;
  271. @State isFac: boolean = false;
  272. @State favList: Array<VideoItem> = []
  273. @Consume isFavMusic: boolean
  274. @State isClickedPLayAll: boolean = false;
  275. private scrollerForlist: ListScroller = new ListScroller();
  276. private knockController: KnockController | undefined = undefined;
  277. imagesF: ImageFrameInfo[] = [
  278. { src: $r("app.media.app_loading0") },
  279. { src: $r("app.media.app_loading1") },
  280. { src: $r("app.media.app_loading2") },
  281. { src: $r("app.media.app_loading3") },
  282. ]
  283. @State animationState: AnimationStatus = AnimationStatus.Initial
  284. // 缓存机制
  285. private cache: Map<string, Array<VideoItem>> = new Map();
  286. private stringCache: Map<string, string> = new Map(); // 新增字符串缓存
  287. // 持久化缓存
  288. private async saveCacheToStorage() {
  289. const cacheArray = Array.from(this.cache.entries());
  290. const stringCacheArray = Array.from(this.stringCache.entries());
  291. await PreferencesUtil.putSync('music_cache', JSON.stringify(cacheArray));
  292. await PreferencesUtil.putSync('music_string_cache', JSON.stringify(stringCacheArray));
  293. }
  294. // 载入缓存
  295. private async loadCacheFromStorage() {
  296. const cacheString = await PreferencesUtil.getStringSync('music_cache', '');
  297. const stringCacheString = await PreferencesUtil.getStringSync('music_string_cache', ''); // 载入字符串缓存
  298. if (cacheString) {
  299. const cacheArray: [string, Array<VideoItem>][] = JSON.parse(cacheString);
  300. this.cache = new Map(cacheArray);
  301. }
  302. if (stringCacheString) {
  303. const stringCacheArray: [string, string][] = JSON.parse(stringCacheString);
  304. this.stringCache = new Map(stringCacheArray);
  305. }
  306. }
  307. // 查找缓存
  308. private findCache(key: string): Array<VideoItem> | undefined {
  309. return this.cache.get(key);
  310. }
  311. // 查找字符串缓存
  312. private findStringCache(key: string): string | undefined {
  313. return this.stringCache.get(key);
  314. }
  315. // 添加缓存
  316. private addCache(key: string, value: Array<VideoItem>) {
  317. this.cache.set(key, value);
  318. }
  319. // 添加字符串缓存
  320. private addStringCache(key: string, value: string) {
  321. this.stringCache.set(key, value);
  322. }
  323. // 删除缓存
  324. private deleteCache(key: string) {
  325. this.cache.delete(key);
  326. this.saveCacheToStorage()
  327. }
  328. // 删除字符串缓存
  329. private deleteStringCache(key: string) {
  330. this.stringCache.delete(key);
  331. }
  332. // 多选机制
  333. @State selectedFiles: Array<VideoItem> = [];
  334. @State isMultiSelect: boolean = false;
  335. @State isAllSelected: boolean = false;
  336. @State appName: string = ''
  337. @State isHasDir: boolean = false
  338. @State packName: string = ''
  339. context = this.getUIContext().getHostContext() as common.UIAbilityContext
  340. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  341. .setTitleTextStyle(FontStyle.Normal)
  342. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  343. .setLeftIcon($r('app.media.menu'))
  344. .setLeftIconWidth(26)
  345. .setLeftIconHeight(26)
  346. .setTitleName('首页')
  347. .setTitleFontSize(18)
  348. .setTitleFontColor(Color.White)
  349. .setTitleBarBackground(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  350. .setTitleBarBottomLineColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  351. .setLeftTitleStateNormalStyleColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  352. .setRightIcon($r('app.media.add'))
  353. .setOnRightClickListener(() => {
  354. this.showSheelDialog()
  355. })
  356. // .setOnTitleClickListener(() => {
  357. // this.showPupDialog()
  358. // })
  359. .setOnLeftClickListener(() => {
  360. this.doSwipBack()
  361. })
  362. doSwipBack() {
  363. if (this.modeType !== 0 && this.isCanBack) {
  364. this.onModeChange()
  365. this.isCanBack = false
  366. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  367. // 返回专辑列表时恢复滚动偏移量,支持列表和网格
  368. setTimeout(() => {
  369. if (this.modeType == 2) {
  370. if (this.isGridMusic) {
  371. let lastOffset = this.mScrollMap.get('lastGridArtistScrollOffset') ?? 0
  372. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  373. } else {
  374. let lastOffset = this.mScrollMap.get('lastListArtistScrollOffset') ?? 0
  375. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  376. }
  377. } else if (this.modeType == 3) {
  378. if (this.isGridMusic) {
  379. let lastOffset = this.mScrollMap.get('lastGridAlBumScrollOffset') ?? 0
  380. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  381. } else {
  382. let lastOffset = this.mScrollMap.get('lastListAlBumScrollOffset') ?? 0
  383. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  384. }
  385. }
  386. }, 200)
  387. return
  388. }
  389. if (this.isHistory || this.isFavMusic) {
  390. this.isHistory = false
  391. this.getSortedFiles(this.currentPath)
  392. return
  393. }
  394. if (this.currentPath === this.rootPath || this.modeType !== 0) {
  395. animateTo({ duration: 555 }, () => {
  396. // 动画闭包内控制Image组件的出现和消失
  397. this.isShowDrawer = !this.isShowDrawer
  398. this.offsetX = 0
  399. })
  400. return
  401. }
  402. //返回上一级歌单的滚动位置
  403. setTimeout(() => {
  404. if (this.modeType == 0) {
  405. if (this.isGridMusic) {
  406. let lastOffset = this.mScrollMap.get('lastGridDirScrollOffset') ?? 0
  407. this.scroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  408. } else {
  409. let lastOffset = this.mScrollMap.get('lastListDirScrollOffset') ?? 0
  410. this.listScroller.scrollTo({ xOffset: 0, yOffset: lastOffset })
  411. }
  412. }
  413. }, 300)
  414. this.currentPath = Utility.getParentDirectory(this.currentPath)
  415. Logger.info('this.currentPath2 = ' + this.currentPath)
  416. this.getSortedFiles(this.currentPath)
  417. }
  418. // 组件生命周期
  419. aboutToAppear() {
  420. if(PreferencesUtil.getBooleanSync('isFirstTiped',true)){
  421. this.tipPopup = !this.tipPopup
  422. PreferencesUtil.putSync('isFirstTiped',false)
  423. }
  424. this.initSetting()
  425. this.UNKONWN = Utility.resourceToString(this.context, $r('app.string.unknown'));
  426. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  427. Utility.getAppName(getContext(this)).then((appName: string) => {
  428. this.appName = appName
  429. })
  430. this.packName = AppUtil.getBundleName()
  431. this.loadCacheFromStorage(); // 加载缓存
  432. this.mkDownLoadDir()
  433. let eventMusic: emitter.InnerEvent = { eventId: 2 }
  434. // 监听广播事件(打开其他应用处理)
  435. emitter.on(eventMusic, (eventData: emitter.EventData) => {
  436. this.saveVideoDatas([eventData.data?.message], true)
  437. });
  438. //侧滑广播接收时间
  439. let eventUpdateSwipeBack: emitter.InnerEvent = { eventId: 888 }
  440. // 监听广播事件(打开其他应用处理)
  441. emitter.on(eventUpdateSwipeBack, (eventData: emitter.EventData) => {
  442. animateTo({ duration: 555 }, () => {
  443. this.doSwipBack()
  444. })
  445. });
  446. //ScanFilePage广播接收时间
  447. let eventScanUpdate: emitter.InnerEvent = { eventId: 101 }
  448. // 监听ScanFilePage广播事件(更新数据库)
  449. emitter.on(eventScanUpdate, (eventData: emitter.EventData) => {
  450. this.doUpdateData()
  451. });
  452. let eventSetting: emitter.InnerEvent = { eventId: 333 }
  453. // 监听广播事件(通用设置配置更新)
  454. emitter.on(eventSetting, (eventData: emitter.EventData) => {
  455. this.doChangeSetting()
  456. });
  457. let event: Callback<InterruptEvent> = (event) => {
  458. LogUtils.getInstance().LOGI(`onecold 与其他应用音频冲突 被截断点event: ${JSON.stringify(event)}`);
  459. this.savePlaybackPosition()
  460. if (event.hintType === InterruptHintType.INTERRUPT_HINT_PAUSE) {
  461. this.pause();
  462. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_RESUME) {
  463. this.startPlayOrResumePlay();
  464. } else if (event.hintType === InterruptHintType.INTERRUPT_HINT_STOP) {
  465. this.stop();
  466. }
  467. }
  468. this.mIjkMediaPlayer.on('audioInterrupt', event);
  469. // 音频设备断连回调处理
  470. // let deviceChangeEvent: Callback<InterruptEvent> = (event) => {
  471. // LogUtils.getInstance().LOGI(`Heanup deviceChange event: ${JSON.stringify(event)}`);
  472. // if (event.reason === DeviceChangeReason.REASON_OLD_DEVICE_UNAVAILABLE) { // 音频设备断开连接
  473. // this.pause();
  474. // }
  475. // }
  476. // this.mIjkMediaPlayer.on('deviceChange', deviceChangeEvent);
  477. this.makeWorker()
  478. //折叠屏的屏幕显示模式变化
  479. display.on('foldDisplayModeChange', (data) => {
  480. this.doChangeBarHeight()
  481. });
  482. display.on('foldStatusChange', (data) => {
  483. Logger.info('onecold foldStatusChange ')
  484. });
  485. this.isCoverRectangle = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_RECTANGLE, true)
  486. // 读取 themeMode 并同步 currentColorMode
  487. this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
  488. this.applyThemeMode(this.themeMode)
  489. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  490. AppStorage.setOrCreate('themeColor', themeColor);
  491. this.themeColor = themeColor;
  492. this.doChangeSetting()
  493. this.windowClass.on('windowSizeChange', (size) => {
  494. LogUtil.info('onecold windowSizeChange')
  495. this.doChangeBarHeight()
  496. let viewWidth = px2vp(size.width);
  497. let viewHeight = px2vp(size.height);
  498. if(this.isPhoneLan()){
  499. this.is_auto_hide_progress = false
  500. if(this.isHiCar()){
  501. return
  502. }
  503. setTimeout(() => {
  504. this.is_auto_hide_progress = true
  505. }, 6000)
  506. }else{
  507. this.startAutoHide()
  508. }
  509. });
  510. this.eventHub.on('onStateChange', (fg: boolean) => {
  511. if (fg && this.curState === 'STARTED') {
  512. this.stopPip();
  513. }
  514. });
  515. }
  516. startAutoHide() {
  517. if(this.isHiCar()){
  518. return
  519. }
  520. if(PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_HIDE_PROGRESS,false)){
  521. console.info('onecold startAutoHide')
  522. this.is_auto_hide_progress = false
  523. setTimeout(() => {
  524. this.is_auto_hide_progress = true
  525. }, 6000)
  526. }
  527. }
  528. applyThemeMode(mode: number) {
  529. let colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET
  530. if (mode === 1) {
  531. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
  532. } else if (mode === 2) {
  533. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  534. }
  535. AppStorage.setOrCreate('currentColorMode', colorMode)
  536. AppStorage.setOrCreate('isDarkMode', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK)
  537. PreferencesUtil.putSync(SettingPage.THEME_MODE, mode)
  538. AppStorage.setOrCreate('themeMode', mode)
  539. this.isDarkMode = colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  540. // 只有强制浅色/深色时才主动设置
  541. const context = getContext(this) as common.UIAbilityContext
  542. context.getApplicationContext().setColorMode(colorMode)
  543. }
  544. initSetting() {
  545. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  546. this.isCustomizeBg = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
  547. this.customizeBgPath = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
  548. this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, true)
  549. this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
  550. this.isSameTimePlay = PreferencesUtil.getBooleanSync(SettingPage.IS_SAMETIME_PLAY, false)
  551. this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
  552. this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
  553. this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
  554. this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
  555. this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
  556. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
  557. this.isShowAllBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_ALLBAR, true)
  558. this.twoFingerType = PreferencesUtil.getNumberSync(SettingPage.TWO_FINGER_TYPE, 3)
  559. this.isCoverTop = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP, false)
  560. this.isCircleBtn = PreferencesUtil.getBooleanSync(SettingPage.IS_CIRCLE_BTN, true)
  561. this.isShowPlayPageBack = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_PLAYPAGE_BACK, true)
  562. this.isCoverTopBig = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP_BIG, false)
  563. this.isShowSingleLineLyric = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SLLYRIC, false)
  564. this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
  565. this.isPlayListBgGrass = PreferencesUtil.getBooleanSync(SettingPage.IS_PLAYLIST_BG_GRASS, true)
  566. this.isShowHeader = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HEADER, true)
  567. this.volume = PreferencesUtil.getNumberSync('DefalutVolume', this.volume)
  568. this.isSwipe = PreferencesUtil.getBooleanSync(SettingPage.IS_SWIPE, true)
  569. this.openSkipSongAnimate = PreferencesUtil.getBooleanSync(SettingPage.OPEN_SKIPSONG_ANIMATE, true)
  570. //如果是hicar连接状态,这些都是false
  571. if(this.isHiCar()){
  572. this.isShowTitleBar = false//不显示导航栏
  573. if(!(this.windowWidth>1800&&this.windowHeight>=1200))//小屏幕不可以Grid
  574. {
  575. this.isShowHeader = false//二级菜单不显示头部
  576. this.isGridMusic= false//用list不用网格
  577. this.isCoverTopBig = false
  578. }
  579. this.isShowPlayPageBack = true //播放页返回键要显示,方便驾驶员操作
  580. }
  581. if (this.isSavePlayMode) {
  582. this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
  583. }
  584. if (this.isCustomizeBg) {
  585. this.titleBarModel.setRightTitleStateNormalStyleColor(Color.Transparent)
  586. this.titleBarModel.setTitleBarBackground(Color.Transparent)
  587. this.titleBarModel.setTitleBarBottomLineColor(Color.Transparent)
  588. this.titleBarModel.setLeftTitleStateNormalStyleColor(Color.Transparent)
  589. } else {
  590. if (!this.isDarkMode) {
  591. this.titleBarModel.setTitleBarBackground(this.themeColor)
  592. this.titleBarModel.setTitleBarBottomLineColor(this.themeColor)
  593. this.titleBarModel.setRightTitleStateNormalStyleColor(this.themeColor)
  594. this.titleBarModel.setLeftTitleStateNormalStyleColor(this.themeColor)
  595. } else {
  596. this.titleBarModel.setTitleBarBackground($r('app.color.title_bar_bg'))
  597. this.titleBarModel.setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  598. this.titleBarModel.setRightTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  599. this.titleBarModel.setLeftTitleStateNormalStyleColor($r('app.color.title_bar_bg'))
  600. }
  601. }
  602. }
  603. doChangeSetting() {
  604. this.initSetting()
  605. this.deleteCache(this.currentPath)
  606. if (this.modeType === 0) {
  607. this.getSortedFiles(this.currentPath)
  608. }
  609. }
  610. doChangeBarHeight() {
  611. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  612. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  613. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  614. this.setBarHeightNormal()
  615. }
  616. }
  617. onPageShow() {
  618. this.knockController?.immersiveListening();
  619. app.setImageCacheCount(100);
  620. // 设置解码前图片数据内存缓存上限为100MB (100MB=100*1024*1024B=104857600B)
  621. app.setImageRawDataCacheSize(104857600);
  622. Logger.info('onecold onPageShow currentBreakpoint= ' + this.currentBreakpoint)
  623. }
  624. //开启线程查看各个数据库
  625. makeWorker() {
  626. setTimeout(() => {
  627. if (PreferencesUtil.getBooleanSync('isFirstApp', true)) {
  628. ToastUtil.showToast('请到文件扫描页面导入音乐!')
  629. //发送worker通知扫描文件入库,用户反馈4000多首用这个方法扫描会闪退。
  630. // workerInstance.postMessage({
  631. // code: 1,
  632. // data1: this.context,
  633. // data2: this.rootPath,
  634. // data3: this.lockPath,
  635. // data4: PreferencesUtil.getStringSync('COVER_API', ''),
  636. // });
  637. PreferencesUtil.putSync('isFirstApp', false)
  638. } else {
  639. workerInstance.postMessage({ code: 2, data: this.context });
  640. workerInstance.postMessage({ code: 3, data: this.context });
  641. workerInstance.postMessage({ code: 4, data: this.context });
  642. this.getHistoryList(false)
  643. }
  644. }, 1000)
  645. workerInstance.onmessage = (e: MessageEvents): void => {
  646. switch (e.data.code) {
  647. case 101: //第一次扫描文件夹入库
  648. ToastUtil.showToast('刷新同步数据库成功!')
  649. Logger.info('onecold 扫描数据库结束 this.mediaKuList length= ' + this.mediaKuList.length)
  650. this.doUpdateData()
  651. break;
  652. case 102: //查询媒体库列表
  653. this.mediaKuList = e.data.data
  654. Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
  655. Utility.doSortListAscending(this.mediaKuList)
  656. AppStorage.setOrCreate('mediaKuList', this.mediaKuList);
  657. if (this.modeType === 1) {
  658. this.updateListData(this.mediaKuList)
  659. }
  660. break;
  661. case 103: //收到查询艺术家列表
  662. this.artistMap = e.data.data1;
  663. this.artistList = e.data.data2;
  664. break;
  665. case 104: //收到查询专辑列表
  666. this.albumMap = e.data.data1;
  667. this.albumList = e.data.data2
  668. //查询完毕在启动是否自动播放
  669. if (this.isStartAutoPlay) {
  670. this.startPlayOrResumePlay()
  671. }
  672. break;
  673. }
  674. };
  675. // 在调用terminate后,执行onexit
  676. workerInstance.onexit = (code) => {
  677. console.log("main thread terminate");
  678. }
  679. //若Worker处于已销毁或正在销毁等非运行状态时,调用其功能接口,会抛出相应的错误。
  680. // 使用Worker模块时,需要在主线程中注册onerror接口,否则当worker线程出现异常时会发生jscrash问题。
  681. workerInstance.onerror = (err: ErrorEvent) => {
  682. console.log("onerror" + err.message);
  683. }
  684. // let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  685. //碰一碰分享的监听
  686. this.knockController = KnockController.getInstance(this.context);
  687. this.knockController?.immersiveListening();
  688. }
  689. onPageHide(): void {
  690. this.knockController?.immersiveDisableListening();
  691. }
  692. @State isFirstStartPlay: boolean = false
  693. //获取download_path
  694. async mkDownLoadDir() {
  695. const documentViewPicker = new picker.DocumentViewPicker()
  696. let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
  697. this.rootPath = new fileUri.FileUri(documentSaveResult[0]).path
  698. // this.rootPath = this.download_path
  699. this.lockPath = this.rootPath + '/' + LocalMusic.STR_LOCK_VIDEO
  700. this.favPath = this.rootPath + '/' + LocalMusic.STR_FAC_VIDEO
  701. this.historyPath = this.rootPath + '/' + LocalMusic.STR_HISTORY_MUSIC
  702. Logger.info('onecold rootPath = ' + this.rootPath)
  703. Logger.info('onecold lockPath = ' + this.lockPath)
  704. if (!FileUtil.accessSync(this.lockPath)) {
  705. FileUtil.mkdirSync(this.lockPath)
  706. }
  707. if (!FileUtil.accessSync(this.favPath)) {
  708. FileUtil.mkdirSync(this.favPath)
  709. }
  710. if (!FileUtil.accessSync(this.historyPath)) {
  711. FileUtil.mkdirSync(this.historyPath)
  712. }
  713. this.getSortedFiles(this.rootPath).then(() => {
  714. this.isFavMusic = false
  715. //穿山甲
  716. // this.loadBannerAd(CSJUtil.getBannerID())
  717. this.songList = PreferencesUtil.getSync('LastMusicList', []) as Array<VideoItem>
  718. this.currentSong = PreferencesUtil.getSync('LastMusicInfo', undefined) as VideoItem
  719. if (ArrayUtil.isEmpty(this.songList)) {
  720. this.songList = this.getCurFileList()
  721. } else {
  722. this.curIndex = Utility.getIndexFromList(this.songList, this.currentSong.filePath)
  723. }
  724. if (ArrayUtil.isNotEmpty(this.songList)) {
  725. this.isFirstStartPlay = true
  726. this.sonDataSource.pushArrayData(this.songList)
  727. if (this.currentSong === undefined) {
  728. this.isFirstStartPlay = false
  729. this.currentSong = this.songList[0]
  730. }
  731. this.videoUrl = this.currentSong.filePath
  732. this.name = this.currentSong.name
  733. this.cover = this.currentSong.pixelMapPath
  734. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  735. } else {
  736. this.name = '空空如也'
  737. }
  738. })
  739. this.getFavList(false)
  740. }
  741. getFavList(isFavRefresh: boolean) {
  742. this.table.queryByisFav(1, async (result: VideoItem[]) => {
  743. this.favList = result
  744. if (isFavRefresh || this.isFavMusic) { //如果是我的收藏,更新我的收藏数据
  745. this.videoLocalList = this.favList
  746. this.updateListData(this.videoLocalList)
  747. }
  748. })
  749. }
  750. getHistoryList(isRefresh: boolean) {
  751. this.table.queryRecentPlayedRecords(50, async (result: VideoItem[]) => {
  752. this.historyList = result
  753. // for (let i = 0; i < this.historyList.length; i++) {
  754. //
  755. // console.info(`onecold gengxin 1: ${this.historyList[i].name}`);
  756. // console.info(`onecold gengxin 1: ${this.historyList[i].lastPlayedStr}`);
  757. // }
  758. if (isRefresh) {
  759. this.videoLocalList = this.historyList
  760. this.updateListData(this.videoLocalList, true)
  761. }
  762. })
  763. }
  764. // 组件消失生命周期
  765. aboutToDisappear() {
  766. console.info('LifeCycleComponent aboutToDisappear');
  767. this.knockController?.immersiveDisableListening();
  768. this.curIndex = 0
  769. emitter.off(2);
  770. emitter.off(101);
  771. emitter.off(888);
  772. emitter.off(333);
  773. this.mDestroyPage = true;
  774. this.mIjkMediaPlayer.setScreenOnWhilePlaying(false);
  775. if (this.CONTROL_PlayStatus != PlayStatus.INIT) {
  776. this.stop();
  777. }
  778. this.mIjkMediaPlayer.off('audioInterrupt');
  779. if (workerInstance) {
  780. workerInstance.terminate();
  781. }
  782. this.stopPip();
  783. this.destroyPipController()
  784. }
  785. async getSortedFiles(curPath: string, isWorkerPost?: boolean, destPath?: string, isOpen?: boolean) {
  786. this.isFavMusic = false
  787. if (isWorkerPost) {
  788. workerInstance.postMessage({ code: 2, data: this.context }); //刷新媒体库列表
  789. }
  790. if (this.modeType !== 0) {
  791. return
  792. }
  793. this.isCanBack = false
  794. this.currentPath = curPath
  795. this.titleBarModel.setTitleName(getFileDirName(this.currentPath, this.rootPath))
  796. if (curPath === this.rootPath) {
  797. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  798. } else {
  799. this.currentTitleName = getFileDirName(this.currentPath, this.rootPath)
  800. if (this.rootPath === Utility.getParentDirectory(curPath)) {
  801. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  802. }
  803. }
  804. // Get the current file list and calculate its hash
  805. this.fileList = FileUtil.listFileSync(curPath);
  806. const currentHash = simpleHash(this.fileList);
  807. // Check cache
  808. const cachedValue = this.findCache(curPath);
  809. Logger.info('onecold cachedValue = ' + cachedValue)
  810. const cachedHash = this.findStringCache(curPath + '_hash');
  811. const cachedDirList = this.findCache(curPath + "_dirList");
  812. if (cachedValue !== undefined) {
  813. // this.videoLocalList = cachedValue;
  814. Logger.info('onecold 有缓存 cachedValue = ' + cachedValue)
  815. if (this.currentPath != this.rootPath) { //第一个封面赋值给currentTitleCover
  816. this.currentTitleCover = Utility.getFirstCoverFromList(cachedValue)
  817. }
  818. this.updateListData(cachedValue)
  819. }
  820. if (cachedDirList !== undefined) {
  821. this.dirList = cachedDirList
  822. }
  823. //通过当前hash值和缓存hash判断list有没有变化
  824. if (cachedValue && cachedHash === currentHash) {
  825. return;
  826. }
  827. this.fileList = FileUtil.listFileSync(curPath)
  828. let directories: Array<VideoItem> = [];
  829. let files: Array<VideoItem> = [];
  830. for (let i = 0; i < this.fileList.length; i++) {
  831. console.info(`The name of file: ${this.fileList[i]}`);
  832. let path = curPath + '/' + this.fileList[i]
  833. if (FileUtil.isDirectory(path)) {
  834. let item: VideoItem =
  835. new VideoItem(this.fileList[i].toString(), this.fileList[i].toString(), path, CommonConstants.TYPE_IS_DIR, 0,
  836. '')
  837. if (this.isShowDir(item.name)) {
  838. directories.push(item);
  839. }
  840. // directories.sort((a, b) => a.cTime.localeCompare(b.cTime));
  841. // Utility.doSortListAscending(directories)
  842. } else {
  843. if (this.currentPath === this.lockPath&&Utility.isMeidaByExtension(path)) {
  844. let item: VideoItem =
  845. await Utility.uriGetMusicAssetsFromFile(this.context, path, CommonConstants.TYPE_LOCAL, false);
  846. if (!path.endsWith('.lrc') && Utility.isMeidaByExtension(path) && !path.endsWith('.srt')) {
  847. files.push(item);
  848. // files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  849. // this.doSortListAscending(files)
  850. }
  851. }
  852. }
  853. }
  854. this.table.queryByParentPath(curPath, async (result: VideoItem[]) => {
  855. if (this.currentPath !== this.lockPath) {
  856. files = result;
  857. }
  858. files.sort((a, b) => a.cTime.localeCompare(b.cTime));
  859. Utility.doSortListAscending(files)
  860. if (this.currentPath === this.rootPath) {
  861. this.dirList = directories
  862. this.addCache(curPath + "_dirList", this.dirList);
  863. }
  864. //插入广告先注释掉
  865. // if (this.isShowAd && ArrayUtil.isNotEmpty(directories)) {
  866. // let adItem: VideoItem = new VideoItem('', '', '', CommonConstants.TYPE_IS_CSJAD, 0, '')
  867. // directories.push(adItem)
  868. // }
  869. // 合并文件夹和文件,文件夹在前,文件在后,广告在中间
  870. this.videoLocalList = directories.concat(files);
  871. this.updateListData(this.videoLocalList)
  872. if (ArrayUtil.isNotEmpty(files)) {
  873. if (this.currentPath != this.rootPath) {
  874. if (files) {
  875. this.currentTitleCover = Utility.getFirstCoverFromList(files)
  876. }
  877. }
  878. // 缓存结果
  879. this.addCache(curPath, this.videoLocalList);
  880. await this.saveCacheToStorage(); // 保存缓存至本地存储
  881. this.addStringCache(curPath + '_hash', currentHash);
  882. }
  883. console.info(`onecold gengxin 1: ${this.videoLocalList.length}`);
  884. // for (let i = 0; i < this.videoLocalList.length; i++) {
  885. //
  886. // console.info(`onecold gengxin 1: ${this.videoLocalList[i].pixelMapPath}`);
  887. //
  888. // }
  889. // this.setButtonStatus()
  890. if (isOpen) {
  891. if (destPath === undefined) {
  892. // 处理 destPath 为 undefined 的情况
  893. return
  894. }
  895. if (destPath.endsWith('.lrc')) {
  896. ToastUtil.showToast('导入歌词成功!请注意歌词文件和歌曲要同个歌单路径。')
  897. if (StrUtil.isNotEmpty(this.videoUrl)) {
  898. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  899. this.initLyric(lyricPath);
  900. }
  901. return
  902. }
  903. let item2 = new VideoItem(Utility.getMediaNameByUri(destPath), destPath, destPath, 0, 0, '')
  904. this.doPlay(item2)
  905. this.isShowPlay = true
  906. }
  907. });
  908. }
  909. //扫描文件夹入库
  910. async scanDirectory(curPath: string): Promise<VideoItem[]> {
  911. const files = FileUtil.listFileSync(curPath);
  912. let mediaItems: VideoItem[] = [];
  913. Logger.info('onecold scanDirectory start ')
  914. for (const file of files) {
  915. const fPath = `${curPath}/${file}`;
  916. if (fPath === this.lockPath) {
  917. Logger.info(`Skipping locked path: ${fPath}`);
  918. continue;
  919. }
  920. if (FileUtil.isDirectory(fPath)) {
  921. // Recursively scan subdirectories
  922. const subDirItems = await this.scanDirectory(fPath);
  923. mediaItems = mediaItems.concat(subDirItems);
  924. } else {
  925. Logger.info('onecold scanDirectory filePath = ' + fPath)
  926. // Process media files
  927. if (!fPath.endsWith('.lrc') && Utility.isMeidaByExtension(fPath) && !fPath.endsWith('.srt')) {
  928. let mediaItem: VideoItem =
  929. await Utility.uriGetMusicAssetsFromFile(this.context, fPath, CommonConstants.TYPE_LOCAL, true);
  930. mediaItems.push(mediaItem);
  931. this.table.insert(mediaItem, (id: number) => {
  932. });
  933. }
  934. }
  935. }
  936. return mediaItems;
  937. }
  938. updateListData(mList: Array<VideoItem>, noSort?: boolean) {
  939. animateTo({ duration: 888 }, () => {
  940. this.opacityItem = 0;
  941. });
  942. setTimeout(() => {
  943. this.videoLocalList = mList;
  944. if (!noSort) {
  945. if (this.modeType === 0 || this.modeType === 1) {
  946. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  947. this.doSortType(this.sortType)
  948. }
  949. }
  950. this.dataSource.pushArrayData(this.videoLocalList)
  951. animateTo({ duration: 888 }, () => {
  952. this.opacityItem = 1;
  953. });
  954. this.setButtonStatus()
  955. }, 200);
  956. }
  957. //排序模式和多选模式
  958. showPupDialog() {
  959. if (this.modeType === 2 || this.modeType === 3) {
  960. this.titleBarModel.setRightIcon(null)
  961. } else {
  962. this.titleBarModel.setRightIcon(($r('app.media.add')))
  963. }
  964. let dataBean = new BubbleBean()
  965. dataBean.data = ["首页", "媒体库", "艺术家", "专辑", "同步数据"]
  966. dataBean.color = this.themeColor
  967. dataBean.modeType = this.modeType
  968. dataBean.imageRes =
  969. [$r('app.media.home_press'), $r('app.media.kp_music'), $r('app.media.music_menu'), $r('app.media.llq'),
  970. $r('app.media.refresh')]
  971. let pup: XPopup;
  972. if (this.isDarkMode) {
  973. pup = XPopup.Builder()
  974. .setPopupPosition(PopupPosition.BOTTOM)
  975. .atView('pup_positon_music')
  976. .setBackgroundColor(Color.Black)
  977. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  978. .show()
  979. } else {
  980. pup = XPopup.Builder()
  981. .setPopupPosition(PopupPosition.BOTTOM)
  982. .atView('pup_positon_music')
  983. .setBackgroundColor(Color.White)
  984. .asBubble(wrapBuilder(customPopupBuilder), dataBean)
  985. .show()
  986. }
  987. dataBean.onItemClick = (i) => {
  988. XPopup.dismissTop()
  989. switch (i) {
  990. case 0: //首页
  991. this.modeType = 0
  992. this.getSortedFiles(this.currentPath)
  993. break
  994. case 1:
  995. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  996. this.modeType = 1
  997. this.updateListData(this.mediaKuList)
  998. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.media_ku')))
  999. break
  1000. case 2:
  1001. this.modeType = 2
  1002. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1003. this.updateListData(this.artistList)
  1004. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.artist')))
  1005. break
  1006. case 3:
  1007. this.modeType = 3
  1008. this.titleBarModel.setLeftIconMain($r('app.media.menu'))
  1009. this.updateListData(this.albumList)
  1010. this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
  1011. break
  1012. case 4: //同步数据
  1013. this.asyncCurrentPathData()
  1014. break
  1015. }
  1016. }
  1017. }
  1018. getCurFileList(): Array<VideoItem> {
  1019. let files: Array<VideoItem> = [];
  1020. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1021. for (let i = 0; i < this.videoLocalList.length; i++) {
  1022. if (this.videoLocalList[i].type === CommonConstants.TYPE_LOCAL) {
  1023. files.push(this.videoLocalList[i]);
  1024. }
  1025. }
  1026. }
  1027. return files
  1028. }
  1029. setButtonStatus() {
  1030. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1031. this.isZero = false
  1032. } else {
  1033. this.isZero = true
  1034. }
  1035. if (this.currentPath !== this.rootPath &&
  1036. ArrayUtil.isNotEmpty(Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR))) {
  1037. this.isHasDir = true //不为空,说明有子文件夹
  1038. } else {
  1039. this.isHasDir = false
  1040. }
  1041. }
  1042. showRankDialog() {
  1043. if (this.modeType === 2 || this.modeType === 3) {
  1044. //动作面板
  1045. DialogHelper.showBottomSheetDialog({
  1046. title: "请选择排序模式",
  1047. maskColor: Color.Transparent,
  1048. // sheets: ["按名称升序", "按名称降序"],
  1049. sheets: [
  1050. { value: '按名称升序', fontColor: $r('app.color.text_color') },
  1051. { value: '按名称降序', fontColor: $r('app.color.text_color') },
  1052. ],
  1053. backgroundColor: $r('app.color.bg_card'),
  1054. height: '30%',
  1055. transition: AnimationHelper.transitionInDown(555),
  1056. onAction: (index) => {
  1057. switch (index) {
  1058. case 0:
  1059. Utility.doSortListAscending(this.videoLocalList)
  1060. break;
  1061. case 1:
  1062. Utility.doSortListDescending(this.videoLocalList)
  1063. break;
  1064. }
  1065. this.updateListData(this.videoLocalList)
  1066. }
  1067. })
  1068. return
  1069. }
  1070. //动作面板
  1071. DialogHelper.showBottomSheetDialog({
  1072. title: "请选择排序模式",
  1073. maskColor: Color.Transparent,
  1074. height: '75%',
  1075. // sheets: ["按艺术家升序", "按艺术家降序", "按专辑升序", "按专辑降序", "按名称升序", "按名称降序", "按添加时间升序","按添加时间降序"],
  1076. sheets: [
  1077. { value: "按艺术家升序", fontColor: $r('app.color.text_color') },
  1078. { value: "按艺术家降序", fontColor: $r('app.color.text_color') },
  1079. { value: "按专辑升序", fontColor: $r('app.color.text_color') },
  1080. { value: "按专辑降序", fontColor: $r('app.color.text_color') },
  1081. { value: "按名称升序", fontColor: $r('app.color.text_color') },
  1082. { value: "按名称降序", fontColor: $r('app.color.text_color') },
  1083. { value: "按添加时间升序", fontColor: $r('app.color.text_color') },
  1084. { value: "按添加时间降序", fontColor: $r('app.color.text_color') },
  1085. ],
  1086. backgroundColor: $r('app.color.bg_card'),
  1087. transition: AnimationHelper.transitionInDown(555),
  1088. onAction: (index) => {
  1089. this.doSortType(index)
  1090. PreferencesUtil.put(SettingPage.SORT_TYPE, index)
  1091. this.updateListData(this.videoLocalList, true)
  1092. }
  1093. })
  1094. }
  1095. doSortType(index: number) {
  1096. switch (index) {
  1097. case 0:
  1098. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1099. // 类型排序优先级
  1100. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1101. if (typeOrder !== 0) {
  1102. return typeOrder;
  1103. }
  1104. // 处理艺术家可能为undefined的字符串比较
  1105. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1106. const artistB = b.artist?.trim() || '';
  1107. return artistA.localeCompare(artistB);
  1108. });
  1109. break;
  1110. case 1:
  1111. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1112. // 类型排序优先级
  1113. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1114. if (typeOrder !== 0) {
  1115. return typeOrder;
  1116. }
  1117. // 处理艺术家可能为undefined的字符串比较
  1118. const artistA = a.artist?.trim() || ''; // 可选添加 trim() 处理空格
  1119. const artistB = b.artist?.trim() || '';
  1120. return artistB.localeCompare(artistA);
  1121. });
  1122. break;
  1123. case 2:
  1124. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1125. // 类型排序优先级
  1126. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1127. if (typeOrder !== 0) {
  1128. return typeOrder;
  1129. }
  1130. // 处理专辑可能为undefined的字符串比较
  1131. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1132. const albumB = b.album?.trim() || '';
  1133. return albumA.localeCompare(albumB);
  1134. });
  1135. break;
  1136. case 3:
  1137. this.videoLocalList.sort((a: VideoItem, b: VideoItem) => {
  1138. // 类型排序优先级
  1139. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1140. if (typeOrder !== 0) {
  1141. return typeOrder;
  1142. }
  1143. // 处理专辑可能为undefined的字符串比较
  1144. const albumA = a.album?.trim() || ''; // 可选添加 trim() 处理空格
  1145. const albumB = b.album?.trim() || '';
  1146. return albumB.localeCompare(albumA);
  1147. });
  1148. break;
  1149. case 4:
  1150. Utility.doSortListAscending(this.videoLocalList)
  1151. break;
  1152. case 5:
  1153. Utility.doSortListDescending(this.videoLocalList)
  1154. break;
  1155. case 6:
  1156. this.videoLocalList.sort((a, b) => {
  1157. // First, sort by type
  1158. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1159. if (typeOrder !== 0) {
  1160. return typeOrder;
  1161. }
  1162. // If types are the same, sort by cTime in ascending order
  1163. return a.cTime.localeCompare(b.cTime);
  1164. });
  1165. break;
  1166. case 7:
  1167. this.videoLocalList.sort((a, b) => {
  1168. // First, sort by type
  1169. const typeOrder = getTypeOrder(a.type) - getTypeOrder(b.type);
  1170. if (typeOrder !== 0) {
  1171. return typeOrder;
  1172. }
  1173. // If types are the same, sort by cTime in descending order
  1174. return b.cTime.localeCompare(a.cTime);
  1175. });
  1176. break;
  1177. }
  1178. }
  1179. showSheelDialog() {
  1180. // if(PreferencesUtil.getBooleanSync('isFirstMusic',true)) {
  1181. // this.showTips()
  1182. // return
  1183. // }
  1184. this.showAddDialog()
  1185. }
  1186. showAddDialog() {
  1187. if (this.modeType === 2 || this.modeType === 3) {
  1188. return
  1189. }
  1190. DialogHelper.showActionSheetDialog({
  1191. title: "请选择添加方式(建议歌词文件一起导入)",
  1192. // sheets: ["新建歌单", "手动导入", "自动导入"],
  1193. sheets: [
  1194. { value: "新建歌单", fontColor: $r('app.color.text_color') },
  1195. { value: "手动导入", fontColor: $r('app.color.text_color') },
  1196. { value: "自动导入", fontColor: $r('app.color.text_color') },
  1197. { value: "全选导入", fontColor: $r('app.color.text_color') },
  1198. ],
  1199. maskColor: Color.Transparent,
  1200. backgroundColor: $r('app.color.bg_card'),
  1201. transition: AnimationHelper.transitionInDown(555),
  1202. onAction: (index) => {
  1203. switch (index) {
  1204. case 0:
  1205. if (this.modeType === 0) {
  1206. this.showMkDialog()
  1207. } else {
  1208. ToastUtil.showToast('请切换到首页才能新建歌单!')
  1209. }
  1210. break;
  1211. case 1:
  1212. this.callFilePickerSelectFile()
  1213. break;
  1214. case 2:
  1215. this.showTips()
  1216. break;
  1217. case 3:
  1218. this.goSelectMusic()
  1219. break;
  1220. }
  1221. }
  1222. })
  1223. }
  1224. //拉起音频
  1225. goSelectMusic() {
  1226. if (DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_TABLET ||
  1227. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_PC ||
  1228. DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1
  1229. ) {
  1230. ToastUtil.showToast('暂时不支持该设备')
  1231. return
  1232. }
  1233. try {
  1234. let documentSelectOptions = new picker.DocumentSelectOptions();
  1235. documentSelectOptions.authMode = true
  1236. documentSelectOptions.multiAuthMode = true
  1237. documentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO;
  1238. let documentPicker = new picker.DocumentViewPicker(this.context);
  1239. documentPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => {
  1240. if (documentSelectResult !== null && documentSelectResult !== undefined) {
  1241. this.saveVideoDatas(documentSelectResult)
  1242. }
  1243. console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' +
  1244. JSON.stringify(documentSelectResult));
  1245. }).catch((err: BusinessError) => {
  1246. console.error(`DocumentViewPicker.select failed with err, code is: ${err.code}, message is: ${err.message}`);
  1247. });
  1248. } catch (error) {
  1249. let err: BusinessError = error as BusinessError;
  1250. console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1251. }
  1252. }
  1253. async showTips() {
  1254. DialogHelper.showTipsDialog({
  1255. title: '使用提示:自动导入教程',
  1256. content: '用系统自带的文件管理器将:\n\n1、音频文件放入' + '\n\n我的设备/Download/'
  1257. + this.appName + '\n\n2、无需繁琐的勾选和分类步骤。\n\n3、每个子文件夹将被组成一个分组。' +
  1258. '\n\n4、歌词文件的文件名必须和目标歌曲文件名相同(不包含后缀名)。\n\n5、歌词文件和目标歌曲文件必须同个目录。' +
  1259. '\n\n6、电脑上Download的目录是\nDownload/' + this.packName + '。\n\n7、放好文件后如果没显示点击刷新按钮。\n',
  1260. onAction: (action) => {
  1261. if (action == DialogAction.TWO) {
  1262. PreferencesUtil.putSync('isFirstMusic', false)
  1263. router.pushUrl({
  1264. url: 'pages/ScanFilePage'
  1265. });
  1266. }
  1267. }
  1268. })
  1269. }
  1270. showMkDialog() {
  1271. DialogHelper.showTextInputDialog({
  1272. title: '新建歌单',
  1273. maskColor: Color.Transparent,
  1274. text: '',
  1275. transition: AnimationHelper.transitionInDown(666),
  1276. onChange: (text) => {
  1277. console.error("onChange: " + text);
  1278. },
  1279. onAction: (action, dialogId, content) => {
  1280. // ToastUtil.showToast('content = ' +content)
  1281. if (action == DialogAction.TWO) {
  1282. const newName = content
  1283. const newPath = this.currentPath + '/' + newName
  1284. FileUtil.mkdir(newPath, true).then(() => {
  1285. this.cache.delete(this.currentPath); // 删除目标路径缓存
  1286. this.getSortedFiles(this.currentPath)
  1287. }).catch((error: BusinessError) => {
  1288. console.error(error.message);
  1289. });
  1290. }
  1291. }
  1292. })
  1293. }
  1294. @State progress: number = 0;
  1295. async saveVideoDatas(uris: string[], isOpen?: boolean) {
  1296. if (ArrayUtil.isEmpty(uris)) {
  1297. return;
  1298. }
  1299. let newUris: string[] = [];
  1300. this.progress = 0
  1301. DialogHelper.showLoadingProgress({
  1302. progress: this.progress,
  1303. backCancel: false,
  1304. autoCancel: false,
  1305. loadColor: this.themeColor,
  1306. fontColor: this.themeColor
  1307. });
  1308. // 计算所有文件的总大小
  1309. let totalSize = 0;
  1310. for (let uri of uris) {
  1311. const sourceFile = await fileIo.open(uri, fileIo.OpenMode.READ_ONLY);
  1312. totalSize += (await fileIo.stat(sourceFile.fd)).size;
  1313. await fileIo.close(sourceFile.fd);
  1314. }
  1315. let totalRead = 0;
  1316. let destPath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[0]);
  1317. Logger.info(TAG, 'destPath uri: ' + destPath);
  1318. for (let i = 0; i < uris.length; i++) {
  1319. let filePath = this.currentPath + '/' + Utility.getMediaNameByUri(uris[i]);
  1320. Logger.info(TAG, 'filePath uri: ' + filePath);
  1321. newUris.push(filePath);
  1322. try {
  1323. const sourceFile = await fileIo.open(uris[i], fileIo.OpenMode.READ_ONLY);
  1324. const destFile = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  1325. const buffSize = 1024 * 1024; // 1MB 缓冲区大小
  1326. const buffer = new ArrayBuffer(buffSize);
  1327. let len = await fileIo.read(sourceFile.fd, buffer);
  1328. while (len > 0) {
  1329. await fileIo.write(destFile.fd, buffer.slice(0, len));
  1330. totalRead += len;
  1331. // 计算总进度
  1332. this.progress = Math.floor((totalRead / totalSize) * 100);
  1333. DialogHelper.updateLoading('正在导入', this.progress);
  1334. len = await fileIo.read(sourceFile.fd, buffer);
  1335. }
  1336. await fileIo.close(sourceFile.fd);
  1337. await fileIo.close(destFile.fd);
  1338. if (this.currentPath !== this.lockPath) { //判断不是私密音乐,才入库
  1339. if (!filePath.endsWith('.lrc') && Utility.isMeidaByExtension(filePath) && !filePath.endsWith('.srt')) {
  1340. let mediaItem: VideoItem =
  1341. await Utility.uriGetMusicAssetsFromFile(this.context, filePath, CommonConstants.TYPE_LOCAL, true);
  1342. this.table.insert(mediaItem, (id: number) => {
  1343. // 删除目标路径缓存
  1344. this.cache.delete(this.currentPath);
  1345. this.getSortedFiles(this.currentPath, true, destPath, isOpen)
  1346. });
  1347. }
  1348. }
  1349. } catch (error) {
  1350. Logger.error(TAG, 'saveVideoDatas failed with err: ' + JSON.stringify(error));
  1351. }
  1352. }
  1353. DialogHelper.closeLoading()
  1354. this.isZero = false
  1355. // setTimeout(() => {
  1356. // // 删除目标路径缓存
  1357. // this.cache.delete(this.currentPath);
  1358. // this.getSortedFiles(this.currentPath,true,destPath,isOpen)
  1359. // }, 500);
  1360. Logger.info(TAG, 'scan select video result:' + newUris)
  1361. }
  1362. //拉起音频
  1363. // goSelectMusic(){
  1364. //
  1365. // try {
  1366. // let audioSelectOptions = new picker.AudioSelectOptions();
  1367. // let audioPicker = new picker.AudioViewPicker(this.context);
  1368. // audioPicker.select(audioSelectOptions).then((audioSelectResult: Array<string>) => {
  1369. // if (audioSelectResult !== null && audioSelectResult !== undefined) {
  1370. // this.saveVideoDatas(audioSelectResult)
  1371. // }
  1372. // console.info('AudioViewPicker.select successfully, audioSelectResult uri: ' + JSON.stringify(audioSelectResult));
  1373. // }).catch((err: BusinessError) => {
  1374. //
  1375. // console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
  1376. // });
  1377. // } catch (error) {
  1378. // let err: BusinessError = error as BusinessError;
  1379. // console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
  1380. // }
  1381. //
  1382. //
  1383. //
  1384. // }
  1385. goSelectImage(item: VideoItem) {
  1386. if (!item) {
  1387. return
  1388. }
  1389. let selectUris: Array<string> = [];
  1390. let photoPicker = new photoAccessHelper.PhotoViewPicker();
  1391. let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  1392. photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
  1393. photoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目
  1394. photoPicker.select(photoSelectOptions).then(async (photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
  1395. //用一个全局变量存储返回的uri
  1396. selectUris = photoSelectResult.photoUris;
  1397. console.info('photoViewPicker.select to file succeed and uris are:' + selectUris);
  1398. //使用fs.openSync接口,通过uri打开这个文件得到fd
  1399. let file = fs.openSync(selectUris[0], fs.OpenMode.READ_ONLY);
  1400. console.info('file fd: ' + file.fd);
  1401. let name = await MD5.digestSync(this.videoUrl)
  1402. let imagePath = this.context.filesDir + FileUtil.separator + name
  1403. imagePath = fileUri.getUriFromPath(imagePath)
  1404. let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  1405. fileIo.copyFileSync(file.fd, file2.fd)
  1406. fileIo.closeSync(file);
  1407. fileIo.closeSync(file2);
  1408. if (item.filePath == this.currentSong?.filePath) {
  1409. this.cover = imagePath
  1410. }
  1411. if (item) {
  1412. item.pixelMapPath = imagePath
  1413. }
  1414. this.table.updatePixelMapPath(item.filePath, imagePath, (success: boolean, error?: string) => {
  1415. if (success) {
  1416. this.doUpdateData()
  1417. console.log(" onecold 更新音乐封面成功,数据库已同步");
  1418. } else {
  1419. console.error(" onecold 更新音乐封面数据库失败原因: " + error);
  1420. }
  1421. });
  1422. LogUtil.debug("onecold this.cover =" + this.cover)
  1423. }).catch((err: BusinessError) => {
  1424. console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
  1425. })
  1426. }
  1427. // 拉起picker选择文件管理器
  1428. async callFilePickerSelectFile(): Promise<void> {
  1429. try {
  1430. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  1431. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE) {
  1432. DocumentSelectOptions.fileSuffixFilters = CommonConstants.MEDIA_FORMAT
  1433. } else {
  1434. DocumentSelectOptions.mergeMode = picker.MergeTypeMode.AUDIO
  1435. }
  1436. let documentPicker = new picker.DocumentViewPicker();
  1437. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  1438. Logger.info(TAG,
  1439. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  1440. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  1441. this.saveVideoDatas(DocumentSelectResult)
  1442. }
  1443. }).catch((err: BusinessError) => {
  1444. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  1445. });
  1446. } catch (err) {
  1447. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  1448. }
  1449. }
  1450. showWarnIsDeleteFile(item: VideoItem, index: string, filePath: string) {
  1451. //操作确认类弹出框
  1452. DialogHelper.showAlertDialog({
  1453. maskColor: Color.Transparent,
  1454. content: "确定要删除这个文件吗?",
  1455. backgroundColor: Color.Grey,
  1456. transition: AnimationHelper.transitionInUp(555),
  1457. onAction: (action) => {
  1458. if (action == DialogAction.ONE) {
  1459. // ToastUtil.showToast(`您点击了取消按钮`);
  1460. } else if (action == DialogAction.TWO) {
  1461. // ToastUtil.showToast(`您点击了确认按钮`);
  1462. this.doDelete(item, index + '', filePath)
  1463. }
  1464. }
  1465. })
  1466. }
  1467. //删除单个索引index的视频
  1468. doDelete(item: VideoItem, index: string, filePath: string) {
  1469. if (ArrayUtil.isNotEmpty(this.videoLocalList)) {
  1470. Logger.info(TAG, 'delete filePath = ' + filePath);
  1471. if (item.type === CommonConstants.TYPE_IS_DIR) {
  1472. //旧文件删除
  1473. this.table.deleteDataForParentPath(item.filePath, () => {
  1474. FileUtil.rmdir(filePath).then(() => {
  1475. this.videoLocalList.splice(Number(index), 1)
  1476. this.deleteCache(this.currentPath)
  1477. this.getSortedFiles(this.currentPath, true)
  1478. }).catch((error: BusinessError) => {
  1479. console.error(error.message);
  1480. });
  1481. });
  1482. } else {
  1483. this.table.deleteData(item, () => {
  1484. FileUtil.unlink(filePath)
  1485. .catch((error: BusinessError) => {
  1486. console.error(error.message);
  1487. // 可以根据 error.code 判断是否为"文件不存在",如需特殊处理
  1488. })
  1489. .finally(() => {
  1490. this.videoLocalList.splice(Number(index), 1)
  1491. this.deleteCache(this.currentPath)
  1492. this.getSortedFiles(this.currentPath, true)
  1493. });
  1494. });
  1495. }
  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. this.playOrPause()
  1714. }
  1715. // Right-click to fast forward
  1716. if (event.keyCode === KeyCode.KEYCODE_DPAD_RIGHT) {
  1717. this.sessionFastForwardCallback(15);
  1718. }
  1719. // Left-click to rewind
  1720. if (event.keyCode === KeyCode.KEYCODE_DPAD_LEFT) {
  1721. this.sessionRewindCallback(15);
  1722. }
  1723. })
  1724. .onDestroy(() => {
  1725. })
  1726. .width('100%')// .width(this.videoWidth)
  1727. .aspectRatio(this.videoAspectRatio)
  1728. }
  1729. .aspectRatio(this.videoAspectRatio)
  1730. .justifyContent(FlexAlign.Center)
  1731. .backgroundColor(Color.Transparent)
  1732. .visibility(Visibility.Hidden)
  1733. .height(CommonConstants.FULL_PERCENT)
  1734. .width(CommonConstants.FULL_PERCENT)
  1735. Stack() {
  1736. Row() {
  1737. Blank()
  1738. .layoutWeight(1)
  1739. IndexerView(
  1740. {
  1741. indexArray: DEFAULT_INDEX,
  1742. selectedIndex: this.selectedIndex,
  1743. textSize: 12,
  1744. selectedColor: "#ff419ee5",
  1745. normalColor: "#ffa0a0a0",
  1746. floatSelectedTextColor: "#ffffff",
  1747. floatSelectedViewColor: "#ff419ee5",
  1748. onIndexChanged: (index) => {
  1749. this.listScroller.scrollToIndex(index)
  1750. }
  1751. })
  1752. .width(24)
  1753. .height("50%")
  1754. }.visibility(Visibility.None)
  1755. Column() {
  1756. if (!this.isShowCoverHeader()) {
  1757. this.tabTitle()
  1758. }
  1759. if (this.isGridMusic) {
  1760. this.getGridView()
  1761. } else {
  1762. this.getListView()
  1763. }
  1764. if (this.modeType == 0) {
  1765. Column() {
  1766. Button('同步数据', { type: ButtonType.Capsule, stateEffect: true })
  1767. .width(130)
  1768. .height(50)
  1769. .margin({ top: 100, bottom: 40 })
  1770. .backgroundColor(this.themeColor)
  1771. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  1772. .onClick(() => {
  1773. this.asyncCurrentPathData()
  1774. })
  1775. }
  1776. .height(100)
  1777. .position({ top: 260 })
  1778. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  1779. .animation({ duration: 500 }),
  1780. TransitionEffect.scale({ x: 0, y: 0 })))
  1781. .justifyContent(FlexAlign.Center)
  1782. .opacity(this.isZero ? 1 : 0)
  1783. .visibility(this.isZero && !this.isFavMusic && !this.isHistory
  1784. && this.modeType === 0 ? Visibility.Visible : Visibility.None)
  1785. .animation({
  1786. duration: 500,
  1787. curve: 'ease-in-out' // 可选动画曲线
  1788. })
  1789. .width('100%')
  1790. }
  1791. }
  1792. .layoutWeight(1)
  1793. .height('100%')
  1794. }
  1795. .layoutWeight(1)
  1796. .height('100%')
  1797. Row() {
  1798. Button(this.isAllSelected ? '全不选' : '全选', { type: ButtonType.Circle, stateEffect: true })
  1799. .width('35%')
  1800. .height(60)
  1801. .margin({ top: 10, bottom: 10, right: 6 })
  1802. .backgroundColor(this.themeColor)
  1803. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1804. .onClick(() => {
  1805. if (this.isAllSelected) {
  1806. // 全不选
  1807. this.selectedFiles = [];
  1808. } else {
  1809. // 全选
  1810. this.selectedFiles = [...this.getCurFileList()];
  1811. }
  1812. this.isAllSelected = !this.isAllSelected;
  1813. })
  1814. Button('剪切', { type: ButtonType.Circle, stateEffect: true })
  1815. .width('35%')
  1816. .height(60)
  1817. .id('music_cut')
  1818. .margin({ top: 10, bottom: 10, right: 6 })
  1819. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1820. .backgroundColor(this.themeColor)
  1821. .onClick(() => {
  1822. this.showCutDialogForMultipleFiles(false, 'music_cut')
  1823. })
  1824. Button('移动', { type: ButtonType.Circle, stateEffect: true })
  1825. .width('35%')
  1826. .height(60)
  1827. .id('music_cut_current')
  1828. .visibility(this.isHasDir ? Visibility.Visible : Visibility.None)
  1829. .margin({ top: 10, bottom: 10, right: 6 })
  1830. .backgroundColor(this.themeColor)
  1831. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1832. .onClick(() => {
  1833. this.showCutDialogForMultipleFiles(true, 'music_cut_current')
  1834. })
  1835. Button('复制', { type: ButtonType.Circle, stateEffect: true })
  1836. .width('35%')
  1837. .height(60)
  1838. .id('music_copy_current')// .visibility(this.isHasDir?Visibility.None:Visibility.None)
  1839. .margin({ top: 10, bottom: 10, right: 6 })
  1840. .backgroundColor(this.themeColor)
  1841. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1842. .onClick(() => {
  1843. this.showCopyDialogForMultipleFiles(false, 'music_copy_current')
  1844. })
  1845. Button('删除', { type: ButtonType.Circle, stateEffect: true })
  1846. .width('35%')
  1847. .height(60)
  1848. .margin({ top: 10, bottom: 10, right: 6 })
  1849. .visibility(this.isFavMusic ? Visibility.None : Visibility.Visible)
  1850. .backgroundColor(this.themeColor)
  1851. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1852. .onClick(() => {
  1853. this.showWarnIsDelete()
  1854. })
  1855. Button('取消', { type: ButtonType.Circle, stateEffect: true })
  1856. .width('35%')
  1857. .height(60)
  1858. .margin({ top: 10, bottom: 10, right: 6 })
  1859. .backgroundColor(this.themeColor)
  1860. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  1861. .onClick(() => {
  1862. this.selectedFiles = [];
  1863. this.isAllSelected = false
  1864. this.isMultiSelect = false
  1865. })
  1866. }
  1867. .width('100%')
  1868. .justifyContent(FlexAlign.Center)
  1869. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  1870. .opacity(this.isMultiSelect ? 1 : 0)
  1871. .animation({
  1872. duration: 666,
  1873. curve: 'ease-in-out' // 可选动画曲线
  1874. })
  1875. .position(this.isShowCoverHeader() ? { bottom: 78 }
  1876. : { bottom: this.isPhoneLan() ? 130 : 168 }) // 将 Row 固定在底部
  1877. }
  1878. .width('100%')
  1879. .height('100%')
  1880. .alignContent(Alignment.Top)
  1881. Column() {
  1882. this.PlayController()
  1883. }
  1884. .hitTestBehavior(HitTestMode.Transparent)
  1885. .position({ bottom: 0 }) // 将 Row 固定在底部
  1886. .opacity(this.barBottomOpacity)
  1887. }
  1888. .width('100%')
  1889. .height('100%')
  1890. .backgroundImage(this.isCustomizeBg ? this.customizeBgPath : $r('app.color.bottom_control_background'))
  1891. .backgroundImageSize(this.isCoverOpacity() ? { width: '100%' } : { height: '100%' })
  1892. .backgroundImagePosition(Alignment.Center)
  1893. .backdropBlur(this.blurValue)
  1894. .backgroundBrightness({ rate: this.isCustomizeBg ? 0.1 : 0, lightUpDegree: this.bgBrightness })
  1895. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
  1896. }
  1897. }
  1898. asyncCurrentPathData() {
  1899. if (this.modeType == 0) {
  1900. workerInstance.postMessage({
  1901. code: 1,
  1902. data1: this.context,
  1903. data2: this.currentPath,
  1904. data3: this.lockPath,
  1905. data4: PreferencesUtil.getStringSync('COVER_API', ''),
  1906. });
  1907. }
  1908. }
  1909. // 处理文件选择的函数
  1910. handleFileSelection(item: VideoItem, checked: boolean) {
  1911. if (checked) {
  1912. if (!this.selectedFiles.some(x => x.filePath == item.filePath)) {
  1913. this.selectedFiles.push(item);
  1914. }
  1915. } else {
  1916. const index = this.selectedFiles.findIndex(x => x.filePath == item.filePath);
  1917. if (index > -1) {
  1918. this.selectedFiles.splice(index, 1);
  1919. }
  1920. }
  1921. }
  1922. showWarnIsDelete() {
  1923. //操作确认类弹出框
  1924. DialogHelper.showAlertDialog({
  1925. content: "确定要删除这些文件吗?",
  1926. transition: AnimationHelper.transitionInUp(666),
  1927. maskColor: Color.Transparent,
  1928. backgroundColor: Color.Grey,
  1929. onAction: (action) => {
  1930. if (action == DialogAction.ONE) {
  1931. // ToastUtil.showToast(`您点击了取消按钮`);
  1932. } else if (action == DialogAction.TWO) {
  1933. // ToastUtil.showToast(`您点击了确认按钮`);
  1934. this.deleteMultipleFiles()
  1935. }
  1936. }
  1937. })
  1938. }
  1939. //多选删除文件
  1940. deleteMultipleFiles() {
  1941. if (ArrayUtil.isNotEmpty(this.selectedFiles)) {
  1942. this.selectedFiles.forEach((item) => {
  1943. Logger.info(TAG, 'delete filePath = ' + item.filePath);
  1944. if (item.type === CommonConstants.TYPE_IS_DIR) {
  1945. this.table.deleteDataForParentPath(item.filePath, () => {
  1946. FileUtil.rmdir(item.filePath).then(() => {
  1947. this.videoLocalList = this.videoLocalList.filter(v => v !== item);
  1948. this.selectedFiles = [];
  1949. this.isMultiSelect = false
  1950. this.isAllSelected = false
  1951. this.cache.delete(this.currentPath);
  1952. this.getSortedFiles(this.currentPath, true);
  1953. }).catch((error: Error) => {
  1954. console.error(error.message);
  1955. });
  1956. });
  1957. } else {
  1958. this.table.deleteData(item, () => {
  1959. FileUtil.unlink(item.filePath).catch((error: Error) => {
  1960. console.error(error.message);
  1961. }).finally(() => {
  1962. this.videoLocalList = this.videoLocalList.filter(v => v !== item);
  1963. this.selectedFiles = [];
  1964. this.isMultiSelect = false
  1965. this.isAllSelected = false
  1966. this.cache.delete(this.currentPath);
  1967. this.getSortedFiles(this.currentPath, true);
  1968. });
  1969. });
  1970. }
  1971. });
  1972. }
  1973. }
  1974. //多选移动文件
  1975. showCutDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  1976. Logger.info('onecold showCutDialogForMultipleFiles')
  1977. let mList: Array<string> = []
  1978. let rPath = this.rootPath
  1979. if (isCurrent) {
  1980. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  1981. rPath = this.currentPath
  1982. } else {
  1983. mList = Utility.getNameList(this.dirList);
  1984. rPath = this.rootPath
  1985. }
  1986. let dataBean = new BubbleBean();
  1987. dataBean.data = mList;
  1988. dataBean.color = this.themeColor
  1989. dataBean.onItemClick = (i) => {
  1990. const newDirPath = rPath + '/' + mList[i];
  1991. // Logger.info('newDirPath = ' + newDirPath)
  1992. this.selectedFiles.forEach((item) => {
  1993. const newPath = newDirPath + '/' + item.fileName;
  1994. FileUtil.moveFile(item.filePath, newPath, 1).then(async () => {
  1995. ToastUtil.showToast('移动成功');
  1996. this.table.deleteData(item, () => {
  1997. this.cache.delete(this.currentPath); // 删除原路径缓存
  1998. this.cache.delete(newDirPath); // 删除目标路径缓存
  1999. this.getSortedFiles(this.currentPath, true);
  2000. });
  2001. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2002. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2003. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2004. CommonConstants.TYPE_LOCAL, true);
  2005. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2006. this.table.insert(newItem, (id: number) => {
  2007. //加入数据库
  2008. });
  2009. }
  2010. }).catch((error: Error) => {
  2011. console.error(error.message);
  2012. });
  2013. });
  2014. this.isMultiSelect = false
  2015. this.selectedFiles = [];
  2016. this.isAllSelected = false
  2017. XPopup.dismissTop();
  2018. };
  2019. let pup: XPopup
  2020. if (this.isDarkMode) {
  2021. pup = XPopup.Builder()
  2022. .setPopupPosition(PopupPosition.TOP)
  2023. .atView(viewId)
  2024. .setBackgroundColor(Color.Black)
  2025. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2026. .show();
  2027. } else {
  2028. pup = XPopup.Builder()
  2029. .setPopupPosition(PopupPosition.TOP)
  2030. .atView(viewId)
  2031. .setBackgroundColor(Color.White)
  2032. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2033. .show();
  2034. }
  2035. }
  2036. doFav(item: VideoItem) {
  2037. LogUtil.info('onecold doFav isFav=' + item.isFav)
  2038. let isFav = 0
  2039. if (Utility.getIsFav(this.favList, item)) {
  2040. isFav = 0
  2041. } else {
  2042. isFav = 1
  2043. }
  2044. this.table.updateIsFavByFilePath(item.filePath, isFav, async (result: boolean) => {
  2045. if (result) {
  2046. if (isFav === 1) {
  2047. ToastUtil.showToast('收藏成功');
  2048. } else {
  2049. ToastUtil.showToast('取消收藏成功');
  2050. }
  2051. this.deleteCache(this.currentPath)
  2052. this.getFavList(false)
  2053. if (this.modeType === 0 && !this.isFavMusic) {
  2054. LogUtil.info('onecold doFav currentPath =' + this.currentPath)
  2055. this.getSortedFiles(this.currentPath)
  2056. }
  2057. workerInstance.postMessage({ code: 2, data: this.context });
  2058. workerInstance.postMessage({ code: 3, data: this.context });
  2059. workerInstance.postMessage({ code: 4, data: this.context });
  2060. }
  2061. })
  2062. }
  2063. //多选复制文件
  2064. showCopyDialogForMultipleFiles(isCurrent: boolean, viewId: string) {
  2065. console.log('onecold showCopyDialogForMultipleFiles');
  2066. let mList: Array<string> = []
  2067. let rPath = this.rootPath
  2068. if (isCurrent) {
  2069. mList = Utility.getGlobalNameList(this.videoLocalList, CommonConstants.TYPE_IS_DIR);
  2070. rPath = this.currentPath
  2071. } else {
  2072. mList = Utility.getNameList(this.dirList);
  2073. rPath = this.rootPath
  2074. }
  2075. let dataBean = new BubbleBean();
  2076. dataBean.data = mList;
  2077. dataBean.isCopy = true
  2078. dataBean.color = this.themeColor
  2079. dataBean.onItemClick = (i) => {
  2080. const newDirPath = rPath + '/' + mList[i];
  2081. // Logger.info('newDirPath = ' + newDirPath)
  2082. this.selectedFiles.forEach((item) => {
  2083. const newPath = newDirPath + '/' + item.fileName;
  2084. FileUtil.copyFile(item.filePath, newPath, 0).then(async () => {
  2085. ToastUtil.showToast('复制成功');
  2086. this.cache.delete(newDirPath); // 删除目标路径缓存
  2087. this.getSortedFiles(this.currentPath);
  2088. // let newItem = new VideoItem(item.name,newPath,newPath,item.type,item.videoSize,item.cTime,item.pixelMap,
  2089. // item.size,item.pixelMapToString,item.artist,item.album,item.fileName)
  2090. let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newPath,
  2091. CommonConstants.TYPE_LOCAL, true);
  2092. if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
  2093. this.table.insert(newItem, (id: number) => {
  2094. //加入数据库
  2095. });
  2096. }
  2097. }).catch((error: Error) => {
  2098. console.error(error.message);
  2099. });
  2100. });
  2101. this.isMultiSelect = false
  2102. this.selectedFiles = [];
  2103. this.isAllSelected = false
  2104. XPopup.dismissTop();
  2105. };
  2106. let pup: XPopup
  2107. if (this.isDarkMode) {
  2108. pup = XPopup.Builder()
  2109. .setPopupPosition(PopupPosition.TOP)
  2110. .atView(viewId)
  2111. .setBackgroundColor(Color.Black)
  2112. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2113. .show();
  2114. } else {
  2115. pup = XPopup.Builder()
  2116. .setPopupPosition(PopupPosition.TOP)
  2117. .atView(viewId)
  2118. .setBackgroundColor(Color.White)
  2119. .asBubble(wrapBuilder(cutPopupBuilder), dataBean)
  2120. .show();
  2121. }
  2122. }
  2123. @Builder
  2124. private DirItem(item: VideoItem, index?: number) {
  2125. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2126. Row() {
  2127. Image(this.modeType !== 0 && StrUtil.isNotEmpty(item.pixelMapPath) ? item.pixelMapPath :
  2128. $r('app.media.music_group'))
  2129. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2130. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2131. .fillColor(this.themeColor)// .fontSize(33)
  2132. .alt($r('app.media.music_group'))
  2133. .borderRadius('100%')
  2134. .clip(true)
  2135. .margin({ left: 20, top: 8, bottom: 8 })
  2136. Column() {
  2137. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  2138. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2139. .maxLines(1)// .width('88%')
  2140. .animation({
  2141. duration: 555,
  2142. curve: 'ease-in-out',
  2143. })
  2144. .transition({
  2145. type: TransitionType.Insert,
  2146. opacity: 0,
  2147. translate: { x: 160 }
  2148. })
  2149. .margin({ left: 10, right: 20 })
  2150. .fontColor($r('app.color.text_color'))
  2151. Row() {
  2152. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  2153. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2154. .padding({ top: 8 })
  2155. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2156. .fontColor($r('app.color.text_color'))
  2157. .margin({ left: 10 })
  2158. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  2159. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2160. .padding({ top: 8 })
  2161. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2162. .fontColor($r('app.color.text_color'))
  2163. .margin({ left: 10 })
  2164. Blank()
  2165. }
  2166. }
  2167. .height('100%')
  2168. .layoutWeight(1)
  2169. .justifyContent(FlexAlign.Center)
  2170. .alignItems(HorizontalAlign.Start)
  2171. Blank()
  2172. Image($r('app.media.arrow_right'))
  2173. .height(25)
  2174. .margin({ right: 10 })
  2175. .alignSelf(ItemAlign.Center)
  2176. .id(item.filePath)
  2177. }
  2178. }
  2179. .backgroundColor(Color.Transparent)
  2180. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2181. .width('100%')
  2182. .visibility(this.isShowDir(item.name) ? Visibility.Visible : Visibility.None)
  2183. .opacity(this.opacityItem) // 绑定透明度
  2184. }
  2185. isShowDir(dirName: string) {
  2186. this.isShowSimi = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, false)
  2187. this.isShowFAV = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_FAV, true)
  2188. this.isShowHistory = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HISTORY, true)
  2189. if (dirName === undefined) {
  2190. return true
  2191. }
  2192. if (dirName === LocalMusic.STR_LOCK_VIDEO) {
  2193. return this.isShowSimi
  2194. }
  2195. if (dirName === LocalMusic.STR_FAC_VIDEO) {
  2196. return this.isShowFAV
  2197. }
  2198. if (dirName === LocalMusic.STR_HISTORY_MUSIC) {
  2199. return this.isShowHistory
  2200. }
  2201. return true
  2202. }
  2203. @State opacityItem: number = 1; // 控制透明度的状态变量
  2204. @Builder
  2205. private MusicItem(item: VideoItem, index?: number) {
  2206. Button({ type: ButtonType.Normal, stateEffect: true }) {
  2207. Row() {
  2208. Stack() {
  2209. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  2210. .fillColor(this.themeColor)
  2211. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2212. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  2213. .alt($r('app.media.music_red'))
  2214. .borderRadius('100%')
  2215. .clip(true)
  2216. .draggable(false)
  2217. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  2218. .autoResize(true) // 重采样,可减少内存占用
  2219. .opacity(this.opacityItem)// 绑定透明度
  2220. .margin({ left: 20 })
  2221. .gesture(LongPressGesture()
  2222. .onAction(async () => {
  2223. //如果是专辑和艺术家的首页,不能长按
  2224. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2225. return
  2226. //如果是我的收藏 最近播放等也不能长按
  2227. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2228. item.name === LocalMusic.STR_HISTORY_MUSIC
  2229. )
  2230. return
  2231. this.longItemFilePath = item.filePath
  2232. this.tempLyricContent = await this.getLyricContent(item)
  2233. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2234. })
  2235. .onActionEnd((event: GestureEvent) => {
  2236. }))
  2237. }
  2238. Column() {
  2239. Column() {
  2240. Text(item.name)
  2241. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  2242. .maxLines(1)
  2243. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  2244. .animation({
  2245. duration: 555,
  2246. curve: 'Linear',
  2247. })
  2248. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2249. $r('app.color.text_color'))
  2250. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2251. .bindPopup(this.longItemFilePath === item.filePath, {
  2252. builder: this.MenuBuilder(item,index,item.filePath),
  2253. placement: Placement.Top,
  2254. // autoCancel: true,
  2255. mask: {color:'#33000000'},
  2256. // popupColor: Color.Yellow,
  2257. enableArrow: false,//是否显示箭头
  2258. showInSubWindow: false,
  2259. onStateChange: (e) => {
  2260. if (!e.isVisible) {
  2261. this.longItemFilePath = ''
  2262. this.tempLyricContent = ''
  2263. }
  2264. }
  2265. })
  2266. .gesture(LongPressGesture()
  2267. .onAction(async () => {
  2268. //如果是专辑和艺术家的首页,不能长按
  2269. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2270. return
  2271. //如果是我的收藏 最近播放等也不能长按
  2272. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2273. item.name === LocalMusic.STR_HISTORY_MUSIC
  2274. )
  2275. return
  2276. this.longItemFilePath = item.filePath
  2277. this.tempLyricContent = await this.getLyricContent(item)
  2278. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2279. })
  2280. .onActionEnd((event: GestureEvent) => {
  2281. })
  2282. )
  2283. Row() {
  2284. Column(){
  2285. Text(item.md5Str?.includes('Lossless')?
  2286. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  2287. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  2288. .padding({ top: 3,right:6,left:6,bottom:3 })
  2289. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2290. $r('app.color.text_color'))
  2291. .fontWeight(500)
  2292. .borderRadius(12)
  2293. .visibility(StrUtil.isEmpty(item.md5Str)?Visibility.None:Visibility.Visible)
  2294. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2295. .backgroundColor('#FFC107')
  2296. }
  2297. .padding({ top: 8 })
  2298. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  2299. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2300. .padding({ top: 8 })
  2301. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2302. $r('app.color.text_color'))
  2303. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  2304. Blank()
  2305. Text(item.size)
  2306. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  2307. .padding({ top: 8 })
  2308. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  2309. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  2310. $r('app.color.text_color'))
  2311. .margin({ left: 10 })
  2312. }
  2313. .gesture(LongPressGesture()
  2314. .onAction(async () => {
  2315. //如果是专辑和艺术家的首页,不能长按
  2316. if((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  2317. return
  2318. //如果是我的收藏 最近播放等也不能长按
  2319. if(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  2320. item.name === LocalMusic.STR_HISTORY_MUSIC
  2321. )
  2322. return
  2323. this.longItemFilePath = item.filePath
  2324. this.tempLyricContent = await this.getLyricContent(item)
  2325. LogUtil.info('长按this.tempLyricContent = '+this.tempLyricContent)
  2326. })
  2327. .onActionEnd((event: GestureEvent) => {
  2328. })
  2329. )
  2330. }
  2331. .height('100%')
  2332. .width('100%')
  2333. .justifyContent(FlexAlign.Center)
  2334. .alignItems(HorizontalAlign.Start)
  2335. }
  2336. .height('100%')
  2337. .margin({ left: 5 })
  2338. .layoutWeight(1)
  2339. Column() {
  2340. Checkbox({ name: 'checkbox' + index })
  2341. .select(this.selectedFiles.some(x => x.filePath === item.filePath))
  2342. .selectedColor(this.themeColor)
  2343. .shape(CheckBoxShape.CIRCLE)
  2344. .opacity(this.isMultiSelect ? 1 : 0)
  2345. .animation({
  2346. duration: 666,
  2347. curve: 'Smooth' // 可选动画曲线
  2348. })
  2349. .visibility(this.isMultiSelect ? Visibility.Visible : Visibility.None)
  2350. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  2351. .margin({ left: 20, top: 8, bottom: 8 })
  2352. .width(22)
  2353. .height(22)
  2354. ImageAnimator()
  2355. .images(this.imagesF)// 动画数组
  2356. .duration(1000)// 持续
  2357. .state(this.animationState)// 动画状态
  2358. .fillMode(FillMode.Forwards)
  2359. .width(18)
  2360. .margin({ right: 20, top: 8, bottom: 8 })
  2361. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  2362. Visibility.None)
  2363. .height(18)
  2364. .iterations(-1) // 播放次数
  2365. }
  2366. }
  2367. }
  2368. .backgroundColor(Color.Transparent)
  2369. .width('100%')
  2370. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  2371. }
  2372. private readonly tabs: string[] = ['文件夹', '媒体库', '艺术家', '专辑']
  2373. @Builder
  2374. tabTitle() {
  2375. Column() {
  2376. // 使用 Stack 布局来实现绝对定位效果
  2377. Stack() {
  2378. // 背景动画容器
  2379. Row() {
  2380. ForEach(this.tabs, (i: string, index) => {
  2381. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2382. Flex()
  2383. .backgroundColor(this.isDarkMode ? $r('app.color.tab_item_bg') : this.themeColor)
  2384. .borderRadius(20)
  2385. .padding(10)
  2386. .margin(6)
  2387. .width('100%')
  2388. .height('100%')
  2389. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2390. .visibility(this.modeType === index ? Visibility.Visible : Visibility.None)
  2391. .opacity(this.modeType === index ? 1 : 0)
  2392. .animation({
  2393. duration: 666,
  2394. playMode: PlayMode.Normal,
  2395. curve: 'ease-in-out'
  2396. });
  2397. }
  2398. .layoutWeight(1)
  2399. .margin({
  2400. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5,
  2401. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 20 : 5, bottom: 1
  2402. });
  2403. });
  2404. }
  2405. .width('100%')
  2406. .height(50);
  2407. // 导航栏容器
  2408. Row() {
  2409. ForEach(this.tabs, (item: string, index) => {
  2410. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
  2411. Text(item)
  2412. .fontSize(16)
  2413. .fontColor(this.modeType === index ? Color.White : $r('app.color.text_color'))
  2414. .padding(15)
  2415. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2416. .onClick(() => {
  2417. this.modeType = index;
  2418. this.onModeChange();
  2419. });
  2420. }
  2421. .layoutWeight(1)
  2422. .stateStyles({
  2423. pressed: { opacity: 0.6 } // 按压反馈
  2424. });
  2425. });
  2426. }
  2427. .width('100%')
  2428. .height(this.topBarHeight)
  2429. .opacity(this.barOpacity)
  2430. .backgroundColor(Color.Transparent);
  2431. }
  2432. .width('100%')
  2433. .height(this.topBarHeight)
  2434. .opacity(this.barOpacity)
  2435. Line()
  2436. .width('100%')
  2437. .height(1)
  2438. .backgroundColor($r('app.color.index_background'))
  2439. .opacity(this.barOpacity)
  2440. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  2441. }
  2442. .visibility(this.isShowTitleBar ? Visibility.Visible : Visibility.None)
  2443. }
  2444. @State currentTitleName: string = '' //点击歌单,艺术家,专辑进去后的标题
  2445. @State currentTitleCover: string | ResourceStr = '' //点击歌单,艺术家,专辑进去后的封面
  2446. isShowCoverHeader() {
  2447. if (!this.isShowHeader) {
  2448. return false
  2449. }
  2450. if (this.modeType == 0) {
  2451. if (this.isHistory || this.isFavMusic) {
  2452. return true
  2453. }
  2454. if (this.currentPath != this.rootPath) {
  2455. return true
  2456. }
  2457. }
  2458. return (this.modeType == 2 || this.modeType == 3) && this.isCanBack
  2459. }
  2460. @Builder
  2461. coverHeader() {
  2462. if (this.isShowCoverHeader()) {
  2463. Column() {
  2464. Stack() {
  2465. // 居中标题
  2466. Text('')
  2467. .fontSize(18)
  2468. .fontColor(Color.White)
  2469. .align(Alignment.Center)
  2470. // 左右按钮
  2471. Row() {
  2472. Image($r('app.media.left_back_white'))
  2473. .width(28)
  2474. .height(28)
  2475. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2476. .margin({ left: 12, right: 8 })
  2477. .onClick(() => {
  2478. animateTo({ duration: 555 }, () => {
  2479. this.doSwipBack()
  2480. })
  2481. })
  2482. Blank().flexGrow(1)
  2483. if (this.modeType == 0 && !this.isHistory && !this.isFavMusic) {
  2484. Image($r('app.media.add'))
  2485. .width(25)
  2486. .height(25)
  2487. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  2488. .margin({ left: 8, right: 15 })
  2489. .onClick(() => {
  2490. this.showAddDialog()
  2491. })
  2492. }
  2493. }
  2494. .height(48)
  2495. .width('100%')
  2496. .alignItems(VerticalAlign.Center)
  2497. }
  2498. .height(48)
  2499. .width('100%')
  2500. Row() {
  2501. Column() {
  2502. Image(this.currentTitleCover)
  2503. .height(100)
  2504. .width(100)
  2505. .alt(this.imageLabel)
  2506. .borderRadius(8)
  2507. .clickEffect({ level: ClickEffectLevel.HEAVY })
  2508. }
  2509. .alignItems(HorizontalAlign.Start)
  2510. .margin({ left: 30, top: 3, bottom: 15 })
  2511. Column() {
  2512. Column() {
  2513. Text(this.currentTitleName)
  2514. .fontSize(16)
  2515. .maxLines(1)
  2516. .fontWeight(FontWeight.Bold)
  2517. .fontColor($r('app.color.text_color'))
  2518. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2519. if (this.modeType == 3 && ArrayUtil.isNotEmpty(this.videoLocalList)) {
  2520. Text(`艺术家:${this.videoLocalList[0].artist}`)
  2521. .fontSize(14)
  2522. .padding({ top: 8 })
  2523. .maxLines(1)
  2524. .fontWeight(FontWeight.Bold)
  2525. .fontColor($r('app.color.text_color'))
  2526. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2527. if(this.videoLocalList[0].genre){
  2528. Text(`风格:${this.videoLocalList[0].genre}`)
  2529. .fontSize(14)
  2530. .padding({ top: 8 })
  2531. .maxLines(1)
  2532. .visibility(StrUtil.isEmpty(this.videoLocalList[0].genre)||
  2533. this.videoLocalList[0].genre.includes(this.UNKONWN)
  2534. ?Visibility.None:Visibility.Visible)
  2535. .fontWeight(FontWeight.Bold)
  2536. .fontColor($r('app.color.text_color'))
  2537. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2538. }
  2539. if(this.videoLocalList[0].year){
  2540. Text(`发行时间:${this.videoLocalList[0].year}`)
  2541. .fontSize(14)
  2542. .padding({ top: 8 })
  2543. .maxLines(1)
  2544. .visibility(StrUtil.isEmpty(this.videoLocalList[0].year)||
  2545. this.videoLocalList[0].year.includes(this.UNKONWN)
  2546. ?Visibility.None:Visibility.Visible)
  2547. .fontWeight(FontWeight.Bold)
  2548. .fontColor($r('app.color.text_color'))
  2549. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2550. }
  2551. }
  2552. if(this.modeType != 3){
  2553. Row() {
  2554. Text(`共${this.videoLocalList.length}首歌`)
  2555. .fontSize(13)
  2556. .fontWeight(FontWeight.Bold)
  2557. .padding({ top: 8 })
  2558. .fontColor($r('app.color.text_color'))
  2559. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  2560. Blank()
  2561. }
  2562. }
  2563. }
  2564. .height('100%')
  2565. .width('100%')
  2566. .justifyContent(FlexAlign.Center)
  2567. .alignItems(HorizontalAlign.Start)
  2568. }
  2569. .height('100%')
  2570. .layoutWeight(1)
  2571. .margin({ left: 20 })
  2572. }
  2573. this.listViewTitle()
  2574. }
  2575. .backgroundImage(this.getCoverTitleBg())
  2576. .height(250)
  2577. .width('100%')
  2578. .backgroundImageSize({ height: '100%', width: '100%' })
  2579. .backgroundBlurStyle(this.isCustomizeBg ? BlurStyle.NONE : BlurStyle.BACKGROUND_ULTRA_THICK)
  2580. .padding({ top: this.topRectHeight, bottom: this.bottomBarHeight + 48 })
  2581. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  2582. .justifyContent(FlexAlign.SpaceBetween)
  2583. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.7, y: 0.7 }).animation({ duration: 500 }),
  2584. TransitionEffect.scale({ x: 0, y: 0 })))
  2585. } else {
  2586. this.listViewTitle()
  2587. }
  2588. }
  2589. getCoverTitleBg(): ResourceStr | image.PixelMap {
  2590. if (this.isCustomizeBg) {
  2591. return ('rgba(255,255,255,0.2)')
  2592. }
  2593. if (this.isDarkMode) {
  2594. return $r('app.color.user_center_card_background')
  2595. }
  2596. return this.currentTitleCover
  2597. }
  2598. @Builder
  2599. listViewTitle() {
  2600. Column() {
  2601. Row({ space: 8 }) {
  2602. Row({ space: 8 }) {
  2603. Image($r("app.media.hm_playlist"))
  2604. .width(25)
  2605. .margin({ left: 8 })
  2606. .fillColor(this.themeColor)
  2607. Text(`共找到${this.artistList.length}位艺术家`)
  2608. .fontColor($r('app.color.text_color'))
  2609. .fontSize(14)
  2610. .opacity(this.opacityItem)
  2611. .visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
  2612. Text(`共找到${this.albumList.length}张专辑`)
  2613. .fontColor($r('app.color.text_color'))
  2614. .opacity(this.opacityItem)
  2615. .visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2616. .fontSize(14)
  2617. }
  2618. .layoutWeight(1)
  2619. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  2620. Row() {
  2621. TextInput({
  2622. placeholder: this.modeType === 2 ? '输入艺术家名称...' : '输入专辑名称...',
  2623. text: this.searchText
  2624. })
  2625. .height(35)
  2626. .onChange((value: string) => {
  2627. this.onSearchInput(value);
  2628. })
  2629. .layoutWeight(1)
  2630. Text(`取消`)
  2631. .margin({ left: 10, right: 10 })
  2632. .fontColor($r('app.color.text_color'))
  2633. .fontSize(16)
  2634. .onClick(() => {
  2635. this.isSearchMode = false
  2636. this.searchText = ''
  2637. if (this.modeType === 2) {
  2638. this.updateListData(this.artistList)
  2639. } else {
  2640. this.updateListData(this.albumList)
  2641. }
  2642. })
  2643. }
  2644. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  2645. .animation({
  2646. duration: 666,
  2647. curve: 'ease-in-out' // 可选动画曲线
  2648. })
  2649. Blank()
  2650. Image($r("app.media.search"))
  2651. .width(25)
  2652. .visibility(this.modeType === 2 || this.modeType === 3 ? Visibility.Visible : Visibility.None)
  2653. .animation({
  2654. duration: 666,
  2655. curve: 'ease-in-out' // 可选动画曲线
  2656. })// .opacity(this.opacityItem)
  2657. .fillColor(this.themeColor)
  2658. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2659. .onClick(() => {
  2660. this.isSearchMode = true
  2661. })
  2662. Image($r("app.media.top_rank"))
  2663. .width(25)// .opacity(this.opacityItem)
  2664. .fillColor(this.themeColor)
  2665. .animation({
  2666. duration: 666,
  2667. curve: 'ease-in-out' // 可选动画曲线
  2668. })
  2669. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2670. .onClick(() => {
  2671. this.showRankDialog()
  2672. })
  2673. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  2674. .width(25)
  2675. .animation({
  2676. duration: 666,
  2677. curve: 'ease-in-out' // 可选动画曲线
  2678. })
  2679. .fillColor(this.themeColor)
  2680. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2681. .onClick(() => {
  2682. this.isGridMusic = !this.isGridMusic
  2683. })
  2684. }
  2685. .visibility(((this.modeType === 2 || this.modeType === 3) && !this.isCanBack) ? Visibility.Visible :
  2686. Visibility.None)
  2687. .width('100%')
  2688. .padding(10)
  2689. .height(50)
  2690. .border({
  2691. width: { bottom: 1 },
  2692. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2693. })
  2694. Row({ space: 8 }) {
  2695. Row({ space: 8 }) {
  2696. Image($r("app.media.hm_play"))
  2697. .width(25)
  2698. .margin({ left: 8 })
  2699. .fillColor(this.themeColor)
  2700. Text(`播放全部`)
  2701. .fontColor($r('app.color.text_color'))
  2702. .fontSize(14)
  2703. .animation({
  2704. duration: 666,
  2705. curve: 'ease-in-out' // 可选动画曲线
  2706. })
  2707. Text(`(${Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length}首)`)
  2708. .fontColor($r('app.color.text_color'))
  2709. .fontSize(14)
  2710. .opacity(this.opacityItem)
  2711. .animation({
  2712. duration: 666,
  2713. curve: 'ease-in-out' // 可选动画曲线
  2714. })
  2715. }
  2716. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2717. .visibility(this.isSearchMode ? Visibility.None : Visibility.Visible)
  2718. .animation({
  2719. duration: 666,
  2720. curve: 'ease-in-out' // 可选动画曲线
  2721. })
  2722. // .backgroundColor(this.isClickedPLayAll ? $r('app.color.button_click') : Color.Transparent)
  2723. .onTouch((event: TouchEvent) => {
  2724. if (event.type === TouchType.Down) {
  2725. this.isClickedPLayAll = true;
  2726. } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
  2727. this.isClickedPLayAll = false;
  2728. }
  2729. })
  2730. .onClick(() => {
  2731. // ToastUtil.showToast('当前的手机的折叠状态 ='+DisplayUtil.getFoldStatus())
  2732. if (this.modeType === 0) {
  2733. if (ArrayUtil.isNotEmpty(this.getCurFileList())) {
  2734. this.doPlay(this.getCurFileList()[0])
  2735. }
  2736. } else {
  2737. if (ArrayUtil.isNotEmpty(this.mediaKuList)) {
  2738. this.doPlay(this.mediaKuList[0])
  2739. }
  2740. }
  2741. })
  2742. Row() {
  2743. TextInput({ placeholder: '输入名称...', text: this.searchText })
  2744. .height(35)
  2745. .onChange((value: string) => {
  2746. this.onSearchInput(value);
  2747. })
  2748. .layoutWeight(1)
  2749. Text(`取消`)
  2750. .margin({ left: 10, right: 10 })
  2751. .fontColor($r('app.color.text_color'))
  2752. .fontSize(16)
  2753. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2754. .onClick(() => {
  2755. this.isSearchMode = false
  2756. this.searchText = ''
  2757. this.updateListData(this.mediaKuList)
  2758. })
  2759. }
  2760. .visibility(this.isSearchMode ? Visibility.Visible : Visibility.None)
  2761. .animation({
  2762. duration: 666,
  2763. curve: 'ease-in-out' // 可选动画曲线
  2764. })
  2765. Blank()
  2766. Image($r("app.media.search"))
  2767. .width(25)// .visibility(this.modeType===1?Visibility.Visible:Visibility.None)
  2768. .animation({
  2769. duration: 666,
  2770. curve: 'ease-in-out' // 可选动画曲线
  2771. })// .opacity(this.opacityItem)
  2772. .fillColor(this.themeColor)
  2773. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2774. .onClick(() => {
  2775. this.isSearchMode = true
  2776. })
  2777. Image($r("app.media.refresh"))
  2778. .fillColor(this.themeColor)
  2779. .width(25)
  2780. .visibility(this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
  2781. .animation({
  2782. duration: 666,
  2783. curve: 'ease-in-out' // 可选动画曲线
  2784. })
  2785. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2786. .onClick(() => {
  2787. if (this.isFavMusic) {
  2788. this.getFavList(true)
  2789. } else {
  2790. if(this.modeType == 0){
  2791. this.asyncCurrentPathData()
  2792. }else if(this.modeType ==1){
  2793. workerInstance.postMessage({ code: 2, data: this.context });
  2794. }
  2795. }
  2796. })
  2797. Image($r("app.media.top_rank"))
  2798. .width(25)
  2799. .visibility(this.isHistory || this.isSearchMode ? Visibility.None :
  2800. Visibility.Visible)// .opacity(this.opacityItem)
  2801. .animation({
  2802. duration: 666,
  2803. curve: 'ease-in-out' // 可选动画曲线
  2804. })
  2805. .fillColor(this.themeColor)
  2806. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2807. .onClick(() => {
  2808. this.showRankDialog()
  2809. })
  2810. Image(this.isMultiSelect ? $r("app.media.cancel_multi") : $r("app.media.top_flower"))
  2811. .width(24)
  2812. .visibility(this.isHistory || this.isSearchMode ? Visibility.None : Visibility.Visible)
  2813. .animation({
  2814. duration: 666,
  2815. curve: 'ease-in-out' // 可选动画曲线
  2816. })
  2817. .fillColor(this.themeColor)
  2818. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2819. .onClick(() => {
  2820. this.isMultiSelect = !this.isMultiSelect
  2821. })
  2822. SymbolGlyph($r('sys.symbol.trash'))
  2823. .fontColor([this.themeColor])
  2824. .fontSize(25)
  2825. .effectStrategy(1)
  2826. .visibility(this.isHistory ? Visibility.Visible : Visibility.None)
  2827. .animation({
  2828. duration: 666,
  2829. curve: 'ease-in-out' // 可选动画曲线
  2830. })
  2831. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2832. .onClick(() => {
  2833. this.clearVideoHistory() //清空播放记录
  2834. })
  2835. Image(this.isGridMusic ? $r('app.media.list') : $r("app.media.grid"))
  2836. .width(24)
  2837. .animation({
  2838. duration: 666,
  2839. curve: 'ease-in-out' // 可选动画曲线
  2840. })
  2841. .fillColor(this.themeColor)
  2842. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  2843. .bindPopup($$this.tipPopup, {
  2844. builder: this.popupBuilder,
  2845. placement: Placement.Bottom,
  2846. maskColor: 0x33000000,
  2847. enableArrow: true,
  2848. onStateChange: (e) => {
  2849. if (!e.isVisible) {
  2850. this.tipPopup = false;
  2851. }
  2852. }
  2853. })
  2854. .onClick(() => {
  2855. this.isGridMusic = !this.isGridMusic
  2856. })
  2857. }
  2858. .width('100%')
  2859. .padding(10)
  2860. .height(50)
  2861. .visibility(this.modeType === 0 || this.modeType === 1 || this.isCanBack ? Visibility.Visible : Visibility.None)
  2862. .border({
  2863. width: { bottom: 1 },
  2864. color: this.isCustomizeBg ? Color.Transparent : '#12ec5c87'
  2865. })
  2866. }
  2867. .visibility(this.isShowAllBar ? Visibility.Visible : Visibility.None)
  2868. }
  2869. // 第二步:popup构造器定义弹框内容
  2870. @Builder popupBuilder() {
  2871. Column({ space: 2 }) {
  2872. Text('友情提示:双指缩放可以放大缩小列表')
  2873. .fontSize(12)
  2874. .fontWeight(FontWeight.Regular)
  2875. .fontColor($r('app.color.text_color'))
  2876. }
  2877. .justifyContent(FlexAlign.SpaceAround)
  2878. .width(220)
  2879. .height(55)
  2880. .padding(15)
  2881. }
  2882. //搜索功能的实现
  2883. @State searchText: string = ''; // 用户输入内容
  2884. @State filteredList: Array<VideoItem> = []; // 过滤后的结果
  2885. @State isSearchMode: boolean = false
  2886. // 实时搜索逻辑(带防抖)
  2887. private onSearchInput(value: string) {
  2888. this.searchText = value.trim();
  2889. let mSearchList: Array<VideoItem> = []
  2890. switch (this.modeType) {
  2891. case 0:
  2892. mSearchList = this.videoLocalList
  2893. break;
  2894. case 1:
  2895. mSearchList = this.mediaKuList
  2896. break;
  2897. case 2:
  2898. mSearchList = this.artistList
  2899. break;
  2900. case 3:
  2901. mSearchList = this.albumList
  2902. break;
  2903. }
  2904. // 新增条件判断:空输入时显示所有数据
  2905. if (this.searchText === '') {
  2906. this.filteredList = [...mSearchList]; // 创建新数组以触发状态更新
  2907. } else {
  2908. this.filteredList = mSearchList.filter((item: VideoItem) => {
  2909. return item.name.toLowerCase().includes(this.searchText.toLowerCase());
  2910. });
  2911. }
  2912. this.updateListData(this.filteredList);
  2913. // this.isSearchMode = false; // 根据业务需求决定是否启用
  2914. }
  2915. @State dragItem: number = -1
  2916. @State scaleItem: number = -1
  2917. @State neighborItem: number = -1
  2918. @State neighborScale: number = -1
  2919. @State offsetY: number = 0
  2920. private dragRefOffset: number = 0
  2921. private ITEM_INTV: number = 78
  2922. scaleSelect(item: number): number {
  2923. if (this.scaleItem === item) {
  2924. return 1.05
  2925. } else if (this.neighborItem === item) {
  2926. return this.neighborScale
  2927. } else {
  2928. return 1
  2929. }
  2930. }
  2931. itemMove(index: number, newIndex: number): void {
  2932. if (newIndex < 0 || newIndex >= this.videoLocalList.length) {
  2933. return;
  2934. }
  2935. let tmp = this.videoLocalList.splice(index, 1);
  2936. this.videoLocalList.splice(newIndex, 0, tmp[0]);
  2937. this.dataSource.pushArrayData(this.videoLocalList)
  2938. }
  2939. // Grid布局的开始
  2940. private dragRefOffSetX: number = 0;
  2941. private dragRefOffSetY: number = 0;
  2942. private FIX_VP_X: number = 180;
  2943. private FIX_VP_Y: number = 84;
  2944. isDraggable(index: number): boolean {
  2945. return index >= 0;
  2946. }
  2947. getRowEnd(item: number) {
  2948. if (item.toString() === '0') {
  2949. return 1;
  2950. } else {
  2951. return 0;
  2952. }
  2953. }
  2954. // [Start itemMove_start]
  2955. // itemMoveGrid(index: number, newIndex: number): void {
  2956. // if (!this.isDraggable(newIndex)) {
  2957. // return;
  2958. // }
  2959. // let tmp = this.videoLocalList.splice(index, 1);
  2960. // this.videoLocalList.splice(newIndex, 0, tmp[0]);
  2961. // // this.bigItemIndex = this.videoLocalList.findIndex((item) => item === 0);
  2962. // }
  2963. isInLeft(index: number) {
  2964. return index % 2 == 0;
  2965. }
  2966. down(index: number): void {
  2967. if ([this.videoLocalList.length - 1, this.videoLocalList.length - 2].includes(index)) {
  2968. return;
  2969. }
  2970. this.offsetY -= this.FIX_VP_Y;
  2971. this.dragRefOffSetY += this.FIX_VP_Y;
  2972. this.itemMove(index, index + 1);
  2973. }
  2974. up(index: number): void {
  2975. if (!this.isDraggable(index - 2)) {
  2976. return;
  2977. }
  2978. this.offsetY += this.FIX_VP_Y;
  2979. this.dragRefOffSetY -= this.FIX_VP_Y;
  2980. this.itemMove(index, index - 1);
  2981. }
  2982. left(index: number): void {
  2983. if (this.isInLeft(index)) {
  2984. return;
  2985. }
  2986. if (!this.isDraggable(index - 1)) {
  2987. return;
  2988. }
  2989. this.offsetX += this.FIX_VP_X;
  2990. this.dragRefOffSetX -= this.FIX_VP_X;
  2991. this.itemMove(index, index - 1)
  2992. }
  2993. right(index: number): void {
  2994. if (!this.isInLeft(index)) {
  2995. return;
  2996. }
  2997. if (!this.isDraggable(index + 1)) {
  2998. return;
  2999. }
  3000. this.offsetX -= this.FIX_VP_X;
  3001. this.dragRefOffSetX += this.FIX_VP_X;
  3002. this.itemMove(index, index + 1)
  3003. }
  3004. private scroller: Scroller = new Scroller();
  3005. @State startIndex: number = 0
  3006. @State endIndex: number = 0
  3007. @State scaleValue: number = 1
  3008. @State pinchValue: number = 1
  3009. layoutOptionsForHeader: GridLayoutOptions = {
  3010. regularSize: [1, 1], // 只支持[1, 1]
  3011. irregularIndexes: [0], // 索引为0的GridItem占用一行
  3012. };
  3013. @Builder
  3014. getGridView() {
  3015. Grid(this.scroller, this.layoutOptionsForHeader) {
  3016. GridItem() {
  3017. if (this.isShowCoverHeader()) {
  3018. this.coverHeader()
  3019. } else {
  3020. this.listViewTitle()
  3021. }
  3022. }
  3023. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3024. GridItem() {
  3025. Stack({ alignContent: Alignment.Center }) {
  3026. this.MusicItemGrid(item, index)
  3027. }
  3028. }
  3029. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.LongPress,
  3030. {
  3031. preview: MenuPreviewMode.IMAGE,
  3032. previewAnimationOptions: { scale: [0.8, 1.0] },
  3033. })
  3034. .bindContextMenu(this.MenuBuilder(item, index, item.filePath), ResponseType.RightClick,
  3035. {
  3036. preview: MenuPreviewMode.IMAGE,
  3037. previewAnimationOptions: { scale: [0.8, 1.0] },
  3038. })
  3039. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.8, y: 0.8 }).animation({ duration: 500 }),
  3040. TransitionEffect.scale({ x: 0, y: 0 })))
  3041. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3042. .scale({ x: this.scaleItem === index ? 1.02 : 1, y: this.scaleItem === index ? 1.02 : 1 })
  3043. .zIndex(this.dragItem === index ? 1 : 0)
  3044. .translate(this.dragItem === index ? { x: this.offsetX, y: this.offsetY } : { x: 0, y: 0 })
  3045. .hitTestBehavior(this.isDraggable(this.videoLocalList.indexOf(item)) ? HitTestMode.Default : HitTestMode.None)
  3046. //长按拖动代码
  3047. // .gesture(
  3048. // GestureGroup(GestureMode.Sequence,
  3049. // LongPressGesture({ repeat: true })
  3050. // .onAction(() => {
  3051. // this.getUIContext().animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3052. // this.scaleItem = index;
  3053. // })
  3054. // })
  3055. // .onActionEnd(() => {
  3056. // this.getUIContext().animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3057. // this.scaleItem = -1;
  3058. // })
  3059. // }),
  3060. // PanGesture({ fingers: 1, direction: null, distance: 0 })
  3061. // .onActionStart(() => {
  3062. // this.dragItem = index;
  3063. // this.dragRefOffSetX = 0;
  3064. // this.dragRefOffSetY = 0;
  3065. // })
  3066. // .onActionUpdate((event: GestureEvent) => {
  3067. // this.offsetX = event.offsetX - this.dragRefOffSetX;
  3068. // this.offsetY = event.offsetY - this.dragRefOffSetY;
  3069. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3070. // let index = this.videoLocalList.indexOf(item);
  3071. // if (this.offsetY >= this.FIX_VP_Y / 2 && (this.offsetX <= 44 && this.offsetX >= -44)) {
  3072. // this.down(index);
  3073. // } else if (this.offsetY <= -this.FIX_VP_Y / 2 && (this.offsetX <= 44 && this.offsetX >= -44)) {
  3074. // this.up(index);
  3075. // } else if (this.offsetX >= this.FIX_VP_X / 2 && (this.offsetY <= 50 && this.offsetY >= -50)) {
  3076. // this.right(index);
  3077. // } else if (this.offsetX <= -this.FIX_VP_Y / 2 && (this.offsetY <= 50 && this.offsetY >= -50)) {
  3078. // this.left(index);
  3079. // }
  3080. // })
  3081. //
  3082. //
  3083. // // if (this.offsetY > this.FIX_VP_Y * 0.7) {
  3084. // // this.scroller.scrollToIndex(index + 10, true,ScrollAlign.CENTER);
  3085. // // }
  3086. //
  3087. //
  3088. // })
  3089. // .onActionEnd(() => {
  3090. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3091. // this.dragItem = -1;
  3092. // })
  3093. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150 }, () => {
  3094. // this.scaleItem = -1;
  3095. // })
  3096. // })
  3097. // )
  3098. // .onCancel(() => {
  3099. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3100. // this.dragItem = -1;
  3101. // })
  3102. // this.getUIContext().animateTo({ curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150 }, () => {
  3103. // this.scaleItem = -1;
  3104. // })
  3105. // })
  3106. // )
  3107. // [End gesture_start]
  3108. // [EndExclude GridItem_start]
  3109. }, (item: VideoItem) => item.filePath)
  3110. }
  3111. .width(this.isShowHeader ? '100%' : '94%')
  3112. .height('100%')
  3113. .editMode(true)
  3114. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3115. .animation({ duration: 500, curve: Curve.Ease }))
  3116. // .margin({ bottom: this.isCoverOpacity() ? 80 : 175 })
  3117. .margin({
  3118. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+30 : this.topBarHeight+90)
  3119. : (this.isShowCoverHeader() ? this.topBarHeight+45 : this.topBarHeight+128)
  3120. })
  3121. .layoutWeight(1)
  3122. .scrollBar(BarState.Off)
  3123. .supportAnimation(true)
  3124. .cachedCount(this.twoFingerType==1?5:this.twoFingerType==2?4:3)
  3125. // .columnsTemplate('1fr '.repeat(this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM ? 2 : 5))
  3126. .columnsTemplate(
  3127. this.twoFingerType == 3 ? 'repeat(auto-fit, 160)' :
  3128. this.twoFingerType == 2 ? 'repeat(auto-fit, 110)' : 'repeat(auto-fit, 80)'
  3129. )
  3130. .rowsGap(this.isShowDrawer ? 25 : (this.twoFingerType == 3 ? 10 : this.twoFingerType == 2 ? 5 : 1))
  3131. .visibility(this.isGridMusic ? Visibility.Visible : Visibility.None)
  3132. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3133. .gesture(PinchGesture({ fingers: 2 })
  3134. .onActionEnd((event: GestureEvent) => {
  3135. this.setGridTwoFingers()
  3136. })
  3137. .onActionUpdate(e => {
  3138. this.scaleValue = this.pinchValue * e.scale
  3139. })
  3140. .onActionStart(e => {
  3141. }))
  3142. .enableScrollInteraction(true)
  3143. // 滚轴滑动,记录下滑动时的起始位置和终点位置
  3144. .onScrollIndex((start: number, end: number) => {
  3145. this.startIndex = start
  3146. this.endIndex = end
  3147. })
  3148. .onScrollFrameBegin((offset: number) => {
  3149. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  3150. // if (this.isPhoneLan()) {
  3151. // this.setBarHeightHide(offset)
  3152. // } else
  3153. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3154. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3155. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3156. if (this.isScrollHide) {
  3157. this.setBarHeightHide2(offset)
  3158. } else {
  3159. this.setBarHeightNormal()
  3160. }
  3161. } else {
  3162. this.setBarHeightHide(offset)
  3163. }
  3164. return { offsetRemain: offset };
  3165. })
  3166. //允许拖拽音乐和视频到List或Grid上自动导入视频
  3167. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3168. .onDrop((event?: DragEvent) => {
  3169. try {
  3170. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3171. if (dragData !== undefined) {
  3172. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3173. if (records.length > 0) {
  3174. for (let i = 0; i < records.length; i++) {
  3175. let types = records[i].getTypes();
  3176. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3177. const fileUriUds =
  3178. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3179. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3180. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3181. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3182. this.targetFile = fileUriUds.oriUri;
  3183. this.saveVideoDatas([this.targetFile])
  3184. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3185. }
  3186. }
  3187. }
  3188. } else {
  3189. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3190. }
  3191. } else {
  3192. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3193. }
  3194. } catch (error) {
  3195. const err = error as BusinessError;
  3196. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3197. }
  3198. })
  3199. }
  3200. @State targetFile: string = '';
  3201. setGridTwoFingers() {
  3202. this.pinchValue = this.scaleValue;
  3203. Logger.info('this.pinchValue = ' + this.pinchValue);
  3204. if (this.pinchValue >= 1) {
  3205. this.twoFingerType++
  3206. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3207. if (this.twoFingerType > 3) {
  3208. this.twoFingerType = 3
  3209. }
  3210. } else {
  3211. this.twoFingerType--
  3212. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3213. if (this.twoFingerType < 1) {
  3214. this.twoFingerType = 3
  3215. this.isGridMusic = false
  3216. }
  3217. }
  3218. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3219. this.pinchValue = 1;
  3220. this.scaleValue = 1;
  3221. }
  3222. @State longItemFilePath: string = ''
  3223. @State tempLyricContent: string = ''
  3224. @Builder
  3225. private MusicItemGrid(item: VideoItem, index: number) {
  3226. Button({ type: ButtonType.Normal, stateEffect: false }) {
  3227. Stack() {
  3228. Column() {
  3229. Image(StrUtil.isEmpty(item.pixelMapPath) ? Utility.getMusisBg2(index) : item.pixelMapPath)
  3230. .height(this.getGridHeight())
  3231. .width(this.getGridWight())
  3232. .draggable(false)
  3233. .interpolation(ImageInterpolation.Medium)// 用于重采样后的抗锯齿
  3234. .autoResize(true) // 重采样,可减少内存占用
  3235. .alt($r('app.media.ic_avatar2'))
  3236. .clip(true)
  3237. .borderRadius({
  3238. topLeft: 12,
  3239. topRight: 12,
  3240. bottomLeft: 0,
  3241. bottomRight: 0
  3242. })
  3243. .bindSheet(this.longItemFilePath== item.filePath, this.editSheet(item), {
  3244. height: this.isCoverOpacity() ? '95%' : '88%',
  3245. dragBar: true,
  3246. onDisappear: () => {
  3247. this.longItemFilePath = '';
  3248. this.tempLyricContent = ''
  3249. },
  3250. showClose: true,
  3251. preferType: SheetType.CENTER ,
  3252. title: { title: '编辑信息' }
  3253. })
  3254. .draggable(false)
  3255. .opacity(this.opacityItem)// 绑定透明度
  3256. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3257. // .animation({ duration: 500, curve: Curve.Ease }))
  3258. .animation({
  3259. duration: 666,
  3260. curve: 'ease-in-out' // 可选动画曲线
  3261. })
  3262. .margin({
  3263. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3264. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3265. })
  3266. Column() {
  3267. Text(item.name.startsWith('.') ? item.name.replace(/\./g, '') : item.name)
  3268. .fontSize(this.twoFingerType == 1 ? 14 : this.twoFingerType == 2 ? 16 : 18)
  3269. .maxLines(1)
  3270. .fontWeight(FontWeight.Bold)
  3271. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3272. .animation({
  3273. duration: 555,
  3274. curve: 'Linear',
  3275. })
  3276. .bindSheet(this.longItemFilePathDetail== item.filePath, this.detailSheet(item), {
  3277. height: '95%',
  3278. dragBar: true,
  3279. showClose: true,
  3280. onDisappear: () => {
  3281. this.longItemFilePathDetail = '';
  3282. },
  3283. blurStyle:BlurStyle.Thin,
  3284. backgroundColor:Color.Transparent,
  3285. preferType: SheetType.CENTER ,
  3286. title: { title: '详情' }
  3287. })
  3288. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3289. $r('app.color.text_color'))
  3290. Column() {
  3291. Text(`${this.artistMap.get(item.name)?.length ?? 0}首`)
  3292. .fontSize(11)
  3293. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3294. .visibility(this.modeType === 2 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3295. .fontColor($r('app.color.text_color'))
  3296. Text(`${this.albumMap.get(item.name)?.length ?? 0}首`)
  3297. .fontSize(11)
  3298. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
  3299. .visibility(this.modeType === 3 && !this.isCanBack ? Visibility.Visible : Visibility.None)
  3300. .fontColor($r('app.color.text_color'))
  3301. Row(){
  3302. Column(){
  3303. Text(item.md5Str?.includes('Lossless')?
  3304. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  3305. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  3306. .padding({ top: 3,right:6,left:6,bottom:3 })
  3307. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3308. $r('app.color.text_color'))
  3309. .fontWeight(500)
  3310. .borderRadius(12)
  3311. .margin({ left: this.twoFingerType == 3 ? 6 : 8 })
  3312. .backgroundColor('#FFC107')
  3313. .visibility(StrUtil.isEmpty(item.md5Str)?Visibility.None:Visibility.Visible)
  3314. }
  3315. .margin({ top: 2 ,right:6})
  3316. .visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
  3317. ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
  3318. Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
  3319. .fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 13)
  3320. .maxLines(1)
  3321. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  3322. .margin({ top: 2})
  3323. .visibility(item.type == CommonConstants.TYPE_IS_ARTIST
  3324. || item.type == CommonConstants.TYPE_IS_ALBUM
  3325. || item.type == CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3326. .fontWeight(FontWeight.Medium)
  3327. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  3328. $r('app.color.text_color'))
  3329. }
  3330. }
  3331. .alignItems(HorizontalAlign.Center) // 关键:使内容水平居中
  3332. }
  3333. // .bindPopup(this.longItemFilePath === item.filePath, {
  3334. // builder: this.MenuBuilder(item, index, item.filePath),
  3335. // placement: Placement.Top,
  3336. // // autoCancel: true,
  3337. // mask: { color: '#33000000' },
  3338. // // popupColor: Color.Yellow,
  3339. // enableArrow: false, //是否显示箭头
  3340. // showInSubWindow: false,
  3341. // onStateChange: (e) => {
  3342. // if (!e.isVisible) {
  3343. // this.longItemFilePath = ''
  3344. // this.tempLyricContent = ''
  3345. // }
  3346. // }
  3347. // })
  3348. //
  3349. // .gesture(LongPressGesture()
  3350. // .onAction(async () => {
  3351. // //如果是专辑和艺术家的首页,不能长按
  3352. // if ((this.modeType === 2 || this.modeType == 3) && !this.isCanBack) {
  3353. // return
  3354. // }
  3355. // //如果是我的收藏 最近播放等也不能长按
  3356. // if (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3357. // item.name === LocalMusic.STR_HISTORY_MUSIC
  3358. // ) {
  3359. // return
  3360. // }
  3361. // this.longItemFilePath = item.filePath
  3362. // this.tempLyricContent = await this.getLyricContent(item)
  3363. // LogUtil.info('长按this.tempLyricContent = ' + this.tempLyricContent)
  3364. // })
  3365. // .onActionEnd((event: GestureEvent) => {
  3366. //
  3367. // })
  3368. // )
  3369. .height(this.twoFingerType == 3 ? 60 : this.twoFingerType == 2 ? 55 : 42)
  3370. .width(this.getGridWight())
  3371. .justifyContent(FlexAlign.Center)
  3372. .margin({
  3373. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20,
  3374. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 40 : 20
  3375. })
  3376. }
  3377. .width(this.getGridWight())
  3378. .borderRadius(12)
  3379. .backgroundImage(StrUtil.isEmpty(item.pixelMapPath)?Utility.getMusisBg2(index):item.pixelMapPath)
  3380. .backgroundImageSize({ height: '100%', width: '100%' })
  3381. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  3382. .animation({ curve: Curve.Sharp, duration: 300 })
  3383. Checkbox({ name: 'checkbox' + index })
  3384. .select(this.selectedFiles.some(x => x.filePath == item.filePath))
  3385. .selectedColor(this.themeColor)
  3386. .shape(CheckBoxShape.CIRCLE)
  3387. .opacity(this.isMultiSelect ? 1 : 0)
  3388. .animation({
  3389. duration: 666,
  3390. curve: 'Smooth' // 可选动画曲线
  3391. })
  3392. .visibility(this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR ? Visibility.Visible :
  3393. Visibility.None)
  3394. .onChange((checked: boolean) => this.handleFileSelection(item, checked))
  3395. .margin({ left: 20, top: 8, bottom: 8 })
  3396. .width(38)
  3397. .height(38)
  3398. }
  3399. }
  3400. .backgroundColor(Color.Transparent)
  3401. .width('100%')
  3402. .padding({ top: 15 })
  3403. .height(this.getGridAllHeight())
  3404. .onClick(() => {
  3405. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3406. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3407. this.handleFileSelection(item, !isChecked);
  3408. } else {
  3409. this.doPlay(item, index)
  3410. }
  3411. })
  3412. }
  3413. getGridAllHeight() {
  3414. let heightG = 222
  3415. switch (this.twoFingerType) {
  3416. case 1:
  3417. heightG = 118
  3418. break;
  3419. case 2:
  3420. heightG = 168
  3421. break;
  3422. case 3:
  3423. heightG = 222
  3424. break;
  3425. }
  3426. return heightG
  3427. }
  3428. getGridHeight() {
  3429. let heightG = 150
  3430. switch (this.twoFingerType) {
  3431. case 1:
  3432. heightG = 55
  3433. break;
  3434. case 2:
  3435. heightG = 100
  3436. break;
  3437. case 3:
  3438. heightG = 150
  3439. break;
  3440. }
  3441. return heightG
  3442. }
  3443. getGridWight() {
  3444. let wightG = 158
  3445. switch (this.twoFingerType) {
  3446. case 1:
  3447. wightG = 80
  3448. break;
  3449. case 2:
  3450. wightG = 110
  3451. break;
  3452. case 3:
  3453. wightG = 158
  3454. break;
  3455. }
  3456. return wightG
  3457. }
  3458. @State isShowDetail:boolean = false
  3459. // @State isShowDetailGrid:boolean = false
  3460. // @State isShowEditGrid:boolean = false
  3461. @State longItemFilePathDetail:string =''
  3462. @Builder
  3463. MenuBuilder(item: VideoItem, index: number, filePath: string) {
  3464. if(
  3465. ((this.modeType===2||this.modeType==3)&&!this.isCanBack)
  3466. ||(item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3467. item.name === LocalMusic.STR_HISTORY_MUSIC)
  3468. ){
  3469. //如果是专辑和艺术家的首页,不能长按
  3470. //如果是我的收藏 最近播放等也不能长按
  3471. }else{
  3472. Scroll() {
  3473. Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
  3474. Menu() {
  3475. MenuItem({
  3476. symbolStartIcon: new SymbolGlyphModifier(Utility.getIsFav(this.favList, item) ?
  3477. $r('sys.symbol.heart_fill') : $r('sys.symbol.heart')),
  3478. content: Utility.getIsFav(this.favList, item) ? '取消收藏' : '收藏'
  3479. })
  3480. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3481. .onClick(() => {
  3482. if (item) {
  3483. this.doFav(item)
  3484. }
  3485. this.longItemFilePath = ''
  3486. })
  3487. MenuItem({
  3488. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.forward_end_fill')),
  3489. content: '下一首播放'
  3490. })
  3491. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3492. .onClick(() => {
  3493. this.addToNextPlay(item);
  3494. this.longItemFilePath = ''
  3495. })
  3496. MenuItem({
  3497. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
  3498. content: '编辑信息'
  3499. })
  3500. .bindSheet($$this.isShowEdit, this.editSheet(item), {
  3501. height: this.isCoverOpacity() ? '95%' : '88%',
  3502. dragBar: true,
  3503. showClose: true,
  3504. preferType: SheetType.CENTER ,
  3505. title: { title: '编辑信息' }
  3506. })
  3507. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3508. .onClick(async() => {
  3509. this.tempLyricContent = await this.getLyricContent(item);
  3510. // console.info('onecold 长按this.tempLyricContent' +this.tempLyricContent)
  3511. if(this.isGridMusic){
  3512. this.longItemFilePath = item.filePath
  3513. }else{
  3514. this.isShowEdit = !this.isShowEdit;
  3515. }
  3516. })
  3517. MenuItem({
  3518. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.checkmark_square_on_square')),
  3519. content: $r('app.string.select_all')
  3520. })
  3521. .onClick(() => {
  3522. this.isMultiSelect = !this.isMultiSelect
  3523. this.longItemFilePath = ''
  3524. })
  3525. MenuItem({
  3526. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.rename')),
  3527. content: $r('app.string.rename')
  3528. })
  3529. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3530. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3531. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3532. .onClick(() => {
  3533. this.showReNameDialog(item, index + '', filePath)
  3534. this.longItemFilePath = ''
  3535. })
  3536. MenuItem({
  3537. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
  3538. content: $r('app.string.delete')
  3539. })
  3540. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  3541. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  3542. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  3543. .onClick(() => {
  3544. this.showWarnIsDeleteFile(item, index + '', filePath)
  3545. this.longItemFilePath = ''
  3546. })
  3547. MenuItem({
  3548. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.info_circle')),
  3549. content: $r('app.string.detail')
  3550. })
  3551. .bindSheet($$this.isShowDetail, this.detailSheet(item), {
  3552. height:'95%',
  3553. dragBar: true,
  3554. showClose: true,
  3555. blurStyle:BlurStyle.Thin,
  3556. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  3557. backgroundColor:Color.Transparent,
  3558. title: { title: '详情信息' }
  3559. })
  3560. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3561. .onClick(() => {
  3562. if(this.isGridMusic){
  3563. this.longItemFilePathDetail = item.filePath
  3564. }else{
  3565. this.isShowDetail = !this.isShowDetail
  3566. }
  3567. })
  3568. MenuItem({
  3569. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.share')),
  3570. content: $r('app.string.share')
  3571. })
  3572. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  3573. .onClick(() => {
  3574. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  3575. this.longItemFilePath = ''
  3576. })
  3577. }
  3578. .font({ size: 15, weight: FontWeight.Normal })
  3579. }
  3580. .width(180)
  3581. }
  3582. .height('auto')
  3583. }
  3584. }
  3585. private listMaxScrollOffsetY: number = 0
  3586. @State selectedIndex: number = -1
  3587. setlistTwoFingers() {
  3588. this.pinchValue = this.scaleValue;
  3589. Logger.info('this.pinchValue = ' + this.pinchValue);
  3590. if (this.pinchValue >= 1) {
  3591. this.twoFingerType++
  3592. Logger.info('this.twoFingerType1 = ' + this.twoFingerType);
  3593. if (this.twoFingerType > 3) {
  3594. this.twoFingerType = 1
  3595. this.isGridMusic = true
  3596. }
  3597. } else {
  3598. this.twoFingerType--
  3599. Logger.info('this.twoFingerType2 = ' + this.twoFingerType);
  3600. if (this.twoFingerType < 1) {
  3601. this.twoFingerType = 1
  3602. }
  3603. }
  3604. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  3605. this.pinchValue = 1;
  3606. this.scaleValue = 1;
  3607. }
  3608. @Builder
  3609. getListView() {
  3610. List({ scroller: this.listScroller }) {
  3611. ListItemGroup({ header: this.coverHeader() }) {
  3612. LazyForEach(this.dataSource, (item: VideoItem, index: number) => {
  3613. ListItem() {
  3614. Column() {
  3615. if (item.type === CommonConstants.TYPE_IS_DIR
  3616. || item.type === CommonConstants.TYPE_IS_ARTIST || item.type === CommonConstants.TYPE_IS_ALBUM) {
  3617. this.DirItem(item, index)
  3618. } else if (item.type === CommonConstants.TYPE_IS_CSJAD) { //如果是穿山甲广告
  3619. } else {
  3620. this.MusicItem(item, index)
  3621. }
  3622. }
  3623. .shadow(this.scaleItem === index ? {
  3624. radius: 70,
  3625. color: '#15000000',
  3626. offsetX: 0,
  3627. offsetY: 0
  3628. } :
  3629. {
  3630. radius: 0,
  3631. color: '#15000000',
  3632. offsetX: 0,
  3633. offsetY: 0
  3634. })
  3635. .animation({ curve: Curve.Sharp, duration: 300 })
  3636. }
  3637. // .transition(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }))
  3638. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
  3639. .animation({ duration: 500 }),
  3640. TransitionEffect.scale({ x: 0, y: 0 })))
  3641. .clickEffect({ level: ClickEffectLevel.LIGHT })
  3642. .swipeAction((
  3643. (this.isSwipe&&this.modeType == 0 || this.modeType == 1 || ((this.modeType == 3 || this.modeType == 2) && this.isCanBack))
  3644. && item.type !== CommonConstants.TYPE_IS_CSJAD &&
  3645. !this.isHistory) ? { end: this.DeleteButton(item, index, item.filePath) } : {}) //左滑
  3646. .onClick(() => {
  3647. if (this.isMultiSelect && item.type !== CommonConstants.TYPE_IS_DIR) {
  3648. const isChecked = this.selectedFiles.some(x => x.filePath == item.filePath);
  3649. this.handleFileSelection(item, !isChecked);
  3650. } else {
  3651. this.doPlay(item, index)
  3652. }
  3653. })
  3654. //拖动List关键代码开始
  3655. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  3656. .zIndex(this.dragItem === index ? 1 : 0)
  3657. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  3658. .gesture(
  3659. GestureGroup(GestureMode.Sequence,
  3660. LongPressGesture({ repeat: true })
  3661. .onAction((event?: GestureEvent) => {
  3662. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3663. this.scaleItem = index
  3664. })
  3665. })
  3666. .onActionEnd(() => {
  3667. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  3668. this.scaleItem = -1
  3669. })
  3670. }),
  3671. PanGesture({ fingers: 1, direction: null, distance: 0 })
  3672. .onActionStart(() => {
  3673. this.dragItem = index // 记录当前拖动项索引
  3674. this.dragRefOffset = 0 // 重置偏移基准
  3675. })
  3676. .onActionUpdate((event: GestureEvent) => {
  3677. this.offsetY = event.offsetY - this.dragRefOffset;
  3678. this.neighborItem = -1;
  3679. let indexA = this.videoLocalList.indexOf(item);
  3680. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  3681. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  3682. let value: number = 0;
  3683. if (this.offsetY < 0) {
  3684. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  3685. this.neighborItem = indexA - 1;
  3686. this.neighborScale = 1 - value / 20;
  3687. } else if (this.offsetY > 0) {
  3688. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  3689. this.neighborItem = indexA + 1;
  3690. this.neighborScale = 1 - value / 20;
  3691. }
  3692. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.videoLocalList.length) {
  3693. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3694. this.offsetY -= this.ITEM_INTV;
  3695. this.dragRefOffset += this.ITEM_INTV;
  3696. this.itemMove(indexA, indexA + 1);
  3697. });
  3698. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  3699. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3700. this.offsetY += this.ITEM_INTV;
  3701. this.dragRefOffset -= this.ITEM_INTV;
  3702. this.itemMove(indexA, indexA - 1);
  3703. });
  3704. }
  3705. let curListOffset = this.listScroller.currentOffset()
  3706. // 获取手指信息
  3707. let fingerInfo = event.fingerList[0]
  3708. let clickPercentY =
  3709. (fingerInfo.globalY - Number(this.listArea.globalPosition.y)) / Number(this.listArea.height)
  3710. if (clickPercentY > 0.8 && !this.listScroller.isAtEnd()) {
  3711. let scrollVelocity = clickPercentY > 0.9 ? 4 : 2
  3712. if (this.listMaxScrollOffsetY - curListOffset.yOffset > scrollVelocity + 5) {
  3713. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset += scrollVelocity })
  3714. }
  3715. } else if (clickPercentY < 0.2 && curListOffset.yOffset >= 0) {
  3716. let scrollVelocity = clickPercentY < 0.1 ? 4 : 2
  3717. if (curListOffset.yOffset > scrollVelocity + 5) {
  3718. this.listScroller.scrollTo({ xOffset: 0, yOffset: curListOffset.yOffset -= scrollVelocity })
  3719. }
  3720. }
  3721. })
  3722. .onActionEnd((event: GestureEvent) => {
  3723. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3724. this.dragItem = -1
  3725. this.neighborItem = -1
  3726. })
  3727. animateTo({
  3728. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  3729. }, () => {
  3730. this.scaleItem = -1
  3731. })
  3732. })
  3733. )
  3734. .onCancel(() => {
  3735. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  3736. this.dragItem = -1
  3737. this.neighborItem = -1
  3738. })
  3739. animateTo({
  3740. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  3741. }, () => {
  3742. this.scaleItem = -1
  3743. })
  3744. })
  3745. ) //拖动List关键代码结束
  3746. }, (item: VideoItem) => item.filePath)
  3747. }
  3748. }
  3749. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  3750. .gesture(PinchGesture({ fingers: 2 })
  3751. .onActionEnd((event: GestureEvent) => {
  3752. this.setlistTwoFingers()
  3753. })
  3754. .onActionUpdate(e => {
  3755. this.scaleValue = this.pinchValue * e.scale
  3756. })
  3757. .onActionStart(e => {
  3758. }))
  3759. // .divider({ strokeWidth: 1, color: this.isDarkMode? '#333333':'#ffe9f0f0' })
  3760. .margin({
  3761. bottom: this.isCoverOpacity() ? (this.isShowCoverHeader() ? this.topBarHeight+25 : this.topBarHeight+80)
  3762. : (this.isShowCoverHeader() ? this.topBarHeight+35 : this.isHiCarSmall()?this.topBarHeight+90:this.topBarHeight+125)
  3763. })
  3764. .cachedCount(6)
  3765. .borderRadius(20)
  3766. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  3767. TransitionEffect.scale({ x: 0, y: 0 })))
  3768. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  3769. // .animation({ duration: 500, curve: Curve.Ease }))
  3770. .layoutWeight(1)
  3771. .onScrollIndex((start) => {
  3772. this.selectedIndex = start
  3773. })
  3774. .visibility(this.isGridMusic ? Visibility.None : Visibility.Visible)
  3775. .lanes(
  3776. new BreakpointType<number>({
  3777. sm: 1,
  3778. md: 2,
  3779. lg: 2,
  3780. xl: 3,
  3781. xxl: 4
  3782. }).getValue(this.currentBreakpoint),
  3783. new BreakpointType<number>({
  3784. sm: 0,
  3785. md: 12,
  3786. lg: 12,
  3787. xl: 16,
  3788. xxl: 20
  3789. }).getValue(this.currentBreakpoint)
  3790. )
  3791. .onAreaChange((oldValue: Area, newValue: Area) => {
  3792. this.listArea = newValue
  3793. if (this.twoFingerType == 3) {
  3794. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_BIG) - 10
  3795. } else if (this.twoFingerType == 2) {
  3796. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT) - 10
  3797. } else if (this.twoFingerType == 1) {
  3798. this.listMaxScrollOffsetY = this.videoLocalList.length * (ITEM_HEIGHT_SMALL) - 10
  3799. }
  3800. })
  3801. .onScrollFrameBegin((offset: number) => {
  3802. //滚动小屏幕 比如puraX外屏和手机横屏可以隐藏bottomBarHeight topBarHeight
  3803. // if (this.isPhoneLan()) {
  3804. // this.setBarHeightHide(offset)
  3805. // } else
  3806. if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
  3807. (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
  3808. this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
  3809. if (this.isScrollHide) {
  3810. this.setBarHeightHide2(offset)
  3811. } else {
  3812. this.setBarHeightNormal()
  3813. }
  3814. } else {
  3815. this.setBarHeightHide(offset)
  3816. }
  3817. return { offsetRemain: offset };
  3818. })
  3819. //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
  3820. .allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
  3821. .onDrop((event?: DragEvent) => {
  3822. try {
  3823. let dragData: UnifiedData = (event as DragEvent).getData() as UnifiedData;
  3824. if (dragData !== undefined) {
  3825. let records: unifiedDataChannel.UnifiedRecord[] = dragData.getRecords();
  3826. if (records.length > 0) {
  3827. for (let i = 0; i < records.length; i++) {
  3828. let types = records[i].getTypes();
  3829. if (types.includes(uniformTypeDescriptor.UniformDataType.FILE_URI)) {
  3830. const fileUriUds =
  3831. records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
  3832. let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
  3833. if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
  3834. ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
  3835. this.targetFile = fileUriUds.oriUri;
  3836. this.saveVideoDatas([this.targetFile])
  3837. hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
  3838. }
  3839. }
  3840. }
  3841. } else {
  3842. hilog.info(0x0000, TAG, `%{public}s`, `dragData arr is null`);
  3843. }
  3844. } else {
  3845. hilog.info(0x0000, TAG, `%{public}s`, `dragData is undefined`);
  3846. }
  3847. } catch (error) {
  3848. const err = error as BusinessError;
  3849. hilog.error(0x0000, TAG, `startDataLoading errorCode: ${err.code}, errorMessage: ${err.message}`);
  3850. }
  3851. })
  3852. }
  3853. setBarHeightNormal() {
  3854. this.hideDone = false;
  3855. this.getUIContext().animateTo({
  3856. duration: 300
  3857. }, () => {
  3858. this.bottomBarHeight = 55 + 0;
  3859. this.topBarHeight = 50 + 0;
  3860. this.barOpacity = 1;
  3861. this.barBottomOpacity = 1
  3862. this.currentYOffset = 0;
  3863. this.isHiding = false;
  3864. });
  3865. }
  3866. setBarHeightHide(offset: number) {
  3867. if (offset > 0 && !this.hideDone) {
  3868. this.currentYOffset += offset;
  3869. if (this.currentYOffset <= 100) {
  3870. this.bottomBarHeight = this.bottomBarHeight * (1 - this.currentYOffset / 100);
  3871. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  3872. this.barOpacity = 1 - this.currentYOffset / 100;
  3873. this.barBottomOpacity = 1 - this.currentYOffset / 100;
  3874. } else {
  3875. this.topBarHeight = 0;
  3876. this.bottomBarHeight = 0;
  3877. this.barBottomOpacity = 0
  3878. this.barOpacity = 0;
  3879. this.hideDone = true;
  3880. }
  3881. this.isHiding = true;
  3882. }
  3883. if (offset < 0 && this.isHiding) {
  3884. this.hideDone = false;
  3885. this.getUIContext().animateTo({
  3886. duration: 300
  3887. }, () => {
  3888. this.bottomBarHeight = 55 + 0;
  3889. this.topBarHeight = 50 + 0;
  3890. this.barOpacity = 1;
  3891. this.barBottomOpacity = 1
  3892. this.currentYOffset = 0;
  3893. this.isHiding = false;
  3894. });
  3895. }
  3896. }
  3897. //这个方法没隐藏bottomBar,只隐藏topbar
  3898. setBarHeightHide2(offset: number) {
  3899. if (offset > 0 && !this.hideDone) {
  3900. this.currentYOffset += offset;
  3901. if (this.currentYOffset <= 100) {
  3902. this.topBarHeight = this.topBarHeight * (1 - this.currentYOffset / 100);
  3903. this.barOpacity = 1 - this.currentYOffset / 100;
  3904. } else {
  3905. this.topBarHeight = 0;
  3906. this.barOpacity = 0;
  3907. this.hideDone = true;
  3908. }
  3909. this.isHiding = true;
  3910. }
  3911. if (offset < 0 && this.isHiding) {
  3912. this.hideDone = false;
  3913. this.getUIContext().animateTo({
  3914. duration: 300
  3915. }, () => {
  3916. this.topBarHeight = 50 + 0;
  3917. this.barOpacity = 1;
  3918. this.currentYOffset = 0;
  3919. this.isHiding = false;
  3920. });
  3921. }
  3922. }
  3923. private doPlay(item: VideoItem, index?: number, isFromSonPlayList?: boolean) {
  3924. switch (item.type) {
  3925. case CommonConstants.TYPE_IS_DIR:
  3926. // 进入歌单前安全保存当前滚动偏移量,支持列表和网格
  3927. let offsetB = 0
  3928. if (this.isGridMusic) {
  3929. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  3930. let cur = this.scroller.currentOffset()
  3931. if (cur && typeof cur.yOffset === 'number') {
  3932. offsetB = cur.yOffset
  3933. }
  3934. }
  3935. this.mScrollMap.set('lastGridDirScrollOffset', offsetB)
  3936. } else {
  3937. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  3938. let cur = this.listScroller.currentOffset()
  3939. if (cur && typeof cur.yOffset === 'number') {
  3940. offsetB = cur.yOffset
  3941. }
  3942. }
  3943. this.mScrollMap.set('lastListDirScrollOffset', offsetB)
  3944. }
  3945. if (item.name === LocalMusic.STR_LOCK_VIDEO) {
  3946. this.showVerifyDialog()
  3947. this.currentTitleName = '私密音频'
  3948. this.currentTitleCover = $r('app.media.ic_avatar5')
  3949. } else if (item.name === LocalMusic.STR_HISTORY_MUSIC) {
  3950. this.titleBarModel.setTitleName('最近播放')
  3951. this.currentTitleCover = $r('app.media.ic_avatar2')
  3952. this.currentTitleName = '最近播放'
  3953. //加载动画效果
  3954. this.updateListData(this.historyList, true)
  3955. // this.videoLocalList = this.historyList
  3956. if (ArrayUtil.isEmpty(this.historyList)) {
  3957. ToastUtil.showToast('最近播放记录空空如也')
  3958. } else {
  3959. this.currentTitleCover = Utility.getFirstCoverFromList(this.historyList)
  3960. }
  3961. this.isHistory = true
  3962. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  3963. } else if (item.name === LocalMusic.STR_FAC_VIDEO) {
  3964. this.titleBarModel.setTitleName('我的收藏')
  3965. this.currentTitleName = '我的收藏'
  3966. this.currentTitleCover = $r('app.media.ic_avatar1')
  3967. //加载动画效果
  3968. this.updateListData(this.favList)
  3969. if (ArrayUtil.isEmpty(this.favList)) {
  3970. ToastUtil.showToast('无音乐收藏记录')
  3971. } else {
  3972. this.currentTitleCover = Utility.getFirstCoverFromList(this.favList)
  3973. }
  3974. this.isFavMusic = true
  3975. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  3976. } else {
  3977. this.currentTitleName = item.name
  3978. this.currentPath = item.filePath
  3979. this.currentTitleCover = $r('app.media.ic_avatar5')
  3980. this.getSortedFiles(this.currentPath)
  3981. }
  3982. //进入歌单的时候的滚动位置在顶部
  3983. if (this.isGridMusic) {
  3984. this.scroller.scrollToIndex(0)
  3985. }
  3986. setTimeout(() => {
  3987. if (this.modeType == 0) {
  3988. if (!this.isGridMusic) {
  3989. this.listScroller.scrollToIndex(0)
  3990. }
  3991. }
  3992. }, 200)
  3993. break;
  3994. case CommonConstants.TYPE_IS_ARTIST:
  3995. // 进入艺术家前安全保存当前滚动偏移量,支持列表和网格
  3996. let offsetA = 0
  3997. if (this.isGridMusic) {
  3998. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  3999. let cur = this.scroller.currentOffset()
  4000. if (cur && typeof cur.yOffset === 'number') {
  4001. offsetA = cur.yOffset
  4002. }
  4003. }
  4004. this.mScrollMap.set('lastGridArtistScrollOffset', offsetA)
  4005. } else {
  4006. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4007. let cur = this.listScroller.currentOffset()
  4008. if (cur && typeof cur.yOffset === 'number') {
  4009. offsetA = cur.yOffset
  4010. }
  4011. }
  4012. this.mScrollMap.set('lastListArtistScrollOffset', offsetA)
  4013. }
  4014. let mList = this.artistMap.get(item.name)
  4015. if (mList !== undefined && ArrayUtil.isNotEmpty(mList)) {
  4016. Utility.doSortListAscending(mList)
  4017. this.isCanBack = true
  4018. this.titleBarModel.setTitleName(item.name)
  4019. this.currentTitleName = '艺术家:' + item.name
  4020. if (item.pixelMapPath) {
  4021. this.currentTitleCover = item.pixelMapPath
  4022. }
  4023. this.updateListData(mList)
  4024. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4025. }
  4026. //进入歌单的时候的滚动位置在顶部
  4027. if (this.isGridMusic) {
  4028. this.scroller.scrollToIndex(0)
  4029. }
  4030. break;
  4031. case CommonConstants.TYPE_IS_ALBUM:
  4032. // 进入专辑前安全保存当前滚动偏移量,支持列表和网格
  4033. let offset = 0
  4034. if (this.isGridMusic) {
  4035. if (this.scroller && typeof this.scroller.currentOffset === 'function') {
  4036. let cur = this.scroller.currentOffset()
  4037. if (cur && typeof cur.yOffset === 'number') {
  4038. offset = cur.yOffset
  4039. }
  4040. }
  4041. this.mScrollMap.set('lastGridAlBumScrollOffset', offset)
  4042. } else {
  4043. if (this.listScroller && typeof this.listScroller.currentOffset === 'function') {
  4044. let cur = this.listScroller.currentOffset()
  4045. if (cur && typeof cur.yOffset === 'number') {
  4046. offset = cur.yOffset
  4047. }
  4048. }
  4049. this.mScrollMap.set('lastListAlBumScrollOffset', offset)
  4050. }
  4051. let albumList = this.albumMap.get(item.name)
  4052. if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
  4053. Utility.doSortListAscending(albumList)
  4054. this.isCanBack = true
  4055. this.titleBarModel.setTitleName(item.name)
  4056. this.currentTitleName = '专辑:' + item.name
  4057. if (item.pixelMapPath) {
  4058. this.currentTitleCover = item.pixelMapPath
  4059. }
  4060. this.updateListData(albumList)
  4061. this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
  4062. this.mScrollMap.set(item.name, this.selectedIndex)
  4063. }
  4064. //进入歌单的时候的滚动位置在顶部
  4065. if (this.isGridMusic) {
  4066. this.scroller.scrollToIndex(0)
  4067. }
  4068. break;
  4069. case CommonConstants.TYPE_IS_CSJAD:
  4070. return
  4071. break;
  4072. case CommonConstants.TYPE_LOCAL:
  4073. if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
  4074. this.stop();
  4075. }
  4076. if (isFromSonPlayList) { //点击来自右下角的播放列表
  4077. this.currentSong = item
  4078. if (index !== undefined) {
  4079. this.curIndex = index
  4080. }
  4081. } else {
  4082. let globalVideoList = Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL) as VideoItem[];
  4083. this.curIndex = Utility.getCurIndexFromGlobalList(globalVideoList, item.filePath)
  4084. this.songList = globalVideoList
  4085. this.sonDataSource.pushArrayData(this.songList)
  4086. this.currentSong = globalVideoList[this.curIndex]
  4087. }
  4088. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  4089. this.videoUrl = this.currentSong.filePath
  4090. this.name = this.currentSong.name
  4091. this.cover = this.currentSong.pixelMapPath
  4092. this.artist = this.currentSong.artist
  4093. LogUtil.info('this.currentSong.duration =' + this.currentSong.duration)
  4094. LogUtil.info('this.currentSong.sampleRate =' + this.currentSong.sampleRate)
  4095. LogUtil.info('this.currentSongmimeType =' + this.currentSong.mimeType)
  4096. this.startPlayOrResumePlay()
  4097. break;
  4098. }
  4099. }
  4100. @Builder
  4101. PlayController() {
  4102. Column() {
  4103. Line().width('100%').height(1).backgroundColor($r('app.color.index_background'))
  4104. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4105. Row() {
  4106. Row() {
  4107. RotatingCover({ songLabel: this.currentSong?.pixelMapPath })
  4108. Column() {
  4109. Text(this.currentSong?.name)
  4110. .fontSize(16)
  4111. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4112. .maxLines(1)
  4113. .fontColor($r('app.color.text_color'))
  4114. .fontWeight(500)
  4115. Row() {
  4116. Text(this.currentSong?.artist)
  4117. .margin({ top: 2 })
  4118. .fontSize(13)
  4119. .maxLines(1)
  4120. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4121. .fontColor($r('app.color.text_color'))
  4122. }
  4123. }
  4124. .alignItems(HorizontalAlign.Start)
  4125. .margin({ right: 22 })
  4126. }
  4127. .padding({ right: 18 })
  4128. .layoutWeight(1)
  4129. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4130. .onClick(() => {
  4131. if (ArrayUtil.isNotEmpty(this.songList)) {
  4132. this.isShowPlay = true;
  4133. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  4134. this.initLyric(lyricPath);
  4135. this.startAutoHide()
  4136. } else {
  4137. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4138. }
  4139. })
  4140. Row() {
  4141. Image($r('app.media.hm_previous'))
  4142. .height(28)
  4143. .width(28)
  4144. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4145. .margin({ left: 8, right: 16 })
  4146. .fillColor(this.themeColor)
  4147. .displayPriority(2)
  4148. .onClick(() => {
  4149. if (ArrayUtil.isNotEmpty(this.songList)) {
  4150. this.playPrevious()
  4151. } else {
  4152. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4153. }
  4154. })
  4155. //播放进度条
  4156. Stack() {
  4157. Progress({
  4158. value: Math.floor(this.progressValue),
  4159. type: ProgressType.Ring,
  4160. })
  4161. .color(this.themeColor)// 进度条前景色为灰色
  4162. .backgroundColor($r('app.color.index_background'))
  4163. .height(40)
  4164. .aspectRatio(CommonConstants.ASPECT_RATIO)
  4165. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
  4166. .height(38)
  4167. .width(38)
  4168. .displayPriority(3)
  4169. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4170. .fillColor(this.themeColor)
  4171. .onClick(() => {
  4172. if (ArrayUtil.isNotEmpty(this.songList)) {
  4173. this.playOrPause()
  4174. } else {
  4175. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4176. }
  4177. })
  4178. }
  4179. Image($r('app.media.hm_next'))
  4180. .height(28)
  4181. .width(28)
  4182. .margin({
  4183. right: 16,
  4184. left: 16
  4185. })
  4186. .fillColor(this.themeColor)
  4187. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4188. .displayPriority(2)
  4189. .onClick(() => {
  4190. if (ArrayUtil.isNotEmpty(this.songList)) {
  4191. this.playNext()
  4192. } else {
  4193. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4194. }
  4195. })
  4196. Image($r('app.media.hm_playlist'))
  4197. .height(28)
  4198. .width(28)
  4199. .displayPriority(1)
  4200. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  4201. .fillColor(this.themeColor)
  4202. .bindSheet($$this.isShowSheet, this.PlayListSheet(), {
  4203. height: '95%',
  4204. dragBar: true,
  4205. showClose: true,
  4206. blurStyle: BlurStyle.Thin,
  4207. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  4208. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  4209. title: {
  4210. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  4211. + `(${this.songList.length}首)`
  4212. }
  4213. })
  4214. .onClick(() => {
  4215. if (ArrayUtil.isNotEmpty(this.songList)) {
  4216. this.isShowSheet = !this.isShowSheet;
  4217. this.isFrontWhite = false
  4218. LogUtil.info('onecold scrollToIndex = ' + this.curIndex)
  4219. setTimeout(() => {
  4220. this.playListScroller.scrollToIndex(this.curIndex, true, ScrollAlign.CENTER)
  4221. }, 123)
  4222. } else {
  4223. ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
  4224. }
  4225. })
  4226. }
  4227. }
  4228. .width('100%')
  4229. .height(this.bottomBarHeight)
  4230. .justifyContent(FlexAlign.Center)
  4231. .hitTestBehavior(HitTestMode.Transparent)
  4232. .backgroundColor(this.isCustomizeBg ? Color.Transparent : $r('app.color.bottom_control_background'))
  4233. .bindContentCover($$this.isShowPlay, this.MusicPlayBuilder(), {
  4234. // modalTransition: ModalTransition.DEFAULT,
  4235. transition: AnimationHelper.transitionInDown(666),
  4236. backgroundColor: 'rgba(0, 0, 0, 0.9)',
  4237. })
  4238. .padding({
  4239. left: 16,
  4240. right: 16
  4241. })
  4242. Line()
  4243. .width('100%')
  4244. .height(25)
  4245. .backgroundColor($r('app.color.bottom_control_background'))// .visibility(this.isPhoneLan()?Visibility.None:this.isCustomizeBg?Visibility.Hidden:Visibility.Visible)
  4246. .visibility(this.isCustomizeBg ? Visibility.Hidden : Visibility.Visible)
  4247. }
  4248. .clickEffect({ level: ClickEffectLevel.HEAVY })
  4249. }
  4250. @State isFrontWhite: boolean = false
  4251. //播放列表布局
  4252. @Builder
  4253. PlayListSheet() {
  4254. Column() {
  4255. this.PlayList()
  4256. }
  4257. .width('100%')
  4258. .height('100%')
  4259. }
  4260. @State titleStr: string = ''
  4261. @State ablumStr: string = ''
  4262. @State artistStr: string = ''
  4263. @State lyricConStr: string = ''
  4264. @State currentEditItem: string = ''
  4265. doUpdateData() {
  4266. setTimeout(() => {
  4267. if (this.modeType === 0) {
  4268. this.deleteCache(this.currentPath)
  4269. this.getSortedFiles(this.currentPath)
  4270. }
  4271. workerInstance.postMessage({ code: 2, data: this.context });
  4272. workerInstance.postMessage({ code: 3, data: this.context });
  4273. workerInstance.postMessage({ code: 4, data: this.context });
  4274. }, 999)
  4275. }
  4276. //编辑信息
  4277. doEdit(item: VideoItem) {
  4278. if (!item) {
  4279. return
  4280. }
  4281. if (StrUtil.isEmpty(this.titleStr)) {
  4282. ToastUtil.showToast('标题不能为空')
  4283. return
  4284. }
  4285. this.table.updateMediaInfo(item.filePath, this.titleStr, this.artistStr, this.ablumStr,
  4286. (success: boolean, error?: string) => {
  4287. // this.isShowEdit = false
  4288. if(this.isGridMusic){
  4289. this.longItemFilePath =''
  4290. }else{
  4291. this.isShowEdit = false
  4292. }
  4293. if (success) {
  4294. console.log(" onecold 编辑信息成功,数据库已同步");
  4295. ToastUtil.showToast('保存成功')
  4296. this.isShowMoreView = false
  4297. this.name = this.titleStr
  4298. if (item.filePath == this.currentSong?.filePath) {
  4299. this.currentSong.name = this.titleStr
  4300. this.artist = this.artistStr
  4301. this.currentSong.artist = this.artistStr
  4302. this.currentSong.album = this.ablumStr
  4303. }
  4304. this.doUpdateData()
  4305. } else {
  4306. ToastUtil.showToast('保存失败' + error?.toString())
  4307. console.error(" onecold 编辑信息数据库失败原因: " + error);
  4308. }
  4309. });
  4310. let doChangeLyric = false
  4311. if (item.filePath == this.currentSong?.filePath) {
  4312. if (this.lyricConStr !== this.lyricContent) {
  4313. doChangeLyric = true
  4314. }
  4315. } else if (this.lyricConStr !== this.tempLyricContent) {
  4316. doChangeLyric = true
  4317. }
  4318. if (doChangeLyric) {
  4319. let lyricPath = item.filePath.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  4320. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc'
  4321. let isJiaMi = false;
  4322. let realLyricPath = lyricPath
  4323. if (FileUtil.accessSync(jiaMilyricPath)) {
  4324. isJiaMi = true
  4325. realLyricPath = jiaMilyricPath
  4326. console.info("onecold doEdit找到加密本地歌词 ");
  4327. } else {
  4328. isJiaMi = false
  4329. realLyricPath = lyricPath
  4330. console.info("onecold doEdit本地歌词 ");
  4331. }
  4332. this.saveDataToFile(this.lyricConStr, realLyricPath, isJiaMi)
  4333. }
  4334. }
  4335. updateLyricToDB() {
  4336. }
  4337. @Builder
  4338. editSheet(item: VideoItem) {
  4339. Scroll() {
  4340. Column() {
  4341. this.editDetail(item)
  4342. }
  4343. }
  4344. .width('100%')
  4345. .height('100%')
  4346. }
  4347. @Builder
  4348. editDetail(item: VideoItem) {
  4349. Column() {
  4350. if (item) {
  4351. Row() {
  4352. Stack() {
  4353. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') :
  4354. item.pixelMapPath)
  4355. .fillColor(this.themeColor)
  4356. .height(33)
  4357. .width(33)
  4358. .borderRadius('100%')
  4359. .clip(true)
  4360. .opacity(this.opacityItem)// 绑定透明度
  4361. .margin({ left: 20 })
  4362. }
  4363. .width('15%')
  4364. Row() {
  4365. Column() {
  4366. Text(item.name)
  4367. .fontSize(14)
  4368. .maxLines(1)
  4369. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4370. .animation({
  4371. duration: 555,
  4372. curve: 'Linear',
  4373. })
  4374. .fontColor(this.themeColor)
  4375. .margin({ left: 10 })
  4376. Row() {
  4377. Text(item.artist)
  4378. .fontSize(11)
  4379. .maxLines(1)
  4380. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  4381. .padding({ top: 8 })
  4382. .fontColor(this.themeColor)
  4383. .margin({ left: 10 })
  4384. }
  4385. }
  4386. .height('100%')
  4387. .width(100)
  4388. .visibility(this.isDarkMode ? Visibility.None : Visibility.Visible)
  4389. .justifyContent(FlexAlign.Center)
  4390. .alignItems(HorizontalAlign.Start)
  4391. Button('本地封面')
  4392. .fontColor(Color.White)
  4393. .fontSize(12)
  4394. .height(38)
  4395. .width(88)
  4396. .backgroundColor(this.themeColor)
  4397. .stateEffect(true)
  4398. .margin({ right: 5, left: 12 })
  4399. .onClick(async () => {
  4400. this.goSelectImage(item)
  4401. })
  4402. Button('获取封面')
  4403. .fontColor(Color.White)
  4404. .fontSize(12)
  4405. .height(38)
  4406. .width(88)
  4407. .backgroundColor(this.themeColor)
  4408. .stateEffect(true)
  4409. .margin({ right: 12, left: 5 })
  4410. .onClick(async () => {
  4411. this.doSearchCover(item)
  4412. })
  4413. }
  4414. .height('100%')
  4415. .justifyContent(FlexAlign.Start)
  4416. .layoutWeight(1)
  4417. }
  4418. .width('100%')
  4419. .height(58)
  4420. Row() {
  4421. Text('标题:')
  4422. .fontSize(14)
  4423. .fontColor($r('app.color.text_color'))
  4424. .margin({ left: 22 })
  4425. TextInput({ text: item.name })
  4426. .height(40)
  4427. .maxLines(1)
  4428. .fontSize(14)
  4429. .layoutWeight(1)
  4430. .fontColor($r('app.color.text_color'))
  4431. .margin({ right: 20, left: 10 })
  4432. .onChange((val: string) => {
  4433. this.titleStr = val
  4434. })
  4435. }
  4436. .width('100%')
  4437. .margin({ top: 10, bottom: 10 })
  4438. .justifyContent(FlexAlign.Start)
  4439. Row() {
  4440. Text('艺术家:')
  4441. .fontSize(14)
  4442. .fontColor($r('app.color.text_color'))
  4443. .margin({ left: 22 })
  4444. TextInput({ text: item.artist })
  4445. .height(40)
  4446. .maxLines(1)
  4447. .fontSize(14)
  4448. .layoutWeight(1)
  4449. .fontColor($r('app.color.text_color'))
  4450. .margin({ right: 20, left: 10 })
  4451. .onChange((val: string) => {
  4452. this.artistStr = val
  4453. })
  4454. }
  4455. .width('100%')
  4456. .margin({ top: 10, bottom: 10 })
  4457. .justifyContent(FlexAlign.Start)
  4458. Row() {
  4459. Text('专辑名:')
  4460. .fontSize(14)
  4461. .fontColor($r('app.color.text_color'))
  4462. .margin({ left: 22 })
  4463. TextInput({ text: item.album })
  4464. .height(40)
  4465. .maxLines(1)
  4466. .fontSize(14)
  4467. .layoutWeight(1)
  4468. .fontColor($r('app.color.text_color'))
  4469. .margin({ right: 20, left: 10 })
  4470. .onChange((val: string) => {
  4471. this.ablumStr = val
  4472. })
  4473. }
  4474. .width('100%')
  4475. .margin({ top: 10, bottom: 10 })
  4476. .justifyContent(FlexAlign.Start)
  4477. Row() {
  4478. Text('歌词:')
  4479. .fontSize(14)
  4480. .fontColor($r('app.color.text_color'))
  4481. .margin({ left: 22 })
  4482. TextArea({ text: item.filePath === this.currentSong?.filePath ? this.lyricContent : this.tempLyricContent })
  4483. .type(TextAreaType.NORMAL)
  4484. .height(275)
  4485. .fontSize(14)
  4486. .layoutWeight(1)
  4487. .fontColor($r('app.color.text_color'))
  4488. .margin({ right: 20, left: 10 })
  4489. .onChange((val: string) => {
  4490. this.lyricConStr = val
  4491. })
  4492. }
  4493. .width('100%')
  4494. .margin({ top: 10, bottom: 10 })
  4495. .justifyContent(FlexAlign.Start)
  4496. Row() {
  4497. Button('保存')
  4498. .fontColor(Color.White)
  4499. .layoutWeight(1)
  4500. .height(50)
  4501. .width(100)
  4502. .backgroundColor(this.themeColor)
  4503. .stateEffect(true)
  4504. .margin({ right: 20, bottom: 20 })
  4505. .onClick(async () => {
  4506. this.doEdit(item)
  4507. })
  4508. Button('取消')
  4509. .fontColor(Color.White)
  4510. .layoutWeight(1)
  4511. .height(50)
  4512. .width(100)
  4513. .backgroundColor(this.themeColor)
  4514. .stateEffect(true)
  4515. .margin({ left: 20, bottom: 20 })
  4516. .onClick(async () => {
  4517. if(this.isGridMusic){
  4518. this.longItemFilePath =''
  4519. }else{
  4520. this.isShowEdit = false
  4521. }
  4522. })
  4523. }
  4524. .margin({
  4525. left: 38,
  4526. right: 38,
  4527. top: 10,
  4528. bottom: 10
  4529. })
  4530. .width(250)
  4531. .height(60)
  4532. }
  4533. }
  4534. .margin({ bottom: 20 })
  4535. }
  4536. @Builder
  4537. detailSheet(item:VideoItem) {
  4538. Scroll() {
  4539. Column() {
  4540. this.songDetail(item)
  4541. }
  4542. }
  4543. .width('100%')
  4544. .height('100%')
  4545. }
  4546. @Builder
  4547. songDetail(currentItem:VideoItem) {
  4548. Column() {
  4549. if (currentItem) {
  4550. Row() {
  4551. Stack() {
  4552. Image(StrUtil.isEmpty(currentItem.pixelMapPath) ? $r('app.media.music_red') :
  4553. currentItem.pixelMapPath)
  4554. .fillColor(this.themeColor)
  4555. .height(33)
  4556. .width(33)
  4557. .borderRadius('100%')
  4558. .clip(true)
  4559. .opacity(this.opacityItem)// 绑定透明度
  4560. .margin({ left: 20 })
  4561. }
  4562. .width('15%')
  4563. Column() {
  4564. Column() {
  4565. Text(currentItem.name)
  4566. .fontSize(14)
  4567. .maxLines(1)
  4568. .animation({
  4569. duration: 555,
  4570. curve: 'Linear',
  4571. })
  4572. .fontColor($r('app.color.text_color'))
  4573. .margin({ left: 10 })
  4574. Row() {
  4575. Text(StrUtil.isEmpty(currentItem.artist) ? currentItem.cTime :
  4576. currentItem.artist + ' ' + currentItem?.album)
  4577. .fontSize(11)
  4578. .padding({ top: 8 })
  4579. .fontColor($r('app.color.text_color'))
  4580. .margin({ left: 10 })
  4581. }
  4582. }
  4583. .height('100%')
  4584. .width('100%')
  4585. .justifyContent(FlexAlign.Center)
  4586. .alignItems(HorizontalAlign.Start)
  4587. }
  4588. .height('100%')
  4589. }
  4590. .width('100%')
  4591. .height(58)
  4592. .justifyContent(FlexAlign.SpaceBetween)
  4593. Row() {
  4594. Text('歌手名:')
  4595. .fontSize(14)
  4596. .fontColor($r('app.color.text_color'))
  4597. .margin({ left: 22 })
  4598. Text(currentItem?.artist ? currentItem.artist : '未知歌手')
  4599. .fontSize(14)
  4600. .fontColor($r('app.color.text_color'))
  4601. .margin({ left: 10 })
  4602. .layoutWeight(1)
  4603. }
  4604. .width('100%')
  4605. .margin({ top: 10, bottom: 10 })
  4606. .justifyContent(FlexAlign.Start)
  4607. Row() {
  4608. Text('专辑名:')
  4609. .fontSize(14)
  4610. .fontColor($r('app.color.text_color'))
  4611. .margin({ left: 22 })
  4612. Text(currentItem?.album ?currentItem.album : '未知专辑')
  4613. .fontSize(14)
  4614. .margin({ left: 10 })
  4615. .fontColor($r('app.color.text_color'))
  4616. .layoutWeight(1)
  4617. }
  4618. .width('100%')
  4619. .margin({ top: 10, bottom: 10 })
  4620. .justifyContent(FlexAlign.Start)
  4621. Row() {
  4622. Text('时长:')
  4623. .fontSize(14)
  4624. .fontColor($r('app.color.text_color'))
  4625. .margin({ left: 22 })
  4626. Text(StrUtil.isEmpty(currentItem.duration)?
  4627. (this.isShowDetailMore?this.totalTime:'未知'):currentItem.duration)
  4628. .fontSize(14)
  4629. .margin({ left: 10 })
  4630. .fontColor($r('app.color.text_color'))
  4631. .layoutWeight(1)
  4632. }
  4633. .width('100%')
  4634. .margin({ top: 10, bottom: 10 })
  4635. .justifyContent(FlexAlign.Start)
  4636. Row() {
  4637. Text('采样率:')
  4638. .fontSize(14)
  4639. .fontColor($r('app.color.text_color'))
  4640. .margin({ left: 22 })
  4641. Text(Utility.convertToKHz(currentItem.sampleRate))
  4642. .fontSize(14)
  4643. .margin({ left: 10 })
  4644. .fontColor($r('app.color.text_color'))
  4645. .layoutWeight(1)
  4646. }
  4647. .width('100%')
  4648. .margin({ top: 10, bottom: 10 })
  4649. .justifyContent(FlexAlign.Start)
  4650. Row() {
  4651. Text('比特率:')
  4652. .fontSize(14)
  4653. .fontColor($r('app.color.text_color'))
  4654. .margin({ left: 22 })
  4655. Text(currentItem.bit_rate)
  4656. .fontSize(14)
  4657. .margin({ left: 10 })
  4658. .fontColor($r('app.color.text_color'))
  4659. .layoutWeight(1)
  4660. }
  4661. .width('100%')
  4662. .margin({ top: 10, bottom: 10 })
  4663. .justifyContent(FlexAlign.Start)
  4664. Row() {
  4665. Text('风格:')
  4666. .fontSize(14)
  4667. .fontColor($r('app.color.text_color'))
  4668. .margin({ left: 22 })
  4669. Text(currentItem.genre)
  4670. .fontSize(14)
  4671. .margin({ left: 10 })
  4672. .fontColor($r('app.color.text_color'))
  4673. .layoutWeight(1)
  4674. }
  4675. .width('100%')
  4676. .margin({ top: 10, bottom: 10 })
  4677. .justifyContent(FlexAlign.Start)
  4678. Row() {
  4679. Text('发行时间:')
  4680. .fontSize(14)
  4681. .fontColor($r('app.color.text_color'))
  4682. .margin({ left: 22 })
  4683. Text(currentItem.year)
  4684. .fontSize(14)
  4685. .margin({ left: 10 })
  4686. .fontColor($r('app.color.text_color'))
  4687. .layoutWeight(1)
  4688. }
  4689. .width('100%')
  4690. .margin({ top: 10, bottom: 10 })
  4691. .justifyContent(FlexAlign.Start)
  4692. Row() {
  4693. Text('质量评分:')
  4694. .fontSize(14)
  4695. .fontColor($r('app.color.text_color'))
  4696. .margin({ left: 22 })
  4697. Text(currentItem.probe_score+"")
  4698. .fontSize(14)
  4699. .margin({ left: 10 })
  4700. .fontColor($r('app.color.text_color'))
  4701. .layoutWeight(1)
  4702. }
  4703. .width('100%')
  4704. .margin({ top: 10, bottom: 10 })
  4705. .justifyContent(FlexAlign.Start)
  4706. Row() {
  4707. Text('音轨号:')
  4708. .fontSize(14)
  4709. .fontColor($r('app.color.text_color'))
  4710. .margin({ left: 22 })
  4711. Text(currentItem.track)
  4712. .fontSize(14)
  4713. .margin({ left: 10 })
  4714. .fontColor($r('app.color.text_color'))
  4715. .layoutWeight(1)
  4716. }
  4717. .width('100%')
  4718. .margin({ top: 10, bottom: 10 })
  4719. .justifyContent(FlexAlign.Start)
  4720. Row() {
  4721. Text('格式:')
  4722. .fontSize(14)
  4723. .fontColor($r('app.color.text_color'))
  4724. .margin({ left: 22 })
  4725. Text(Utility.formatMimeType(currentItem.mimeType))
  4726. .fontSize(14)
  4727. .margin({ left: 10 })
  4728. .fontColor($r('app.color.text_color'))
  4729. .layoutWeight(1)
  4730. }
  4731. .width('100%')
  4732. .margin({ top: 10, bottom: 10 })
  4733. .justifyContent(FlexAlign.Start)
  4734. Row() {
  4735. Text('播放次数:')
  4736. .fontSize(14)
  4737. .fontColor($r('app.color.text_color'))
  4738. .margin({ left: 22 })
  4739. Text(currentItem.playCount?.toString())
  4740. .fontSize(14)
  4741. .margin({ left: 10 })
  4742. .fontColor($r('app.color.text_color'))
  4743. .layoutWeight(1)
  4744. }
  4745. .width('100%')
  4746. .margin({ top: 10, bottom: 10 })
  4747. .justifyContent(FlexAlign.Start)
  4748. Row() {
  4749. Text('流数量:')
  4750. .fontSize(14)
  4751. .fontColor($r('app.color.text_color'))
  4752. .margin({ left: 22 })
  4753. Text(currentItem.nb_streams?.toString())
  4754. .fontSize(14)
  4755. .margin({ left: 10 })
  4756. .fontColor($r('app.color.text_color'))
  4757. .layoutWeight(1)
  4758. }
  4759. .width('100%')
  4760. .margin({ top: 10, bottom: 10 })
  4761. .justifyContent(FlexAlign.Start)
  4762. Row() {
  4763. Text('文件大小:')
  4764. .fontSize(14)
  4765. .fontColor($r('app.color.text_color'))
  4766. .margin({ left: 22 })
  4767. Text(currentItem.size)
  4768. .fontSize(14)
  4769. .margin({ left: 10 })
  4770. .fontColor($r('app.color.text_color'))
  4771. .layoutWeight(1)
  4772. }
  4773. .width('100%')
  4774. .margin({ top: 10, bottom: 10 })
  4775. .justifyContent(FlexAlign.Start)
  4776. Row() {
  4777. Text('文件名:')
  4778. .fontSize(14)
  4779. .fontColor($r('app.color.text_color'))
  4780. .margin({ left: 22 })
  4781. Text(currentItem.fileName)
  4782. .fontSize(14)
  4783. .margin({ left: 10 })
  4784. .fontColor($r('app.color.text_color'))
  4785. .layoutWeight(1)
  4786. }
  4787. .width('100%')
  4788. .margin({ top: 10, bottom: 10 })
  4789. .justifyContent(FlexAlign.Start)
  4790. Row() {
  4791. Text('修改时间:')
  4792. .fontSize(14)
  4793. .fontColor($r('app.color.text_color'))
  4794. .margin({ left: 22 })
  4795. Text(currentItem.cTime)
  4796. .fontSize(14)
  4797. .margin({ left: 10 })
  4798. .fontColor($r('app.color.text_color'))
  4799. .layoutWeight(1)
  4800. }
  4801. .width('100%')
  4802. .margin({ top: 10, bottom: 10 })
  4803. .justifyContent(FlexAlign.Start)
  4804. Row() {
  4805. Text('存放目录:')
  4806. .fontSize(14)
  4807. .fontColor($r('app.color.text_color'))
  4808. .margin({ left: 22 })
  4809. Text(currentItem.filePath)
  4810. .fontSize(12)
  4811. .margin({ left: 10 })
  4812. .fontColor($r('app.color.text_color'))
  4813. .layoutWeight(1)
  4814. }
  4815. .margin({ top: 10, bottom: 10 })
  4816. .width('100%')
  4817. .justifyContent(FlexAlign.Start)
  4818. }
  4819. }
  4820. .margin({ bottom: 20 })
  4821. }
  4822. //定时关闭布局
  4823. @Builder
  4824. TimeCloseSheet() {
  4825. Scroll() {
  4826. Column() {
  4827. this.TimeClose()
  4828. }
  4829. }
  4830. .width('100%')
  4831. .height('100%')
  4832. }
  4833. //倒计时关闭音乐,退出App功能实现。
  4834. @State selectedMinutes: number = 0 // 0表示未开启
  4835. @State remainingSeconds: number = 0
  4836. // 预设时间选项
  4837. private presetTimes: number[] = [0, 5, 15, 30, 45, 60, -1]
  4838. private formatTime(seconds: number): string {
  4839. const mins = Math.floor(seconds / 60)
  4840. const secs = seconds % 60
  4841. return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
  4842. }
  4843. // 开始倒计时
  4844. private handleTimeSelect(minutes: number) {
  4845. if (minutes === this.selectedMinutes) {
  4846. this.stopCountdown();
  4847. this.selectedMinutes = 0;
  4848. return;
  4849. }
  4850. this.selectedMinutes = minutes;
  4851. this.remainingSeconds = minutes * 60;
  4852. this.startCountdown(); // 新增调用
  4853. }
  4854. @Builder
  4855. TimeClose() {
  4856. Column() {
  4857. // 倒计时显示区域
  4858. Text(this.selectedMinutes > 0 ?
  4859. `剩余时间:${this.formatTime(this.remainingSeconds)}` :
  4860. "定时关闭未开启")
  4861. .fontSize(17)
  4862. .fontColor($r('app.color.text_color'))
  4863. .margin({ top: 2, bottom: 8 });
  4864. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  4865. ForEach(this.presetTimes, (minutes: number, index: number) => {
  4866. // 单行时间选项容器
  4867. Row() {
  4868. // 文字描述区域
  4869. Text(this.getDisplayText(minutes))
  4870. .fontSize(15)
  4871. .fontColor(minutes === this.selectedMinutes ? this.themeColor :
  4872. $r('app.color.text_color'))// 选中态颜色变化
  4873. .textAlign(TextAlign.Start)
  4874. .layoutWeight(1); // 占据剩余空间
  4875. // 复选框样式的选择器
  4876. Row() {
  4877. if (minutes === this.selectedMinutes) {
  4878. // 选中状态 - 带勾号的圆形复选框
  4879. Row() {
  4880. // 使用系统内置的勾号图标
  4881. Image($r('sys.media.ohos_ic_public_ok'))
  4882. .width(14)
  4883. .height(14)
  4884. .fillColor(Color.White)
  4885. }
  4886. .width(24)
  4887. .height(24)
  4888. .borderRadius(12)
  4889. .backgroundColor(this.themeColor)
  4890. .justifyContent(FlexAlign.Center)
  4891. .alignItems(VerticalAlign.Center)
  4892. } else {
  4893. // 未选中状态的圆形边框
  4894. Row()
  4895. .width(24)
  4896. .height(24)
  4897. .borderRadius(12)
  4898. .border({
  4899. width: 2,
  4900. color: $r('app.color.text_color'),
  4901. style: BorderStyle.Solid
  4902. })
  4903. .backgroundColor(Color.Transparent)
  4904. }
  4905. }
  4906. .width(24)
  4907. .height(24)
  4908. .margin({ left: 20 })
  4909. .justifyContent(FlexAlign.Center)
  4910. .alignItems(VerticalAlign.Center)
  4911. }
  4912. .width('100%')
  4913. .padding({
  4914. top: 18,
  4915. bottom: 18,
  4916. left: 18,
  4917. right: 18
  4918. })
  4919. .backgroundColor(minutes === this.selectedMinutes ? $r('app.color.timeColor_bg') :
  4920. $r('app.color.bottom_control_background')) // 选中背景高亮
  4921. .borderRadius(12)
  4922. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  4923. .margin({ bottom: 18 })
  4924. .onClick(() => this.handleSelect(minutes)); // 点击整行触发选择
  4925. });
  4926. }
  4927. .width('100%')
  4928. .padding(16)
  4929. }
  4930. }
  4931. // 获取显示文本
  4932. private getDisplayText(minutes: number): string {
  4933. if (minutes === -1) {
  4934. return Utility.resourceToString(getContext(this), $r('app.string.customize'));
  4935. }
  4936. return minutes === 0 ? Utility.resourceToString(getContext(this), $r('app.string.close')) :
  4937. `${minutes}` + Utility.resourceToString(getContext(this), $r('app.string.minute_after'));
  4938. }
  4939. // 处理选择事件
  4940. private handleSelect(minutes: number): void {
  4941. if (minutes === -1) { // 自定义
  4942. // 弹出自定义时间对话框
  4943. DialogHelper.showTextInputDialog({
  4944. title: '自定义时间',
  4945. maskColor: Color.Transparent,
  4946. inputType: InputType.Number,
  4947. text: '',
  4948. onChange: (text) => {
  4949. console.error("onChange: " + text);
  4950. },
  4951. onAction: (action, dialogId, content) => {
  4952. if (action == DialogAction.TWO) {
  4953. const customMinutes = Number(content);
  4954. if (customMinutes > 0) {
  4955. this.handleTimeSelect(customMinutes); // 设置自定义时间
  4956. ToastUtil.showToast("设置成功," + customMinutes + "分钟后定时关闭");
  4957. }
  4958. }
  4959. }
  4960. });
  4961. } else {
  4962. this.handleTimeSelect(minutes); // 统一调用选择处理方法
  4963. }
  4964. }
  4965. // 添加定时器引用
  4966. private timerId: number = -1;
  4967. // 启动/重置倒计时
  4968. private startCountdown() {
  4969. // 清除旧定时器
  4970. if (this.timerId !== -1) {
  4971. clearInterval(this.timerId);
  4972. }
  4973. // 创建新定时器
  4974. if (this.selectedMinutes > 0) {
  4975. this.timerId = setInterval(() => {
  4976. if (this.remainingSeconds === 15) {
  4977. this.showConfirmationDialog();
  4978. }
  4979. if (this.remainingSeconds > 0) {
  4980. this.remainingSeconds -= 1;
  4981. } else {
  4982. this.stopCountdown();
  4983. this.handleTimeout();
  4984. }
  4985. }, 1000);
  4986. }
  4987. }
  4988. // 15倒计时后再次提示显示确认是否关闭App对话框
  4989. private showConfirmationDialog() {
  4990. DialogHelper.showAlertDialog({
  4991. backgroundColor: $r('app.color.btn_green'),
  4992. title: '确认关闭',
  4993. maskColor: Color.Transparent,
  4994. content: "马上到达定时关闭时间,您是否确定要退出应用?",
  4995. borderStyle: BorderStyle.Dashed,
  4996. primaryButton: '暂不关闭',
  4997. secondaryButton: '确定',
  4998. onAction: (action) => {
  4999. if (action == DialogAction.ONE) { //暂不关闭,取消定时
  5000. this.stopCountdown();
  5001. this.selectedMinutes = 0
  5002. } else if (action == DialogAction.TWO) {
  5003. }
  5004. }
  5005. })
  5006. }
  5007. // 停止倒计时
  5008. private stopCountdown() {
  5009. if (this.timerId !== -1) {
  5010. clearInterval(this.timerId);
  5011. this.timerId = -1;
  5012. }
  5013. }
  5014. // 超时处理
  5015. private handleTimeout() {
  5016. // 执行播放器关闭逻辑
  5017. this.selectedMinutes = 0;
  5018. ToastUtil.showToast(" 定时关闭已完成");
  5019. this.stop(); // 假设存在的播放器实例
  5020. //退出APP
  5021. const mContext = getContext(this) as common.UIAbilityContext
  5022. mContext.terminateSelf();
  5023. AvSessionController.getInstance(true).unregisterSessionListener()
  5024. }
  5025. //倒计时关闭音乐,退出App功能实现结束。
  5026. //播放列表的拖动List 重新排序
  5027. @State sonDataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.songList)
  5028. //左滑操作 移动文件 重命名 删除等操作
  5029. @Builder
  5030. sonButton(item: VideoItem, index: number, filePath: string) {
  5031. Row() {
  5032. //加入下一首播放
  5033. Button() {
  5034. Image($r('app.media.next_to_play'))
  5035. .fillColor(Color.White)
  5036. .width(20)
  5037. }
  5038. .width(40)
  5039. .height(40)
  5040. .type(ButtonType.Circle)
  5041. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5042. .backgroundColor(this.themeColor)
  5043. .margin(5)
  5044. .onClick(() => {
  5045. this.addToNextPlay(item);
  5046. })
  5047. Button() {
  5048. Image($r('app.media.close'))
  5049. .fillColor(Color.White)
  5050. .width(20)
  5051. }
  5052. .width(40)
  5053. .height(40)
  5054. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5055. .type(ButtonType.Circle)
  5056. .backgroundColor(this.themeColor)
  5057. .margin(5)
  5058. .onClick(() => {
  5059. this.songList.splice(Number(index), 1)
  5060. this.sonDataSource.pushArrayData(this.songList)
  5061. })
  5062. Button() {
  5063. Image($r('app.media.share2'))
  5064. .fillColor(Color.White)
  5065. .width(20)
  5066. }
  5067. .width(40)
  5068. .height(40)
  5069. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  5070. .type(ButtonType.Circle)
  5071. .backgroundColor(this.themeColor)
  5072. .margin(5)
  5073. .onClick(() => {
  5074. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  5075. })
  5076. }
  5077. }
  5078. itemMoveSon(index: number, newIndex: number): void {
  5079. if (newIndex < 0 || newIndex >= this.songList.length) {
  5080. return;
  5081. }
  5082. let tmp = this.songList.splice(index, 1);
  5083. this.songList.splice(newIndex, 0, tmp[0]);
  5084. this.sonDataSource.pushArrayData(this.songList)
  5085. this.curIndex = Utility.getIndexFromList(this.songList, this.videoUrl)
  5086. }
  5087. @Builder
  5088. PlayList() {
  5089. List({ scroller: this.playListScroller }) {
  5090. LazyForEach(this.sonDataSource, (item: VideoItem, index: number) => {
  5091. ListItem() {
  5092. this.MusicItemSon(item, index)
  5093. }
  5094. .swipeAction({ end: this.sonButton(item, index, item.filePath) }) //左滑
  5095. .animation({
  5096. duration: 666,
  5097. curve: 'ease-in-out' // 可选动画曲线
  5098. })
  5099. .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 600 }),
  5100. TransitionEffect.scale({ x: 0, y: 0 })))
  5101. .clickEffect({ level: ClickEffectLevel.MIDDLE })
  5102. //拖动List关键代码开始
  5103. .scale({ x: this.scaleSelect(index), y: this.scaleSelect(index) })
  5104. .zIndex(this.dragItem === index ? 1 : 0)
  5105. .translate(this.dragItem === index ? { y: this.offsetY } : { y: 0 })
  5106. .gesture(
  5107. GestureGroup(GestureMode.Sequence,
  5108. LongPressGesture({ repeat: true })
  5109. .onAction((event?: GestureEvent) => {
  5110. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5111. this.scaleItem = index
  5112. })
  5113. })
  5114. .onActionEnd(() => {
  5115. animateTo({ curve: Curve.Friction, duration: 300 }, () => {
  5116. this.scaleItem = -1
  5117. })
  5118. }),
  5119. PanGesture({ fingers: 1, direction: null, distance: 0 })
  5120. .onActionStart(() => {
  5121. this.dragItem = index // 记录当前拖动项索引
  5122. this.dragRefOffset = 0 // 重置偏移基准
  5123. })
  5124. .onActionUpdate((event: GestureEvent) => {
  5125. this.offsetY = event.offsetY - this.dragRefOffset;
  5126. this.neighborItem = -1;
  5127. let indexA = this.songList.indexOf(item);
  5128. // LogUtil.info('onecold indexA = '+indexA +' index=='+index)
  5129. let curveValue: curves.ICurve = curves.initCurve(Curve.Sharp);
  5130. let value: number = 0;
  5131. if (this.offsetY < 0) {
  5132. value = curveValue.interpolate(-this.offsetY / this.ITEM_INTV);
  5133. this.neighborItem = indexA - 1;
  5134. this.neighborScale = 1 - value / 20;
  5135. } else if (this.offsetY > 0) {
  5136. value = curveValue.interpolate(this.offsetY / this.ITEM_INTV);
  5137. this.neighborItem = indexA + 1;
  5138. this.neighborScale = 1 - value / 20;
  5139. }
  5140. if (this.offsetY > this.ITEM_INTV / 2 && indexA + 1 < this.songList.length) {
  5141. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5142. this.offsetY -= this.ITEM_INTV;
  5143. this.dragRefOffset += this.ITEM_INTV;
  5144. this.itemMoveSon(indexA, indexA + 1);
  5145. });
  5146. } else if (this.offsetY < -this.ITEM_INTV / 2 && indexA - 1 >= 0) {
  5147. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5148. this.offsetY += this.ITEM_INTV;
  5149. this.dragRefOffset -= this.ITEM_INTV;
  5150. this.itemMoveSon(indexA, indexA - 1);
  5151. });
  5152. }
  5153. })
  5154. .onActionEnd((event: GestureEvent) => {
  5155. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5156. this.dragItem = -1
  5157. this.neighborItem = -1
  5158. })
  5159. animateTo({
  5160. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  5161. }, () => {
  5162. this.scaleItem = -1
  5163. })
  5164. })
  5165. )
  5166. .onCancel(() => {
  5167. animateTo({ curve: curves.interpolatingSpring(0, 1, 400, 38) }, () => {
  5168. this.dragItem = -1
  5169. this.neighborItem = -1
  5170. })
  5171. animateTo({
  5172. curve: curves.interpolatingSpring(14, 1, 170, 17), delay: 150
  5173. }, () => {
  5174. this.scaleItem = -1
  5175. })
  5176. })
  5177. ) //拖动List关键代码结束
  5178. .onClick(() => {
  5179. this.doPlay(item, index, true)
  5180. })
  5181. }, (item: VideoItem) => item.filePath)
  5182. }
  5183. .width('100%')
  5184. .height('100%')
  5185. // .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  5186. // .animation({ duration: 500, curve: Curve.Ease }))
  5187. .cachedCount(10)
  5188. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  5189. .gesture(PinchGesture({ fingers: 2 })
  5190. .onActionEnd((event: GestureEvent) => {
  5191. this.setlistTwoFingers()
  5192. })
  5193. .onActionUpdate(e => {
  5194. this.scaleValue = this.pinchValue * e.scale
  5195. })
  5196. .onActionStart(e => {
  5197. }))
  5198. .padding({
  5199. bottom: 0
  5200. })
  5201. }
  5202. @Builder
  5203. private MusicItemSon(item: VideoItem, index?: number) {
  5204. Button({ type: ButtonType.Normal, stateEffect: true }) {
  5205. Row() {
  5206. Stack() {
  5207. Image(StrUtil.isEmpty(item.pixelMapPath) ? $r('app.media.music_red') : item.pixelMapPath)
  5208. .height(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  5209. .width(this.twoFingerType == 3 ? 55 : this.twoFingerType == 2 ? 35 : 30)
  5210. .alt($r('app.media.music_red'))
  5211. .fillColor(this.themeColor)
  5212. .borderRadius('100%')
  5213. .clip(true)
  5214. .margin({ left: 20 })
  5215. }
  5216. .width('15%')
  5217. Column() {
  5218. Column() {
  5219. Text(item.name)
  5220. .fontSize(this.twoFingerType == 1 ? 12 : this.twoFingerType == 2 ? 15 : 18)
  5221. .fontColor(this.curIndex === index ? this.themeColor :
  5222. this.isFrontWhite ? Color.White : $r('app.color.text_color'))
  5223. .maxLines(1)
  5224. .margin({ left: this.twoFingerType == 3 ? 18 : 10 })
  5225. Row() {
  5226. Column(){
  5227. Text(item.md5Str?.includes('Lossless')?
  5228. Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
  5229. .fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
  5230. .padding({ top: 3,right:6,left:6,bottom:3 })
  5231. .fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
  5232. $r('app.color.text_color'))
  5233. .fontWeight(500)
  5234. .borderRadius(12)
  5235. .margin({ left: this.twoFingerType == 3 ? 12 : 10 })
  5236. .backgroundColor('#FFC107')
  5237. }
  5238. .padding({ top: 8 })
  5239. Text(StrUtil.isEmpty(item.artist) ? item.cTime : item.artist + ' ' + item?.album)
  5240. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  5241. .padding({ top: 8 })
  5242. .fontColor(this.curIndex === index ? this.themeColor :
  5243. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  5244. .margin({ left: this.twoFingerType == 3 ? 5 : 3 })
  5245. Blank()
  5246. Text(item.size)
  5247. .fontSize(this.twoFingerType == 1 ? 11 : this.twoFingerType == 2 ? 12 : 14)
  5248. .padding({ top: 8 })
  5249. .visibility(StrUtil.isEmpty(item.artist) ? Visibility.Visible : Visibility.None)
  5250. .fontColor(this.curIndex === index ? $r('app.color.title_bar_bg_text') :
  5251. this.isFrontWhite ? $r('app.color.playlistText_color') : $r('app.color.text_color'))
  5252. .margin({ left: 10 })
  5253. }
  5254. }
  5255. .height('100%')
  5256. .width('100%')
  5257. .justifyContent(FlexAlign.Center)
  5258. .alignItems(HorizontalAlign.Start)
  5259. }
  5260. .height('100%')
  5261. .width('65%')
  5262. Column() {
  5263. ImageAnimator()
  5264. .images(this.imagesF)// 动画数组
  5265. .duration(1000)// 持续
  5266. .state(this.animationState)// 动画状态
  5267. .fillMode(FillMode.Forwards)
  5268. .width(18)
  5269. .visibility(this.videoUrl === item.filePath ? this.isMultiSelect ? Visibility.None : Visibility.Visible :
  5270. Visibility.None)
  5271. .height(18)
  5272. .iterations(-1) // 播放次数
  5273. }
  5274. .width('20%')
  5275. }
  5276. }
  5277. .backgroundColor(Color.Transparent)
  5278. .width('100%')
  5279. .height(this.twoFingerType == 3 ? ITEM_HEIGHT_BIG : this.twoFingerType == 2 ? ITEM_HEIGHT : ITEM_HEIGHT_SMALL)
  5280. .shadow(this.scaleItem === index ? {
  5281. radius: 70,
  5282. color: '#15000000',
  5283. offsetX: 0,
  5284. offsetY: 0
  5285. } :
  5286. {
  5287. radius: 0,
  5288. color: '#15000000',
  5289. offsetX: 0,
  5290. offsetY: 0
  5291. })
  5292. .animation({ curve: Curve.Sharp, duration: 300 })
  5293. }
  5294. @Builder
  5295. MusicPlayBuilder() {
  5296. Column() {
  5297. this.IjkMusicPlayerView()
  5298. }
  5299. .height('100%')
  5300. .width('100%')
  5301. .onDisAppear(() => {
  5302. this.translateY = 0;
  5303. })
  5304. .translate({ y: this.translateY })
  5305. .gesture(
  5306. PanGesture(this.panOption)
  5307. .onActionUpdate((event?: GestureEvent) => {
  5308. if (event) {
  5309. // 只允许向下滑动,向上滑动时限制为0
  5310. this.translateY = Math.max(0, event.offsetY);
  5311. }
  5312. })
  5313. .onActionEnd((event?: GestureEvent) => {
  5314. // 使用更低的阈值和滑动速度判断
  5315. const minDistance = 100; // 最小滑动距离 100vp
  5316. const minVelocity = 500; // 最小滑动速度
  5317. // 获取滑动速度(如果可用)
  5318. const velocity = event?.velocityY || 0;
  5319. // 判断是否应该关闭:距离足够 或者 速度足够快
  5320. const shouldClose = this.translateY > minDistance || velocity > minVelocity;
  5321. if (shouldClose) {
  5322. // 添加关闭动画
  5323. this.getUIContext().animateTo({
  5324. duration: 300,
  5325. curve: Curve.Smooth
  5326. }, () => {
  5327. this.isShowPlay = false;
  5328. this.translateY = 0;
  5329. })
  5330. } else {
  5331. // 回弹动画
  5332. this.getUIContext().animateTo({
  5333. duration: 300,
  5334. curve: Curve.Smooth
  5335. }, () => {
  5336. this.translateY = 0;
  5337. })
  5338. }
  5339. })
  5340. )
  5341. }
  5342. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD; //一多界面适配
  5343. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  5344. HeightBreakpoint.HEIGHT_LG;
  5345. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  5346. @State topBarHeight: number = 50
  5347. @State barOpacity: number = 1
  5348. @State barBottomOpacity: number = 1
  5349. private hideDone: boolean = false;
  5350. @State currentYOffset: number = 0;
  5351. @State bottomBarHeight: number = 60;
  5352. private isHiding: boolean = false;
  5353. //是否是Pura X外屏,或者小屏幕
  5354. isPuraWP() {
  5355. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  5356. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  5357. }
  5358. //是否是Pura X外屏,或者小屏幕,手机横屏
  5359. /**
  5360. * 是否是Pura X外屏,或者小屏幕,手机横屏
  5361. * @returns
  5362. */
  5363. isCoverOpacity() {
  5364. if (this.isPuraWP()) {
  5365. return true
  5366. }
  5367. if (this.isPhoneLan()) {
  5368. return true
  5369. }
  5370. if (deviceInfo.marketName.includes('Pura X')
  5371. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  5372. return true
  5373. }
  5374. return false
  5375. }
  5376. //是不是手机横屏
  5377. isPhoneLan() {
  5378. // LogUtil.info('twocold this.currentHeightBreakpoint = '+this.currentHeightBreakpoint)
  5379. // LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
  5380. LogUtil.info('hicar isPhoneLan width= ' + this.windowWidth);
  5381. LogUtil.info('hicar isPhoneLan height= ' + this.windowHeight);
  5382. LogUtil.info(`twocold hicarWindow size: ${this.windowWidth}x${this.windowHeight}, this.isHiCarStatus: ${this.isHiCarStatus}`);
  5383. LogUtil.info(`twocold hicar Window size: ${this.windowWidth}x${this.windowHeight}, isHiCarSmall: ${this.isHiCarSmall()}`);
  5384. if (this.isHiCarKuanBianPing()) {
  5385. return true
  5386. }
  5387. if (this.isHiCar()) {
  5388. return false
  5389. }
  5390. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  5391. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_SM
  5392. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_MD&&this.isLandscape) { //如果是手机横屏,返回true
  5393. return true
  5394. }
  5395. return false
  5396. }
  5397. //是不是1920x720的hicar的屏幕分辨率
  5398. isHiCarKuanBianPing(){
  5399. if(!this.isHiCar()){
  5400. return false
  5401. }
  5402. const hiCarAspectRatios: HiCarAspectRatio[] = [
  5403. { ratio: 1920 / 720, name: "1920x720" },
  5404. ];
  5405. const currentRatio: number = this.windowWidth / this.windowHeight;
  5406. const RATIO_TOLERANCE: number = 0.18; // 宽高比容差
  5407. LogUtil.info('twocold isHiCarKuanBianPing currentRatio = ' + currentRatio)
  5408. for (const hiCarRatio of hiCarAspectRatios) {
  5409. LogUtil.info('twocold isHiCarKuanBianPing hiCarRatio= ' + hiCarRatio.ratio)
  5410. LogUtil.info('twocold isHiCarKuanBianPing Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  5411. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  5412. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  5413. return true;
  5414. }
  5415. }
  5416. return false;
  5417. }
  5418. //是不是hicar的屏幕分辨率
  5419. isHiCarSmall() {
  5420. if(!this.isHiCar()){
  5421. return false
  5422. }
  5423. if(this.windowWidth>1800&&this.windowHeight>=1200)//大屏幕可以Grid
  5424. return false
  5425. const hiCarAspectRatios: HiCarAspectRatio[] = [
  5426. { ratio: 800 / 480, name: "800x480" },
  5427. { ratio: 1280 / 720, name: "1280x720" },
  5428. ];
  5429. const currentRatio: number = this.windowWidth / this.windowHeight;
  5430. const RATIO_TOLERANCE: number = 0.18; // 宽高比容差
  5431. LogUtil.info('twocold isHiCarSmall currentRatio = ' + currentRatio)
  5432. for (const hiCarRatio of hiCarAspectRatios) {
  5433. LogUtil.info('twocold isHiCarSmall hiCarRatio= ' + hiCarRatio.ratio)
  5434. LogUtil.info('twocold isHiCarSmall Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
  5435. LogUtil.info('twocold isHiCarSmall isHiCarStatus= ' + this.isHiCarStatus);
  5436. if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
  5437. // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
  5438. return true;
  5439. }
  5440. }
  5441. return false;
  5442. }
  5443. isHiCar() {
  5444. return this.isHiCarStatus&&this.curDisplayIsHiCar;
  5445. }
  5446. //是不是正常的手机竖屏
  5447. isPhonePortrait() {
  5448. // LogUtil.info('twocold this.currentHeightBreakpoint = ' + this.currentHeightBreakpoint)
  5449. // LogUtil.info('twocold this.currentWidthBreakpoint = ' + this.currentWidthBreakpoint)
  5450. // LogUtil.info('Heanup 当前设备类型:' + DeviceUtil.getDeviceType())
  5451. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  5452. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG
  5453. && this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_SM) { //如果是手机横屏,返回false
  5454. return true
  5455. }
  5456. return false
  5457. }
  5458. @State showSpeedDialog: boolean = false
  5459. @State longPressSpeed: number = 3 //长按默认倍数
  5460. @Builder
  5461. SpeedDialog() {
  5462. Stack() {
  5463. Column() {
  5464. Text('已切换至' + this.longPressSpeed + '倍速播放')
  5465. .fontColor(Color.White)
  5466. .visibility(Visibility.Hidden)
  5467. }
  5468. .backgroundColor(Color.Black)
  5469. .borderRadius(20)
  5470. .padding({
  5471. top: 10,
  5472. right: 20,
  5473. left: 15,
  5474. bottom: 20
  5475. })
  5476. .opacity(0.6)
  5477. Text('已切换至' + this.longPressSpeed + '倍速播放')
  5478. .fontColor(Color.White)
  5479. }
  5480. .transition(TransitionEffect.OPACITY.animation({ duration: 500, curve: Curve.Ease }))
  5481. .zIndex(5)
  5482. .margin({ top: 80 })
  5483. }
  5484. @Builder
  5485. IjkMusicPlayerView() {
  5486. Column() {
  5487. Column() {
  5488. Column() {
  5489. //播放标题
  5490. Column() {
  5491. this.PlayTitle()
  5492. }
  5493. .position({ x: 0, y: this.isCoverOpacity() ? 15 : 40 })
  5494. .width('100%')
  5495. .margin({ top: 0 })
  5496. .height(PlayConstants.HEIGHT)
  5497. .visibility(DeviceUtil.getDeviceType() == resourceManager.DeviceType.DEVICE_TYPE_2IN1 ?
  5498. Visibility.Visible : this.isShowPlayPageBack ? Visibility.Visible : Visibility.None)
  5499. if (this.showSpeedDialog) {
  5500. this.SpeedDialog()
  5501. }
  5502. Stack() {
  5503. //手势拖动快进
  5504. Column()
  5505. .width(CommonConstants.FULL_PERCENT)
  5506. .height('100%')
  5507. .gesture(
  5508. GestureGroup(GestureMode.Parallel,
  5509. // 长按屏幕倍数播放
  5510. LongPressGesture({ repeat: true })
  5511. .onAction(() => {
  5512. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  5513. this.showSpeedDialog = true;
  5514. this.mIjkMediaPlayer.setSpeed(this.longPressSpeed + 'f');
  5515. }
  5516. })
  5517. .onActionEnd(() => {
  5518. this.showSpeedDialog = false;
  5519. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  5520. }),
  5521. //双击屏幕暂停或者播放
  5522. TapGesture({ count: 2 })
  5523. .onAction((event: GestureEvent) => {
  5524. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  5525. ToastUtil.showToast('已暂停')
  5526. }
  5527. this.playOrPause()
  5528. })
  5529. )
  5530. )
  5531. }
  5532. .height('65%')
  5533. Swiper() {
  5534. this.CoverInfo()
  5535. this.PlayerLyrics()
  5536. }
  5537. .onChange((index: number) => {
  5538. this.currentSwiperIndex = index
  5539. })
  5540. .indicator(false)
  5541. // .indicator(this.currentBreakpoint === BreakpointTypeEnum.SM ?
  5542. // new DotIndicator()
  5543. // .top(this.isCoverOpacity()?0:10)
  5544. //
  5545. // .selectedColor($r('app.color.select_swiper'))
  5546. // .color($r('app.color.slider_track')):false
  5547. // )
  5548. .displayCount(new BreakpointType({
  5549. sm: 1,
  5550. md: 2,
  5551. lg: 2,
  5552. xl: 2,
  5553. xxl: 2
  5554. }).getValue(this.currentBreakpoint))
  5555. .clip(false)
  5556. .loop(false)
  5557. .autoPlay(false)
  5558. // .interval(8000)
  5559. .position({ x: 0, y: this.isCoverOpacity() ? 30 : 40 })
  5560. .height('100%')
  5561. .hitTestBehavior(HitTestMode.Transparent)
  5562. Image($r('app.media.icon_replay'))
  5563. .objectFit(ImageFit.Auto)
  5564. .width('120px')
  5565. .height('120px')
  5566. .position({ x: '45.1%', y: '47.5%' })// .visibility(this.replayVisible)
  5567. .border({ width: 0 })
  5568. .visibility(Visibility.None)
  5569. .borderStyle(BorderStyle.Dashed)// .hitTestBehavior(HitTestMode.Transparent)
  5570. .onClick(() => {
  5571. this.startPlayOrResumePlay();
  5572. })
  5573. }
  5574. .width(CommonConstants.FULL_PERCENT)
  5575. .height(CommonConstants.FULL_PERCENT)
  5576. .justifyContent(FlexAlign.End)
  5577. }
  5578. .justifyContent(FlexAlign.End)
  5579. .margin({ bottom: 8 })
  5580. }
  5581. // .backgroundImage(this.imageLabelBg)
  5582. .backgroundImage(this.isPuraWP() && this.currentSwiperIndex === 0 ?
  5583. (StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover) : this.imageLabelBg)
  5584. .backgroundImageSize(this.isPuraWP() ? { width: '100%' } : { height: '150%', width: '100%' })
  5585. // .backgroundImagePosition(Alignment.Center)
  5586. .animation({
  5587. duration: 666,
  5588. curve: 'ease-in-out' // 可选动画曲线
  5589. })
  5590. .backgroundBlurStyle(this.isPuraWP() && this.currentSwiperIndex === 0 ? BlurStyle.NONE :
  5591. BlurStyle.BACKGROUND_ULTRA_THICK)
  5592. .hitTestBehavior(HitTestMode.Transparent)
  5593. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  5594. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  5595. .backgroundBrightness({ rate: this.isPuraWP() ? 0.1 : 0, lightUpDegree: -0.1 })
  5596. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
  5597. .onClick(() => {
  5598. // this.startAutoHide()
  5599. if(this.isHiCar())
  5600. return
  5601. if(this.is_auto_hide_progress){
  5602. this.is_auto_hide_progress = false
  5603. }
  5604. this.startAutoHide()
  5605. })
  5606. }
  5607. @State progressValue: number = 0;
  5608. @State currentTime: string = "00:00";
  5609. @State totalTime: string = "00:00";
  5610. @State loadingVisible: Visibility = Visibility.None;
  5611. @State replayVisible: Visibility = Visibility.None;
  5612. @State slideEnable: boolean = false;
  5613. @State aspRatio: number = 0.5;
  5614. @State mContext: object | undefined = undefined;
  5615. // private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
  5616. @State mFirst: boolean = true;
  5617. @State mDestroyPage: boolean = false;
  5618. @State playSpeed: number = 1;
  5619. @State oldSeconds: number = 0;
  5620. @State isSeekTo: boolean = false;
  5621. @State isCurrentTime: boolean = false;
  5622. @State videoWidth: string = '100%';
  5623. @State videoHeight: string = '100%';
  5624. @State initAspectRatio: number = 1;
  5625. @State videoAspectRatio: number = this.initAspectRatio;
  5626. private videoUrl: string = '';
  5627. private last: number = 0;
  5628. @State videoParentAspectRatio: number = this.initAspectRatio;
  5629. private mIjkMediaPlayer = IjkMediaPlayer.getInstance();
  5630. @State CONTROL_PlayStatus: number = PlayStatus.INIT;
  5631. @State PROGRESS_MAX_VALUE: number = 100;
  5632. @State updateProgressTimer: number = 0;
  5633. @State isHide: boolean = false; //是否因此播放器的按钮,默认是进入横屏模式隐藏,点击视频的时候显示
  5634. @State name: string = '';
  5635. // @State loop: boolean = false;
  5636. @State playType: number = 0; //0:连续播放 1:单片重复播放 2:正常播放 3:随机播放
  5637. @State multiple: string = '1.0X';
  5638. xcomponentController: XComponentController = new XComponentController()
  5639. private panOptionBright: PanGestureOptions =
  5640. new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down });
  5641. private panOptionVolume: PanGestureOptions =
  5642. new PanGestureOptions({ direction: PanDirection.Vertical | PanDirection.Up | PanDirection.Down });
  5643. private panOptionSeekTo: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Horizontal });
  5644. //手势的音量控制和亮度控制
  5645. private positionX: number = PlayConstants.POSITION_X;
  5646. private positionY: number = PlayConstants.POSITION_Y;
  5647. private windowClass: window.Window = globalThis.windowClass
  5648. @State volume: number = 0.3;
  5649. @State volumeShow: boolean = PlayConstants.VOLUME_SHOW;
  5650. @State bright: number = PlayConstants.BRIGHT;
  5651. @State brightShow: boolean = PlayConstants.BRIGHT_SHOW;
  5652. @State seekToShow: boolean = PlayConstants.BRIGHT_SHOW;
  5653. @State screenWidth: number = 0
  5654. @State screenHeight: number = 0
  5655. @State statusBarHeight: number = 0
  5656. @State isYesFull: boolean = false
  5657. private seekValue: number = 0
  5658. @State isVideoLock: boolean = false; // Whether the video playback is locked
  5659. eventHub = getContext().eventHub;
  5660. //投播组件
  5661. private avSessionController: AvSessionController = AvSessionController.getInstance(false);
  5662. private castController: avSession.AVCastController | undefined = undefined;
  5663. @State isCastPlaying: boolean = false;
  5664. @State currentTime2: number = 0;
  5665. @State currentStringTime: string = '00:00';
  5666. @State duration: number = 0;
  5667. @State isReady: boolean = false;
  5668. @State durationTime: number = 0;
  5669. @State durationStringTime: string = '00:00';
  5670. @StorageLink('isPlaying') @Watch('animationRoFun') isPlaying: boolean = false;
  5671. // @State isPlaying: boolean = false;
  5672. private castSeek: boolean = false;
  5673. private castItem: avSession.AVQueueItem | undefined = undefined;
  5674. // @State isBgPlayOpen:boolean = true //是否启用后台播放
  5675. @State imageLabel: PixelMap | Resource = CommonConstants.musicBgList[0];
  5676. @State imageLabelBg: PixelMap | Resource = CommonConstants.musicBgList[0];
  5677. @State rotateAngle2: number = 0
  5678. @StorageLink('imageColor') imageColor: string = 'rgba(0, 0, 2, 1.00)';
  5679. @State cover: string | undefined = '';
  5680. @State artist: string | undefined = ''
  5681. // 1.初始化controller
  5682. private lyricController: LyricController = new LyricController()
  5683. private lyricControllerXF: LyricController = new LyricController() //悬浮歌词控制器
  5684. private lyricControllerSingle: LyricController = new LyricController() //播放页单行歌词控制器
  5685. private parser = new LyricParser()
  5686. @State randomColor: string = 'rgb(0,0,0)'
  5687. @State randomShakenX: number = 0
  5688. @State randomShakenY: number = 0
  5689. @State lyricTextSize: number = 24
  5690. @State lyricContent: string = ''
  5691. @State isDebug: boolean = false
  5692. @State isHightLightCenter: boolean = true
  5693. /**
  5694. * 初始化歌词加载与展示逻辑
  5695. * @param lyricPath 歌词文件路径(支持普通.lrc和加密.lrcc)
  5696. * @param isOnLineAndToast 是否弹出Toast提示(可选)获取在线歌词为true
  5697. * @param isApi2 是否使用API2获取歌词(可选)
  5698. *
  5699. * 主要流程:
  5700. * 1. 设置歌词显示样式(字号、颜色、行距、对齐、动画等)。
  5701. * 2. 优先尝试本地读取歌词文件(支持加密和普通两种后缀)。
  5702. * 3. 若本地无歌词且满足条件(调试模式或会员且安装时间超过2天),则联网获取歌词。
  5703. * 4. 获取到歌词后,解析并设置到lyricController,并保存到本地。
  5704. * 5. 本地有歌词时,读取文件内容(自动检测编码,支持解密),解析后设置到lyricController。
  5705. * 6. 解析失败或读取失败时,清空歌词显示。
  5706. *
  5707. * 注意事项:
  5708. * - 仅会员且安装时间超过2天才可联网获取歌词(调试模式isDebug=true时跳过限制)。
  5709. * - 支持加密歌词文件(.lrcc),自动检测并解密。
  5710. * - 歌词内容解析后通过lyricController驱动UI渲染。
  5711. */
  5712. async initLyric(lyricPath: string, isOnLineAndToast?: boolean, isApi2?: boolean) {
  5713. if (StrUtil.isEmpty(lyricPath)) {
  5714. return
  5715. }
  5716. this.initPipLyricSetting()
  5717. this.lyricControllerSingle
  5718. .setTextSize(15)
  5719. .setCacheSize(4)
  5720. .setTextColor("#FFFFFF")
  5721. .setHighlightColor("#FFFFFF")
  5722. .setHighlightScale(1.2)
  5723. .setEmptyHint("")
  5724. .setAlignMode('center')
  5725. .setAnimationDuration(500)
  5726. .setSingleLine(true)
  5727. this.lyricContent = ''
  5728. this.lyricController
  5729. .setTextSize(this.currentLyricSize)
  5730. .setCacheSize(4)
  5731. .setTextColor("#DDDDDD")
  5732. .setHighlightColor("#FFFFFF")
  5733. .setEmptyHint("")
  5734. .setAnimationDuration(1000)
  5735. this.currentLyricAlignMode = PreferencesUtil.getNumberSync('LyricAlignMode', 1)
  5736. this.blurDegree = PreferencesUtil.getNumberSync('setBlurDegree', 3)
  5737. this.setBlurDegree(this.blurDegree, false)
  5738. this.setLyricAlignMode(this.currentLyricAlignMode, false)
  5739. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSize', 18), false)
  5740. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSize', 1.23), false)
  5741. this.lyricController.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpace', 10))
  5742. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColor', '#FFFFFF'), false)
  5743. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColor', '#FFFFFF'), false)
  5744. this.isHightLightCenter = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, true)
  5745. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  5746. this.lyricTextWeight = PreferencesUtil.getNumberSync('lyricTextWeight', 400)
  5747. this.lyricController.setTextWeight(this.lyricTextWeight)
  5748. this.showSingleLyric = false
  5749. this.timeOffset = 0
  5750. this.lyricController.setLyric(null)
  5751. this.lyricControllerSingle.setLyric(null)
  5752. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc'
  5753. console.log("onecold lyricPath =" + lyricPath)
  5754. let neiqianLrc = ''
  5755. let lyContent = this.currentSong?.lyricContent
  5756. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  5757. neiqianLrc = lyContent
  5758. }
  5759. if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast) {
  5760. console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
  5761. //赋值给this.lyricContent,播控中心才可以显示歌词
  5762. this.lyricContent = neiqianLrc
  5763. // 将文件内容按行分割成字符串数组
  5764. let lines = neiqianLrc.split('\n').map(line => line.trim());
  5765. // 3.解析歌词
  5766. let lyric = this.parser.parse(lines);
  5767. // 4.设置歌词
  5768. this.lyricController.setLyric(lyric);
  5769. this.lyricControllerXF.setLyric(lyric)
  5770. this.lyricControllerSingle.setLyric(lyric)
  5771. return
  5772. }
  5773. if (isOnLineAndToast || ((!FileUtil.accessSync(lyricPath) && !FileUtil.accessSync(jiaMilyricPath))
  5774. && !Utility.isVideoByExtension(this.videoUrl))) {
  5775. if (this.currentSong !== undefined) {
  5776. // ToastUtil.showShort('正在为你搜索在线歌词!')
  5777. //判断是不是赞助会员,是会员的话才开启歌词功能
  5778. // if (!this.isDebug) {
  5779. // if (!Utility.isNoble()) {
  5780. // LogUtil.debug("onecold 不是赞助会员")
  5781. // return
  5782. // }
  5783. // if(!Utility.isPassInstallTime(33)){
  5784. // LogUtil.debug("onecold not pass time")
  5785. // // LogUtil.debug("onecold 用户安装app没超过12天" )
  5786. // return
  5787. // }
  5788. // }
  5789. let artist = this.currentSong?.artist
  5790. if (artist === undefined) {
  5791. artist = ''
  5792. }
  5793. if (isApi2 === undefined) {
  5794. isApi2 = false
  5795. }
  5796. NetAxiosUtil.getLyric(this.name, artist, isApi2).then((res) => {
  5797. // LogUtil.debug("onecold res =" + res)
  5798. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  5799. if (StrUtil.isNotEmpty(res)) {
  5800. this.lyricContent = res
  5801. let lines = res.split('\n').map(line => line.trim());
  5802. // 3.解析歌词
  5803. let lyric = this.parser.parse(lines);
  5804. // 4.设置歌词
  5805. this.lyricController.setLyric(lyric);
  5806. this.lyricControllerXF.setLyric(lyric)
  5807. this.lyricControllerSingle.setLyric(lyric)
  5808. this.showSingleLyric = true
  5809. // 4.保存歌词文件lyric到本地
  5810. this.saveDataToFile(res, jiaMilyricPath, true)
  5811. } else {
  5812. this.lyricController.setLyric(null)
  5813. this.lyricControllerXF.setLyric(null)
  5814. this.lyricControllerSingle.setLyric(null)
  5815. if (isOnLineAndToast) {
  5816. ToastUtil.showShort('未获取到歌词!')
  5817. }
  5818. }
  5819. } else {
  5820. this.lyricController.setLyric(null)
  5821. this.lyricControllerXF.setLyric(null)
  5822. this.lyricControllerSingle.setLyric(null)
  5823. if (isOnLineAndToast) {
  5824. ToastUtil.showShort('未获取到歌词!')
  5825. }
  5826. }
  5827. })
  5828. } else {
  5829. this.lyricController.setLyric(null)
  5830. this.lyricControllerXF.setLyric(null)
  5831. this.lyricControllerSingle.setLyric(null)
  5832. if (isOnLineAndToast) {
  5833. ToastUtil.showShort('未获取到歌词!')
  5834. }
  5835. }
  5836. return
  5837. }
  5838. try {
  5839. let isJiaMi = false;
  5840. let realLyricPath = lyricPath
  5841. if (FileUtil.accessSync(jiaMilyricPath)) {
  5842. isJiaMi = true
  5843. realLyricPath = jiaMilyricPath
  5844. console.info("onecold 找到加密本地歌词 ");
  5845. } else {
  5846. isJiaMi = false
  5847. realLyricPath = lyricPath
  5848. console.info("onecold 找到本地歌词 ");
  5849. }
  5850. // 3.读取文件内容并指定编码为 UTF-8
  5851. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  5852. const stat = await fileIo.stat(file.fd);
  5853. const arrayBuffer = new ArrayBuffer(stat.size);
  5854. fs.read(file.fd, arrayBuffer)
  5855. .then((readLen: number) => {
  5856. console.info("read file data succeed");
  5857. // let buf = buffer.from(arrayBuffer, 0, readLen);
  5858. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  5859. // 检查 buf 是否为空
  5860. if (buf.length === 0) {
  5861. throw new Error("Buffer is empty after reading the file");
  5862. }
  5863. try {
  5864. // 检测文件编码
  5865. // let detectedEncoding = chardet.detect(buf);
  5866. // console.info("onecoldT Detected encoding: " + detectedEncoding);
  5867. let detectedEncoding = this.detect(arrayBuffer)
  5868. console.info("onecoldT Detected encoding: " + detectedEncoding);
  5869. // 使用检测到的编码解码,解决中文乱码问题
  5870. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  5871. console.info("onecoldT Detected textDecoder: " + textDecoder);
  5872. let fileContent = textDecoder.decode(buf);
  5873. console.info(`onecoldT The content of file1: ${fileContent}`);
  5874. //解密
  5875. if (isJiaMi) {
  5876. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent))
  5877. }
  5878. console.info(`onecold The content of file2: ${fileContent}`);
  5879. this.lyricContent = fileContent
  5880. // 将文件内容按行分割成字符串数组
  5881. let lines = fileContent.split('\n').map(line => line.trim());
  5882. console.info(`onecold The content of file: ${fileContent}`);
  5883. // 3.解析歌词
  5884. let lyric = this.parser.parse(lines);
  5885. // 4.设置歌词
  5886. this.lyricController.setLyric(lyric);
  5887. this.lyricControllerXF.setLyric(lyric)
  5888. this.lyricControllerSingle.setLyric(lyric)
  5889. this.showSingleLyric = true
  5890. console.info(`The content of file: ${fileContent}`);
  5891. } catch (chardetError) {
  5892. console.error("chardet.detect failed with error: " + chardetError.message);
  5893. this.lyricController.setLyric(null);
  5894. this.lyricControllerXF.setLyric(null)
  5895. this.lyricControllerSingle.setLyric(null)
  5896. }
  5897. })
  5898. .catch((err: BusinessError) => {
  5899. this.lyricController.setLyric(null)
  5900. this.lyricControllerXF.setLyric(null)
  5901. this.lyricControllerSingle.setLyric(null)
  5902. console.error("read file data failed with error message: " + err.message + ", error code: " + err.code);
  5903. })
  5904. .catch((err: Error) => {
  5905. this.lyricController.setLyric(null)
  5906. this.lyricControllerXF.setLyric(null)
  5907. this.lyricControllerSingle.setLyric(null)
  5908. console.error("read file 2 data failed with error message: " + err.message);
  5909. })
  5910. .finally(() => {
  5911. fs.closeSync(file);
  5912. });
  5913. } catch (error) {
  5914. this.lyricController.setLyric(null)
  5915. this.lyricControllerSingle.setLyric(null)
  5916. this.lyricControllerXF.setLyric(null)
  5917. Logger.error(TAG, 'init Lyric failed with err: ' + JSON.stringify(error));
  5918. }
  5919. }
  5920. detect(data: ArrayBuffer): string {
  5921. //创建检测对象
  5922. let detector: UniversalDetector = new UniversalDetector();
  5923. // 传入检测数据并实时判断编码格式
  5924. detector.handleData(data, 0, data.byteLength);
  5925. // 标记检测数据 读取结束
  5926. detector.dataEnd();
  5927. // 获取检测结果
  5928. let detected: string = detector.getDetectedCharset();
  5929. // 释放资源
  5930. detector.reset();
  5931. return detected;
  5932. }
  5933. //初始化悬浮歌词的自定义设置
  5934. initPipLyricSetting() {
  5935. this.lyricControllerXF
  5936. .setTextSize(this.currentLyricSize)
  5937. .setCacheSize(4)
  5938. .setTextColor("#DDDDDD")
  5939. .setHighlightColor("#FFFFFF")// .setLineSpace(18)
  5940. .setEmptyHint("")
  5941. .setAnimationDuration(1000)
  5942. this.currentLyricAlignModePip = PreferencesUtil.getNumberSync('LyricAlignModePip', 0)
  5943. this.blurDegreePip = PreferencesUtil.getNumberSync('setBlurDegreePip', 3)
  5944. this.setBlurDegree(this.blurDegreePip, true)
  5945. this.setLyricAlignMode(this.currentLyricAlignModePip, true)
  5946. this.setLyricTextSize(PreferencesUtil.getNumberSync('LyricTextSizePip', 18), true)
  5947. this.setHighLyricTextSize(PreferencesUtil.getNumberSync('HighLyricTextSizePip', 1.23), true)
  5948. this.lyricControllerXF.setLineSpace(PreferencesUtil.getNumberSync('LyricLineSpacePip', 10))
  5949. this.changeLyricColor(PreferencesUtil.getStringSync('LyricColorPip', '#FFFFFF'), true)
  5950. this.changeLyricHightLightColor(PreferencesUtil.getStringSync('LyricHighLightColorPip', '#FFFFFF'), true)
  5951. this.lyricControllerXF.setHightLightCenter(true)
  5952. this.lyricTextWeightPip = PreferencesUtil.getNumberSync('lyricTextWeightPip', 400)
  5953. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  5954. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  5955. this.pipBgIndex = PreferencesUtil.getNumberSync('pipBgIndex', 0)
  5956. if (this.pipBgIndex === 0) {
  5957. if (this.cover) {
  5958. this.pipBg = this.cover
  5959. } else {
  5960. this.pipBg = this.imageColor
  5961. }
  5962. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  5963. }
  5964. }
  5965. //根据item返回歌词内容
  5966. async getLyricContent(item: VideoItem): Promise<string> {
  5967. let neiqianLrc = ''
  5968. let lyContent = item?.lyricContent
  5969. if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
  5970. neiqianLrc = lyContent
  5971. return neiqianLrc
  5972. }
  5973. try {
  5974. let filePath = item.filePath;
  5975. let lyricPath = filePath.substring(0, filePath.lastIndexOf('.')) + '.lrc';
  5976. let jiaMilyricPath = lyricPath.substring(0, lyricPath.lastIndexOf('.')) + '.lrcc';
  5977. let isJiaMi = false;
  5978. let realLyricPath = lyricPath;
  5979. if (FileUtil.accessSync(jiaMilyricPath)) {
  5980. isJiaMi = true;
  5981. realLyricPath = jiaMilyricPath;
  5982. console.info("onecold 找到加密本地歌词");
  5983. } else {
  5984. console.info("onecold 找到本地歌词");
  5985. }
  5986. let file = fs.openSync(realLyricPath, fs.OpenMode.READ_ONLY);
  5987. const stat = await fileIo.stat(file.fd);
  5988. const arrayBuffer = new ArrayBuffer(stat.size);
  5989. const readLen = await fs.read(file.fd, arrayBuffer);
  5990. console.info("read file data succeed");
  5991. let buf = new Uint8Array(arrayBuffer, 0, readLen);
  5992. if (buf.length === 0) {
  5993. throw new Error("Buffer is empty after reading the file");
  5994. }
  5995. // let detectedEncoding = chardet.detect(buf);
  5996. let detectedEncoding = this.detect(arrayBuffer)
  5997. console.info("Detected encoding: " + detectedEncoding);
  5998. let textDecoder = new util.TextDecoder(detectedEncoding || 'utf-8');
  5999. let fileContent = textDecoder.decode(buf);
  6000. console.info(`onecold The content of file1: ${fileContent}`);
  6001. if (isJiaMi) {
  6002. fileContent = StrUtil.unit8ArrayToStr(Base64Util.decodeSync(fileContent));
  6003. }
  6004. console.info(`onecold The content of file2: ${fileContent}`);
  6005. fs.closeSync(file);
  6006. return fileContent;
  6007. } catch (error) {
  6008. console.error('init Lyric failed with err: ' + JSON.stringify(error));
  6009. return '';
  6010. }
  6011. }
  6012. async saveDataToFile(content: string, filePath: string, isJiaMi?: boolean) {
  6013. if (StrUtil.isEmpty(filePath)) {
  6014. return
  6015. }
  6016. try {
  6017. //将content进行加密
  6018. // let jiaMilyricPath = filePath.substring(0,filePath.lastIndexOf('.'))+'.lrcc'
  6019. let lyricContent = ''
  6020. if (isJiaMi) {
  6021. lyricContent = Base64Util.encodeToStrSync(StrUtil.strToUint8Array(content))
  6022. } else {
  6023. lyricContent = content
  6024. }
  6025. const file = await fileIo.open(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE);
  6026. // 清空文件内容
  6027. await fileIo.truncate(file.fd, 0);
  6028. await fileIo.write(file.fd, lyricContent);
  6029. await fileIo.close(file);
  6030. console.log('onecold lyric file Data saved successfully.');
  6031. } catch (error) {
  6032. console.error('onecold lyric file Failed to save data:', error);
  6033. }
  6034. }
  6035. /**
  6036. * Get largest proportion color of an image.
  6037. */
  6038. getImageColor() {
  6039. if (!this.context) {
  6040. return;
  6041. }
  6042. let bg = Utility.getMusisBg()
  6043. this.imageLabel = bg
  6044. ColorConversion.setSysBarLightBackground(true);
  6045. this.context.resourceManager.getMediaContent(bg)
  6046. .then((value: Uint8Array) => {
  6047. let buffer = value.buffer as ArrayBuffer;
  6048. image.createImageSource(buffer).createPixelMap().then((pixelMap) => {
  6049. effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
  6050. if (error) {
  6051. Logger.error('Failed to create color picker.');
  6052. } else {
  6053. let color = colorPicker.getLargestProportionColor();
  6054. let colorArr = ColorConversion.dealColor(color.red, color.green, color.blue);
  6055. this.imageColor = `rgba(${colorArr[0]}, ${colorArr[1]}, ${colorArr[2]}, 1)`;
  6056. }
  6057. })
  6058. let headFilter = effectKit.createEffect(pixelMap);
  6059. if (headFilter !== null) {
  6060. headFilter.blur(15);
  6061. headFilter.getEffectPixelMap().then((value) => {
  6062. this.imageLabelBg = value;
  6063. })
  6064. }
  6065. })
  6066. .catch((error: BusinessError) => {
  6067. Logger.error(`${error.code} + ${error.message}`)
  6068. })
  6069. })
  6070. .catch((error: BusinessError) => {
  6071. Logger.error(`${error.code} + ${error.message}`)
  6072. })
  6073. }
  6074. setImageColor(cover: string) {
  6075. if (!this.context) {
  6076. return;
  6077. }
  6078. if (cover === undefined) {
  6079. return;
  6080. }
  6081. ImageUtil.imagePathToPixelMap(cover).then((value) => {
  6082. let headFilter = effectKit.createEffect(value);
  6083. if (headFilter !== null) {
  6084. headFilter.blur(15);
  6085. headFilter.getEffectPixelMap().then((value) => {
  6086. this.imageLabelBg = value;
  6087. })
  6088. }
  6089. }).catch((error: BusinessError) => {
  6090. Logger.error(`${error.code} + ${error.message}`)
  6091. })
  6092. }
  6093. setImageColor2(cover: string) {
  6094. if (!this.context) {
  6095. return;
  6096. }
  6097. if (cover === undefined) {
  6098. return;
  6099. }
  6100. LogUtils.getInstance().LOGI("setImageColor2--> cover ==" + cover);
  6101. ImageUtils.getImageDealData(getContext(this), cover, this.videoUrl).then((data) => {
  6102. this.imageColor = data.imageColor;
  6103. if (data.blurPixelMap) {
  6104. this.imageLabelBg = data.blurPixelMap;
  6105. }
  6106. })
  6107. }
  6108. // 定义开始旋转的方法
  6109. // 定时器用于一百毫秒执行一次旋转角度
  6110. @State timer: number = 0
  6111. @State rotateAngle: number = 0
  6112. //封面旋转动画
  6113. animationRoFun() {
  6114. if (this.isPlaying && !this.isCoverRectangle) {
  6115. this.timer = setInterval(() => {
  6116. this.rotateAngle += 1
  6117. }, 100)
  6118. this.startRotation()
  6119. } else {
  6120. clearInterval(this.timer)
  6121. this.stopRotation()
  6122. }
  6123. }
  6124. // 定义开始旋转的方法
  6125. startRotation() {
  6126. if (this.isPlaying) {
  6127. animateTo({
  6128. duration: 777,
  6129. iterations: 1,
  6130. curve: Curve.Linear
  6131. }, () => {
  6132. this.rotateAngle2 = 0
  6133. })
  6134. }
  6135. }
  6136. // 回调,暂停和播放按钮回调,下一首和上一首
  6137. playChange() {
  6138. // if(this.isCoverRectangle){
  6139. // return
  6140. // }
  6141. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  6142. this.setIsPlaying(true)
  6143. this.animationState = AnimationStatus.Running
  6144. } else {
  6145. this.setIsPlaying(false)
  6146. this.animationState = AnimationStatus.Paused
  6147. }
  6148. }
  6149. // 定义停止旋转的方法
  6150. stopRotation() {
  6151. if (this.isCoverRectangle) {
  6152. this.rotateAngle = 0
  6153. } else {
  6154. //唱针以左上角为点选择逆时针40度
  6155. animateTo({
  6156. duration: 1000,
  6157. curve: Curve.Linear,
  6158. iterations: 1,
  6159. }, () => {
  6160. this.rotateAngle2 = -40;
  6161. });
  6162. }
  6163. }
  6164. @Builder
  6165. private LyricsTopItem() {
  6166. Row() {
  6167. Stack() {
  6168. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  6169. .height(55)
  6170. .width(55)
  6171. .alt(this.imageLabel)
  6172. .borderRadius(8)
  6173. .clickEffect({ level: ClickEffectLevel.HEAVY })
  6174. .margin({ left: this.currentLyricAlignMode === 0 ? 28 : -15 })
  6175. }
  6176. .width('18%')
  6177. Column() {
  6178. Column() {
  6179. Text(this.name)
  6180. .fontSize(16)
  6181. .maxLines(1)
  6182. .fontWeight(FontWeight.Bolder)
  6183. .fontColor(this.currentLyricColor)
  6184. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  6185. Row() {
  6186. Text(this.currentSong?.artist !== undefined ? this.currentSong?.artist : '')
  6187. .fontSize(13)
  6188. .fontWeight(FontWeight.Bold)
  6189. .padding({ top: 8 })
  6190. .fontColor(this.currentLyricColor)
  6191. .margin({ left: this.currentLyricAlignMode === 0 ? 18 : 0 })
  6192. Blank()
  6193. }
  6194. }
  6195. .height('100%')
  6196. .width('100%')
  6197. .justifyContent(FlexAlign.Center)
  6198. .alignItems(HorizontalAlign.Start)
  6199. }
  6200. .height('100%')
  6201. .width('65%')
  6202. Column() {
  6203. Image($r('app.media.lyric'))
  6204. .width(28)
  6205. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6206. .margin({ right: 30 })
  6207. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6208. .onClick(() => {
  6209. this.isLyricSetting = !this.isLyricSetting;
  6210. })
  6211. .bindSheet($$this.isLyricSetting, this.lyricSettingSheet(false), {
  6212. height: this.isCoverOpacity() ? '95%' : '88%',
  6213. dragBar: true,
  6214. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  6215. showClose: true,
  6216. blurStyle: BlurStyle.Thin,
  6217. backgroundColor: Color.Transparent,
  6218. // title: { title: $r('app.string.lyric_setting') }
  6219. })
  6220. }
  6221. .width('18%')
  6222. }
  6223. .width('82%')
  6224. .height(58)
  6225. .justifyContent(FlexAlign.SpaceBetween)
  6226. }
  6227. //歌词显示
  6228. @Builder
  6229. PlayerLyrics() {
  6230. Column() {
  6231. Column() {
  6232. this.LyricsTopItem()
  6233. }
  6234. .height(this.isPuraWP() ? 15 : 58)
  6235. .visibility(this.currentBreakpoint !== BreakpointTypeEnum.SM ?
  6236. Visibility.None : Visibility.Visible)
  6237. .margin({ left: 6, top: this.isPuraWP() ? 5 : 38 })
  6238. .width("100%")
  6239. Column() {
  6240. LyricView2({
  6241. controller: this.lyricController,
  6242. enableSeek: true,
  6243. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  6244. seekLineColor: "#80ffffff", // 滑动定位线颜色
  6245. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  6246. onSeekAction: (position: number) => { // 滑动歌词触发seek定位回调
  6247. if (!this.isPlaying) {
  6248. this.startPlayOrResumePlay()
  6249. } else {
  6250. this.isSeekTo = true;
  6251. this.mDestroyPage = false;
  6252. this.showLoadIng();
  6253. this.seekTo(position + "");
  6254. this.isSeekTo = false;
  6255. }
  6256. return true
  6257. }
  6258. })
  6259. .width("100%")
  6260. .layoutWeight(1)
  6261. .margin({ left: this.currentLyricAlignMode === 0 ? 0 : 50, top: 2, bottom: this.isPhoneLan()||this.isHiCarKuanBianPing() ? 40 : 10 })
  6262. if (this.isPhoneLan()) {
  6263. Column() {
  6264. this.playProgressView()
  6265. // this.playCenterView()
  6266. }
  6267. .margin({ bottom: 20, right: this.currentLyricAlignMode == 0 ? 0 : 30 })
  6268. }
  6269. }
  6270. .position({
  6271. top: this.currentBreakpoint !== BreakpointTypeEnum.SM ? (this.isPhoneLan() ? 0 : 45) :
  6272. (this.isPuraWP() ? 58 : 99)
  6273. })
  6274. .justifyContent(FlexAlign.Center)
  6275. .height(this.isCoverOpacity() ? this.isPhoneLan()?'95%':'90%' : '82%')
  6276. }
  6277. }
  6278. @Builder
  6279. SingleLyricView() {
  6280. Column() {
  6281. Column() {
  6282. LyricView2({
  6283. controller: this.lyricControllerSingle,
  6284. enableSeek: false,
  6285. seekUIColor: "#ff0000", // 滑动定位的按钮和文本颜色
  6286. seekLineColor: "#80ffffff", // 滑动定位线颜色
  6287. seekUIStyle: "listItem", // 滑动定位样式(seekLine传统样式,listItem类似抖音汽水音乐样式)
  6288. })
  6289. }
  6290. .height(66)
  6291. .margin({ bottom: 20 })
  6292. }
  6293. }
  6294. //播放器的底部控制中心,上一首,暂停,下一首,播放进度条等
  6295. @Builder
  6296. BottomControl() {
  6297. Column() {
  6298. this.TopPlayProgressView()
  6299. //播放 暂停,下一首,上一首
  6300. this.playCenterView()
  6301. //播放进度条
  6302. this.BottomView()
  6303. }
  6304. .position({ bottom: this.isHiCarSmall()?50:(this.isCoverOpacity() ? 55 : 70) }) // 将 固定在底部
  6305. }
  6306. //播放控制上一首 下一首 暂停和播放
  6307. @Builder
  6308. playCenterView(){
  6309. Row() {
  6310. Row({ space: 20 }) {
  6311. Button({type:ButtonType.Circle,stateEffect:true}){
  6312. //更多功能
  6313. Image($r('app.media.menu'))
  6314. .width(24)
  6315. .clickEffect({level:ClickEffectLevel.MIDDLE})
  6316. .bindSheet($$this.isShowMoreView, this.PlayMoreSheet(), {
  6317. height: this.isCoverOpacity() ? '95%' : '93%',
  6318. preferType: this.currentBreakpoint!==BreakpointTypeEnum.SM?SheetType.CENTER:SheetType.BOTTOM,
  6319. dragBar: true,
  6320. showClose: true,
  6321. blurStyle: BlurStyle.Thin,
  6322. backgroundColor: Color.Transparent,
  6323. })
  6324. }
  6325. .margin({ left: 5 })
  6326. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6327. .backgroundColor(Color.Transparent)
  6328. .onClick(() => {
  6329. this.isShowMoreView = !this.isShowMoreView;
  6330. })
  6331. Button({type:ButtonType.Circle,stateEffect:true}){
  6332. Image($r('app.media.ic_previous'))
  6333. .width(33)
  6334. .clickEffect({level:ClickEffectLevel.HEAVY})
  6335. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6336. }
  6337. .onClick(async () => {
  6338. this.playPrevious()
  6339. })
  6340. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6341. .backgroundColor(Color.Transparent)
  6342. .margin({ left: 5 })
  6343. }
  6344. Button({type:ButtonType.Circle,stateEffect:true}){
  6345. Column() {
  6346. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ?
  6347. (this.isCircleBtn?$r('app.media.hm_pause'):$r('app.media.ic_public_play'))
  6348. : (this.isCircleBtn?$r('app.media.hm_play2'):$r('app.media.ic_public_pause')))
  6349. .width(this.isPhoneLan()?45:55)
  6350. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6351. .fillColor(Color.White)
  6352. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6353. .onClick(async () => {
  6354. this.playOrPause()
  6355. })
  6356. }
  6357. }
  6358. .backgroundColor(Color.Transparent)
  6359. .layoutWeight(1)
  6360. // .margin({ left: 38, right: 38 })
  6361. Row({ space: 20 }) {
  6362. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  6363. Image($r('app.media.ic_next'))
  6364. .width(33)
  6365. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6366. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6367. .onClick(() => {
  6368. this.playNext();
  6369. })
  6370. }
  6371. .backgroundColor(Color.Transparent)
  6372. .margin({ right: 5 })
  6373. .width(33)
  6374. Button({type:ButtonType.Circle,stateEffect:true}){
  6375. //添加或取消收藏
  6376. Image(Utility.getIsFav(this.favList,this.currentSong)?
  6377. $r('app.media.add_fac_light'):$r('app.media.add_fac'))
  6378. .width(24)
  6379. .clickEffect({level:ClickEffectLevel.MIDDLE})
  6380. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6381. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6382. .onClick(async () => {
  6383. if(this.currentSong){
  6384. this.doFav(this.currentSong)
  6385. }
  6386. })
  6387. }
  6388. .backgroundColor(Color.Transparent)
  6389. .width(24)
  6390. }
  6391. // .margin({ left: 5 })
  6392. }
  6393. .width('95%')
  6394. .margin({ bottom:this.isCoverOpacity()?0:20 })
  6395. .justifyContent(FlexAlign.SpaceEvenly)
  6396. }
  6397. //播放进度条
  6398. @Builder
  6399. TopPlayProgressView(){
  6400. Row() {
  6401. Column(){
  6402. Row(){
  6403. Slider({
  6404. value: this.progressValue,
  6405. min: 0,
  6406. max: this.PROGRESS_MAX_VALUE,
  6407. step: 1,
  6408. style: SliderStyle.InSet
  6409. })
  6410. .blockColor('rgba(255,255,255,1)')
  6411. .trackColor('rgba(255,255,255,0.3)')
  6412. .selectedColor(Color.White)
  6413. .trackThickness(4)
  6414. .layoutWeight(1)
  6415. .showSteps(false)
  6416. .showTips(true)
  6417. .enabled(this.slideEnable)
  6418. .onChange((value: number, mode: SliderChangeMode) => {
  6419. // if (mode == 2) {
  6420. this.isSeekTo = true;
  6421. this.mDestroyPage = false;
  6422. this.showLoadIng();
  6423. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  6424. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  6425. this.seekTo(seekValue + "");
  6426. // this.setProgress()
  6427. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  6428. this.isSeekTo = false;
  6429. // }
  6430. })
  6431. }
  6432. .padding({ right: 7,left:14 })
  6433. Row(){
  6434. Text(this.currentTime)
  6435. .fontSize(10)
  6436. .fontColor(Color.White)
  6437. Blank()
  6438. .layoutWeight(1)
  6439. Text(this.totalTime)
  6440. .fontSize(10)
  6441. .fontColor(Color.White)
  6442. }
  6443. .justifyContent(FlexAlign.Start)
  6444. .padding({ right: 18,left:36 })
  6445. }
  6446. }
  6447. //x5的竖屏模式需要99%
  6448. .width(this.isLandscape?'80%':'93%')
  6449. .justifyContent(FlexAlign.Center)
  6450. .margin({bottom:5})
  6451. .animation({
  6452. duration: 666,
  6453. curve: 'ease-in-out' // 可选动画曲线
  6454. })
  6455. }
  6456. //播放进度条
  6457. @Builder
  6458. BottomView(){
  6459. Row() {
  6460. Button({type:ButtonType.Circle,stateEffect:true}){
  6461. Column() {
  6462. if (this.playType === 0) {
  6463. Image($r('app.media.loop'))
  6464. .width(27)
  6465. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6466. } else if (this.playType === 1) {
  6467. Image($r('app.media.single'))
  6468. .width(27)
  6469. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6470. } else if (this.playType === 2) {
  6471. Image($r('app.media.normal_play'))
  6472. .width(27)
  6473. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6474. } else if (this.playType === 3) {
  6475. Image($r('app.media.random'))
  6476. .width(27)
  6477. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6478. }
  6479. }
  6480. }
  6481. .layoutWeight(1)
  6482. .margin({ left: 5 })
  6483. .backgroundColor(Color.Transparent)
  6484. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6485. .onClick(async () => {
  6486. this.setLoopMode()
  6487. })
  6488. Button({type:ButtonType.Circle,stateEffect:true}){
  6489. Column() {
  6490. Image($r('app.media.full_4'))
  6491. .width(25)
  6492. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6493. }
  6494. }
  6495. .layoutWeight(1)
  6496. .backgroundColor(Color.Transparent)
  6497. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6498. .onClick(async () => {
  6499. if (this.isLandscape) {
  6500. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  6501. } else {
  6502. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  6503. }
  6504. })
  6505. Button({type:ButtonType.Circle,stateEffect:true}){
  6506. Column() {
  6507. Image($r('app.media.lyric'))
  6508. .width(26)
  6509. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6510. }
  6511. }
  6512. .layoutWeight(1)
  6513. .backgroundColor(Color.Transparent)
  6514. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6515. .onClick(async () => {
  6516. this.isLyricSetting = !this.isLyricSetting;
  6517. })
  6518. //播放列表
  6519. Button({type:ButtonType.Circle,stateEffect:true}){
  6520. Image($r('app.media.hm_playlist'))
  6521. .width(24)
  6522. .fillColor(Color.White)
  6523. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6524. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  6525. height: '95%',
  6526. dragBar: true,
  6527. showClose: true,
  6528. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  6529. blurStyle: BlurStyle.Thin,
  6530. backgroundColor: this.isPlayListBgGrass?Color.Transparent:$r('app.color.silvery'),
  6531. title: {
  6532. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  6533. + `(${this.songList.length}首)`
  6534. }
  6535. })
  6536. }
  6537. .layoutWeight(1)
  6538. .backgroundColor(Color.Transparent)
  6539. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  6540. .onClick(() => {
  6541. this.isShowSheetView = !this.isShowSheetView;
  6542. if(this.isPlayListBgGrass){
  6543. this.isFrontWhite = true
  6544. }else{
  6545. this.isFrontWhite = false
  6546. }
  6547. setTimeout(() => {
  6548. this.playListScroller.scrollToIndex(this.curIndex,true, ScrollAlign.CENTER)
  6549. }, 123)
  6550. })
  6551. }
  6552. .width(this.isLandscape?'88%':'95%')
  6553. .justifyContent(FlexAlign.SpaceAround)
  6554. .height(30)
  6555. .margin({top:3})
  6556. .animation({
  6557. duration: 666,
  6558. curve: 'ease-in-out' // 可选动画曲线
  6559. })
  6560. }
  6561. //旧版本播放进度条
  6562. @Builder
  6563. playProgressView() {
  6564. Row() {
  6565. Button({ type: ButtonType.Circle, stateEffect: true }) {
  6566. Column() {
  6567. if (this.playType === 0) {
  6568. Image($r('app.media.loop'))
  6569. .width($r('app.float.control_image_width'))
  6570. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6571. } else if (this.playType === 1) {
  6572. Image($r('app.media.single'))
  6573. .width($r('app.float.control_image_width'))
  6574. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6575. } else if (this.playType === 2) {
  6576. Image($r('app.media.normal_play'))
  6577. .width($r('app.float.control_image_width'))
  6578. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6579. } else if (this.playType === 3) {
  6580. Image($r('app.media.random'))
  6581. .width($r('app.float.control_image_width'))
  6582. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6583. }
  6584. }
  6585. }
  6586. .visibility(this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  6587. .animation({
  6588. duration: 666,
  6589. curve: 'ease-in-out' // 可选动画曲线
  6590. })
  6591. .backgroundColor(Color.Transparent)
  6592. .margin({ left: 20, right: 10 })
  6593. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6594. .onClick(async () => {
  6595. this.setLoopMode()
  6596. })
  6597. Text(this.currentTime)
  6598. .fontSize($r('app.float.slider_font_size'))
  6599. .fontColor(Color.White)
  6600. .margin(3)
  6601. Slider({
  6602. value: this.progressValue,
  6603. min: 0,
  6604. max: this.PROGRESS_MAX_VALUE,
  6605. step: 1,
  6606. style: SliderStyle.OutSet
  6607. })
  6608. .width('600px')
  6609. .blockColor('rgba(255,255,255,1)')
  6610. .trackColor('rgba(255,255,255,0.3)')
  6611. .selectedColor(Color.White)
  6612. .trackThickness(PlayConstants.PROGRESS_TRACK_THICKNESS)
  6613. .layoutWeight(1)
  6614. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  6615. .showSteps(false)
  6616. .showTips(true)
  6617. .enabled(this.slideEnable)
  6618. .onChange((value: number, mode: SliderChangeMode) => {
  6619. // if (mode == 2) {
  6620. this.isSeekTo = true;
  6621. this.mDestroyPage = false;
  6622. this.showLoadIng();
  6623. LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
  6624. let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
  6625. this.seekTo(seekValue + "");
  6626. // this.setProgress()
  6627. LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
  6628. this.isSeekTo = false;
  6629. // }
  6630. })
  6631. Text(this.totalTime)
  6632. .fontSize($r('app.float.slider_font_size'))
  6633. .fontColor(Color.White)
  6634. .margin(3)
  6635. .margin({ left: PlayConstants.PROGRESS_MARGIN_LEFT })
  6636. //播放列表
  6637. Button({ type: ButtonType.Circle, stateEffect: true }) {
  6638. Image($r('app.media.hm_playlist'))
  6639. .width($r('app.float.control_image_width'))
  6640. .fillColor(Color.White)
  6641. .aspectRatio(CommonConstants.ASPECT_RATIO)
  6642. .bindSheet($$this.isShowSheetView, this.PlayListSheet(), {
  6643. height: '95%',
  6644. dragBar: true,
  6645. showClose: true,
  6646. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  6647. blurStyle: BlurStyle.Thin,
  6648. backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
  6649. title: {
  6650. title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
  6651. + `(${this.songList.length}首)`
  6652. }
  6653. })
  6654. }
  6655. .visibility( this.is_auto_hide_progress ? Visibility.None : Visibility.Visible)
  6656. .animation({
  6657. duration: 666,
  6658. curve: 'ease-in-out' // 可选动画曲线
  6659. })
  6660. .backgroundColor(Color.Transparent)
  6661. .margin({ right: 20, left: 10 })
  6662. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6663. .onClick(() => {
  6664. this.isShowSheetView = !this.isShowSheetView;
  6665. if (this.isPlayListBgGrass) {
  6666. this.isFrontWhite = true
  6667. } else {
  6668. this.isFrontWhite = false
  6669. }
  6670. setTimeout(() => {
  6671. this.playListScroller.scrollToIndex(this.curIndex, true, ScrollAlign.CENTER)
  6672. }, 123)
  6673. })
  6674. }
  6675. //x5的竖屏模式需要99%
  6676. .width(this.isPhonePortrait() ? '93.4%'
  6677. : this.currentHeightBreakpoint == 1 && this.currentWidthBreakpoint == 2 ? '99%' : '82%')
  6678. .height(this.isPhoneLan() ? 25 : 33)
  6679. .animation({
  6680. duration: 666,
  6681. curve: 'ease-in-out' // 可选动画曲线
  6682. })
  6683. }
  6684. isBigScreen() {
  6685. if (this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_LG) {
  6686. return true
  6687. }
  6688. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  6689. && this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  6690. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG) {
  6691. return false
  6692. } else {
  6693. return true
  6694. }
  6695. return false
  6696. }
  6697. @State is_auto_hide_progress: boolean = false //手机横屏自动隐藏播放进退条,点击屏幕可以显示,倒计时4秒后又自动隐藏
  6698. @State isCoverRectangle: boolean = false
  6699. @State isCoverTop: boolean = true
  6700. // 添加控制缩放的状态变量
  6701. @State scaleValueImage: number = 1
  6702. @Builder
  6703. CoverInfo() {
  6704. Column() {
  6705. //如果是方形,判断是不是封面在顶部,如果不是顶部,显示musicNameInfo, 如果是圆形显示musicNameInfo
  6706. if (this.isCoverRectangle) {
  6707. if (!this.isCoverTop) {
  6708. this.musicNameInfo(false)
  6709. }
  6710. } else {
  6711. this.musicNameInfo(false)
  6712. }
  6713. Stack() {
  6714. // 唱片旋转效果
  6715. Image($r('app.media.ic_music_disc'))
  6716. .width(245)
  6717. .height(245)
  6718. .margin({ right: 20, left: 20 })
  6719. .aspectRatio(1)
  6720. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  6721. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  6722. .borderRadius('100%')
  6723. .align(Alignment.Center)
  6724. .clip(true)// .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
  6725. .rotate({
  6726. angle: this.rotateAngle,
  6727. centerX: "50%",
  6728. centerY: "50%",
  6729. })
  6730. .animation({
  6731. duration: 100,
  6732. curve: Curve.Linear
  6733. })
  6734. .shadow({
  6735. radius: 30,
  6736. color: this.randomColor
  6737. })
  6738. Column() {
  6739. if (this.isCoverTop && !this.isCoverOpacity() && this.isCoverRectangle) {
  6740. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)// .height(this.isCoverOpacity() ? 250 : this.isCoverRectangle ? 320 : 162)
  6741. .width(this.isBigScreen() ? '72%' : this.isCoverTopBig ? '100%' : '86%')
  6742. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  6743. .alt(this.imageLabel)
  6744. .margin({ right: 8, left: 8, top: 8 })
  6745. .aspectRatio(1)
  6746. .opacity(this.opacityValueImage)
  6747. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  6748. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  6749. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  6750. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  6751. .align(Alignment.Center)//
  6752. .clip(true)
  6753. .rotate({
  6754. x: 0,
  6755. y: 0,
  6756. z: 1,
  6757. angle: this.rotateAngle
  6758. })
  6759. .onClick(() => {
  6760. this.getImageColor()
  6761. })
  6762. this.musicNameInfo(false)
  6763. } else {
  6764. Image(StrUtil.isEmpty(this.cover) ? this.imageLabel : this.cover)
  6765. .height(this.isHiCarSmall()?(this.isHiCarKuanBianPing()?140:px2vp(this.windowHeight)*0.38):(this.isCoverOpacity() ? 250 : this.isCoverRectangle ? 320 : 162))
  6766. .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
  6767. .alt(this.imageLabel)
  6768. .margin({ right: 20, left: 20 })
  6769. .aspectRatio(1)
  6770. .opacity(this.opacityValueImage)
  6771. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  6772. .visibility(this.isPuraWP() ? Visibility.None : Visibility.Visible)
  6773. .borderRadius(this.isCoverRectangle ? 20 : '100%')
  6774. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.8 })
  6775. .align(Alignment.Center)//
  6776. .clip(true)
  6777. .rotate({
  6778. x: 0,
  6779. y: 0,
  6780. z: 1,
  6781. angle: this.rotateAngle
  6782. })
  6783. .onClick(() => {
  6784. this.getImageColor()
  6785. })
  6786. if (this.isPhoneLan()) {
  6787. Text(this.name)
  6788. .fontSize(18)
  6789. .fontWeight(FontWeight.Bold)
  6790. .margin({ top: 13 })
  6791. .textOverflow({ overflow: TextOverflow.Ellipsis })
  6792. .maxLines(1)
  6793. .width('99%')
  6794. .textAlign(TextAlign.Center)
  6795. .fontColor(Color.White)
  6796. }
  6797. }
  6798. }
  6799. // 唱针以左上角为点选择逆时针40度
  6800. Image($r('app.media.ic_music_cover_hand'))
  6801. .height(130)
  6802. .margin({ bottom: 220, top: 0 })
  6803. .align(Alignment.Top)
  6804. .rotate({ angle: this.rotateAngle2, centerX: 0, centerY: 0 })
  6805. .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
  6806. .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
  6807. Column({ space: 8 }) {
  6808. Text(this.name)
  6809. .fontSize(this.isPuraWP() ? 24 : (this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22))
  6810. .fontWeight(FontWeight.Bold)
  6811. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  6812. .maxLines(1)
  6813. .width('48%')
  6814. .textAlign(TextAlign.Center)
  6815. .fontColor(Color.White)
  6816. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  6817. Text(this.artist)
  6818. .fontSize(this.isPuraWP() ? 18 : (this.isCoverOpacity() ? 12 : 15))
  6819. .fontColor(Color.White)
  6820. .fontWeight(FontWeight.Bold)
  6821. .visibility(this.isPhoneLan() ? Visibility.None : Visibility.Visible)
  6822. }
  6823. .justifyContent(FlexAlign.Start)
  6824. .zIndex(1)
  6825. .visibility(this.isCoverOpacity() ? Visibility.Visible : Visibility.None)
  6826. }
  6827. .margin({
  6828. bottom: this.isCoverOpacity() || this.isCoverRectangle ?
  6829. (this.isPhonePortrait() && this.isShowSingleLineLyric ? 20 : 55) : 0,
  6830. top: this.isCoverOpacity() ? 0 : 20
  6831. })
  6832. if (this.isPhonePortrait() && this.isShowSingleLineLyric) {
  6833. this.SingleLyricView()
  6834. }
  6835. if (this.isPhoneLan()) {
  6836. Column() {
  6837. this.playCenterView()
  6838. // this.playProgressView()
  6839. }
  6840. .position({ left: 40, bottom: 48 })
  6841. } else {
  6842. this.BottomControl()
  6843. }
  6844. }
  6845. .width(CommonConstants.FULL_PERCENT)
  6846. .clip(true)
  6847. }
  6848. @Builder
  6849. private musicNameInfo(isHidden: boolean) {
  6850. Column({ space: 8 }) {
  6851. Text(this.name)
  6852. .fontSize(this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22)
  6853. .fontWeight(FontWeight.Bold)
  6854. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  6855. .maxLines(1)
  6856. .width('99%')
  6857. .textAlign(TextAlign.Center)
  6858. .fontColor(Color.White)
  6859. Text(this.artist + ' ' + this.currentSong?.album)
  6860. .fontSize(this.isCoverOpacity() ? 12 : 15)
  6861. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  6862. .fontColor(Color.White)
  6863. .textAlign(TextAlign.Center)
  6864. .visibility(StrUtil.isEmpty(this.artist)?Visibility.None:Visibility.Visible)
  6865. .width('99%')
  6866. .maxLines(1)
  6867. }
  6868. .margin({ top: this.isCoverOpacity() ? 20 : isHidden ? 40 : 20 })
  6869. .zIndex(1)
  6870. .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果
  6871. .visibility(this.isCoverOpacity() || isHidden ? Visibility.None : Visibility.Visible)
  6872. }
  6873. @Builder
  6874. private PlayTitle() {
  6875. Row() {
  6876. Row() {
  6877. Image($r('app.media.ic_back_down'))
  6878. .width($r('app.float.title_image_size'))// .aspectRatio(CommonConstants.ASPECT_RATIO)
  6879. .hitTestBehavior(HitTestMode.Transparent)
  6880. Text(this.name + ' ' + this.artist)
  6881. .fontColor(Color.White)
  6882. .fontSize($r('app.float.title_font_size'))
  6883. .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
  6884. .maxLines(1)
  6885. .visibility(Visibility.None)
  6886. .margin({ left: 2, right: 30 })
  6887. }
  6888. .layoutWeight(1)
  6889. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6890. .visibility(this.isHide ? Visibility.Hidden : Visibility.Visible)
  6891. .onClick(() => {
  6892. this.isShowPlay = false;
  6893. })
  6894. Column() {
  6895. AVCastPicker({
  6896. normalColor: Color.White,
  6897. onStateChange: this.onStateVastChange
  6898. })
  6899. .width(24)
  6900. .height(24)
  6901. }
  6902. .visibility(this.isHide ? Visibility.Hidden : Visibility.None)
  6903. }
  6904. .width(PlayConstants.ROW_WIDTH)
  6905. }
  6906. @Builder
  6907. lyricSettingSheet(isPip: boolean) {
  6908. Scroll() {
  6909. this.lyricSetting(isPip)
  6910. }
  6911. .width('100%')
  6912. .height('100%')
  6913. }
  6914. @Builder
  6915. lyricSetting(isPip: boolean) {
  6916. Column() {
  6917. // 时间调节模块
  6918. if (!isPip) {
  6919. this.BuildTimeControls()
  6920. }
  6921. // 字号控制模块
  6922. this.BuildFontControls(isPip)
  6923. }
  6924. }
  6925. // 歌词时间偏移状态
  6926. @State timeOffset: number = 0.0
  6927. @State currentLyricColor: string = '#FFFFFF'
  6928. @State currentLyricColorPip: string = '#FFFFFF'
  6929. @State currentHighLightLyricColor: string = '#FF4081'
  6930. @State currentHighLightLyricColorPip: string = '#FF4081'
  6931. // 歌词字号状态
  6932. @State currentLyricSize: number = 20
  6933. @State currentLyricSizePip: number = 20
  6934. // 高亮歌词放大倍数
  6935. @State currentHightLyricSize: number = 1.2
  6936. @State currentHightLyricSizePip: number = 1.2
  6937. @State currentLyricLineSpace: number = 10
  6938. @State currentLyricLineSpacePip: number = 10
  6939. @State currentLyricAlignMode: number = 1
  6940. @State currentLyricAlignModePip: number = 1
  6941. @State blurDegree: number = 2
  6942. @State blurDegreePip: number = 2
  6943. @State isShowSelectColor: boolean = false
  6944. @State isShowHLSelectColor: boolean = false
  6945. @State isShowPipBgSelectColor: boolean = false
  6946. @State pipLyWidth: number = 330
  6947. @State pipLyHeight: number = 120
  6948. // 构建颜色选择器
  6949. @Builder
  6950. SelectColor(isHighColor: boolean, isPip: boolean, isBGPip?: boolean) {
  6951. Row({ space: 10 }) {
  6952. HSBColorPicker({
  6953. color: '#FFFFFF',
  6954. radius: 8,
  6955. layout: HSBColorPickerLayout.COLUMN,
  6956. predefine: ['#8b27f4', '#73f9fc', '#fffe55', '#f5cee3', '#eb4827', '#e93bf4', '#3e68f4', '#c5e6d3', '#e4e4e4',
  6957. '#fa7105'],
  6958. onChange: (value: string) => isHighColor ? this.changeLyricHightLightColor(value, isPip) :
  6959. this.changeLyricColor(value, isPip, isBGPip)
  6960. })
  6961. .height(250)
  6962. .layoutWeight(1)
  6963. .padding(25)
  6964. }
  6965. .width('66%')
  6966. }
  6967. @State isOpenPip: boolean = false
  6968. @State pipBgIndex: number = 0
  6969. // 构建字号控制器
  6970. @Builder
  6971. BuildFontControls(isPip: boolean) {
  6972. Column() {
  6973. if (isPip) {
  6974. Column() {
  6975. Row() {
  6976. Text('悬浮歌词')
  6977. .margin({ left: 18 })
  6978. .fontSize(15)
  6979. .fontColor(Color.White)
  6980. .fontWeight(480)
  6981. .layoutWeight(1)
  6982. Toggle({ type: ToggleType.Switch, isOn: this.isOpenPip })
  6983. .selectedColor(this.themeColor)
  6984. .switchPointColor(Color.White)
  6985. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  6986. .margin({ right: 18 })
  6987. .onChange((checked: boolean) => {
  6988. this.isOpenPip = checked;
  6989. if (this.isOpenPip) {
  6990. this.startPip()
  6991. } else {
  6992. this.stopPip()
  6993. }
  6994. PreferencesUtil.put('isOpenPip', this.isOpenPip)
  6995. })
  6996. .width(50)
  6997. .height(30);
  6998. }
  6999. .height(55)
  7000. }
  7001. .backgroundColor(Color.Transparent)
  7002. .borderRadius(15)
  7003. .margin({
  7004. left: 30,
  7005. right: 30,
  7006. top: 0,
  7007. bottom: 20
  7008. })
  7009. .padding(0)
  7010. .border({
  7011. color: Color.White,
  7012. width: 1.8
  7013. })
  7014. }
  7015. Row() {
  7016. Text(`歌词居中:`)
  7017. .fontSize(14)
  7018. .fontColor(Color.White)
  7019. .margin({ left: 2 })
  7020. Row() {
  7021. ForEach(['居中', '居左'], (size: string, index: number) => {
  7022. Button(size)
  7023. .width(60)
  7024. .height(28)
  7025. .fontSize(12)
  7026. .fontColor('#FFFFFF')
  7027. .backgroundColor((!isPip && this.currentLyricAlignMode === index) ||
  7028. (isPip && this.currentLyricAlignModePip === index) ? this.themeColor : Color.Transparent)
  7029. .border({
  7030. color: (!isPip && this.currentLyricAlignMode === index) ||
  7031. (isPip && this.currentLyricAlignModePip === index) ?
  7032. '#007DFF' : '#DDDDDD',
  7033. width: 1.8
  7034. })
  7035. .onClick(() => {
  7036. this.setLyricAlignMode(index, isPip)
  7037. })
  7038. .margin({ left: 10, right: 8 })
  7039. })
  7040. }
  7041. .width('76%')
  7042. Blank()
  7043. }
  7044. .margin({
  7045. top: 10,
  7046. bottom: 10,
  7047. right: 20,
  7048. left: 20
  7049. })
  7050. if (isPip) {
  7051. Row() {
  7052. Text(`悬浮背景:`)
  7053. .fontSize(14)
  7054. .fontColor(Color.White)
  7055. Select([
  7056. { value: CommonConstants.PIP_LYRIC_BG[0] },
  7057. { value: CommonConstants.PIP_LYRIC_BG[1] }])
  7058. .font({ size: 13, weight: FontWeight.Medium })
  7059. .fontColor(Color.White)
  7060. .margin({ left: 10 })
  7061. .selected(this.pipBgIndex)
  7062. .value(CommonConstants.PIP_LYRIC_BG[this.pipBgIndex])
  7063. .onSelect(async (_index: number, text?: string | undefined) => {
  7064. this.pipBgIndex = _index
  7065. PreferencesUtil.put('pipBgIndex', this.pipBgIndex)
  7066. if (this.pipBgIndex === 0) {
  7067. if (this.cover) {
  7068. this.pipBg = this.cover
  7069. } else {
  7070. this.pipBg = this.imageColor
  7071. }
  7072. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  7073. } else {
  7074. this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
  7075. }
  7076. })
  7077. Column() {
  7078. }
  7079. .backgroundColor(this.pipBg)
  7080. .margin({ left: 10, right: 10 })
  7081. .borderRadius(20)
  7082. .height(28)
  7083. .width(28)
  7084. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7085. Row() {
  7086. SymbolGlyph($r('sys.symbol.paintbrush'))
  7087. .fontColor([Color.White])
  7088. .effectStrategy(1)
  7089. Text(`选择颜色`)
  7090. .fontSize(13)
  7091. .margin({ left: 10 })
  7092. .fontColor(Color.White)
  7093. }
  7094. }
  7095. .visibility(this.pipBgIndex === 1 ? Visibility.Visible : Visibility.None)
  7096. .backgroundColor(Color.Transparent)
  7097. .border({
  7098. color: '#FFFFFF',
  7099. radius: 20,
  7100. width: 1.8
  7101. })
  7102. .height(36)
  7103. .width(110)
  7104. .onClick(() => {
  7105. this.isShowPipBgSelectColor = !this.isShowPipBgSelectColor
  7106. })
  7107. .bindPopup(this.isShowPipBgSelectColor, {
  7108. builder: this.SelectColor(false, isPip, true),
  7109. placement: Placement.Top,
  7110. mask: { color: '#33000000' },
  7111. enableArrow: false, //是否显示箭头
  7112. showInSubWindow: false,
  7113. onStateChange: (e) => {
  7114. if (!e.isVisible) {
  7115. this.isShowPipBgSelectColor = false
  7116. }
  7117. }
  7118. })
  7119. }
  7120. .width('76%')
  7121. .margin({ bottom: 5, right: 45, left: 20 })
  7122. }
  7123. if (!isPip) {
  7124. Row() {
  7125. Text(`高亮居中:`)
  7126. .fontSize(14)
  7127. .fontColor(Color.White)
  7128. Column() {
  7129. Toggle({ type: ToggleType.Switch, isOn: this.isHightLightCenter })
  7130. .selectedColor(this.themeColor)
  7131. .switchPointColor(Color.White)
  7132. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7133. .onChange((checked: boolean) => {
  7134. this.isHightLightCenter = checked;
  7135. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isHightLightCenter)
  7136. this.lyricController.setHightLightCenter(this.isHightLightCenter)
  7137. })
  7138. .width(50)
  7139. .height(30)
  7140. .alignSelf(ItemAlign.Start)
  7141. .margin({ left: 12 })
  7142. Blank()
  7143. }
  7144. .width('76%')
  7145. }
  7146. .margin({
  7147. left: 20,
  7148. right: 15,
  7149. top: 10,
  7150. bottom: 10
  7151. })
  7152. }
  7153. Row() {
  7154. Text(`歌词颜色:`)
  7155. .fontSize(14)
  7156. .fontColor(Color.White)
  7157. Text(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  7158. .fontSize(15)
  7159. .fontColor(Color.White)
  7160. .margin({ left: 12, right: 12 })
  7161. Column() {
  7162. }
  7163. .backgroundColor(isPip ? this.currentLyricColorPip : this.currentLyricColor)
  7164. .margin({ right: 12 })
  7165. .borderRadius(20)
  7166. .height(28)
  7167. .width(28)
  7168. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7169. Row() {
  7170. SymbolGlyph($r('sys.symbol.paintbrush'))
  7171. .fontColor([Color.White])
  7172. .effectStrategy(1)
  7173. Text(`选择颜色`)
  7174. .fontSize(13)
  7175. .margin({ left: 10 })
  7176. .fontColor(Color.White)
  7177. }
  7178. }
  7179. .backgroundColor(Color.Transparent)
  7180. .border({
  7181. color: '#FFFFFF',
  7182. radius: 20,
  7183. width: 1.8
  7184. })
  7185. .height(36)
  7186. .width(110)
  7187. .onClick(() => {
  7188. this.isShowSelectColor = !this.isShowSelectColor
  7189. })
  7190. .bindPopup(this.isShowSelectColor, {
  7191. builder: this.SelectColor(false, isPip),
  7192. placement: Placement.Top,
  7193. mask: { color: '#33000000' },
  7194. enableArrow: false, //是否显示箭头
  7195. showInSubWindow: false,
  7196. onStateChange: (e) => {
  7197. if (!e.isVisible) {
  7198. this.isShowSelectColor = false
  7199. }
  7200. }
  7201. })
  7202. }
  7203. .width('76%')
  7204. .margin({
  7205. top: 10,
  7206. bottom: 10,
  7207. right: 45,
  7208. left: 20
  7209. })
  7210. Row() {
  7211. Text(`高亮颜色:`)
  7212. .fontSize(14)
  7213. .fontColor(Color.White)
  7214. Text(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  7215. .fontSize(15)
  7216. .fontColor(Color.White)
  7217. .margin({ left: 12, right: 12 })
  7218. Column() {
  7219. }
  7220. .backgroundColor(isPip ? this.currentHighLightLyricColorPip : this.currentHighLightLyricColor)
  7221. .margin({ right: 12 })
  7222. .borderRadius(20)
  7223. .height(28)
  7224. .width(28)
  7225. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7226. Row() {
  7227. SymbolGlyph($r('sys.symbol.paintbrush'))
  7228. .fontColor([Color.White])
  7229. .effectStrategy(1)
  7230. Text(`选择颜色`)
  7231. .fontSize(13)
  7232. .margin({ left: 10 })
  7233. .fontColor(Color.White)
  7234. }
  7235. }
  7236. .backgroundColor(Color.Transparent)
  7237. .border({
  7238. color: '#FFFFFF',
  7239. radius: 20,
  7240. width: 1.8
  7241. })
  7242. .height(36)
  7243. .width(110)
  7244. .onClick(() => {
  7245. this.isShowHLSelectColor = !this.isShowHLSelectColor
  7246. })
  7247. .bindPopup(this.isShowHLSelectColor, {
  7248. builder: this.SelectColor(true, isPip),
  7249. placement: Placement.Top,
  7250. mask: { color: '#33000000' },
  7251. enableArrow: false, //是否显示箭头
  7252. showInSubWindow: false,
  7253. onStateChange: (e) => {
  7254. if (!e.isVisible) {
  7255. this.isShowHLSelectColor = false
  7256. }
  7257. }
  7258. })
  7259. }
  7260. .width('76%')
  7261. .margin({
  7262. top: 10,
  7263. bottom: 10,
  7264. right: 45,
  7265. left: 20
  7266. })
  7267. if (isPip) {
  7268. Row() {
  7269. Text(`显示宽度:`)
  7270. .fontSize(14)
  7271. .fontColor(Color.White)
  7272. Slider({
  7273. value: this.pipLyWidth,
  7274. min: 10,
  7275. max: 800,
  7276. step: 1,
  7277. style: SliderStyle.OutSet
  7278. })
  7279. .blockColor(this.themeColor)
  7280. .trackColor($r('app.color.speed_text_color'))
  7281. .selectedColor(Color.White)
  7282. .trackThickness(6)
  7283. .onChange((value: number) => {
  7284. this.pipLyWidth = value
  7285. if (this.pipController) {
  7286. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  7287. PreferencesUtil.putSync('pipLyWidth', this.pipLyWidth)
  7288. }
  7289. })
  7290. .width('76%')
  7291. }
  7292. .margin({
  7293. left: 20,
  7294. right: 15,
  7295. top: 5,
  7296. bottom: 5
  7297. })
  7298. Row() {
  7299. Text(`显示高度:`)
  7300. .fontSize(14)
  7301. .fontColor(Color.White)
  7302. Slider({
  7303. value: this.pipLyHeight,
  7304. min: 10,
  7305. max: 1000,
  7306. step: 1,
  7307. style: SliderStyle.OutSet
  7308. })
  7309. .blockColor(this.themeColor)
  7310. .trackColor($r('app.color.speed_text_color'))
  7311. .selectedColor(Color.White)
  7312. .trackThickness(6)
  7313. .onChange((value: number) => {
  7314. this.pipLyHeight = value
  7315. if (this.pipController) {
  7316. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  7317. PreferencesUtil.putSync('pipLyHeight', this.pipLyHeight)
  7318. }
  7319. })
  7320. .width('76%')
  7321. }
  7322. .margin({
  7323. left: 20,
  7324. right: 15,
  7325. top: 5,
  7326. bottom: 5
  7327. })
  7328. }
  7329. Row() {
  7330. Text(`歌词字号:`)
  7331. .fontSize(14)
  7332. .fontColor(Color.White)
  7333. Slider({
  7334. value: isPip ? this.currentLyricSizePip : this.currentLyricSize,
  7335. min: 12,
  7336. max: 30,
  7337. step: 0.1,
  7338. style: SliderStyle.OutSet
  7339. })
  7340. .blockColor(this.themeColor)
  7341. .trackColor($r('app.color.speed_text_color'))
  7342. .selectedColor(Color.White)
  7343. .trackThickness(6)
  7344. .onChange((value: number) => {
  7345. this.setLyricTextSize(value, isPip)
  7346. })
  7347. .width('76%')
  7348. }
  7349. .margin({
  7350. left: 20,
  7351. right: 15,
  7352. top: 5,
  7353. bottom: 5
  7354. })
  7355. Row() {
  7356. Text(`高亮倍数:`)
  7357. .fontSize(14)
  7358. .fontColor(Color.White)
  7359. Slider({
  7360. value: isPip ? this.currentHightLyricSizePip : this.currentHightLyricSize,
  7361. min: 1,
  7362. max: 2,
  7363. step: 0.1,
  7364. style: SliderStyle.OutSet
  7365. })
  7366. .blockColor(this.themeColor)
  7367. .trackColor($r('app.color.speed_text_color'))
  7368. .selectedColor(Color.White)
  7369. .trackThickness(6)
  7370. .onChange((value: number) => {
  7371. this.setHighLyricTextSize(value, isPip)
  7372. })
  7373. .width('76%')
  7374. }
  7375. .margin({
  7376. left: 20,
  7377. right: 15,
  7378. top: 5,
  7379. bottom: 5
  7380. })
  7381. Row() {
  7382. Text(`歌词间隙:`)
  7383. .fontSize(14)
  7384. .fontColor(Color.White)
  7385. Slider({
  7386. value: isPip ? this.currentLyricLineSpacePip : this.currentLyricLineSpace,
  7387. min: 0,
  7388. max: 100,
  7389. step: 1,
  7390. style: SliderStyle.OutSet
  7391. })
  7392. .blockColor(this.themeColor)
  7393. .trackColor($r('app.color.speed_text_color'))
  7394. .selectedColor(Color.White)
  7395. .trackThickness(6)
  7396. .onChange((value: number) => {
  7397. this.setLyricLineSpace(value, isPip)
  7398. })
  7399. .width('76%')
  7400. }
  7401. .margin({
  7402. left: 20,
  7403. right: 15,
  7404. top: 5,
  7405. bottom: 5
  7406. })
  7407. //取值间隔为100,默认为400,取值越大,字体越粗
  7408. Row() {
  7409. Text(`歌词字重:`)
  7410. .fontSize(14)
  7411. .fontColor(Color.White)
  7412. Slider({
  7413. value: isPip ? this.lyricTextWeightPip : this.lyricTextWeight,
  7414. min: 100,
  7415. max: 900,
  7416. step: 100,
  7417. style: SliderStyle.OutSet
  7418. })
  7419. .blockColor(this.themeColor)
  7420. .trackColor($r('app.color.speed_text_color'))
  7421. .selectedColor(Color.White)
  7422. .trackThickness(6)
  7423. .onChange((value: number) => {
  7424. if (isPip) {
  7425. this.lyricTextWeightPip = value
  7426. this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
  7427. PreferencesUtil.putSync('lyricTextWeightPip', this.lyricTextWeightPip)
  7428. } else {
  7429. this.lyricTextWeight = value
  7430. this.lyricController.setTextWeight(this.lyricTextWeight)
  7431. PreferencesUtil.putSync('lyricTextWeight', this.lyricTextWeight)
  7432. }
  7433. })
  7434. .width('76%')
  7435. }
  7436. .margin({
  7437. left: 20,
  7438. right: 15,
  7439. top: 5,
  7440. bottom: 5
  7441. })
  7442. if (!isPip) {
  7443. Row() {
  7444. Text(`歌词模糊:`)
  7445. .fontSize(14)
  7446. .fontColor(Color.White)
  7447. Slider({
  7448. value: isPip ? this.blurDegreePip : this.blurDegree,
  7449. min: 0,
  7450. max: 5,
  7451. step: 0.1,
  7452. style: SliderStyle.OutSet
  7453. })
  7454. .blockColor(this.themeColor)
  7455. .trackColor($r('app.color.speed_text_color'))
  7456. .selectedColor(Color.White)
  7457. .trackThickness(6)
  7458. .onChange((value: number) => {
  7459. this.setBlurDegree(value, isPip)
  7460. })
  7461. .width('76%')
  7462. }
  7463. .margin({
  7464. left: 20,
  7465. right: 15,
  7466. top: 5,
  7467. bottom: 15
  7468. })
  7469. }
  7470. Row() {
  7471. this.pushLyricButton($r('app.media.cut_current'), 0, '本地歌词')
  7472. this.pushLyricButton($r('app.media.white_search'), 1, '获取歌词')
  7473. }
  7474. .justifyContent(FlexAlign.Center)
  7475. .margin({ top: 3, bottom: 10 })
  7476. }
  7477. }
  7478. private setBlurDegree(index: number, isPip: boolean) {
  7479. if (isPip) {
  7480. this.blurDegreePip = index
  7481. this.lyricControllerXF.setBlurDegree(this.blurDegreePip)
  7482. PreferencesUtil.putSync('setBlurDegreePip', this.blurDegreePip)
  7483. } else {
  7484. this.blurDegree = index
  7485. this.lyricController.setBlurDegree(this.blurDegree)
  7486. PreferencesUtil.putSync('setBlurDegree', this.blurDegree)
  7487. }
  7488. }
  7489. private setLyricAlignMode(index: number, isPip: boolean) {
  7490. if (isPip) {
  7491. this.currentLyricAlignModePip = index
  7492. if (this.currentLyricAlignModePip === 1) {
  7493. this.lyricControllerXF.setAlignMode("left")
  7494. } else {
  7495. this.lyricControllerXF.setAlignMode("center")
  7496. }
  7497. PreferencesUtil.putSync('LyricAlignModePip', this.currentLyricAlignModePip)
  7498. } else {
  7499. this.currentLyricAlignMode = index
  7500. if (this.currentLyricAlignMode === 1) {
  7501. this.lyricController.setAlignMode("left")
  7502. } else {
  7503. this.lyricController.setAlignMode("center")
  7504. }
  7505. PreferencesUtil.putSync('LyricAlignMode', this.currentLyricAlignMode)
  7506. }
  7507. }
  7508. private setLyricTextSize(index: number, isPip: boolean) {
  7509. if (isPip) {
  7510. this.currentLyricSizePip = index
  7511. this.lyricControllerXF.setTextSize(this.currentLyricSizePip)
  7512. PreferencesUtil.putSync('LyricTextSizePip', this.currentLyricSizePip)
  7513. } else {
  7514. this.currentLyricSize = index
  7515. this.lyricController.setTextSize(this.currentLyricSize)
  7516. PreferencesUtil.putSync('LyricTextSize', this.currentLyricSize)
  7517. }
  7518. }
  7519. private setHighLyricTextSize(scale: number, isPip: boolean) {
  7520. if (isPip) {
  7521. this.currentHightLyricSizePip = scale
  7522. this.lyricControllerXF
  7523. .setHighlightScale(this.currentHightLyricSizePip)
  7524. PreferencesUtil.putSync('HighLyricTextSizePip', scale)
  7525. } else {
  7526. this.currentHightLyricSize = scale
  7527. this.lyricController
  7528. .setHighlightScale(this.currentHightLyricSize)
  7529. PreferencesUtil.putSync('HighLyricTextSize', scale)
  7530. }
  7531. }
  7532. private setLyricLineSpace(index: number, isPip: boolean) {
  7533. if (isPip) {
  7534. this.currentLyricLineSpacePip = index
  7535. this.lyricControllerXF.setLineSpace(this.currentLyricLineSpacePip)
  7536. PreferencesUtil.putSync('LyricLineSpacePip', this.currentLyricLineSpacePip)
  7537. } else {
  7538. this.currentLyricLineSpace = index
  7539. this.lyricController.setLineSpace(this.currentLyricLineSpace)
  7540. PreferencesUtil.putSync('LyricLineSpace', this.currentLyricLineSpace)
  7541. }
  7542. }
  7543. private changeLyricColor(color: string, isPip: boolean, isBG?: boolean) {
  7544. LogUtil.info('onecold isBG = ' + isBG)
  7545. if (isBG) { //如果是设置悬浮背景
  7546. this.pipBg = color
  7547. PreferencesUtil.putSync('BGColorPip', this.pipBg)
  7548. this.nodeController.updateBgColor(this.pipBg, this.lyricControllerXF)
  7549. return
  7550. }
  7551. if (isPip) {
  7552. this.currentLyricColorPip = color
  7553. this.lyricControllerXF
  7554. .setTextColor(this.currentLyricColorPip)
  7555. PreferencesUtil.putSync('LyricColorPip', this.currentLyricColorPip)
  7556. } else {
  7557. this.currentLyricColor = color
  7558. this.lyricController
  7559. .setTextColor(this.currentLyricColor)
  7560. PreferencesUtil.putSync('LyricColor', this.currentLyricColor)
  7561. }
  7562. }
  7563. private changeLyricHightLightColor(color: string, isPip: boolean) {
  7564. if (isPip) {
  7565. this.currentHighLightLyricColorPip = color
  7566. this.lyricControllerXF
  7567. .setHighlightColor(this.currentHighLightLyricColorPip)
  7568. PreferencesUtil.putSync('LyricHighLightColorPip', this.currentHighLightLyricColorPip)
  7569. } else {
  7570. this.currentHighLightLyricColor = color
  7571. this.lyricController
  7572. .setHighlightColor(this.currentHighLightLyricColor)
  7573. PreferencesUtil.putSync('LyricHighLightColor', this.currentHighLightLyricColor)
  7574. }
  7575. }
  7576. // 构建时间控制器
  7577. @Builder
  7578. BuildTimeControls() {
  7579. Column() {
  7580. // 时间显示
  7581. Text(this.getTimeText())
  7582. .fontSize(18)
  7583. .fontColor(Color.White)
  7584. .margin({ bottom: 10 })
  7585. Row() {
  7586. this.PrecisionTimeButton($r('app.media.ic_previous'), -0.5, ' -0.5s ')
  7587. this.PrecisionTimeButton($r('app.media.loop'), 0, '重置')
  7588. this.PrecisionTimeButton($r('app.media.ic_next'), 0.5, ' +0.5s ')
  7589. }
  7590. .justifyContent(FlexAlign.Center)
  7591. }
  7592. .margin({ top: 12, bottom: 8 })
  7593. }
  7594. // 精度按钮组件
  7595. @Builder
  7596. PrecisionTimeButton(icon: Resource, step: number, label: string) {
  7597. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7598. Column() {
  7599. Image(icon)
  7600. .width(28)
  7601. .margin({ bottom: 5 })
  7602. .opacity(this.isButtonDisabled(step) ? 0.5 : 1)
  7603. Text(label)
  7604. .fontSize(12)
  7605. .fontColor('#FFFFFF')
  7606. }
  7607. }
  7608. .backgroundColor(Color.Transparent)
  7609. .enabled(!this.isButtonDisabled(step))
  7610. .onClick(() => this.handlePrecisionAdjust(step))
  7611. .padding(5)
  7612. .width(66)
  7613. .height(66)
  7614. .margin({ left: 18, right: 18 })
  7615. .border({
  7616. color: '#FFFFFF',
  7617. width: 1.8
  7618. })
  7619. }
  7620. private handlePrecisionAdjust(step: number) {
  7621. if (step === 0) {
  7622. this.timeOffset = 0
  7623. return
  7624. }
  7625. // 精度处理:保留1位小数
  7626. const newOffset = Number((this.timeOffset + step).toFixed(5))
  7627. // 边界保护(±15.0秒)
  7628. if (newOffset < -30.0 || newOffset > 30.0) {
  7629. // this.triggerEdgeFeedback(newOffset) // 触发边界反馈
  7630. return
  7631. }
  7632. // 状态更新
  7633. this.timeOffset = newOffset
  7634. }
  7635. // 按钮禁用逻辑
  7636. private isButtonDisabled(step: number): boolean {
  7637. const futureOffset = this.timeOffset + step
  7638. return (futureOffset < -30.0) || (futureOffset > 30.0)
  7639. }
  7640. // 时间显示文本升级
  7641. private getTimeText(): string {
  7642. const absValue = Math.abs(this.timeOffset)
  7643. return this.timeOffset === 0
  7644. ? '歌词时间已重置'
  7645. : `歌词已${this.timeOffset < 0 ? '延后' : '提前'} ${absValue.toFixed(1)} 秒`
  7646. }
  7647. // 导入 本地歌词 搜索歌词
  7648. @Builder
  7649. pushLyricButton(icon: Resource, step: number, label: string) {
  7650. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7651. Row() {
  7652. Image(icon)
  7653. .width(14)
  7654. .margin({ left: 13 })
  7655. Text(label)
  7656. .fontSize(12)
  7657. .margin({ left: 6 })
  7658. .fontColor('#FFFFFF')
  7659. }
  7660. }
  7661. .onClick(() => {
  7662. switch (step) {
  7663. case 0:
  7664. this.callFilePickerSelectFileForLyric()
  7665. break;
  7666. case 1:
  7667. //判断是不是赞助会员
  7668. if (PreferencesUtil.getStringSync('LRC_API', '') === '') {
  7669. this.isLyricSetting = false
  7670. this.showTipsDialog()
  7671. return
  7672. }
  7673. if (StrUtil.isNotEmpty(this.videoUrl)) {
  7674. ToastUtil.showToast('正在获取')
  7675. this.isLyricSetting = false
  7676. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  7677. this.initLyric(lyricPath, true);
  7678. }
  7679. break;
  7680. }
  7681. })
  7682. .padding(5)
  7683. .width(110)
  7684. .backgroundColor(Color.Transparent)
  7685. .height(40)
  7686. .margin({ left: 6, right: 6 })
  7687. .border({
  7688. color: '#FFFFFF',
  7689. radius: 20,
  7690. width: 1.8
  7691. })
  7692. }
  7693. showVipDialog() {
  7694. DialogHelper.showCustomContentDialog({
  7695. dialogId: 'vip',
  7696. title: "友情提示",
  7697. autoCancel: false, //点击遮障层时,不关闭弹窗
  7698. backCancel: true, //点击返回键,不关闭弹窗
  7699. contentBuilder: () => {
  7700. this.customVipBuilder("该功能需开通会员,非常感谢您的支持!")
  7701. },
  7702. buttons: [],
  7703. })
  7704. }
  7705. //去赞助的自定义内容
  7706. @Builder
  7707. customVipBuilder(content: string) {
  7708. Column() {
  7709. Text(content)
  7710. .fontColor(Color.Gray)
  7711. .fontSize(16)
  7712. .alignSelf(ItemAlign.Start)
  7713. .margin({ bottom: 15 })
  7714. .fontSize(16)
  7715. Row() {
  7716. Button('取消')
  7717. .fontColor(Color.White)
  7718. .backgroundColor(this.themeColor)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  7719. .height(50)
  7720. .layoutWeight(1)
  7721. .stateEffect(true)
  7722. .margin({ right: 6 })
  7723. .onClick(() => {
  7724. DialogHelper.closeDialog('vip'); //关闭弹框
  7725. })
  7726. Button('开通')
  7727. .fontColor(Color.White)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  7728. .layoutWeight(1)
  7729. .height(50)
  7730. .backgroundColor(this.themeColor)
  7731. .stateEffect(true)
  7732. .margin({ left: 6 })
  7733. .onClick(() => {
  7734. DialogHelper.closeDialog('vip'); //关闭弹框
  7735. this.isShowPlay = false
  7736. this.mType = 1 //跳转到用户中心
  7737. // router.pushUrl({
  7738. // url: 'pages/VipPage'
  7739. // }, router.RouterMode.Single);
  7740. })
  7741. }
  7742. }
  7743. .width("100%")
  7744. .padding(10)
  7745. }
  7746. showTipsDialog() {
  7747. DialogHelper.showCustomContentDialog({
  7748. dialogId: 'tips',
  7749. title: "友情提示",
  7750. autoCancel: false, //点击遮障层时,不关闭弹窗
  7751. backCancel: true, //点击返回键,不关闭弹窗
  7752. contentBuilder: () => {
  7753. this.customTipsBuilder("请到设置界面配置API服务器地址!")
  7754. },
  7755. buttons: [],
  7756. })
  7757. }
  7758. @Builder
  7759. customTipsBuilder(content: string) {
  7760. Column() {
  7761. Text(content)
  7762. .fontColor(Color.Gray)
  7763. .fontSize(16)
  7764. .alignSelf(ItemAlign.Start)
  7765. .margin({ bottom: 15 })
  7766. .fontSize(16)
  7767. Row() {
  7768. Button('取消')
  7769. .fontColor(Color.White)
  7770. .backgroundColor(this.themeColor)
  7771. .height(50)
  7772. .layoutWeight(1)
  7773. .stateEffect(true)
  7774. .margin({ right: 6 })
  7775. .onClick(() => {
  7776. DialogHelper.closeDialog('tips'); //关闭弹框
  7777. })
  7778. Button('跳转')
  7779. .fontColor(Color.White)//
  7780. .layoutWeight(1)
  7781. .height(50)
  7782. .backgroundColor(this.themeColor)
  7783. .stateEffect(true)
  7784. .margin({ left: 6 })
  7785. .onClick(() => {
  7786. DialogHelper.closeDialog('tips'); //关闭弹框
  7787. this.isShowPlay = false
  7788. this.mType = 3
  7789. // router.pushUrl({
  7790. // url: 'pages/SettingPage'
  7791. // }, router.RouterMode.Single);
  7792. })
  7793. }
  7794. }
  7795. .width("100%")
  7796. .padding(10)
  7797. }
  7798. @Builder
  7799. PlayMoreSheet() {
  7800. Column() {
  7801. this.MoreList()
  7802. }
  7803. .width('100%')
  7804. .height('100%')
  7805. }
  7806. @Builder
  7807. MoreList() {
  7808. Scroll() {
  7809. Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
  7810. ForEach(this.moreItems, (more: MoreItem, index: number) => {
  7811. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  7812. Row() {
  7813. if (more.id === 3&&this.currentSong) {
  7814. Image(more.image)
  7815. .width(24)
  7816. .height(24)
  7817. .margin({ left: 10, right: 10 })
  7818. Text(more.title)
  7819. .fontSize(16)
  7820. .fontColor(Color.White)
  7821. .bindSheet($$this.isShowDetailMore, this.detailSheet(this.currentSong), {
  7822. height: this.isCoverOpacity() ? '95%' : '95%',
  7823. dragBar: true,
  7824. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7825. showClose: true,
  7826. blurStyle: BlurStyle.Thin,
  7827. backgroundColor: Color.Transparent,
  7828. title: { title: '歌曲信息' }
  7829. })
  7830. } else if (more.id === 15 && this.currentSong) { //编辑信息
  7831. Image(more.image)
  7832. .width(24)
  7833. .height(24)
  7834. .margin({ left: 10, right: 10 })
  7835. Text(more.title)
  7836. .fontSize(16)
  7837. .fontColor(Color.White)
  7838. .bindSheet($$this.isShowEdit, this.editSheet(this.currentSong), {
  7839. height: this.isCoverOpacity() ? '95%' : '93%',
  7840. dragBar: true,
  7841. showClose: true,
  7842. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7843. // blurStyle:BlurStyle.Thin,
  7844. // backgroundColor:Color.Transparent,
  7845. title: { title: '编辑信息' }
  7846. })
  7847. } else if (more.id === 5) { //定时关闭
  7848. Image(more.image)
  7849. .width(24)
  7850. .height(24)
  7851. .margin({ left: 10, right: 10 })
  7852. Text(more.title)
  7853. .fontSize(16)
  7854. .fontColor(Color.White)
  7855. .onClick(() => {
  7856. this.doMore(more.id)
  7857. })
  7858. .bindSheet($$this.isShowTimeCloseMore, this.TimeCloseSheet(), {
  7859. height: this.isCoverOpacity() ? '95%' : '95%',
  7860. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7861. dragBar: true,
  7862. showClose: true,
  7863. title: { title: $r('app.string.time_close') }
  7864. })
  7865. } else if (more.id === 2) { //歌词设置
  7866. Image(more.image)
  7867. .width(24)
  7868. .height(24)
  7869. .margin({ left: 10, right: 10 })
  7870. Text(more.title)
  7871. .fontSize(16)
  7872. .fontColor(Color.White)
  7873. } else if (more.id === 16) { //悬浮歌词设置
  7874. Image(more.image)
  7875. .width(24)
  7876. .height(24)
  7877. .margin({ left: 10, right: 10 })
  7878. Text(more.title)
  7879. .fontSize(16)
  7880. .fontColor(Color.White)
  7881. .bindSheet($$this.showPipLyric, this.lyricSettingSheet(true), {
  7882. height: this.isCoverOpacity() ? '95%' : '95%',
  7883. dragBar: true,
  7884. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7885. showClose: true,
  7886. blurStyle: BlurStyle.Thin,
  7887. backgroundColor: Color.Transparent,
  7888. title: { title: '悬浮歌词' }
  7889. })
  7890. } else if (more.id === 11) {
  7891. Image(more.image)
  7892. .width(24)
  7893. .height(24)
  7894. .margin({ left: 10, right: 10 })
  7895. Text(more.title)
  7896. .fontSize(16)
  7897. .fontColor(Color.White)
  7898. .bindSheet($$this.isJumpSetting, this.JumpTopEndSheet(), {
  7899. height: this.isCoverOpacity() ? '95%' : '60%',
  7900. dragBar: true,
  7901. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  7902. showClose: true,
  7903. blurStyle: BlurStyle.Thin,
  7904. backgroundColor: Color.Transparent,
  7905. title: { title: '跳过头尾' }
  7906. })
  7907. } else if (more.id === 12) { //投播
  7908. AVCastPicker({
  7909. customPicker: (): void => this.TPImageBuilder(more),
  7910. onStateChange: (state) => {
  7911. if (state == AVCastPickerState.STATE_APPEARING) {
  7912. console.log(' The picker starts showing.');
  7913. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  7914. console.log(' The picker finishes presenting.');
  7915. }
  7916. },
  7917. pickerStyle: AVCastPickerStyle.STYLE_PANEL,
  7918. sessionType: 'video'
  7919. })
  7920. .id('AVCastPicker')
  7921. } else {
  7922. Image(more.image)
  7923. .width(24)
  7924. .height(24)
  7925. .margin({ left: 10, right: 10 })
  7926. .onClick(() => {
  7927. this.doMore(more.id)
  7928. })
  7929. Text(more.id == 17 ? (this.isLandscape ? '竖屏模式' : '横屏模式') : more.title)
  7930. .fontSize(16)
  7931. .fontColor(Color.White)
  7932. .onClick(() => {
  7933. this.doMore(more.id)
  7934. })
  7935. Select([//倍速
  7936. { value: '0.25x' },
  7937. { value: '0.5x' },
  7938. { value: '0.75x' },
  7939. { value: '1x' },
  7940. { value: '1.25x' },
  7941. { value: '1.5x' },
  7942. { value: '1.75x' },
  7943. { value: '2x' },
  7944. { value: '3x' }])
  7945. .font({ size: 16, weight: FontWeight.Medium })
  7946. .fontColor($r('sys.color.white'))
  7947. .margin({ left: 25 })
  7948. .visibility(more.id === 1 ? Visibility.Visible : Visibility.None)
  7949. .selected(CommonConstants.video_speed_list.indexOf(this.playSpeed))
  7950. .value(Utility.optimizedFormat(this.playSpeed))
  7951. .onSelect(async (_index: number, text?: string | undefined) => {
  7952. let speed = parseFloat(text?.replace('x', '') || '1');
  7953. if (!CommonConstants.video_speed_list.includes(speed)) {
  7954. speed = 1;
  7955. }
  7956. this.playSpeed = speed
  7957. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  7958. })
  7959. Slider({
  7960. value: this.volume,
  7961. min: 0,
  7962. max: 1,
  7963. step: 0.1,
  7964. style: SliderStyle.OutSet
  7965. })
  7966. .margin({ left: 18, right: 8 })
  7967. .blockColor(this.themeColor)
  7968. .trackColor($r('app.color.speed_text_color'))
  7969. .selectedColor(Color.White)
  7970. .trackThickness(9)
  7971. .visibility(more.id === 9 ? Visibility.Visible : Visibility.None)
  7972. .onChange((value: number) => {
  7973. this.volume = value;
  7974. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  7975. PreferencesUtil.putSync('DefalutVolume',this.volume)
  7976. })
  7977. .layoutWeight(1)
  7978. Blank()
  7979. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  7980. .selectedColor(this.themeColor)
  7981. .switchPointColor(Color.White)
  7982. .margin({ right: 15 })
  7983. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  7984. .visibility(more.id == 6 ? Visibility.Visible : Visibility.None)
  7985. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  7986. if (more.id == 6) {
  7987. this.isMusicMemoryPlay = checked;
  7988. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  7989. if (this.isMusicMemoryPlay) {
  7990. ToastUtil.showToast('记忆播放已开启')
  7991. } else {
  7992. ToastUtil.showToast('记忆播放已关闭')
  7993. }
  7994. }
  7995. })
  7996. .width(48)
  7997. .height(24);
  7998. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  7999. .selectedColor(this.themeColor)
  8000. .switchPointColor(Color.White)
  8001. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8002. .margin({ right: 15 })
  8003. .visibility(more.id == 7 ? Visibility.Visible : Visibility.None)
  8004. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8005. if (more.id == 7) {
  8006. this.isMusicBGCover = checked;
  8007. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  8008. if (this.isMusicBGCover) {
  8009. ToastUtil.showToast('播放背景随音乐封面已开启')
  8010. } else {
  8011. ToastUtil.showToast('播放背景随音乐封面已关闭')
  8012. }
  8013. }
  8014. })
  8015. .width(48)
  8016. .height(24);
  8017. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  8018. .selectedColor(this.themeColor)
  8019. .switchPointColor(Color.White)
  8020. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8021. .margin({ right: 15 })
  8022. .visibility(more.id == 8 ? Visibility.Visible : Visibility.None)
  8023. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8024. if (more.id == 8) {
  8025. this.isSavePlayMode = checked;
  8026. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  8027. if (this.isSavePlayMode) {
  8028. ToastUtil.showToast('保存播放模式已开启')
  8029. } else {
  8030. ToastUtil.showToast('保存播放模式已关闭')
  8031. }
  8032. }
  8033. })
  8034. .width(48)
  8035. .height(24);
  8036. Toggle({ type: ToggleType.Switch, isOn: this.isCoverRectangle })
  8037. .selectedColor(this.themeColor)
  8038. .switchPointColor(Color.White)
  8039. .clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.5 })
  8040. .margin({ right: 15 })
  8041. .visibility(more.id == 13 ? Visibility.Visible : Visibility.None)
  8042. .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
  8043. if (more.id == 13) {
  8044. this.isCoverRectangle = checked;
  8045. PreferencesUtil.put(SettingPage.IS_COVER_RECTANGLE, this.isCoverRectangle)
  8046. if (this.isCoverRectangle) {
  8047. ToastUtil.showToast('封面方形已开启')
  8048. this.animationRoFun()
  8049. } else {
  8050. ToastUtil.showToast('封面圆形已开启')
  8051. this.animationRoFun()
  8052. }
  8053. }
  8054. })
  8055. .width(48)
  8056. .height(24);
  8057. }
  8058. }
  8059. .width('100%')
  8060. .height(45)
  8061. .padding(15)
  8062. .backgroundColor(Color.Transparent)
  8063. .borderRadius(12)
  8064. .margin({ bottom: 6 })
  8065. }
  8066. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.9 })
  8067. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  8068. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  8069. .backgroundColor(Color.Transparent)
  8070. .onClick(() => {
  8071. this.doMore(more.id)
  8072. })
  8073. });
  8074. }
  8075. .width('100%')
  8076. .padding(16)
  8077. }.margin({ bottom: 18 })
  8078. }
  8079. @Builder
  8080. TPImageBuilder(more: MoreItem): void {
  8081. Row() {
  8082. Image($r('app.media.tuoping'))
  8083. .width(22)
  8084. .height(22)
  8085. .margin({ left: 10, right: 10 })
  8086. Text(more.title)
  8087. .fontSize(16)
  8088. .fontColor(Color.White)
  8089. }
  8090. .width('100%')
  8091. .layoutWeight(1)
  8092. .alignItems(VerticalAlign.Center)
  8093. .justifyContent(FlexAlign.Start)
  8094. }
  8095. private moreItems: MoreItem[] = [
  8096. { id: 1, image: $r('app.media.speed'), title: '倍速' },
  8097. { id: 2, image: $r('app.media.lyric'), title: '歌词' },
  8098. { id: 17, image: $r('app.media.full_4'), title: '横屏模式' },
  8099. { id: 16, image: $r('app.media.hua_zhong_hua'), title: '悬浮歌词' },
  8100. { id: 14, image: $r('app.media.cover_online'), title: '获取封面' },
  8101. { id: 15, image: $r('app.media.rename2'), title: '编辑信息' },
  8102. { id: 5, image: $r('app.media.time_close'), title: '定时关闭' },
  8103. { id: 10, image: $r('app.media.ring_tone'), title: '设为铃声' },
  8104. { id: 11, image: $r('app.media.time_close'), title: '跳过头尾' },
  8105. { id: 12, image: $r('app.media.toubo'), title: '投播' },
  8106. { id: 3, image: $r('app.media.hua_zhong_hua'), title: '详情' },
  8107. { id: 4, image: $r('app.media.share2'), title: '分享' },
  8108. { id: 9, image: $r('app.media.volume_white'), title: '调整音量' },
  8109. { id: 6, image: $r('app.media.memory'), title: '记忆播放' },
  8110. { id: 13, image: $r('app.media.rectangle'), title: '封面方形' },
  8111. { id: 8, image: $r('app.media.cut_current'), title: '保存播放模式' },
  8112. { id: 7, image: $r('app.media.playlist2'), title: '播放背景随音乐封面' },
  8113. ];
  8114. @State isShowMoreView: boolean = false;
  8115. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  8116. @State isShowTimeCloseMore: boolean = false
  8117. @State isShowDetailMore: boolean = false
  8118. @State isMusicBGCover: boolean = true
  8119. @State isSavePlayMode: boolean = true
  8120. @State isLyricSetting: boolean = false
  8121. @State isJumpSetting: boolean = false
  8122. @State isShowEdit: boolean = false
  8123. @State showPipLyric: boolean = false
  8124. async setRingTone() {
  8125. if (StrUtil.isEmpty(this.videoUrl) || StrUtil.isEmpty(this.name)) {
  8126. return
  8127. }
  8128. // 确定后的逻辑
  8129. let ringtoneTypeList: Array<ringtone.RingtoneType> = ringtone.getSupportedRingtoneTypes();
  8130. LogUtil.info('onecold getSupportedRingtoneTypes : ' + JSON.stringify(ringtoneTypeList));
  8131. let dataTypeList: Array<uniformTypeDescriptor.UniformDataType> =
  8132. ringtone.getSupportedDataTypes(ringtone.RingtoneType.NOTIFICATION);
  8133. LogUtil.info('onecold getSupportedDataTypes: ' + JSON.stringify(dataTypeList));
  8134. //let fileName: string = audioPath.substring(audioPath.lastIndexOf('/') + 1, audioPath.lastIndexOf('.'));
  8135. await ringtone.startRingtoneSetting(getContext(this) as common.UIAbilityContext
  8136. , this.videoUrl, this.name).then(res => {
  8137. LogUtil.info('onecold setFlag :' + res);
  8138. });
  8139. }
  8140. doMore(moreId: number) {
  8141. switch (moreId) {
  8142. case 2: //歌词
  8143. this.isLyricSetting = !this.isLyricSetting;
  8144. this.isShowMoreView = false
  8145. break;
  8146. case 3: //详情
  8147. this.isShowDetailMore = !this.isShowDetailMore;
  8148. break;
  8149. case 4: //分享
  8150. if (this.currentSong !== undefined) {
  8151. Utility.doShareMusic(this.currentSong, getContext(this) as common.UIAbilityContext)
  8152. }
  8153. this.isShowMoreView = false
  8154. break;
  8155. case 5: //定时关闭
  8156. this.isShowTimeCloseMore = !this.isShowTimeCloseMore;
  8157. break;
  8158. case 10: //设为铃声
  8159. this.setRingTone()
  8160. this.isShowMoreView = false
  8161. break;
  8162. case 11: //跳过头尾
  8163. this.isJumpSetting = !this.isJumpSetting;
  8164. break;
  8165. case 13: //倍速
  8166. break;
  8167. case 14: //搜索封面
  8168. if (this.currentSong !== undefined) {
  8169. this.doSearchCover(this.currentSong)
  8170. }
  8171. this.isShowMoreView = false
  8172. break;
  8173. case 15: //编辑信息
  8174. this.isShowEdit = !this.isShowEdit;
  8175. break;
  8176. case 16: //悬浮歌词
  8177. this.showPipLyric = !this.showPipLyric;
  8178. break;
  8179. case 17: //横屏模式
  8180. if (this.isLandscape) {
  8181. this.setOrientation(window.Orientation.USER_ROTATION_PORTRAIT);
  8182. } else {
  8183. this.setOrientation(window.Orientation.USER_ROTATION_LANDSCAPE);
  8184. }
  8185. this.isShowMoreView = false
  8186. break;
  8187. }
  8188. }
  8189. /**
  8190. * 切换横竖屏
  8191. *
  8192. */
  8193. setOrientation(orientation: number) {
  8194. this.windowClass.setPreferredOrientation(orientation).then(() => {
  8195. Logger.info('setWindowOrientation: ' + orientation + ' Succeeded.');
  8196. }).catch((err: BusinessError) => {
  8197. Logger.info('setWindowOrientation: ' + orientation + ' Failed. Cause: ' + JSON.stringify(err));
  8198. });
  8199. }
  8200. /**
  8201. * 画中画功能(悬浮歌词功能)
  8202. *
  8203. */
  8204. private nodeController: TextNodeController = new TextNodeController('#000000', this.lyricControllerXF);
  8205. pipController?: PiPWindow.PiPController;
  8206. navigationId: string = '';
  8207. @State curState: string = '';
  8208. @State curError: ResourceStr = '';
  8209. @State pipBg: string = '#E8E8E8'
  8210. @State buttonAction: string = '';
  8211. //开启画中画功能
  8212. async startPip() {
  8213. this.nodeController = new TextNodeController(this.pipBg, this.lyricControllerXF);
  8214. if (!this.pipController) {
  8215. await this.createPipController();
  8216. }
  8217. if (!this.pipController) {
  8218. Logger.info(`[${TAG}] pipController create error`);
  8219. return;
  8220. }
  8221. await this.pipController.startPiP();
  8222. }
  8223. async stopPip() {
  8224. if (!this.pipController) {
  8225. Logger.info(`[${TAG}] pipController is not exist`);
  8226. return;
  8227. }
  8228. this.isOpenPip = false
  8229. await this.pipController.stopPiP();
  8230. }
  8231. async createPipController() {
  8232. this.pipController = await PiPWindow.create({
  8233. context: getContext(this),
  8234. componentController: this.xcomponentController,
  8235. navigationId: this.navigationId,
  8236. templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY,
  8237. controlGroups: [PiPWindow.VideoPlayControlGroup.VIDEO_PREVIOUS_NEXT],
  8238. customUIController: this.nodeController,
  8239. });
  8240. this.pipLyWidth = PreferencesUtil.getNumberSync('pipLyWidth', 330)
  8241. this.pipLyHeight = PreferencesUtil.getNumberSync('pipLyHeight', 120)
  8242. this.pipController.updateContentSize(this.pipLyWidth, this.pipLyHeight);
  8243. this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => {
  8244. this.onStateChange(state, reason);
  8245. });
  8246. this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => {
  8247. this.onActionEvent(event, status);
  8248. });
  8249. }
  8250. destroyPipController() {
  8251. if (!this.pipController) {
  8252. return;
  8253. }
  8254. this.pipController.off('stateChange');
  8255. this.pipController.off('controlPanelActionEvent');
  8256. this.pipController = undefined;
  8257. }
  8258. onStateChange(state: PiPWindow.PiPState, reason: string) {
  8259. switch (state) {
  8260. case PiPWindow.PiPState.ABOUT_TO_START:
  8261. this.curState = 'ABOUT_TO_START';
  8262. this.curError = $r('app.string.current_error_hint');
  8263. break;
  8264. case PiPWindow.PiPState.STARTED:
  8265. this.curState = 'STARTED';
  8266. this.curError = $r('app.string.current_error_hint');
  8267. break;
  8268. case PiPWindow.PiPState.ABOUT_TO_STOP:
  8269. this.curState = 'ABOUT_TO_STOP';
  8270. this.curError = $r('app.string.current_error_hint');
  8271. break;
  8272. case PiPWindow.PiPState.STOPPED:
  8273. this.curState = 'STOPPED';
  8274. this.curError = $r('app.string.current_error_hint');
  8275. this.stopPip()
  8276. this.destroyPipController()
  8277. break;
  8278. case PiPWindow.PiPState.ABOUT_TO_RESTORE:
  8279. this.curState = 'ABOUT_TO_RESTORE';
  8280. this.curError = $r('app.string.current_error_hint');
  8281. break;
  8282. case PiPWindow.PiPState.ERROR:
  8283. this.curState = 'ERROR';
  8284. this.curError = reason;
  8285. break;
  8286. default:
  8287. break;
  8288. }
  8289. Logger.info(`[${TAG}] onecold onStateChange: ${this.curState}, reason: ${reason}`);
  8290. }
  8291. onActionEvent(event: PiPWindow.PiPActionEventType, status: number | undefined) {
  8292. LogUtil.info('onecold onActionEvent = ' + event + ' status=' + status)
  8293. switch (event) {
  8294. case 'playbackStateChanged':
  8295. if (status === 0) {
  8296. this.pause();
  8297. } else {
  8298. this.startPlayOrResumePlay();
  8299. }
  8300. break;
  8301. case 'nextVideo':
  8302. // 切换到下一个视频
  8303. this.playNext()
  8304. break;
  8305. case 'previousVideo':
  8306. // 切换到上一个视频
  8307. this.playPrevious()
  8308. break;
  8309. case 'previousVideo':
  8310. // 切换到上一个视频
  8311. this.playPrevious()
  8312. break;
  8313. default:
  8314. }
  8315. this.buttonAction = event + `-status:${status}`;
  8316. Logger.info(`[${TAG}] onActionEvent: ${this.buttonAction} status:${status}}`);
  8317. }
  8318. /**
  8319. * 画中画功能(悬浮歌词功能)结束
  8320. *
  8321. */
  8322. doSearchCover(item: VideoItem) {
  8323. if (PreferencesUtil.getStringSync('COVER_API', '') === '') {
  8324. this.isShowMoreView = false
  8325. this.showTipsDialog()
  8326. return
  8327. }
  8328. if (item !== undefined) {
  8329. let artist = item?.artist
  8330. if (StrUtil.isEmpty(artist) || artist === undefined) {
  8331. artist = ''
  8332. }
  8333. this.searchCover(item, item.name, artist)
  8334. }
  8335. }
  8336. searchCover(item: VideoItem, title: string, artist: string) {
  8337. NetAxiosUtil.getLyricCover(title, artist, PreferencesUtil.getStringSync('COVER_API', '')).then(async (res) => {
  8338. LogUtil.debug("onecold res =" + res)
  8339. if (StrUtil.isNotEmpty(res) && res !== 'unknown' && res !== 'Timeout was reached') {
  8340. if (item.filePath == this.currentSong?.filePath) {
  8341. this.cover = res
  8342. if (this.currentSong) {
  8343. this.currentSong.pixelMapPath = res
  8344. }
  8345. }
  8346. this.table.updatePixelMapPath(item.filePath, res, (success: boolean, error?: string) => {
  8347. if (success) {
  8348. this.doUpdateData()
  8349. console.log(" onecold 更新音乐封面成功,数据库已同步");
  8350. } else {
  8351. console.error(" onecold 更新音乐封面数据库失败原因: " + error);
  8352. }
  8353. });
  8354. LogUtil.debug("onecold this.cover =" + this.cover)
  8355. }
  8356. })
  8357. }
  8358. @State jumpTopTime: number = 0
  8359. @State jumpEndTime: number = 0
  8360. @State isOpenJump: boolean = false
  8361. @Builder
  8362. JumpTopEndSheet() {
  8363. Scroll() {
  8364. Column() {
  8365. Column() {
  8366. Text('仅对本播放列表有效')
  8367. .fontSize(16)
  8368. .fontColor($r('app.color.text_color'))
  8369. // 跳过头尾
  8370. Column() {
  8371. Row() {
  8372. Text('跳过片头:')
  8373. .fontSize(16)
  8374. .fontColor($r('app.color.text_color'))
  8375. Text(this.jumpTopTime + 's')
  8376. .fontSize(16)
  8377. .fontColor($r('app.color.text_color'))
  8378. }
  8379. .margin({ bottom: 5 })
  8380. Row() {
  8381. Slider({
  8382. value: this.jumpTopTime,
  8383. min: 0,
  8384. max: 120,
  8385. step: 1,
  8386. style: SliderStyle.OutSet
  8387. })
  8388. .blockColor(this.themeColor)
  8389. .trackColor($r('app.color.speed_text_color'))
  8390. .selectedColor(Color.White)
  8391. .trackThickness(8)
  8392. .onChange((value: number) => {
  8393. this.jumpTopTime = value;
  8394. })
  8395. .width('85%')
  8396. }
  8397. .alignItems(VerticalAlign.Top)
  8398. }
  8399. .margin({ top: 10, bottom: 10 })
  8400. // 跳过头尾
  8401. Column() {
  8402. Row() {
  8403. Text('跳过片尾:')
  8404. .fontSize(16)
  8405. .fontColor($r('app.color.text_color'))
  8406. Text(this.jumpEndTime + 's')
  8407. .fontSize(16)
  8408. .fontColor($r('app.color.text_color'))
  8409. }
  8410. .margin({ bottom: 5 })
  8411. Row() {
  8412. Slider({
  8413. value: this.jumpEndTime,
  8414. min: 0,
  8415. max: 120,
  8416. step: 1,
  8417. style: SliderStyle.OutSet
  8418. })
  8419. .blockColor(this.themeColor)
  8420. .trackColor($r('app.color.speed_text_color'))
  8421. .selectedColor(Color.White)
  8422. .trackThickness(8)
  8423. .onChange((value: number) => {
  8424. this.jumpEndTime = value;
  8425. })
  8426. .width('85%')
  8427. }
  8428. .alignItems(VerticalAlign.Top)
  8429. }
  8430. .margin({ top: 10, bottom: 10 })
  8431. Row() {
  8432. Button('保存设置')
  8433. .fontColor(Color.White)
  8434. .layoutWeight(1)
  8435. .height(40)
  8436. .width(80)
  8437. .backgroundColor(this.themeColor)
  8438. .stateEffect(true)
  8439. .margin({ left: 0, bottom: 20 })
  8440. .onClick(async () => {
  8441. if (!Utility.isNoble()) {
  8442. this.isJumpSetting = false
  8443. this.isShowMoreView = false
  8444. this.showVipDialog()
  8445. return
  8446. }
  8447. if (this.currentSong === undefined) {
  8448. return
  8449. }
  8450. if (this.modeType === 0) {
  8451. let parentPath = FileUtil.getParentPath(this.videoUrl)
  8452. PreferencesUtil.putSync(parentPath + 'isOpenJump', true)
  8453. PreferencesUtil.putSync(parentPath + 'jumpEndTime', this.jumpEndTime)
  8454. PreferencesUtil.putSync(parentPath + 'jumpTopTime', this.jumpTopTime)
  8455. } else if (this.modeType === 1) { //媒体库
  8456. PreferencesUtil.putSync(1 + 'isOpenJump', true)
  8457. PreferencesUtil.putSync(1 + 'jumpEndTime', this.jumpEndTime)
  8458. PreferencesUtil.putSync(1 + 'jumpTopTime', this.jumpTopTime)
  8459. } else if (this.modeType === 2) { //艺术家
  8460. if (this.currentSong?.artist) {
  8461. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'isOpenJump', true)
  8462. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpEndTime', this.jumpEndTime)
  8463. PreferencesUtil.putSync(this.currentSong?.artist + 2 + 'jumpTopTime', this.jumpTopTime)
  8464. }
  8465. } else if (this.modeType === 3) { //专辑
  8466. if (this.currentSong?.album) {
  8467. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'isOpenJump', true)
  8468. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpEndTime', this.jumpEndTime)
  8469. PreferencesUtil.putSync(this.currentSong?.album + 3 + 'jumpTopTime', this.jumpTopTime)
  8470. }
  8471. }
  8472. ToastUtil.showShort("保存成功")
  8473. this.isJumpSetting = false
  8474. })
  8475. }
  8476. .margin({
  8477. left: 38,
  8478. right: 38,
  8479. top: 10,
  8480. bottom: 10
  8481. })
  8482. .width(120)
  8483. .height(50)
  8484. }
  8485. }
  8486. }
  8487. .width('100%')
  8488. .height('100%')
  8489. }
  8490. // 应用可以通过onStateChange接口监听组件显示/消失状态,当组件显示时建议不要销毁AVCastPicker的显示;当组件消失时,再根据业务隐藏AVCastPicker。
  8491. private onStateVastChange(state: AVCastPickerState) {
  8492. if (state == AVCastPickerState.STATE_APPEARING) {
  8493. console.log('The picker starts showing.');
  8494. } else if (state == AVCastPickerState.STATE_DISAPPEARING) {
  8495. console.log('The picker finishes presenting.');
  8496. }
  8497. }
  8498. private showSelectLyric() {
  8499. DialogHelper.showActionSheetDialog({
  8500. title: '温馨提醒:\n1.歌词文件名必须和目标歌曲文件名相同\n2.歌词文件和目标歌曲要同个歌单路径。',
  8501. // sheets: ["本地歌词", "搜索歌词"],
  8502. sheets: [
  8503. { value: "本地歌词", fontColor: $r('app.color.text_color') },
  8504. { value: "搜索歌词", fontColor: $r('app.color.text_color') },
  8505. ],
  8506. maskColor: Color.Transparent,
  8507. backgroundColor: $r('app.color.bg_card'),
  8508. transition: AnimationHelper.transitionInDown(666),
  8509. onAction: (index) => {
  8510. switch (index) {
  8511. case 0:
  8512. this.callFilePickerSelectFileForLyric()
  8513. break;
  8514. case 1:
  8515. if (StrUtil.isNotEmpty(this.videoUrl)) {
  8516. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  8517. this.initLyric(lyricPath);
  8518. }
  8519. break;
  8520. }
  8521. }
  8522. })
  8523. }
  8524. // 拉起picker选择文件管理器
  8525. async callFilePickerSelectFileForLyric(): Promise<void> {
  8526. try {
  8527. let DocumentSelectOptions = new picker.DocumentSelectOptions();
  8528. DocumentSelectOptions.maxSelectNumber = 1
  8529. DocumentSelectOptions.fileSuffixFilters = CommonConstants.LYRIC_FORMAT
  8530. let documentPicker = new picker.DocumentViewPicker();
  8531. documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
  8532. Logger.info(TAG,
  8533. 'DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
  8534. if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
  8535. this.saveVideoDatasLyric(DocumentSelectResult)
  8536. }
  8537. }).catch((err: BusinessError) => {
  8538. Logger.error(TAG, 'DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
  8539. });
  8540. } catch (err) {
  8541. Logger.error(TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
  8542. }
  8543. }
  8544. async saveVideoDatasLyric(uris: string[]) {
  8545. if (ArrayUtil.isEmpty(uris)) {
  8546. return
  8547. }
  8548. let newUris: string[] = [];
  8549. for (let i = 0; i < uris.length; i++) {
  8550. let filePath = getContext(this).filesDir + '/' + Utility.getMediaNameByUri(uris[i])
  8551. Logger.info(TAG, 'filePath uri: ' + filePath);
  8552. newUris.push(filePath)
  8553. let file = fileIo.openSync(uris[i], fileIo.OpenMode.READ_ONLY)
  8554. let file2 = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  8555. fileIo.copyFileSync(file.fd, file2.fd)
  8556. fileIo.closeSync(file);
  8557. fileIo.closeSync(file2);
  8558. this.initLyric(filePath)
  8559. }
  8560. }
  8561. private initDelayPlay(context: object) {
  8562. this.mContext = context;
  8563. }
  8564. startPipLyric() {
  8565. if (this.pipController) {
  8566. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  8567. PiPWindow.PiPControlStatus.PLAY);
  8568. }
  8569. this.isOpenPip = PreferencesUtil.getBooleanSync('isOpenPip', false)
  8570. if (this.isOpenPip) {
  8571. this.startPip()
  8572. } else {
  8573. this.stopPip()
  8574. }
  8575. }
  8576. private startPlayOrResumePlay() {
  8577. this.startPipLyric()
  8578. this.mDestroyPage = false;
  8579. this.animationState = AnimationStatus.Running
  8580. LogUtils.getInstance().LOGI("startPlayOrResumePlay start this.CONTROL_PlayStatus:" + this.CONTROL_PlayStatus)
  8581. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  8582. this.stopProgressTask();
  8583. this.startProgressTask();
  8584. this.play(this.videoUrl.toString());
  8585. }
  8586. if (this.CONTROL_PlayStatus == PlayStatus.PAUSE) {
  8587. this.mIjkMediaPlayer.start();
  8588. this.setProgress()
  8589. this.CONTROL_PlayStatus = PlayStatus.PLAY
  8590. }
  8591. this.setIsPlaying(true)
  8592. this.updateSessionPlayState(true)
  8593. this.watchStatus();
  8594. this.updateLastPlayTimeStr(this.videoUrl)
  8595. }
  8596. updateLastPlayTimeStr(filePath: string) {
  8597. let lastPlayTime = DateUtil.getTodayStr('yyyy-MM-dd HH:mm:ss')
  8598. this.table.updateLastPlayedStrByFilePath(filePath, lastPlayTime, (success: boolean, error?: string) => {
  8599. if (success) {
  8600. this.getHistoryList(false)
  8601. console.log(" onecold 更新最近播放时间成功,数据库已同步");
  8602. } else {
  8603. console.error(" onecold 更新最近播放时间数据库失败原因: " + error);
  8604. }
  8605. });
  8606. }
  8607. private completionNum(num: number): string | number {
  8608. if (num < 10) {
  8609. return '0' + num;
  8610. } else {
  8611. return num;
  8612. }
  8613. }
  8614. private stringForTime(timeMs: number): string {
  8615. let totalSeconds: number | string = (timeMs / 1000);
  8616. let newSeconds: number | string = totalSeconds % 60;
  8617. let minutes: number | string = (totalSeconds / 60) % 60;
  8618. let hours: number | string = totalSeconds / 3600;
  8619. //LogUtils.getInstance().LOGI("stringForTime hours:" + hours + ",minutes:" + minutes + ",seconds:" + newSeconds);
  8620. hours = this.completionNum(Math.floor(Math.floor(hours * 100) / 100));
  8621. minutes = this.completionNum(Math.floor(Math.floor(minutes * 100) / 100));
  8622. newSeconds = Math.floor(Math.floor(newSeconds * 100) / 100)
  8623. if (this.isCurrentTime) {
  8624. if (this.oldSeconds < newSeconds || newSeconds === 0 || this.isSeekTo) {
  8625. this.oldSeconds = newSeconds
  8626. } else {
  8627. newSeconds = this.oldSeconds
  8628. }
  8629. }
  8630. newSeconds = this.completionNum(newSeconds);
  8631. if (hours > 0) {
  8632. return hours + ":" + minutes + ":" + newSeconds;
  8633. } else {
  8634. return minutes + ":" + newSeconds;
  8635. }
  8636. }
  8637. private setProgress() {
  8638. let position = this.mIjkMediaPlayer.getCurrentPosition();
  8639. let duration = this.mIjkMediaPlayer.getDuration();
  8640. let pos = 0;
  8641. if (duration > 0) {
  8642. this.slideEnable = true;
  8643. let curPercent = position / duration;
  8644. pos = curPercent * 100;
  8645. if (pos > this.PROGRESS_MAX_VALUE) {
  8646. this.progressValue = this.PROGRESS_MAX_VALUE
  8647. } else {
  8648. this.progressValue = pos;
  8649. }
  8650. }
  8651. // LogUtils.getInstance()
  8652. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  8653. this.totalTime = this.stringForTime(duration);
  8654. if (position > duration) {
  8655. position = duration;
  8656. }
  8657. this.isCurrentTime = true;
  8658. this.lyricController.updatePosition(position + this.timeOffset * 1000)
  8659. this.lyricControllerXF.updatePosition(position + this.timeOffset * 1000)
  8660. this.lyricControllerSingle.updatePosition(position + this.timeOffset * 1000)
  8661. this.currentTime = this.stringForTime(position);
  8662. this.isCurrentTime = false
  8663. if (this.mIjkMediaPlayer.isPlaying()) {
  8664. this.randomColor =
  8665. `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
  8666. // 判断是否播放到结束时间
  8667. if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
  8668. if (position >= duration - this.jumpEndTime * 1000) {
  8669. this.playNext()
  8670. }
  8671. }
  8672. } else {
  8673. this.randomColor = 'rbg(0,0,0)'
  8674. }
  8675. }
  8676. private startProgressTask() {
  8677. let that = this;
  8678. this.updateProgressTimer = setInterval(() => {
  8679. //LogUtils.getInstance().LOGI("startProgressTask");
  8680. if (!that.mDestroyPage) {
  8681. that.setProgress();
  8682. }
  8683. }, 300);
  8684. }
  8685. private stopProgressTask() {
  8686. LogUtils.getInstance().LOGI("stopProgressTask");
  8687. clearInterval(this.updateProgressTimer);
  8688. }
  8689. private showLoadIng() {
  8690. this.loadingVisible = Visibility.Visible;
  8691. this.replayVisible = Visibility.None;
  8692. }
  8693. private hideLoadIng() {
  8694. this.loadingVisible = Visibility.None;
  8695. this.replayVisible = Visibility.None;
  8696. }
  8697. private showRePlay() {
  8698. this.loadingVisible = Visibility.None;
  8699. this.replayVisible = Visibility.Visible;
  8700. }
  8701. private async play(url: string) {
  8702. let that = this;
  8703. that.showLoadIng();
  8704. //设置XComponent回调的context
  8705. if (!!this.mContext) {
  8706. this.mIjkMediaPlayer.setContext(this.mContext, 'xcomponentId');
  8707. }
  8708. if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
  8709. this.mIjkMediaPlayer.reset();
  8710. }
  8711. this.CONTROL_PlayStatus = PlayStatus.PLAY;
  8712. //设置debug模式
  8713. this.mIjkMediaPlayer.setDebug(false);
  8714. //初始化配置
  8715. this.mIjkMediaPlayer.native_setup();
  8716. // 初始化配置后需要重新设置音频流音量,否则音量为默认值1.0 针对dsf格式设置最大值1.0
  8717. if(this.videoUrl.toLowerCase().endsWith('.dsf')){
  8718. this.mIjkMediaPlayer.setVolume('1', '1');
  8719. }else{
  8720. this.mIjkMediaPlayer.setVolume(this.volume.toString(), this.volume.toString());
  8721. }
  8722. //设置视频源
  8723. this.mIjkMediaPlayer.setDataSource(url);
  8724. //设置视频源http请求头
  8725. let headers = new Map([
  8726. ["user_agent", "Mozilla/5.0 BiliDroid/7.30.0 (bbcallen@gmail.com)"],
  8727. ["referer", "https://www.bilibili.com"]
  8728. ]);
  8729. this.mIjkMediaPlayer.setDataSourceHeader(headers);
  8730. // if(PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN,false)){
  8731. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", "1"); // 启用硬件解码,会导致无法顺序播放
  8732. // }
  8733. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  8734. //使用精确寻帧 例如,拖动播放后,会寻找最近的关键帧进行播放,很有可能关键帧的位置不是拖动后的位置,而是较前的位置.可以设置这个参数来解决问题
  8735. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", "1");
  8736. const fileSize = await this.getFileSize(this.videoUrl);
  8737. let bufferSize = 1 * 1024 ; // 默认缓冲区大小为1MB
  8738. if (fileSize > 3 * 1024 * 1024 * 1024) { // 文件大于3GB
  8739. bufferSize = 25 * 1024 * 1024; // 设置缓冲区大小为25MB
  8740. }
  8741. // 使用软件解码(通常比硬件解码更节省内存)
  8742. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", '0');
  8743. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", '0');
  8744. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", '1024');
  8745. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", '500000');
  8746. //预读数据的缓冲区大小.修复大文件播放前几秒挂掉的bug,太大了会导致倍数播放失效
  8747. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", bufferSize + '');
  8748. //停止预读的最小帧数
  8749. // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100");
  8750. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", '1'); ////重连模式,如果中途服务器断开了连接,让它重新连接
  8751. // 设置其他缓冲相关选项
  8752. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100"); // 设置最小缓冲帧数
  8753. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-frames", "1000"); // 设置最大缓冲
  8754. //启动预加载
  8755. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", "1");
  8756. // 设置无缓冲,这是播放器的缓冲区,有数据就播放
  8757. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", "0");
  8758. //跳帧处理,放CPU处理较慢时,进行跳帧处理,保证播放流程,画面和声音同步
  8759. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", "5");
  8760. // 最大缓冲cache是3s, 有时候网络波动,会突然在短时间内收到好几秒的数据
  8761. // 因此需要播放器丢包,才不会累积延时
  8762. // 这个和第三个参数packet-buffering无关。
  8763. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max_cached_duration", "3000");
  8764. // 无限制收流
  8765. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1");
  8766. this.mIjkMediaPlayer.setOptionLong(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1")
  8767. // 屏幕常亮
  8768. this.mIjkMediaPlayer.setScreenOnWhilePlaying(true);
  8769. // 设置超时
  8770. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", "10000000");
  8771. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "connect_timeout", "10000000");
  8772. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "addrinfo_timeout", "10000000");
  8773. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_timeout", "10000000");
  8774. // 变速播放
  8775. this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", "1");
  8776. this.mIjkMediaPlayer.setSpeed(this.playSpeed + 'f');
  8777. let Speed = this.mIjkMediaPlayer.getSpeed()
  8778. LogUtils.getInstance().LOGI('getSpeed--' + Speed)
  8779. //是否开启循环播放
  8780. // this.mIjkMediaPlayer.setLoopCount(this.loop);
  8781. let mOnVideoSizeChangedListener: OnVideoSizeChangedListener = {
  8782. onVideoSizeChanged: (width: number, height: number, sar_num: number, sar_den: number) => {
  8783. if (height === 0) {
  8784. return;
  8785. }
  8786. const va = width / height;
  8787. const vpa = that.videoParentAspectRatio;
  8788. if (vpa > va) {
  8789. that.videoWidth = (width / (height * vpa)) * 100 + '%';
  8790. } else {
  8791. that.videoWidth = '100%';
  8792. }
  8793. if (width && height) {
  8794. that.videoAspectRatio = width / height;
  8795. }
  8796. LogUtils.getInstance()
  8797. .LOGI("setOnVideoSizeChangedListener-->go:" + width + "," + height + "," + sar_num + "," + sar_den);
  8798. that.hideLoadIng();
  8799. }
  8800. }
  8801. this.mIjkMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
  8802. let mOnPreparedListener: OnPreparedListener = {
  8803. onPrepared: async () => {
  8804. LogUtils.getInstance().LOGI("setOnPreparedListener-->go");
  8805. try {
  8806. // this.cover = this.songList[this.curIndex].pixelMapPath
  8807. // this.artist = this.songList[this.curIndex].artist
  8808. // this.videoUrl = this.songList[this.curIndex].filePath
  8809. let isBgCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  8810. if (isBgCover && this.cover !== undefined && StrUtil.isNotEmpty(this.cover)) {
  8811. this.setImageColor2(this.cover)
  8812. } else {
  8813. this.getImageColor();
  8814. }
  8815. //保存碰一碰分享的当前的歌曲
  8816. AppStorage.setOrCreate('currentSong',this.currentSong) ;
  8817. let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
  8818. await this.initLyric(lyricPath);
  8819. setTimeout(() => {
  8820. this.avSessionController.initAvSession(false);
  8821. this.avSessionController.setAVMetadataMusic(this.songList[this.curIndex], this.duration, this.lyricContent);
  8822. this.setAvSessionListener();
  8823. this.updateSessionPlayState(true)
  8824. this.setCurrentPlayMode()
  8825. }, 500)
  8826. //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  8827. let timeoutPlay = 0
  8828. if (StrUtil.isNotEmpty(this.videoUrl) &&
  8829. (this.videoUrl.toLowerCase().endsWith('.rmvb') || this.videoUrl.toLowerCase().endsWith('.flac'))) {
  8830. timeoutPlay = 1000
  8831. }
  8832. //跳过片头片尾关键代码,以下是跳过片头的关键代码
  8833. if (this.modeType === 0) { //文件夹
  8834. let parentPath = FileUtil.getParentPath(this.videoUrl)
  8835. this.jumpTopTime = PreferencesUtil.getNumberSync(parentPath + 'jumpTopTime')
  8836. this.jumpEndTime = PreferencesUtil.getNumberSync(parentPath + 'jumpEndTime')
  8837. this.isOpenJump = PreferencesUtil.getBooleanSync(parentPath + 'isOpenJump', false)
  8838. } else if (this.modeType === 1) { //媒体库
  8839. this.jumpTopTime = PreferencesUtil.getNumberSync(1 + 'jumpTopTime')
  8840. this.jumpEndTime = PreferencesUtil.getNumberSync(1 + 'jumpEndTime')
  8841. this.isOpenJump = PreferencesUtil.getBooleanSync(1 + 'isOpenJump', false)
  8842. } else if (this.modeType === 2) { //艺术家
  8843. if (this.currentSong?.artist) {
  8844. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpTopTime')
  8845. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpEndTime')
  8846. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.artist + 2 + 'isOpenJump', false)
  8847. }
  8848. } else if (this.modeType === 3) { //专辑
  8849. if (this.currentSong?.album) {
  8850. this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpTopTime')
  8851. this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpEndTime')
  8852. this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.album + 3 + 'isOpenJump', false)
  8853. }
  8854. }
  8855. this.duration = this.mIjkMediaPlayer.getDuration()
  8856. if (this.isOpenJump) { //用户是否设置跳过片头片尾
  8857. if (this.mIjkMediaPlayer != null) {
  8858. if (this.jumpTopTime * 1000 <= this.duration) {
  8859. // 调用 seekTo 方法,跳到指定时间
  8860. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  8861. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  8862. this.seekTo(this.jumpTopTime * 1000 + ""); // 跳到开头
  8863. }
  8864. }, timeoutPlay)
  8865. } else {
  8866. // 提示用户无法跳过
  8867. ToastUtil.showToast('跳过时间超过视频时长');
  8868. }
  8869. }
  8870. } else {
  8871. this.jumpTopTime = 0
  8872. this.jumpEndTime = 0
  8873. console.error('onecold 最后一首: isFirstStartPlay = ' + this.isFirstStartPlay);
  8874. console.error('onecold 最后一首: isMemoryLastPlay = ' + this.isMemoryLastPlay);
  8875. console.error('onecold 最后一首: PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false) = ' +
  8876. PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false));
  8877. //记忆播放(每一首都会记忆播放)
  8878. if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
  8879. setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
  8880. if (PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)) {
  8881. this.restorePlaybackPosition() //读取播放记忆功能
  8882. } else if (this.isMemoryLastPlay && this.isFirstStartPlay) {
  8883. console.error('onecold 最后一首:读取播放记忆功能 = ' + this.isFirstStartPlay);
  8884. this.restorePlaybackPosition() //读取播放记忆功能
  8885. }
  8886. this.isFirstStartPlay = false
  8887. }, timeoutPlay)
  8888. } else {
  8889. this.isFirstStartPlay = false
  8890. }
  8891. }
  8892. this.saveLastPlayList()
  8893. } catch (error) {
  8894. let err: BusinessError = error as BusinessError;
  8895. console.error('onecold failed with err: ' + JSON.stringify(err));
  8896. }
  8897. }
  8898. }
  8899. this.mIjkMediaPlayer.setOnPreparedListener(mOnPreparedListener);
  8900. let mOnTimedTextListener: OnTimedTextListener = {
  8901. onTimedText: () => {
  8902. }
  8903. }
  8904. this.mIjkMediaPlayer.setOnTimedTextListener(mOnTimedTextListener)
  8905. let mOnCompletionListener: OnCompletionListener = {
  8906. onCompletion: () => {
  8907. LogUtils.getInstance().LOGI("OnCompletionListener-->go")
  8908. if (this.playType == 0) { //0:连续播放 1:单片重复播放 2:正常播放
  8909. this.playNext()
  8910. } else if (this.playType == 1) { //1:单片重复播放
  8911. this.CONTROL_PlayStatus = PlayStatus.INIT
  8912. that.startPlayOrResumePlay();
  8913. } else if (this.playType == 2) { //2:正常播放,单曲播完
  8914. that.showRePlay();
  8915. that.currentTime = that.stringForTime(this.mIjkMediaPlayer.getDuration());
  8916. that.progressValue = this.PROGRESS_MAX_VALUE;
  8917. that.slideEnable = false;
  8918. that.stop();
  8919. // ToastUtil.showToast('开始重新播放')
  8920. } else if (this.playType == 3) { //3:随机播放
  8921. this.randomPlay()
  8922. }
  8923. }
  8924. }
  8925. this.mIjkMediaPlayer.setOnCompletionListener(mOnCompletionListener);
  8926. let mOnBufferingUpdateListener: OnBufferingUpdateListener = {
  8927. onBufferingUpdate: (percent: number) => {
  8928. LogUtils.getInstance().LOGI("OnBufferingUpdateListener-->go:" + percent);
  8929. let MediaInfo = this.mIjkMediaPlayer.getMediaInfo()
  8930. LogUtils.getInstance().LOGI('getMediaInfo---' + MediaInfo);
  8931. let VideoWidth = this.mIjkMediaPlayer.getVideoWidth()
  8932. LogUtils.getInstance().LOGI('getVideoWidth---' + VideoWidth);
  8933. let VideoHeight = this.mIjkMediaPlayer.getVideoHeight()
  8934. LogUtils.getInstance().LOGI('getVideoHeight---' + VideoHeight);
  8935. let VideoSarNum = this.mIjkMediaPlayer.getVideoSarNum()
  8936. LogUtils.getInstance().LOGI('getVideoSarNum---' + VideoSarNum);
  8937. let VideoSarDen = this.mIjkMediaPlayer.getVideoSarDen()
  8938. LogUtils.getInstance().LOGI('getVideoSarDen---' + VideoSarDen);
  8939. let AudioSessionId = this.mIjkMediaPlayer.getAudioSessionId()
  8940. LogUtils.getInstance().LOGI('getAudioSessionId---' + AudioSessionId);
  8941. let Looping = this.mIjkMediaPlayer.isLooping()
  8942. LogUtils.getInstance().LOGI('isLooping---' + Looping);
  8943. }
  8944. }
  8945. this.mIjkMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
  8946. let mOnSeekCompleteListener: OnSeekCompleteListener = {
  8947. onSeekComplete: () => {
  8948. LogUtils.getInstance().LOGI("OnSeekCompleteListener-->go");
  8949. that.startPlayOrResumePlay();
  8950. }
  8951. }
  8952. this.mIjkMediaPlayer.setOnSeekCompleteListener(mOnSeekCompleteListener);
  8953. let mOnInfoListener: OnInfoListener = {
  8954. onInfo: (what: number, extra: number) => {
  8955. LogUtils.getInstance().LOGI("OnInfoListener-->go:" + what + "===" + extra);
  8956. that.hideLoadIng();
  8957. }
  8958. }
  8959. this.mIjkMediaPlayer.setOnInfoListener(mOnInfoListener);
  8960. let mOnErrorListener: OnErrorListener = {
  8961. onError: (what: number, extra: number) => {
  8962. this.stopProgressTask();
  8963. LogUtils.getInstance().LOGI("OnErrorListener-->go:" + what + "===" + extra + " this.videoUrl=" + this.videoUrl)
  8964. that.hideLoadIng();
  8965. if (StrUtil.isNotEmpty(this.videoUrl) && !FileUtil.accessSync(this.videoUrl)) {
  8966. ToastUtil.showToast(Utility.resourceToString(getContext(), $r('app.string.file_not_exist')))
  8967. } else {
  8968. ToastUtil.showToast(getContext()
  8969. .resourceManager
  8970. .getStringByNameSync("Honey_the_video_is_playing_errant_The_system_is_wandering"))
  8971. }
  8972. }
  8973. }
  8974. this.mIjkMediaPlayer.setOnErrorListener(mOnErrorListener);
  8975. this.mIjkMediaPlayer.setMessageListener();
  8976. this.mIjkMediaPlayer.prepareAsync();
  8977. this.mIjkMediaPlayer.start();
  8978. }
  8979. //保存最后播放的那首歌和已经对应的播放列表
  8980. saveLastPlayList() {
  8981. PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
  8982. PreferencesUtil.putSync('LastMusicList', this.songList)
  8983. }
  8984. // 清空播放记录
  8985. clearVideoHistory() {
  8986. this.table.clearPlayHistory((success: boolean, error?: string) => {
  8987. if (success) {
  8988. this.historyList = [];
  8989. this.updateListData(this.historyList)
  8990. // PreferencesUtil.putSync(LocalMusic.HISTORY_MUSIC, this.historyList)
  8991. ToastUtil.showToast('清空播放记录成功')
  8992. } else {
  8993. console.error(" onecold 清空播放记录数据库失败原因: " + error);
  8994. }
  8995. });
  8996. }
  8997. public async setAvSessionListener() {
  8998. if (!this.avSessionController) {
  8999. return;
  9000. }
  9001. this.avSessionController.getAvSession()?.on('play', this.sessionPlayCallback);
  9002. this.avSessionController.getAvSession()?.on('pause', this.sessionPauseCallback);
  9003. this.avSessionController.getAvSession()?.on('stop', this.sessionStopCallback);
  9004. this.avSessionController.getAvSession()?.on('playNext', this.sessionPlayNextCallback);
  9005. this.avSessionController.getAvSession()?.on('playPrevious', this.sessionPlayPreviousCallback);
  9006. this.avSessionController.getAvSession()?.on('fastForward', this.sessionFastForwardCallback);
  9007. this.avSessionController.getAvSession()?.on('rewind', this.sessionRewindCallback);
  9008. this.avSessionController.getAvSession()?.on('seek', this.sessionSeekCallback);
  9009. this.avSessionController.getAvSession()?.on('setLoopMode', this.sessionSetLoopModeCallback);
  9010. this.avSessionController.getAvSession()?.on('toggleFavorite', this.sessionToggleFavoriteCallback);
  9011. this.avSessionController.getAvSession()?.on('outputDeviceChange', this.sessionOutputDeviceChange)
  9012. }
  9013. setLoopMode() {
  9014. let itype = this.playType + 1
  9015. if (itype >= 4) {
  9016. this.playType = 0
  9017. ToastUtil.showToast('连续播放')
  9018. } else if (itype === 1) {
  9019. this.playType = 1
  9020. ToastUtil.showToast('单曲循环')
  9021. } else if (itype === 2) {
  9022. this.playType = 2
  9023. ToastUtil.showToast('单曲播完')
  9024. } else if (itype === 3) {
  9025. this.playType = 3
  9026. ToastUtil.showToast('随机播放')
  9027. } else if (itype === 0) {
  9028. this.playType = 0
  9029. ToastUtil.showToast('连续播放')
  9030. }
  9031. PreferencesUtil.putSync('musicPlayType', this.playType)
  9032. this.setCurrentPlayMode()
  9033. }
  9034. private sessionSetLoopModeCallback = (mode: number) => {
  9035. if (this.mIjkMediaPlayer != null) {
  9036. ToastUtil.showToast('当前播放模式:' + mode)
  9037. Logger.info('onecold 当前播放模式= ' + mode)
  9038. let hmPlayMode = mode + 1
  9039. if (hmPlayMode >= 4) {
  9040. hmPlayMode = 0
  9041. }
  9042. if (hmPlayMode === 1) {
  9043. this.playType = 1
  9044. ToastUtil.showToast('单曲循环')
  9045. } else if (hmPlayMode === 0) {
  9046. this.playType = 2
  9047. ToastUtil.showToast('单曲播完')
  9048. } else if (hmPlayMode === 3) {
  9049. this.playType = 3
  9050. ToastUtil.showToast('随机播放')
  9051. } else if (hmPlayMode === 2) {
  9052. this.playType = 0
  9053. ToastUtil.showToast('连续播放')
  9054. }
  9055. PreferencesUtil.putSync('musicPlayType', this.playType)
  9056. // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
  9057. let playBackState: avSession.AVPlaybackState = {
  9058. loopMode: hmPlayMode,
  9059. };
  9060. this.avSessionController.getAvSession()?.setAVPlaybackState(playBackState).then(() => {
  9061. console.info(`set setLoopMode AVPlaybackState successfully`);
  9062. }).catch((err: BusinessError) => {
  9063. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  9064. });
  9065. }
  9066. }
  9067. setCurrentPlayMode() {
  9068. if (!this.avSessionController) {
  9069. return;
  9070. }
  9071. let mLoopMode = 0
  9072. switch (this.playType) {
  9073. case 0:
  9074. mLoopMode = avSession.LoopMode.LOOP_MODE_LIST //连续播放
  9075. break;
  9076. case 1:
  9077. mLoopMode = avSession.LoopMode.LOOP_MODE_SINGLE //单曲
  9078. break;
  9079. case 2:
  9080. mLoopMode = avSession.LoopMode.LOOP_MODE_SEQUENCE //正常播放
  9081. break;
  9082. case 3:
  9083. mLoopMode = avSession.LoopMode.LOOP_MODE_SHUFFLE //随机播放
  9084. break;
  9085. }
  9086. // 应用启动时/内部切换循环模式,需要把应用内的当前的循环模式设置给AVSession。
  9087. let playBState: avSession.AVPlaybackState = {
  9088. loopMode: mLoopMode,
  9089. isFavorite: Utility.getIsFav(this.favList, this.currentSong),
  9090. };
  9091. this.avSessionController.getAvSession()?.setAVPlaybackState(playBState).then(() => {
  9092. console.info(`set setLoopMode AVPlaybackState successfully`);
  9093. }).catch((err: BusinessError) => {
  9094. console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
  9095. });
  9096. }
  9097. private sessionToggleFavoriteCallback = (assetId: string) => {
  9098. if (this.mIjkMediaPlayer != null && this.currentSong) {
  9099. console.info(`on toggleFavorite `);
  9100. // 应用收到收藏命令,进行收藏处理。
  9101. this.isFac = Utility.getIsFav(this.favList, this.currentSong)
  9102. this.doFav(this.currentSong)
  9103. // 应用内完成或者取消收藏,把新的收藏状态设置给AVSession。
  9104. let playbackState: avSession.AVPlaybackState = {
  9105. isFavorite: !this.isFac,
  9106. };
  9107. this.avSessionController.getAvSession()?.setAVPlaybackState(playbackState).then(() => {
  9108. console.info(`SetAVPlaybackState successfully`);
  9109. }).catch((err: BusinessError) => {
  9110. console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  9111. });
  9112. }
  9113. }
  9114. private sessionOutputDeviceChange = async (connectState: avSession.ConnectionState,
  9115. device: avSession.OutputDeviceInfo) => {
  9116. let currentDevice: avSession.DeviceInfo = device?.devices?.[0];
  9117. if (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  9118. connectState === avSession.ConnectionState.STATE_CONNECTED) {
  9119. await this.startCasting();
  9120. } else if ((currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_REMOTE &&
  9121. connectState === avSession.ConnectionState.STATE_DISCONNECTED) ||
  9122. (currentDevice.castCategory === avSession.AVCastCategory.CATEGORY_LOCAL &&
  9123. connectState === avSession.ConnectionState.STATE_CONNECTED)) {
  9124. if (device) {
  9125. this.endCasting();
  9126. }
  9127. }
  9128. };
  9129. private async startCasting() {
  9130. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  9131. this.setPlaybackStateChangeListener();
  9132. this.pause();
  9133. this.initQueueItem();
  9134. this.prepare();
  9135. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  9136. refToIsCasting?.set(true);
  9137. this.castSeek = true;
  9138. this.isCastPlaying = true;
  9139. }
  9140. async changeCasting() {
  9141. this.castController = await this.avSessionController.getAvSession()?.getAVCastController();
  9142. this.initQueueItem();
  9143. this.prepare();
  9144. this.setPlaybackStateChangeListener();
  9145. this.isCastPlaying = true;
  9146. this.castSeek = true;
  9147. }
  9148. public endCasting() {
  9149. this.avSessionController.getAvSession()?.stopCasting();
  9150. this.stopCast();
  9151. this.isCastPlaying = false;
  9152. let refToIsCasting: AbstractProperty<boolean> | undefined = AppStorage.ref('isCasting');
  9153. refToIsCasting?.set(false);
  9154. this.pause();
  9155. this.setIsPlaying(false);
  9156. // if (this.curIndex === this.curSource.index) {
  9157. // this.play
  9158. // this.seek(this.currentTime * 1000);
  9159. // this.setIsPlaying(true);
  9160. // } else {
  9161. // this.pauseVideo();
  9162. // this.setIsPlaying(false);
  9163. // }
  9164. }
  9165. public setIsPlaying(isPlayer: boolean) {
  9166. this.isPlaying = isPlayer;
  9167. }
  9168. private setPlaybackStateChangeListener(): void {
  9169. this.castController?.on('playbackStateChange', 'all', this.playbackStateChangeListener);
  9170. this.castController?.on('endOfStream', this.reloadCasting);
  9171. this.castController?.on('playNext', this.playNextCallback);
  9172. this.castController?.on('playPrevious', this.playPreviousCallback);
  9173. }
  9174. private updateSessionPlayState(isPlay: boolean): void {
  9175. // if(!this.isBgPlayOpen)
  9176. // return
  9177. Logger.info(TAG, `updateIsPlay isPlay: ${isPlay}`);
  9178. this.setAVSessionPlayState({
  9179. state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
  9180. position: {
  9181. elapsedTime: this.mIjkMediaPlayer.getCurrentPosition(),
  9182. updateTime: new Date().getTime()
  9183. }
  9184. });
  9185. }
  9186. private setAVSessionPlayState(playbackState: avSession.AVPlaybackState): void {
  9187. this.avSessionController.setAvSessionPlayState(playbackState)
  9188. }
  9189. private positionChange(position: number) {
  9190. this.currentTime2 = position / 1000;
  9191. this.currentStringTime = secondToTime(Math.floor(position / 1000));
  9192. }
  9193. private playDurationChange(duration: number) {
  9194. this.duration = duration;
  9195. this.durationTime = Math.floor(this.duration / 1000);
  9196. this.durationStringTime = secondToTime((this.durationTime));
  9197. }
  9198. private playbackStateChangeListener = (playbackState: avSession.AVPlaybackState) => {
  9199. const duration = playbackState?.extras?.duration;
  9200. if (typeof duration === 'number') {
  9201. this.playDurationChange(duration as number);
  9202. }
  9203. if (typeof playbackState?.position?.elapsedTime !== 'undefined') {
  9204. this.positionChange(playbackState?.position?.elapsedTime);
  9205. }
  9206. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PAUSE ||
  9207. playbackState.state === CommonConstants2.PLAYBACK_STATE_STOP ||
  9208. playbackState.state === CommonConstants2.PLAYBACK_STATE_PREPARE ||
  9209. playbackState.state === CommonConstants2.PLAYBACK_STATE_INITIAL) {
  9210. this.isCastPlaying = false;
  9211. }
  9212. if (playbackState.state === CommonConstants2.PLAYBACK_STATE_PLAY) {
  9213. this.isCastPlaying = true;
  9214. }
  9215. };
  9216. private reloadCasting = async () => {
  9217. let item = this.songList[this.curIndex];
  9218. let uri = fileUri.getUriFromPath(item.filePath);
  9219. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  9220. // description.startPosition = 0;
  9221. this.castItem = {
  9222. itemId: this.curIndex,
  9223. description: {
  9224. assetId: item.filePath,
  9225. title: item.name,
  9226. artist: '',
  9227. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  9228. // mediaUri: item.filePath,
  9229. fdSrc: {
  9230. fd: file.fd
  9231. },
  9232. // 该字段大写,音频'AUDIO',视频'VIDEO'
  9233. mediaType: 'VIDEO',
  9234. mediaSize: item.videoSize,
  9235. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  9236. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  9237. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  9238. duration: this.duration,
  9239. // albumCoverUri: 'https://www.example.jpeg',
  9240. // albumTitle: '《ExampleAlbum》',
  9241. appName: this.appName,
  9242. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  9243. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  9244. }
  9245. };
  9246. this.prepare();
  9247. this.isCastPlaying = true;
  9248. };
  9249. public playNextCallback = (): void => {
  9250. this.playNext()
  9251. };
  9252. public playPreviousCallback = (): void => {
  9253. this.playPrevious()
  9254. };
  9255. async prepare() {
  9256. await this.castController?.prepare(this.castItem);
  9257. await this.castController?.start(this.castItem);
  9258. }
  9259. public initQueueItem() {
  9260. let item = this.songList[this.curIndex];
  9261. let time = this.currentTime;
  9262. let uri = fileUri.getUriFromPath(item.filePath);
  9263. let file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
  9264. this.castItem = {
  9265. itemId: this.curIndex,
  9266. description: {
  9267. assetId: item.filePath,
  9268. title: item.name,
  9269. artist: '',
  9270. // 网络资源投播,设置mediaUri; 本地资源投播,将本地文件打开后,相关的文件描述符设置到fdSrc
  9271. fdSrc: {
  9272. fd: file.fd
  9273. },
  9274. // 该字段大写,音频'AUDIO',视频'VIDEO'
  9275. mediaType: 'AUDIO',
  9276. mediaSize: item.videoSize,
  9277. //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
  9278. startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
  9279. // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
  9280. duration: this.duration,
  9281. // albumCoverUri: 'https://www.example.jpeg',
  9282. // albumTitle: '《ExampleAlbum》',
  9283. appName: this.appName,
  9284. // DRM资源,需要配置支持的DRM类型, 以chinaDRM为例。
  9285. // drmScheme: '3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c',
  9286. }
  9287. };
  9288. }
  9289. async stopCast() {
  9290. try {
  9291. this.castController?.off('playbackStateChange');
  9292. this.castController?.off('endOfStream');
  9293. this.castController?.off('playNext');
  9294. this.castController?.off('playPrevious');
  9295. this.castController?.off('error');
  9296. } catch (error) {
  9297. hilog.info(0x0000, TAG, `Failed to setAVCastController. code: ${error.code}, message: ${error.message}`);
  9298. }
  9299. }
  9300. private sessionPlayCallback = (): void => {
  9301. this.playOrPause()
  9302. };
  9303. private sessionPauseCallback = (): void => {
  9304. this.playOrPause()
  9305. };
  9306. private playOrPause() {
  9307. if (!this.debounce()) {
  9308. return;
  9309. }
  9310. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  9311. this.pause();
  9312. } else {
  9313. this.startPlayOrResumePlay();
  9314. this.playChange()
  9315. }
  9316. }
  9317. private sessionPlayNextCallback = (): void => {
  9318. this.playNext()
  9319. };
  9320. private sessionPlayPreviousCallback = (): void => {
  9321. this.playPrevious()
  9322. };
  9323. private sessionStopCallback = (): void => {
  9324. this.stop()
  9325. };
  9326. private sessionFastForwardCallback = (time?: number) => {
  9327. if (!time) {
  9328. return;
  9329. }
  9330. if (this.mIjkMediaPlayer != null) {
  9331. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9332. let seeTime = curPosition + time * 1000;
  9333. // 限制 seekValue 在合法范围内
  9334. if (seeTime < 0) {
  9335. seeTime = 0;
  9336. } else if (seeTime > this.duration) {
  9337. seeTime = this.duration;
  9338. }
  9339. Logger.info('onecold seeTime= ' + seeTime)
  9340. this.setSeekToActionProgress(seeTime)
  9341. this.seekTo(seeTime + "")
  9342. }
  9343. };
  9344. /**
  9345. * Gesture method onActionUpdate.
  9346. *
  9347. * @param event Gesture event.手势拖动设置快进和后退
  9348. */
  9349. private setSeekToActionProgress(position: number) {
  9350. // let position = this.mIjkMediaPlayer.getCurrentPosition();
  9351. let duration = this.mIjkMediaPlayer.getDuration();
  9352. let pos = 0;
  9353. if (duration > 0) {
  9354. this.slideEnable = true;
  9355. let curPercent = position / duration;
  9356. pos = curPercent * 100;
  9357. if (pos > this.PROGRESS_MAX_VALUE) {
  9358. this.progressValue = this.PROGRESS_MAX_VALUE
  9359. } else {
  9360. this.progressValue = pos;
  9361. }
  9362. }
  9363. // LogUtils.getInstance()
  9364. // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
  9365. this.totalTime = this.stringForTime(duration);
  9366. if (position > duration) {
  9367. position = duration;
  9368. }
  9369. this.isCurrentTime = true;
  9370. this.currentTime = this.stringForTime(position);
  9371. this.isCurrentTime = false
  9372. }
  9373. private sessionRewindCallback = (time?: number) => {
  9374. if (!time) {
  9375. return;
  9376. }
  9377. if (this.mIjkMediaPlayer != null) {
  9378. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9379. let seeTime = curPosition - time * 1000;
  9380. // 限制 seekValue 在合法范围内
  9381. if (seeTime < 0) {
  9382. seeTime = 0;
  9383. } else if (seeTime > this.duration) {
  9384. seeTime = this.duration;
  9385. }
  9386. Logger.info('onecold seeTime= ' + seeTime)
  9387. this.setSeekToActionProgress(seeTime)
  9388. this.seekTo(seeTime + "")
  9389. }
  9390. };
  9391. private sessionSeekCallback = (seekTime: number) => {
  9392. if (this.mIjkMediaPlayer != null) {
  9393. const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
  9394. this.seekTo(seekTime + "")
  9395. }
  9396. };
  9397. private async getFileSize(filePath: string): Promise<number> {
  9398. try {
  9399. const stat = await fs.stat(filePath);
  9400. return stat.size;
  9401. } catch (err) {
  9402. console.error('Failed to get file size: ' + err.message);
  9403. return 0;
  9404. }
  9405. }
  9406. private pause() {
  9407. if (this.mIjkMediaPlayer.isPlaying()) {
  9408. this.savePlaybackPosition();
  9409. this.mIjkMediaPlayer.pause();
  9410. this.setProgress();
  9411. this.mDestroyPage = true;
  9412. this.CONTROL_PlayStatus = PlayStatus.PAUSE;
  9413. this.updateSessionPlayState(false)
  9414. this.playChange()
  9415. if (this.pipController) {
  9416. this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
  9417. PiPWindow.PiPControlStatus.PAUSE);
  9418. }
  9419. }
  9420. }
  9421. private stop() {
  9422. this.savePlaybackPosition();
  9423. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9424. this.mIjkMediaPlayer.stop();
  9425. this.mIjkMediaPlayer.release();
  9426. this.stopProgressTask();
  9427. this.updateSessionPlayState(false)
  9428. this.playChange()
  9429. this.watchStatus();
  9430. }
  9431. //保持记忆播放功能
  9432. private savePlaybackPosition() {
  9433. if (this.mIjkMediaPlayer != null) {
  9434. const position = this.mIjkMediaPlayer.getCurrentPosition();
  9435. // ToastUtil.showToast('保存记忆播放 = ' + position)
  9436. const duration = this.mIjkMediaPlayer.getDuration();
  9437. const threshold = 5000; // 阈值,单位为毫秒(这里设为5秒)
  9438. // 如果播放位置接近视频末尾,则保存 position 为 0
  9439. const playbackPosition = (duration - position < threshold) ? 0 : position;
  9440. PreferencesUtil.putSync(this.videoUrl, playbackPosition);
  9441. }
  9442. }
  9443. //获取记忆播放功能
  9444. private restorePlaybackPosition() {
  9445. const position: number = PreferencesUtil.getNumberSync(this.videoUrl, 0);
  9446. // ToastUtil.showToast('position = ' + position)
  9447. if (this.mIjkMediaPlayer != null && position > 0) {
  9448. // ToastUtil.showToast('seekTo = ' + position)
  9449. this.seekTo(position + "");
  9450. }
  9451. }
  9452. private seekTo(value: string) {
  9453. if (StrUtil.isNotEmpty(this.videoUrl) && this.videoUrl.toLowerCase().endsWith('.wma')) {
  9454. ToastUtil.showToast('wma格式不支持拖动快进。')
  9455. return
  9456. }
  9457. this.mIjkMediaPlayer.seekTo(value);
  9458. // this.startPlayOrResumePlay()
  9459. // 在这里恢复计时器状态
  9460. this.setProgress()
  9461. // this.startProgressTask();
  9462. }
  9463. // 添加到下一首播放
  9464. private addToNextPlay(song: VideoItem) {
  9465. if (!this.debounce()) {
  9466. return;
  9467. }
  9468. if (this.currentSong) {
  9469. if (this.currentSong === song) {
  9470. ToastUtil.showToast('当前已经在播放这首歌了!')
  9471. return
  9472. }
  9473. }
  9474. // 如果未开始播放或队列为空
  9475. if (this.curIndex === -1 || this.songList.length === 0) {
  9476. this.songList = [song];
  9477. this.curIndex = 0;
  9478. this.doPlay(song)
  9479. return;
  9480. }
  9481. // 插入到当前索引+1的位置
  9482. const insertPos = this.curIndex + 1;
  9483. this.songList.splice(insertPos, 0, song);
  9484. this.songList = [...this.songList]; // 触发状态更新
  9485. this.sonDataSource.pushArrayData(this.songList)
  9486. ToastUtil.showToast('已添加至下一首播放')
  9487. }
  9488. //下一个
  9489. private playNext() {
  9490. if (!this.debounce()) {
  9491. return;
  9492. }
  9493. if (this.playType == 3) { //3:随机播放
  9494. this.randomPlay()
  9495. return;
  9496. }
  9497. if (ArrayUtil.isNotEmpty(this.songList)) {
  9498. if (this.curIndex == this.songList.length - 1) {
  9499. this.curIndex = 0;
  9500. } else {
  9501. this.curIndex++;
  9502. }
  9503. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9504. this.stop();
  9505. this.currentSong = this.songList[this.curIndex]
  9506. this.videoUrl = this.songList[this.curIndex].filePath;
  9507. this.artist = this.songList[this.curIndex].artist
  9508. this.name = this.songList[this.curIndex].name
  9509. //this.cover = this.songList[this.curIndex].pixelMapPath
  9510. this.changeImageAnimation()
  9511. }
  9512. }
  9513. changeImageAnimation() {
  9514. if(this.openSkipSongAnimate){
  9515. // 第一步:淡出动画
  9516. this.getUIContext()?.animateTo({
  9517. duration: 500,
  9518. curve: Curve.EaseOut,
  9519. }, () => {
  9520. this.opacityValueImage = 0.1;
  9521. if(this.isCoverRectangle){
  9522. this.scaleValueImage = 0.88
  9523. }
  9524. });
  9525. // 第二步:切换图片后淡入
  9526. setTimeout(() => {
  9527. this.cover = this.songList[this.curIndex].pixelMapPath
  9528. this.getUIContext()?.animateTo({
  9529. duration: 500,
  9530. curve: Curve.EaseIn,
  9531. }, () => {
  9532. this.opacityValueImage = 1;
  9533. this.scaleValueImage = 1 // 图标恢复到原始大小
  9534. this.startPlayOrResumePlay()
  9535. });
  9536. }, 500);
  9537. }else{
  9538. this.cover = this.songList[this.curIndex].pixelMapPath
  9539. this.startPlayOrResumePlay()
  9540. }
  9541. }
  9542. // 存储已播放的歌曲索引
  9543. private playedIndices: Set<number> = new Set();
  9544. //随机播放
  9545. private randomPlay() {
  9546. // if (!this.debounce()) {
  9547. // return;
  9548. // }
  9549. if (ArrayUtil.isNotEmpty(this.songList)) {
  9550. if (this.songList.length > 3) {
  9551. // 如果所有歌曲都播放过一次,清空已播放索引集合
  9552. if (this.playedIndices.size === this.songList.length) {
  9553. this.playedIndices.clear();
  9554. }
  9555. // 随机选择一个未播放的歌曲索引
  9556. let newIndex: number;
  9557. // 添加超时机制防止无限循环
  9558. let attempt = 0;
  9559. const maxAttempts = 100; // 根据需求调整
  9560. do {
  9561. newIndex = RandomUtil.getRandomNumber(0, this.songList.length - 1);
  9562. attempt++;
  9563. } while (this.playedIndices.has(newIndex) && attempt < maxAttempts);
  9564. if (attempt >= maxAttempts) {
  9565. // 处理无法找到新索引的情况(如随机选择或按顺序播放)
  9566. newIndex = Math.floor(Math.random() * this.songList.length);
  9567. }
  9568. this.curIndex = newIndex;
  9569. this.playedIndices.add(newIndex);
  9570. } else {
  9571. // 当歌曲数量小于或等于3时,直接播放下一首
  9572. if (this.curIndex == this.songList.length - 1) {
  9573. this.curIndex = 0;
  9574. } else {
  9575. this.curIndex++;
  9576. }
  9577. }
  9578. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9579. this.stop();
  9580. this.currentSong = this.songList[this.curIndex];
  9581. this.videoUrl = this.songList[this.curIndex].filePath;
  9582. this.name = this.songList[this.curIndex].name;
  9583. this.artist = this.songList[this.curIndex].artist
  9584. // this.cover = this.songList[this.curIndex].pixelMapPath
  9585. this.changeImageAnimation()
  9586. }
  9587. }
  9588. private playIndex(index: number) {
  9589. if (!this.debounce()) {
  9590. return;
  9591. }
  9592. if (ArrayUtil.isNotEmpty(this.songList)) {
  9593. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9594. this.stop();
  9595. this.currentSong = this.songList[this.curIndex]
  9596. this.videoUrl = this.songList[index].filePath;
  9597. this.name = this.songList[index].name
  9598. this.artist = this.songList[this.curIndex].artist
  9599. this.curIndex = index;
  9600. this.changeImageAnimation()
  9601. }
  9602. }
  9603. //上一个
  9604. private playPrevious() {
  9605. if (!this.debounce()) {
  9606. return;
  9607. }
  9608. if (this.playType == 3) { //3:随机播放的上一首应该应该播放历史记录的第二首
  9609. this.randomModePlayFromHistory()
  9610. return;
  9611. }
  9612. if (this.curIndex == 0) {
  9613. this.curIndex = this.songList.length - 1;
  9614. } else {
  9615. this.curIndex--;
  9616. }
  9617. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9618. this.stop();
  9619. this.currentSong = this.songList[this.curIndex]
  9620. this.videoUrl = this.songList[this.curIndex].filePath;
  9621. this.name = this.songList[this.curIndex].name
  9622. this.artist = this.songList[this.curIndex].artist
  9623. this.changeImageAnimation()
  9624. }
  9625. //随机播放模式下点击上一首: 上一首应该应该播放历史记录的第二首
  9626. private randomModePlayFromHistory() {
  9627. if (this.historyList.length >= 2) {
  9628. // 播放历史记录的第二首
  9629. const prevSong = this.historyList[1];
  9630. this.curIndex = this.songList.findIndex(song => song.filePath === prevSong.filePath);
  9631. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9632. this.stop();
  9633. this.currentSong = prevSong;
  9634. this.videoUrl = prevSong.filePath;
  9635. this.cover = prevSong.pixelMapPath
  9636. this.artist = prevSong.artist
  9637. this.name = prevSong.name;
  9638. this.startPlayOrResumePlay();
  9639. } else {
  9640. // 如果历史记录不足两首,可根据需求处理,这里简单按普通逻辑处理
  9641. if (this.curIndex === 0) {
  9642. this.curIndex = this.songList.length - 1;
  9643. } else {
  9644. this.curIndex--;
  9645. }
  9646. this.CONTROL_PlayStatus = PlayStatus.INIT;
  9647. this.stop();
  9648. this.currentSong = this.songList[this.curIndex];
  9649. this.videoUrl = this.songList[this.curIndex].filePath;
  9650. this.artist = this.songList[this.curIndex].artist
  9651. this.name = this.songList[this.curIndex].name;
  9652. this.changeImageAnimation()
  9653. }
  9654. }
  9655. debounce() {
  9656. const delay = 600;
  9657. let cur = new Date().getTime();
  9658. if (cur - this.last > delay) {
  9659. this.last = cur;
  9660. return true;
  9661. }
  9662. return false;
  9663. }
  9664. /**
  9665. * Sets whether the screen is a constant based on the playback status.
  9666. */
  9667. watchStatus() {
  9668. // let windowClass = GlobalContext.getContext().getObject('windowClass') as window.Window;
  9669. if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
  9670. this.windowClass.setWindowKeepScreenOn(true);
  9671. } else {
  9672. this.windowClass.setWindowKeepScreenOn(false);
  9673. }
  9674. }
  9675. /**
  9676. * Volume gesture method onActionStart.
  9677. *
  9678. * @param event Gesture event.
  9679. */
  9680. private customDialogComponentIdMM: number = 0
  9681. @Builder
  9682. customDialogComponentMM() {
  9683. Column() {
  9684. Row() {
  9685. Blank()
  9686. Text('验证密码')
  9687. .fontSize(22)
  9688. .fontColor($r('app.color.pri_bg'))
  9689. .margin({ top: 18 })
  9690. Blank()
  9691. Image($r('app.media.close'))
  9692. .fillColor(Color.White)
  9693. .margin({ top: 18, right: 18 })
  9694. .width(20)
  9695. .onClick(() => {
  9696. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  9697. })
  9698. }
  9699. .width('100%') // 使Row占据整个宽度
  9700. .justifyContent(FlexAlign.SpaceBetween); // 在Row中创建空间
  9701. Verify({
  9702. onVerifyCompleted: this.handleVerifyCompleted.bind(this)
  9703. });
  9704. }.height('60%')
  9705. .backgroundColor($r('app.color.index_background'))
  9706. .justifyContent(FlexAlign.SpaceBetween)
  9707. }
  9708. private handleVerifyCompleted(isSuccess: boolean) {
  9709. if (isSuccess) {
  9710. console.log('验证成功');
  9711. // 在这里处理验证成功后的逻辑
  9712. promptAction.closeCustomDialog(this.customDialogComponentIdMM)
  9713. this.currentPath = this.lockPath
  9714. this.getSortedFiles(this.currentPath)
  9715. } else {
  9716. // console.log('验证失败');
  9717. ToastUtil.showToast('验证失败')
  9718. }
  9719. }
  9720. private showVerifyDialog() {
  9721. promptAction.openCustomDialog({
  9722. transition: TransitionEffect.asymmetric(
  9723. TransitionEffect.OPACITY.animation({ duration: 888 }).combine(
  9724. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  9725. ,
  9726. TransitionEffect.OPACITY.animation({ delay: 888, duration: 888 }).combine(
  9727. TransitionEffect.translate({ y: 888 }).animation({ duration: 888 }))
  9728. ),
  9729. builder: () => {
  9730. this.customDialogComponentMM()
  9731. },
  9732. isModal: true,
  9733. autoCancel: true,
  9734. maskColor: Color.Transparent,
  9735. alignment: DialogAlignment.Bottom,
  9736. onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
  9737. console.info("reason" + JSON.stringify(dismissDialogAction.reason))
  9738. console.log("dialog onWillDismiss")
  9739. if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
  9740. dismissDialogAction.dismiss()
  9741. }
  9742. if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
  9743. dismissDialogAction.dismiss()
  9744. }
  9745. }
  9746. }).then((dialogId: number) => {
  9747. this.customDialogComponentIdMM = dialogId
  9748. })
  9749. }
  9750. //左滑操作 移动文件 重命名 删除等操作
  9751. @Builder
  9752. DeleteButton(item: VideoItem, index: number, filePath: string) {
  9753. Row() {
  9754. //加入收藏
  9755. Button() {
  9756. Image(Utility.getIsFav(this.favList, item) ? $r('app.media.add_fac_light2') : $r('app.media.add_fac'))
  9757. .fillColor(Color.White)
  9758. .width(20)
  9759. }
  9760. .width(40)
  9761. .height(40)
  9762. .type(ButtonType.Circle)
  9763. .backgroundColor(this.themeColor)
  9764. .margin(5)
  9765. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  9766. .onClick(() => {
  9767. if (item) {
  9768. this.doFav(item)
  9769. }
  9770. })
  9771. //加入下一首播放
  9772. Button() {
  9773. Image($r('app.media.next_to_play'))
  9774. .fillColor(Color.White)
  9775. .width(20)
  9776. }
  9777. .width(40)
  9778. .height(40)
  9779. .type(ButtonType.Circle)
  9780. .backgroundColor(this.themeColor)
  9781. .margin(5)
  9782. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  9783. .onClick(() => {
  9784. this.addToNextPlay(item);
  9785. })
  9786. //复制文件
  9787. Button() {
  9788. Image($r('app.media.copy'))
  9789. .fillColor(Color.White)
  9790. .width(20)
  9791. }
  9792. .width(40)
  9793. .height(40)
  9794. .type(ButtonType.Circle)
  9795. .backgroundColor(this.themeColor)
  9796. .margin(5)
  9797. .id(filePath + 'copy')
  9798. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  9799. .onClick(() => {
  9800. this.showCopyDialog(false, item, index, filePath + 'copy');
  9801. })
  9802. //移动文件
  9803. Button() {
  9804. Image($r('app.media.cut'))
  9805. .fillColor(Color.White)
  9806. .width(20)
  9807. }
  9808. .width(40)
  9809. .height(40)
  9810. .type(ButtonType.Circle)
  9811. .backgroundColor(this.themeColor)
  9812. .margin(5)
  9813. .id(filePath)
  9814. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  9815. .onClick(() => {
  9816. this.showCutDialog(false, item, index, filePath);
  9817. })
  9818. Button() {
  9819. Image($r('app.media.cut_current'))
  9820. .fillColor(Color.White)
  9821. .width(20)
  9822. }
  9823. .width(40)
  9824. .height(40)
  9825. .type(ButtonType.Circle)
  9826. .backgroundColor(this.themeColor)
  9827. .margin(5)
  9828. .id(filePath + 'current')
  9829. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None :
  9830. (this.isHasDir ? Visibility.Visible : Visibility.None))
  9831. .onClick(() => {
  9832. this.showCutDialog(true, item, index, filePath + 'current');
  9833. })
  9834. //重命名
  9835. Button() {
  9836. Image($r('app.media.rename2'))
  9837. .fillColor(Color.White)
  9838. .width(20)
  9839. }
  9840. .width(40)
  9841. .height(40)
  9842. .type(ButtonType.Circle)
  9843. .backgroundColor(this.themeColor)
  9844. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  9845. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  9846. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  9847. .margin(5)
  9848. .onClick(() => {
  9849. this.showReNameDialog(item, index + '', filePath)
  9850. })
  9851. Button() {
  9852. Image($r('app.media.delete2'))
  9853. .fillColor(Color.White)
  9854. .width(20)
  9855. }
  9856. .width(40)
  9857. .height(40)
  9858. .type(ButtonType.Circle)
  9859. .backgroundColor(this.themeColor)
  9860. .visibility(item.type === CommonConstants.TYPE_IS_DIR ?
  9861. (item.name === LocalMusic.STR_LOCK_VIDEO || item.name === LocalMusic.STR_FAC_VIDEO ||
  9862. item.name === LocalMusic.STR_HISTORY_MUSIC ? Visibility.None : Visibility.Visible) : Visibility.Visible)
  9863. .margin(5)
  9864. .onClick(() => {
  9865. this.showWarnIsDeleteFile(item, index + '', filePath)
  9866. })
  9867. Button() {
  9868. Image($r('app.media.share2'))
  9869. .fillColor(Color.White)
  9870. .width(20)
  9871. }
  9872. .width(40)
  9873. .height(40)
  9874. .type(ButtonType.Circle)
  9875. .backgroundColor(this.themeColor)
  9876. .margin(5)
  9877. .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
  9878. .onClick(() => {
  9879. Utility.doShareMusic(item, getContext(this) as common.UIAbilityContext)
  9880. })
  9881. }
  9882. }
  9883. /**
  9884. * 穿山甲banner广告
  9885. */
  9886. // private declare bannerAd: CSJNativeExpressAd;
  9887. // @State private status: string = "未加载"
  9888. // @State private isShowAd: boolean = false
  9889. // private declare mAdSlot: AdSlot;
  9890. // private mBiddingAdm = '' //服务端bidding才需要设置
  9891. // private expressLoadAdListener: NativeExpressAdListener = {
  9892. // /**
  9893. // * 加载失败的回调
  9894. // *
  9895. // * @param code
  9896. // * @param message
  9897. // */
  9898. // onError: (code: number, message: string) => {
  9899. // console.error("加载广告失败,code=" + code + ",message=" + message);
  9900. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  9901. // },
  9902. //
  9903. // /**
  9904. // * 广告加载成功的回调,接入方可以在这个回调中进行渲染
  9905. // *
  9906. // * @param ads 返回的广告列表
  9907. // */
  9908. //
  9909. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  9910. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  9911. // if (ads && ads.length > 0) {
  9912. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  9913. // ad.setExpressInteractionListener({
  9914. // /**
  9915. // *广告的点击回调
  9916. // * @param type 广告的交互类型
  9917. // */
  9918. // onAdClicked: (type: number) => {
  9919. // console.log("BannerExpressAdPage==onAdClicked......");
  9920. // },
  9921. //
  9922. // /**
  9923. // * 广告的展示回调 每个广告仅回调一次
  9924. // * @param type 广告的交互类型
  9925. // */
  9926. // onAdShow: (type: number) => {
  9927. // console.log("BannerExpressAdPage==onAdShow......");
  9928. // },
  9929. //
  9930. // /**
  9931. // * 模板渲染失败
  9932. // */
  9933. // onRenderFail: (code: number, msg: string) => {
  9934. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  9935. // },
  9936. //
  9937. // /**
  9938. // * 模板渲染成功
  9939. // * @param width 返回view的宽 单位 vp
  9940. // * @param height 返回view的高 单位 vp
  9941. // */
  9942. // onRenderSuccess: (width: number, height: number) => {
  9943. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  9944. // this.bannerAd = ad;
  9945. // this.status = "广告加载完成待展示";
  9946. //
  9947. // this.showBannerAd()
  9948. // }
  9949. // })
  9950. // //渲染广告
  9951. // ad.setSlideIntervalTime(30 * 1000); //设置轮播时间长
  9952. // this.setDislikeCallback(ad); //设置dislike
  9953. // ad.render(this.getUIContext())
  9954. // this.status = "广告加载中...";
  9955. // });
  9956. // }
  9957. // }
  9958. // }
  9959. //
  9960. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  9961. // ad.setDislikeCallback({
  9962. // /**
  9963. // * dislike show
  9964. // */
  9965. // onShow: () => {
  9966. // console.log("BannerExpressAdPage==dislike......show");
  9967. // },
  9968. //
  9969. // /**
  9970. // * @param position 选择的位置
  9971. // * @param value 选择的内容
  9972. // * @param enforceRemove 是否强制关闭广告
  9973. // */
  9974. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  9975. // this.isShowAd = false;
  9976. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value +
  9977. // ",enforce=" + enforceRemove);
  9978. // },
  9979. //
  9980. // /**
  9981. // * 点击取消
  9982. // */
  9983. // onCancel: () => {
  9984. // console.log("BannerExpressAdPage==dislike......onCancel");
  9985. // }
  9986. //
  9987. // })
  9988. // }
  9989. /**
  9990. * 加载Banner广告
  9991. */
  9992. loadBannerAd(rit: string) {
  9993. // if (Utility.isNoble()) {
  9994. // return
  9995. // }
  9996. // if (!Utility.isPassInstallTime(2)) {
  9997. // return
  9998. // }
  9999. // this.isShowAd = false;
  10000. // let adCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
  10001. // this.mAdSlot = new AdSlotBuilder()
  10002. // .setCodeId(rit)
  10003. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  10004. // .setAdCount(1)
  10005. // .setBidAdm(this.mBiddingAdm)
  10006. // .build()
  10007. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  10008. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  10009. // this.status = "广告加载中..."
  10010. }
  10011. /**
  10012. * 展示Banner广告
  10013. */
  10014. // showBannerAd() {
  10015. // if (!this.bannerAd) {
  10016. // return
  10017. // }
  10018. // this.isShowAd = true
  10019. // this.status = "已展示"
  10020. // }
  10021. /**
  10022. * 穿山甲广告代码结束
  10023. */
  10024. }
  10025. //视频气泡窗口的布局
  10026. @Builder
  10027. function customPopupBuilder(dataBu: BubbleBean) {
  10028. List() {
  10029. LazyForEach(new LazyDataSource(dataBu.data), (item: string, index: number) => {
  10030. ListItem() {
  10031. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  10032. Row() {
  10033. Column() {
  10034. Image(dataBu.imageRes[index])
  10035. .height(28)
  10036. .fillColor(dataBu.color)
  10037. .alignSelf(ItemAlign.Center)
  10038. }
  10039. .width(32)
  10040. Text(item)
  10041. .padding({
  10042. top: 10,
  10043. bottom: 10,
  10044. right: 10,
  10045. left: 10
  10046. })
  10047. .fontColor(dataBu.modeType == index ? dataBu.color : $r('app.color.index_tab_font_color'))
  10048. .textAlign(TextAlign.Start)
  10049. .width("100%")
  10050. }
  10051. }
  10052. .backgroundColor($r('app.color.settings_background_main'))
  10053. .margin({ top: 6, bottom: 6 })
  10054. }
  10055. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  10056. .animation({ duration: 500, curve: Curve.Ease, delay: 100 * index }),
  10057. TransitionEffect.scale({ x: 0, y: 0 })))
  10058. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  10059. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  10060. .onClick(() => {
  10061. dataBu.onItemClick?.(index)
  10062. })
  10063. })
  10064. }
  10065. .width(120)
  10066. .divider({
  10067. strokeWidth: 1,
  10068. color: "#22FFFFFF"
  10069. })
  10070. }
  10071. // Function to calculate a hash for the file list
  10072. function simpleHash(fileList: string[]): string {
  10073. let hash = 0;
  10074. const str = fileList.join(',');
  10075. for (let i = 0; i < str.length; i++) {
  10076. const char = str.charCodeAt(i);
  10077. hash = (hash << 5) - hash + char;
  10078. hash |= 0; // Convert to 32bit integer
  10079. }
  10080. return hash.toString();
  10081. }
  10082. interface MoreItem {
  10083. id: number;
  10084. image: Resource;
  10085. title: string;
  10086. }
  10087. //视频气泡窗口的布局
  10088. @Builder
  10089. function cutPopupBuilder(dataBu: BubbleBean) {
  10090. Column() {
  10091. Text(dataBu.isCopy ? '将文件复制到' : '将文件移动到')
  10092. .padding({
  10093. top: 10,
  10094. bottom: 10,
  10095. right: 10,
  10096. left: 10
  10097. })
  10098. .textAlign(TextAlign.Start)
  10099. .width(160)
  10100. .fontWeight(666)
  10101. .fontSize(16)
  10102. List() {
  10103. ForEach(dataBu.data, (item: string, index: number) => {
  10104. ListItem() {
  10105. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  10106. Row() {
  10107. Column() {
  10108. Image($r('app.media.music_group'))
  10109. .height(28)
  10110. .fillColor(dataBu.color)
  10111. .alignSelf(ItemAlign.Center)
  10112. }
  10113. .width(32)
  10114. Text(item.startsWith('.') ? item.replace(/\./g, '') : item)
  10115. .padding({
  10116. top: 10,
  10117. bottom: 10,
  10118. right: 10,
  10119. left: 10
  10120. })
  10121. .textAlign(TextAlign.Start).width("100%")// .fontColor(Color.Gray)
  10122. .fontSize(15)
  10123. }
  10124. }
  10125. .backgroundColor(Color.Transparent)
  10126. .margin({ top: 7, bottom: 7 })
  10127. }
  10128. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
  10129. .animation({ duration: 500 }),
  10130. TransitionEffect.scale({ x: 0, y: 0 })))
  10131. // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 500 }),
  10132. // TransitionEffect.scale({ x: 0, y: 0 }) ))
  10133. .onClick(() => {
  10134. dataBu.onItemClick?.(index)
  10135. })
  10136. })
  10137. }
  10138. .width(150)
  10139. .divider({
  10140. strokeWidth: 1,
  10141. color: "#22FFFFFF"
  10142. })
  10143. }
  10144. .height(300)
  10145. .padding({
  10146. bottom: 30
  10147. })
  10148. }
  10149. function getFileDirName(filePath: string,rootPath:string): string{
  10150. if(filePath===rootPath){
  10151. return '首页'
  10152. }
  10153. let result = FileUtil.getFileName(filePath)
  10154. if(StrUtil.isEmpty(result))
  10155. return ''
  10156. if(result.startsWith('.'))
  10157. result = result.replace(/\./g, '')
  10158. return result
  10159. }