...
This commit is contained in:
parent
5a6dad2f24
commit
e979b78fb5
@ -100,6 +100,18 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".wall.MyWallpaperService"
|
||||
android:label="Bums Live Wallpaper"
|
||||
android:permission="android.permission.BIND_WALLPAPER">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.wallpaper.WallpaperService" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.service.wallpaper"
|
||||
android:resource="@xml/wallpaper" />
|
||||
</service>
|
||||
<!-- <activity-->
|
||||
<!-- android:name=".apps.AppDrawer"-->
|
||||
<!-- android:label="@string/lunar_settings"-->
|
||||
|
||||
@ -0,0 +1,193 @@
|
||||
package bums.lunatic.launcher.wall
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.media.MediaCodec
|
||||
import android.media.MediaExtractor
|
||||
import android.media.MediaFormat
|
||||
import android.renderscript.Allocation
|
||||
import android.renderscript.Element
|
||||
import android.renderscript.RenderScript
|
||||
import android.renderscript.ScriptIntrinsicYuvToRGB
|
||||
import android.renderscript.Type
|
||||
import android.service.wallpaper.WallpaperService
|
||||
import android.view.SurfaceHolder
|
||||
import bums.lunatic.launcher.R
|
||||
|
||||
|
||||
class MyWallpaperService : WallpaperService() {
|
||||
override fun onCreateEngine(): Engine {
|
||||
return VideoEngine()
|
||||
}
|
||||
|
||||
inner class VideoEngine : Engine() {
|
||||
lateinit var holder: SurfaceHolder
|
||||
private var renderThread: RenderThread? = null
|
||||
|
||||
override fun onCreate(surfaceHolder: SurfaceHolder) {
|
||||
super.onCreate(surfaceHolder)
|
||||
this.holder = surfaceHolder
|
||||
}
|
||||
|
||||
override fun onSurfaceCreated(holder: SurfaceHolder) {
|
||||
super.onSurfaceCreated(holder)
|
||||
renderThread = RenderThread(holder, getApplicationContext())
|
||||
renderThread?.start()
|
||||
}
|
||||
|
||||
override fun onSurfaceDestroyed(holder: SurfaceHolder?) {
|
||||
super.onSurfaceDestroyed(holder)
|
||||
renderThread?.interrupt()
|
||||
renderThread = null
|
||||
}
|
||||
}
|
||||
}
|
||||
class RenderThread(
|
||||
private val holder: SurfaceHolder,
|
||||
private val context: Context
|
||||
) : Thread() {
|
||||
|
||||
private var running = true
|
||||
|
||||
private var extractor: MediaExtractor? = null
|
||||
private var codec: MediaCodec? = null
|
||||
private var videoTrackIndex: Int = -1
|
||||
private val bufferInfo = MediaCodec.BufferInfo()
|
||||
|
||||
private var rs: RenderScript? = null
|
||||
private var yuvToRgb: ScriptIntrinsicYuvToRGB? = null
|
||||
|
||||
private var width = 0
|
||||
private var height = 0
|
||||
|
||||
override fun run() {
|
||||
try {
|
||||
// 1. MediaExtractor 초기화
|
||||
extractor = MediaExtractor().apply {
|
||||
val afd = context.resources.openRawResourceFd(R.raw.sample)
|
||||
setDataSource(afd.fileDescriptor, afd.startOffset, afd.length)
|
||||
afd.close()
|
||||
for (i in 0 until trackCount) {
|
||||
val format = getTrackFormat(i)
|
||||
val mime = format.getString(MediaFormat.KEY_MIME) ?: ""
|
||||
if (mime.startsWith("video/")) {
|
||||
videoTrackIndex = i
|
||||
selectTrack(i)
|
||||
width = format.getInteger(MediaFormat.KEY_WIDTH)
|
||||
height = format.getInteger(MediaFormat.KEY_HEIGHT)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (videoTrackIndex < 0) {
|
||||
// 비디오 트랙 없음 종료
|
||||
return
|
||||
}
|
||||
|
||||
// 2. MediaCodec 초기화 (Surface가 아닌 직접 버퍼 받을 것)
|
||||
extractor?.getTrackFormat(videoTrackIndex)?.let { format ->
|
||||
codec = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME)!!).apply {
|
||||
configure(format, null, null, 0)
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
// 3. RenderScript 초기화
|
||||
rs = RenderScript.create(context)
|
||||
yuvToRgb = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs))
|
||||
|
||||
var isEOS = false
|
||||
while (running && !isInterrupted) {
|
||||
if (!isEOS) {
|
||||
val inputBufferIndex = codec?.dequeueInputBuffer(10000) ?: -1
|
||||
if (inputBufferIndex >= 0) {
|
||||
val inputBuffer = codec?.getInputBuffer(inputBufferIndex)
|
||||
if (inputBuffer != null) {
|
||||
val sampleSize = extractor?.readSampleData(inputBuffer, 0) ?: -1
|
||||
if (sampleSize < 0) {
|
||||
codec?.queueInputBuffer(
|
||||
inputBufferIndex,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
MediaCodec.BUFFER_FLAG_END_OF_STREAM
|
||||
)
|
||||
isEOS = true
|
||||
} else {
|
||||
val presentationTimeUs = extractor?.sampleTime ?: 0L
|
||||
codec?.queueInputBuffer(inputBufferIndex, 0, sampleSize, presentationTimeUs, 0)
|
||||
extractor?.advance()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val outputBufferIndex = codec?.dequeueOutputBuffer(bufferInfo, 10000) ?: -1
|
||||
if (outputBufferIndex >= 0) {
|
||||
val outputBuffer = codec?.getOutputBuffer(outputBufferIndex)
|
||||
if (bufferInfo.size > 0 && outputBuffer != null) {
|
||||
val yuvData = ByteArray(bufferInfo.size)
|
||||
outputBuffer.get(yuvData)
|
||||
|
||||
// 4. RenderScript로 YUV → Bitmap 변환
|
||||
val bitmap = convertYUVToBitmap(yuvData, width, height)
|
||||
|
||||
// 5. Canvas에 그리기
|
||||
val canvas = holder.lockCanvas()
|
||||
if (canvas != null) {
|
||||
canvas.drawBitmap(bitmap, 0f, 0f, null)
|
||||
|
||||
// 오버레이 예: 텍스트 그리기
|
||||
val paint = Paint().apply {
|
||||
color = Color.WHITE
|
||||
textSize = 40f
|
||||
}
|
||||
canvas.drawText("Live Wallpaper Overlay", 50f, 50f, paint)
|
||||
|
||||
holder.unlockCanvasAndPost(canvas)
|
||||
}
|
||||
|
||||
outputBuffer.clear()
|
||||
}
|
||||
codec?.releaseOutputBuffer(outputBufferIndex, false)
|
||||
} else if (outputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
|
||||
// format 변경 시 처리할 것 (필요시)
|
||||
}
|
||||
|
||||
// 프레임 타이밍 조절 (예: 30fps 제한)
|
||||
sleep(33)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
// 리소스 해제
|
||||
codec?.stop()
|
||||
codec?.release()
|
||||
extractor?.release()
|
||||
rs?.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
private fun convertYUVToBitmap(yuvByteArray: ByteArray, width: Int, height: Int): Bitmap {
|
||||
val yuvType = Type.Builder(rs, Element.U8(rs)).setX(yuvByteArray.size)
|
||||
val inAllocation = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT)
|
||||
|
||||
val rgbaType = Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height)
|
||||
val outAllocation = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT)
|
||||
|
||||
inAllocation.copyFrom(yuvByteArray)
|
||||
yuvToRgb?.setInput(inAllocation)
|
||||
yuvToRgb?.forEach(outAllocation)
|
||||
|
||||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
outAllocation.copyTo(bitmap)
|
||||
|
||||
inAllocation.destroy()
|
||||
outAllocation.destroy()
|
||||
|
||||
return bitmap
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/res/raw/sample.mp4
Normal file
BIN
app/src/main/res/raw/sample.mp4
Normal file
Binary file not shown.
@ -178,4 +178,5 @@
|
||||
<string name="carName">차량 블루투스 이름</string>
|
||||
|
||||
<string name="preview_text"><![CDATA[여섯글자마다 방점을찍어놔가사관찰하다 반쯤놓치거나해석잘안되면 몇번돌리든가이건이를테면 덤비는리듬과손묶인채붙는 일종의노름판\n신도구제불능 내가물오른밤감방에날가둬 내가패를까도가난한니네가 판돈잃지않게나하고니네가 의견일치한게아마처음일걸 그마저운일걸\n존나좋음이퀄 내중저음일걸이배열어쩌면 너에대한배려너에겐어쩌면 언어적배리어그럼넌글렀어 지망생여기에잠들다글로써 훗날니묘비에\n\nFor sale my rhymes never usedFor sale my rhymes never used판매자바로너 니가씨발오너For sale my rhymes never used\n\n노예처럼일해서왕처럼지배성탄처럼지내설탕뿌려위에성공을말했기에난그길위에선딱그어이젠자봐주의깊게\n멈칫할시간도없는듯써내려활자로활짝갠곳에돈비내려초라한핀조명과낮은무대위목표를조준하기에충분했지\n시인의신이될준비는치밀해흘러군침이계속이기기위해처음시작했던이유따윈잊어\n맨발맨손으로역사들을빚어미안해난비션갖고와내기적자음모음이어리듬위에띄어금은보화이쁜걸로손에끼워\n\nUh she suckin\' my soul likeDe La to the SoulI shout out to the RhondaBut before I\'m sober\n변태는 변태인데 underground 모범생맨날 난 오덕 돼 활자에 꼬여내 팔자도 고쳐낼 하나의 초월체를만들려 고쳐댄 rhyme들만 몇 truck 돼\n그러다 깨어나 여기에빼어난 묘기에 없네 기본기내 눈엔 수명이 대본처럼 읽히네뭐처럼 비치네 뭐처럼 비치네\nFuck all of ya list manIf it ain\'t Forbes list mayneYour wristwatch cheaper thanMy profile picture damn\nPicture the future and믿어 like it\'s happendBig ass house foreign cars have several\n미녀 fine ass apple hip 내 옆에 같이 태우고Top of the top으로 가 죽어야 들어 잠은넌 안 죽었다는 척갖은 폼 잡으면 뭐하냐\n좆밥들 또 반년만 가면 쏙다 들어가는 거 다 보여내 눈엔 너가 금방 죽어다음 무덤 안 들어갈 주검한 우물 파는 넌 밟고서땅을 쳐봐 내 발자국을\n]]></string>
|
||||
<string name="wallpaper_desc">test\n</string>
|
||||
</resources>
|
||||
|
||||
6
app/src/main/res/xml/wallpaper.xml
Normal file
6
app/src/main/res/xml/wallpaper.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<!-- res/xml/wallpaper.xml -->
|
||||
<wallpaper
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:settingsActivity="com.example.MySettingsActivity"
|
||||
android:thumbnail="@drawable/ic_search"
|
||||
android:description="@string/wallpaper_desc"/>
|
||||
Loading…
x
Reference in New Issue
Block a user