با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
HDR یا محدوده دینامیکی بالا، طیف گستردهتری از رنگها و کنتراست بیشتر بین روشنترین سفیدها و تیرهترین سایهها را فراهم میکند، و در نتیجه کیفیت ویدیویی شبیهتر به آنچه که چشم غیرمسلح میبیند، ارائه میکند.
میتوانید پخش ویدیوی HDR را در برنامه خود برای پیشنمایش و پخش محتوای ویدیوی HDR تنظیم کنید.
این مقاله فرض میکند که قبلاً پشتیبانی اولیه پخش ویدیو را به برنامه خود اضافه کردهاید. برای جزئیات بیشتر در مورد پخش، به مستندات ExoPlayer مراجعه کنید.
پیش نیاز دستگاه
همه دستگاه های اندرویدی از پخش HDR پشتیبانی نمی کنند. قبل از پخش محتوای ویدیویی HDR در برنامه خود، تعیین کنید که آیا دستگاه شما شرایط زیر را دارد یا خیر:
اندروید 7.0 یا بالاتر (لایه API 24) را هدف قرار می دهد.
دارای رسیور با قابلیت HDR و دسترسی به صفحه نمایش با قابلیت HDR.
پشتیبانی از پخش HDR را بررسی کنید
از Display.getHdrCapabilities() برای پرس و جو در مورد قابلیت های HDR نمایشگر استفاده کنید. این روش اطلاعات مربوط به نمایه های HDR پشتیبانی شده و محدوده روشنایی نمایشگر را برمی گرداند.
کد زیر بررسی می کند که آیا دستگاه از پخش HLG10 پشتیبانی می کند یا خیر. در اندروید 13، HLG10 حداقل استانداردی است که سازندگان دستگاه باید از آن پشتیبانی کنند، اگر دستگاه قادر به پخش HDR باشد:
کاتلین
// Check if display supports the HDR typevalcapabilities=display?.hdrCapabilities?.supportedHdrTypes?:intArrayOf()if(!capabilities.contains(HDR_TYPE_HLG)){throwRuntimeException("Display does not support desired HDR type");}
جاوا
// Check if display supports the HDR typeint[]list=getDisplay().getHdrCapabilities().getSupportedHdrTypes();Listcapabilities=Arrays.stream(list).boxed().collect(Collectors.toList());if(!capabilities.contains(HDR_TYPE_HLG)){thrownewRuntimeException("Display does not support desired HDR type");}
اگر برنامه شما از ExoPlayer استفاده نمی کند، پخش HDR را با استفاده از MediaCodec از طریق SurfaceView تنظیم کنید.
MediaCodec را با استفاده از SurfaceView تنظیم کنید
یک جریان پخش استاندارد MediaCodec را با استفاده از SurfaceView تنظیم کنید. این به شما امکان می دهد محتوای ویدیویی HDR را بدون هیچ گونه کنترل خاصی برای پخش HDR نمایش دهید:
MediaCodec : محتوای ویدیویی HDR را رمزگشایی می کند.
SurfaceView : محتوای ویدیویی HDR را نمایش می دهد.
کد زیر بررسی می کند که آیا کدک از نمایه HDR پشتیبانی می کند یا خیر، سپس MediaCodec با استفاده از SurfaceView راه اندازی می کند:
کاتلین
// Check if there's a codec that supports the specific HDR profilevallist=MediaCodecList(MediaCodecList.REGULAR_CODECS)varformat=MediaFormat()/* media format from the container */;format.setInteger(MediaFormat.KEY_PROFILE,MediaCodecInfo.CodecProfileLevel.AV1ProfileMain10)valcodecName=list.findDecoderForFormat(format)?:throwRuntimeException("No codec supports the format")// Here is a standard MediaCodec playback flowvalcodec:MediaCodec=MediaCodec.createByCodecName(codecName);valsurface:Surface=surfaceView.holder.surfacevalcallback:MediaCodec.Callback=(object:MediaCodec.Callback(){overridefunonInputBufferAvailable(codec:MediaCodec,index:Int){queue.offer(index)}overridefunonOutputBufferAvailable(codec:MediaCodec,index:Int,info:MediaCodec.BufferInfo){codec.releaseOutputBuffer(index,timestamp)}overridefunonError(codec:MediaCodec,e:MediaCodec.CodecException){// handle error}overridefunonOutputFormatChanged(codec:MediaCodec,format:MediaFormat){// handle format change}})codec.setCallback(callback)codec.configure(format,surface,crypto,0/* flags */)codec.start()while(/* until EOS */){valindex=queue.poll()valbuffer=codec.getInputBuffer(index)buffer?.put(/* write bitstream */)codec.queueInputBuffer(index,offset,size,timestamp,flags)}codec.stop()codec.release()
جاوا
// Check if there's a codec that supports the specific HDR profileMediaCodecListlist=newMediaCodecList(MediaCodecList.REGULAR_CODECS);MediaFormatformat=/* media format from the container */;format.setInteger(MediaFormat.KEY_PROFILE,CodecProfileLevel.AV1ProfileMain10);StringcodecName=list.findDecoderForFormat(format);if(codecName==null){thrownewRuntimeException("No codec supports the format");}// Below is a standard MediaCodec playback flowMediaCodeccodec=MediaCodec.getCodecByName(codecName);Surfacesurface=surfaceView.getHolder().getSurface();MediaCodec.Callbackcallback=newMediaCodec.Callback(){@OverridevoidonInputBufferAvailable(MediaCodeccodec,intindex){queue.offer(index);}@OverridevoidonOutputBufferAvailable(MediaCodeccodec,intindex){// release the buffer for rendercodec.releaseOutputBuffer(index,timestamp);}@OverridevoidonOutputFormatChanged(MediaCodeccodec,MediaFormatformat){// handle format change}@OverridevoidonError(MediaCodeccodec,MediaCodec.CodecExceptionex){// handle error}};codec.setCallback(callback);codec.configure(format,surface,crypto,0/* flags */);codec.start();while(/* until EOS */){intindex=queue.poll();ByteBufferbuffer=codec.getInputBuffer(index);buffer.put(/* write bitstream */);codec.queueInputBuffer(index,offset,size,timestamp,flags);}codec.stop();codec.release();
برای اجرای بیشتر MediaCodec با استفاده از SurfaceView ، به نمونههای دوربین Android مراجعه کنید.
منابع
برای اطلاعات بیشتر در مورد پخش HDR، به منابع زیر مراجعه کنید:
HDR
ضبط ویدیوی HDR : نحوه تنظیم فیلمبرداری HDR با استفاده از APIهای Camera2 را بیاموزید.
ExoPlayer : یاد بگیرید که چگونه برنامه خود را با کتابخانه ExoPlayer راه اندازی کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# HDR video playback\n\nHDR, or High Dynamic Range, provides a wider range of colors and greater\ncontrast between the brightest whites and darkest shadows, resulting in video\nquality that more closely resembles what the naked eye perceives.\n\nYou can set up HDR video playback in your app to preview and play back HDR video\ncontent.\n\nThis article assumes that you've already added basic video playback support to\nyour app. See the [ExoPlayer](/guide/topics/media/exoplayer) documentation for\nmore details on playback.\n\nDevice prerequisites\n--------------------\n\nNot all Android devices support HDR playback. Before playing back HDR\nvideo content in your app, determine if your device meets the following\nprerequisites:\n\n- Targets Android 7.0 or higher (API layer 24).\n- Has a HDR-capable decoder and access to a HDR-capable display.\n\nCheck for HDR playback support\n------------------------------\n\nUse [`Display.getHdrCapabilities()`](/reference/android/view/Display#getHdrCapabilities()) to query a display's HDR capabilities. The method returns information about the supported HDR profiles and luminance range for the display.\n\nThe following code checks if the device supports HLG10 playback. Starting in Android 13, HLG10 is the minimum standard that device makers must support if the device is capable of HDR playback: \n\n### Kotlin\n\n```kotlin\n// Check if display supports the HDR type\nval capabilities = display?.hdrCapabilities?.supportedHdrTypes ?: intArrayOf()\nif (!capabilities.contains(HDR_TYPE_HLG)) {\n throw RuntimeException(\"Display does not support desired HDR type\");\n}\n```\n\n### Java\n\n```java\n// Check if display supports the HDR type\nint[] list = getDisplay().getHdrCapabilities().getSupportedHdrTypes();\nList capabilities = Arrays.stream(list).boxed().collect(Collectors.toList());\nif (!capabilities.contains(HDR_TYPE_HLG)) {\n throw new RuntimeException(\"Display does not support desired HDR type\");\n}\n```\n\nSet up HDR playback in your app\n-------------------------------\n\nIf your app uses [ExoPlayer](https://exoplayer.dev/), it supports HDR playback by default. See [Check for HDR playback support](#check_for_hdr_playback_support) for next steps.\n\nIf your app does not use ExoPlayer, set up HDR playback using `MediaCodec` via `SurfaceView`.\n| **Note:** HDR playback has limited support on [`TextureView`](/reference/android/view/TextureView) in Android 13 (API layer 33) and higher. When playing back HDR video content, `TextureView` transcodes the video from HDR to SDR, resulting in playback with possible loss of detail including clipped colors and video banding. If at all possible, you should use `SurfaceView` for HDR playback.\n\n### Set up MediaCodec using SurfaceView\n\nSet up a standard [`MediaCodec`](/reference/android/media/MediaCodec) playback flow using [`SurfaceView`](https://developer.android.com/reference/android/view/SurfaceView). This allows you to display HDR video content without any special handling for HDR playback:\n\n- `MediaCodec`: Decodes HDR video content.\n- `SurfaceView`: Displays HDR video content.\n\nThe following code checks if the codec supports the HDR profile, then sets up `MediaCodec` using `SurfaceView`: \n\n### Kotlin\n\n```kotlin\n// Check if there's a codec that supports the specific HDR profile\nval list = MediaCodecList(MediaCodecList.REGULAR_CODECS) var format = MediaFormat() /* media format from the container */;\nformat.setInteger(MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AV1ProfileMain10)\nval codecName = list.findDecoderForFormat (format) ?: throw RuntimeException (\"No codec supports the format\")\n\n// Here is a standard MediaCodec playback flow\nval codec: MediaCodec = MediaCodec.createByCodecName(codecName);\nval surface: Surface = surfaceView.holder.surface\nval callback: MediaCodec.Callback = (object : MediaCodec.Callback() {\n override fun onInputBufferAvailable(codec: MediaCodec, index: Int) {\n queue.offer(index)\n }\n\n override fun onOutputBufferAvailable(\n codec: MediaCodec,\n index: Int,\n info: MediaCodec.BufferInfo\n ) {\n codec.releaseOutputBuffer(index, timestamp)\n }\n\n override fun onError(codec: MediaCodec, e: MediaCodec.CodecException) {\n // handle error\n }\n\n override fun onOutputFormatChanged(\n codec: MediaCodec, format: MediaFormat\n ) {\n // handle format change\n }\n})\n\ncodec.setCallback(callback)\ncodec.configure(format, surface, crypto, 0 /* flags */)\ncodec.start()\nwhile (/* until EOS */) {\n val index = queue.poll()\n val buffer = codec.getInputBuffer(index)\n buffer?.put(/* write bitstream */)\n codec.queueInputBuffer(index, offset, size, timestamp, flags)\n}\ncodec.stop()\ncodec.release()\n```\n\n### Java\n\n```java\n// Check if there's a codec that supports the specific HDR profile\nMediaCodecList list = new MediaCodecList(MediaCodecList.REGULAR_CODECS);\nMediaFormat format = /* media format from the container */;\nformat.setInteger(\n MediaFormat.KEY_PROFILE, CodecProfileLevel.AV1ProfileMain10);\nString codecName = list.findDecoderForFormat(format);\nif (codecName == null) {\n throw new RuntimeException(\"No codec supports the format\");\n}\n\n// Below is a standard MediaCodec playback flow\nMediaCodec codec = MediaCodec.getCodecByName(codecName);\nSurface surface = surfaceView.getHolder().getSurface();\nMediaCodec.Callback callback = new MediaCodec.Callback() {\n @Override\n void onInputBufferAvailable(MediaCodec codec, int index) {\n queue.offer(index);\n }\n\n @Override\n void onOutputBufferAvailable(MediaCodec codec, int index) {\n // release the buffer for render\n codec.releaseOutputBuffer(index, timestamp);\n }\n\n @Override\n void onOutputFormatChanged(MediaCodec codec, MediaFormat format) {\n // handle format change\n }\n\n @Override\n void onError(MediaCodec codec, MediaCodec.CodecException ex) {\n // handle error\n }\n\n};\ncodec.setCallback(callback);\ncodec.configure(format, surface, crypto, 0 /* flags */);\ncodec.start();\nwhile (/* until EOS */) {\n int index = queue.poll();\n ByteBuffer buffer = codec.getInputBuffer(index);\n buffer.put(/* write bitstream */);\n codec.queueInputBuffer(index, offset, size, timestamp, flags);\n}\ncodec.stop();\ncodec.release();\n```\n\nFor more `MediaCodec` implementations using `SurfaceView`, see the [Android Camera samples](https://github.com/android/camera-samples).\n| **Note:** Android takes screenshots in SDR. HDR content is tonemapped to SDR in screenshots.\n\nResources\n---------\n\nFor more information related to HDR playback, see the following resources:\n\n### HDR\n\n- [HDR video capture](/training/camera2/hdr-video-capture): learn how to set up HDR video capture using the Camera2 APIs.\n- [Camera2Video sample on Github](https://github.com/android/camera-samples/tree/main/Camera2Video): see a working app with HDR capture and playback functionality.\n\n### Media\n\n- [Media API reference](/reference/android/media/package-summary): learn more about the Media APIs.\n- [ExoPlayer](https://exoplayer.dev/): learn how to set up your app with the ExoPlayer library."]]