미디어 항목에는 여러 트랙이 있을 수 있습니다. 예를 들어 여러 개의
자막 (서로 다른 언어) 또는 여러 개의 대체 오디오 스트림
(다양한 언어)
GCKMediaInformation 드림
는 미디어 항목을 나타내는 클래스입니다. 컬렉션과
GCKMediaTrack 객체
미디어 항목이 있는 경우 앱에서
mediaTracks 속성 앱이 로드되기 전에 이 연결을 설정해야 합니다.
다음 코드에서와 같이 미디어를 수신기에 전달합니다.
<ph type="x-smartling-placeholder"></ph>
<ph type="x-smartling-placeholder"></ph>
Swift
#pragma mark - GCKRequestDelegate-(void)requestDidComplete:(GCKRequest*)request{if(request==self.styleChangeRequest){NSLog(@"Style update completed.");self.styleChangeRequest=nil;}}
상태 업데이트를 참고하세요.
참조하세요. 앱은 사용자가 텍스트 스타일을 업데이트할 수 있도록 해야 함
트랙을 삭제할 수 있습니다.
iOS 7 이상에 기본 스타일이 제공되며 가져올 수 있습니다.
정적 메서드 +[GCKMediaTextTrackStyle
createDefault]를 통해 호출될 수 있습니다.
변경할 수 있는 텍스트 트랙 스타일 요소는 다음과 같습니다.
포그라운드 (텍스트) 색상 및 불투명도
배경 색상 및 불투명도
가장자리 유형
가장자리 색상
글꼴 배율
글꼴 모음
글꼴 스타일
상태 업데이트 받기
여러 발신자가 동일한 수신자에게 연결된 경우
각 발신자가 수신자의 변경사항을 인지하도록
다른 발신자가 변경을 요청했기 때문입니다.
발신자가 수신자로부터 상태 업데이트를 수신하려면 앱에서 다음 조건을 충족해야 합니다.
등록
GCKRemoteMediaClientListener
만약
GCKMediaTextTrackStyle 드림
현재 미디어가 변경되면 연결된 모든 발신자에게 알림이 전송됩니다.
GCP 콘솔과
-[remoteMediaClient:didUpdateMediaMetadata:] 및
-[remoteMediaClient:didUpdateMediaStatus:] 콜백을 호출합니다. 이 경우
수신기 SDK가 새 스타일이
전송에 관계없이 연결된 모든 발신자에게 알림을 전송합니다. 그러나
활성 트랙 목록이 업데이트되며
연결된 발신자의 -[remoteMediaClient:didUpdateMediaStatus:]님이
있습니다.
CORS 요구사항 충족
가변 품질 미디어 스트리밍의 경우 Google Cast에 CORS 헤더가 있어야 하므로
단순한 mp4 미디어 스트림에도 트랙이 포함된 경우 CORS가 필요합니다. 만약
모든 미디어에서 트랙을 사용하려면 두 트랙 모두에 대해 CORS를 사용 설정해야 합니다.
미디어 스트림도 있습니다 따라서 CORS 헤더를 사용할 수 없는 경우
mp4 미디어를 저장할 수 있으며
간단한 부제목을 추가할 수 있습니다
서버를 업데이트하지 않으면 미디어를 스트리밍할 수 없습니다.
적절한 CORS 헤더를 포함할 수 있습니다. 또한 최소한
Content-Type, Accept-Encoding 및 Range 헤더를 지원합니다. Note that the
마지막 두 헤더는 이전에 필요하지 않았을 수 있는 추가 헤더입니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-25(UTC)"],[[["\u003cp\u003eMedia tracks can be audio, video, or text (subtitles/captions), represented by \u003ccode\u003eGCKMediaTrack\u003c/code\u003e objects with unique identifiers and attributes.\u003c/p\u003e\n"],["\u003cp\u003eAssociate \u003ccode\u003eGCKMediaTrack\u003c/code\u003e objects with a \u003ccode\u003eGCKMediaInformation\u003c/code\u003e object representing the media item before loading it to the receiver.\u003c/p\u003e\n"],["\u003cp\u003eActivate or deactivate tracks on the receiver using \u003ccode\u003esetActiveTrackIDs\u003c/code\u003e on \u003ccode\u003eGCKRemoteMediaClient\u003c/code\u003e with the track IDs or an empty array.\u003c/p\u003e\n"],["\u003cp\u003eStyle text tracks using \u003ccode\u003eGCKMediaTextTrackStyle\u003c/code\u003e and apply it with \u003ccode\u003esetTextTrackStyle\u003c/code\u003e on \u003ccode\u003eGCKRemoteMediaClient\u003c/code\u003e, and receive status updates via \u003ccode\u003eGCKRemoteMediaClientListener\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCORS headers are required for media streams with Tracks, including simple mp4 files with subtitles, ensuring the server allows necessary headers.\u003c/p\u003e\n"]]],[],null,["# Using Media Tracks\n\nA media track can be an audio or video stream object, or a text object (subtitle\nor caption).\n| **Note:** The [Styled](/cast/docs/styled_receiver) and [Default Media](/cast/docs/web_receiver#default_media_web_receiver) Receivers allow you to use only the text tracks with the API. To work with the audio and video tracks, you must develop a [Custom Receiver](/cast/docs/web_receiver/basic).\n\nA [`GCKMediaTrack`](/cast/docs/reference/ios/interface_g_c_k_media_track)\nobject represents a track. It consists of a unique numeric identifier and other\nattributes such as a content ID and title. A `GCKMediaTrack` instance can be\ncreated as follows:\nSwift \n\n```swift\nlet captionsTrack = GCKMediaTrack.init(identifier: 1,\n contentIdentifier: \"https://some-url/caption_en.vtt\",\n contentType: \"text/vtt\",\n type: GCKMediaTrackType.text,\n textSubtype: GCKMediaTextTrackSubtype.captions,\n name: \"English Captions\",\n languageCode: \"en\",\n customData: nil)\n```\nObjective-C \n\n```objective-c\nGCKMediaTrack *captionsTrack =\n [[GCKMediaTrack alloc] initWithIdentifier:1\n contentIdentifier:@\"https://some-url/caption_en.vtt\"\n contentType:@\"text/vtt\"\n type:GCKMediaTrackTypeText\n textSubtype:GCKMediaTextTrackSubtypeCaptions\n name:@\"English Captions\"\n languageCode:@\"en\"\n customData:nil];\n```\n\nA media item can have multiple tracks; for example, it can have multiple\nsubtitles (each for a different language) or multiple alternative audio streams\n(for different languages).\n[`GCKMediaInformation`](/cast/docs/reference/ios/interface_g_c_k_media_information)\nis the class that represents a media item. To associate a collection of\n[`GCKMediaTrack`](/cast/docs/reference/ios/interface_g_c_k_media_track) objects\nwith a media item, your app should update its\n`mediaTracks` property. Your app needs to make this association before it loads\nthe media to the receiver, as in the following code:\nSwift \n\n```swift\nlet tracks = [captionsTrack]\n\nlet url = URL.init(string: \"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4\")\nguard let mediaURL = url else {\n print(\"invalid mediaURL\")\n return\n}\n\nlet mediaInfoBuilder = GCKMediaInformationBuilder.init(contentURL: mediaURL)\nmediaInfoBuilder.streamType = GCKMediaStreamType.none;\nmediaInfoBuilder.contentType = \"video/mp4\"\nmediaInfoBuilder.metadata = metadata;\nmediaInfoBuilder.mediaTracks = tracks;\nmediaInformation = mediaInfoBuilder.build()\n```\nObjective-C \n\n```objective-c\nNSArray *tracks = @[captionsTrack];\n\nGCKMediaInformationBuilder *mediaInfoBuilder =\n [[GCKMediaInformationBuilder alloc] initWithContentURL:\n [NSURL URLWithString:@\"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4\"]];\nmediaInfoBuilder.streamType = GCKMediaStreamTypeNone;\nmediaInfoBuilder.contentType = @\"video/mp4\";\nmediaInfoBuilder.metadata = metadata;\nmediaInfoBuilder.mediaTracks = tracks;\nself.mediaInformation = [mediaInfoBuilder build];\n```\n\nActivate one or more tracks that were associated with the media item (after the\nmedia is loaded) by calling `-[setActiveTrackIDs:]` on\n[`GCKRemoteMediaClient`](/cast/docs/reference/ios/interface_g_c_k_remote_media_client)\nand passing the IDs of the tracks to be activated. For example, the following\ncode activates the captions track created above.\nSwift \n\n```swift\nsessionManager.currentSession?.remoteMediaClient?.setActiveTrackIDs([1])\n```\nObjective-C \n\n```objective-c\n[self.sessionManager.currentSession.remoteMediaClient setActiveTrackIDs:@[@1]];\n```\n\nTo deactivate a track on the current media item, call\n`-[setActiveTrackIDs:]` on\n[`GCKRemoteMediaClient`](/cast/docs/reference/ios/interface_g_c_k_remote_media_client)\nwith an empty array or nil. The following code disables the captions track.\nSwift \n\n```swift\nsessionManager.currentSession?.remoteMediaClient?.setActiveTrackIDs([])\n```\nObjective-C \n\n```objective-c\n[self.sessionManager.currentSession.remoteMediaClient setActiveTrackIDs:@[]];\n```\n\nStyle text tracks\n-----------------\n\nThe\n[`GCKMediaTextTrackStyle`](/cast/docs/reference/ios/interface_g_c_k_media_text_track_style)\nclass encapsulates the style information of a text track. A track style can be\napplied to the currently playing media item by calling\n[`-[GCKRemoteMediaClient\nsetTextTrackStyle]`](/cast/docs/reference/ios/interface_g_c_k_media_control_channel).\nThe track style created in the code below turns text red (FF) at 50% opacity\n(80) and sets a serif font.\nSwift \n\n```swift\nlet textTrackStyle = GCKMediaTextTrackStyle.createDefault()\ntextTrackStyle.foregroundColor = GCKColor.init(cssString: \"#FF000080\")\ntextTrackStyle.fontFamily = \"serif\"\nstyleChangeRequest = sessionManager.currentSession?.remoteMediaClient?.setTextTrackStyle(textTrackStyle)\nstyleChangeRequest?.delegate = self\n```\nObjective-C \n\n```objective-c\nGCKMediaTextTrackStyle *textTrackStyle = [GCKMediaTextTrackStyle createDefault];\n[textTrackStyle setForegroundColor:[[GCKColor alloc] initWithCSSString:@\"#FF000080\"]];\n[textTrackStyle setFontFamily:@\"serif\"];\nself.styleChangeRequest = [self.sessionManager.currentSession.remoteMediaClient setTextTrackStyle:textTrackStyle];\nself.styleChangeRequest.delegate = self;\n```\n\nYou can use the returned\n[`GCKRequest`](/cast/docs/reference/ios/interface_g_c_k_request) object for\ntracking this request.\nSwift \n\n```swift\n// MARK: - GCKRequestDelegate\n\nfunc requestDidComplete(_ request: GCKRequest) {\n if request == styleChangeRequest {\n print(\"Style update completed.\")\n styleChangeRequest = nil\n }\n}\n```\nObjective-C \n\n```objective-c\n#pragma mark - GCKRequestDelegate\n\n- (void)requestDidComplete:(GCKRequest *)request {\n if (request == self.styleChangeRequest) {\n NSLog(@\"Style update completed.\");\n self.styleChangeRequest = nil;\n }\n}\n```\n\nSee [Status updates](/cast/docs/ios_sender_advanced#receive_status_updates)\nbelow for more information. Apps should allow users to update the style for text\ntracks, either using the settings provided by the system or by the app itself.\nThere is a default style provided (in iOS 7 and later), which can be retrieved\nvia the static method [`+[GCKMediaTextTrackStyle\ncreateDefault]`](/cast/docs/reference/ios/interface_g_c_k_media_text_track_style).\nThe following text track style elements can be changed:\n\n- Foreground (text) color and opacity\n- Background color and opacity\n- Edge type\n- Edge Color\n- Font Scale\n- Font Family\n- Font Style\n\nReceive status updates\n----------------------\n\nWhen multiple senders are connected to the same receiver, it is important\nfor each sender to be aware of the changes on the receiver even if those\nchanges were initiated from other senders.\n| **Note:** This is important for all apps, not only those that explicitly support multiple senders, because some Cast devices have control inputs (remotes, buttons) that behave as virtual senders, affecting the status on the receiver.\n\nTo ensure your sender receives status updates from the receiver, your app should\nregister a\n[`GCKRemoteMediaClientListener`](/cast/docs/reference/ios/protocol_g_c_k_remote_media_client_listener-p).\nIf the\n[`GCKMediaTextTrackStyle`](/cast/docs/reference/ios/interface_g_c_k_media_text_track_style)\nof the current media changes, then all of the connected senders will be notified\nthrough both the\n`-[remoteMediaClient:didUpdateMediaMetadata:]` and the\n`-[remoteMediaClient:didUpdateMediaStatus:]` callbacks. In this case, the\nReceiver SDK does not verify whether the new style is different from the\nprevious one and notifies all the connected senders regardless. If, however,\nthe list of active tracks is updated, only the\n`-[remoteMediaClient:didUpdateMediaStatus:]` in connected senders will be\nnotified.\n| **Note:** The list of tracks associated with the currently loaded media cannot be changed. If needed, you have to update the tracks information on the [`GCKMediaInformation`](/cast/docs/reference/ios/interface_g_c_k_media_information) object and reload the media.\n\nSatisfy CORS requirements\n-------------------------\n\nFor adaptive media streaming, Google Cast requires the presence of CORS headers,\nbut even simple mp4 media streams require CORS if they include Tracks. If you\nwant to enable Tracks for any media, you must enable CORS for both your track\nstreams and your media streams. So, if you do not have CORS headers available\nfor your simple mp4 media on your server, and you then add a simple subtitle\ntrack, you will not be able to stream your media unless you update your server\nto include the appropriate CORS header. In addition, you need to allow at least\nthe following headers: Content-Type, Accept-Encoding, and Range. Note that the\nlast two headers are additional headers that you may not have needed previously."]]