.m3u8 확장자를 가짐.m3u8 파일을 이용해서 클라이언트에게 전달
일반적인 경우 AV Inputs를 통해 데이터를 서버로 보내고 서버는 Media encoder를 통해 Stream semegmenter로 변환한다. 이때 HEVC, AG-3를 통해 인코딩한다.
인코딩한 결과는 Fragmented MPEG-4파일 or MPEG- transport stream 로 나온다.
Stream segmenter는 비디오/오디오 스트림을 일정 시간의 조각(segment)로 나눔
서버는 이 segment들의 목록을 가진 index file을 생성하고 저장함
HSL가 지원하는 Segment는 Fragment MPEG-4, MPEG-2 Transport Streams이외에도 Packed Audio, WebVTT, IMSC Subtitles가 있음
라이브 스트리밍의 경우 위 index File에 있는 segment 리스트를 계속 갱신해야하는데 일반적으로는 아래와 같이 진행됨
segment들의 URI들을 담고 있는 index 파일를 서버에서 관리한다고 했는데 해당 파일을 playlist파일 이라고도함
각종 태그들로 관리되고있는데 해당 태그에 대해서는 나중에 다룸
// Create a player instance.
val player = ExoPlayer.Builder(context).build()
// Set the media item to be played.
player.setMediaItem(MediaItem.fromUri(hlsUri))
// Prepare the player.
player.prepare()
URI가 HLS playlist의 URI인 경우 위와 같이 간단하게 설정이 가능함.
만약 URI가 .m3u8이 아닌 경우 MediaItem.Builder의 setMimeType에 MimeTypes.APPLICATION_M3U8을 설정해서 명시적으로 선언할 수 있다.
만약 커스텀 옵션을 사용하고 싶다면 HlsMediaSource를 ExoPlayer에 전달해주면 된다.
// Create a data source factory.
val dataSourceFactory: DataSource.Factory = DefaultHttpDataSource.Factory()
// Create a HLS media source pointing to a playlist uri.
val hlsMediaSource =
HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(hlsUri))
// Create a player instance.
val player = ExoPlayer.Builder(context).build()
// Set the HLS media source as the playlist with a single media item.
player.setMediaSource(hlsMediaSource)
// Prepare the player.
player.prepare()
Creating high quality HLS content
In order to get the most out of ExoPlayer, there are certain guidelines you can follow to improve your HLS content. Read our Medium post about HLS playback in ExoPlayer for a full explanation. The main points are:
Use precise segment durations.
Use a continuous media stream; avoid changes in the media structure across segments.
Use the #EXT-X-INDEPENDENT-SEGMENTS tag.
Prefer demuxed streams, as opposed to files that include both video and audio.
Include all information you can in the Multivariant Playlist.
The following guidelines apply specifically for live streams:
Use the #EXT-X-PROGRAM-DATE-TIME tag.
Use the #EXT-X-DISCONTINUITY-SEQUENCE tag.
Provide a long live window. One minute or more is great.