1use crate::{arc, av, cg, cm, define_cls, define_obj_type, ns, objc};
2
3#[cfg(feature = "blocks")]
4use crate::blocks;
5
6#[doc(alias = "AVPlayerItemStatus")]
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[repr(isize)]
9pub enum Status {
10 Unknown = 0,
11 ReadyToPlay = 1,
12 Failed = 2,
13}
14
15define_obj_type!(
16 #[doc(alias = "AVPlayerItem")]
17 pub Item(ns::Id)
18);
19
20impl Item {
21 define_cls!(AV_PLAYER_ITEM);
22
23 #[objc::msg_send(playerItemWithURL:)]
24 pub fn with_url(val: &ns::Url) -> arc::R<Self>;
25
26 #[objc::msg_send(playerItemWithAsset:)]
27 pub fn with_asset(val: &av::Asset) -> arc::R<Self>;
28
29 #[objc::msg_send(playerItemWithAsset:automaticallyLoadedAssetKeys:)]
30 pub fn with_asset_auto_loaded_keys(
31 val: &av::Asset,
32 asset_keys: Option<&ns::Array<ns::String>>,
33 ) -> arc::R<Self>;
34
35 #[objc::msg_send(copy)]
36 pub fn copy(&self) -> arc::R<Self>;
37
38 #[objc::msg_send(status)]
39 pub fn status(&self) -> Status;
40
41 #[objc::msg_send(error)]
46 pub fn error(&self) -> Option<arc::R<ns::Error>>;
47}
48
49impl Item {
51 #[objc::msg_send(asset)]
53 pub fn asset(&self) -> arc::R<av::Asset>;
54
55 #[objc::msg_send(tracks)]
56 pub fn tracks(&self) -> arc::R<ns::Array<av::PlayerItemTrack>>;
57
58 #[objc::msg_send(duration)]
59 pub fn duration(&self) -> cm::Time;
60
61 #[objc::msg_send(presentationSize)]
62 pub fn presentation_size(&self) -> cg::Size;
63
64 #[objc::msg_send(automaticallyLoadedAssetKeys)]
65 pub fn auto_loaded_asset_keys(&self) -> arc::R<ns::Array<ns::String>>;
66}
67
68impl Item {
70 #[objc::msg_send(canPlayFastForward)]
71 pub fn can_play_fast_forward(&self) -> bool;
72
73 #[objc::msg_send(canPlaySlowForward)]
74 pub fn can_play_slow_forward(&self) -> bool;
75
76 #[objc::msg_send(canPlayReverse)]
77 pub fn can_play_reverse(&self) -> bool;
78
79 #[objc::msg_send(canPlaySlowReverse)]
80 pub fn can_play_slow_reverse(&self) -> bool;
81
82 #[objc::msg_send(canPlayFastReverse)]
83 pub fn can_play_fast_reverse(&self) -> bool;
84
85 #[objc::msg_send(canStepForward)]
86 pub fn can_step_forward(&self) -> bool;
87
88 #[objc::msg_send(canStepBackward)]
89 pub fn can_step_backward(&self) -> bool;
90
91 #[objc::msg_send(configuredTimeOffsetFromLive)]
92 pub fn configured_time_offset_from_live(&self) -> bool;
93
94 #[objc::msg_send(setConfiguredTimeOffsetFromLive:)]
95 pub fn set_configured_time_offset_from_live(&mut self, val: cm::Time);
96
97 #[objc::msg_send(recommendedTimeOffsetFromLive)]
98 pub fn recommended_time_offset_from_live(&self) -> cm::Time;
99
100 #[objc::msg_send(automaticallyPreservesTimeOffsetFromLive)]
101 pub fn automatically_preserves_time_offset_from_live(&self) -> bool;
102
103 #[objc::msg_send(setAutomaticallyPreservesTimeOffsetFromLive:)]
104 pub fn set_automatically_preserves_time_offset_from_live(&mut self, val: bool);
105}
106
107impl Item {
109 #[objc::msg_send(currentTime)]
110 pub fn current_time(&self) -> cm::Time;
111
112 #[objc::msg_send(forwardPlaybackEndTime)]
113 pub fn forward_playback_end_time(&self) -> cm::Time;
114
115 #[objc::msg_send(setForwardPlaybackEndTime:)]
116 pub fn set_forward_playback_end_time(&mut self, val: cm::Time);
117
118 #[objc::msg_send(reversePlaybackEndTime)]
119 pub fn reverse_playback_end_time(&self) -> cm::Time;
120
121 #[objc::msg_send(setReversePlaybackEndTime:)]
122 pub fn set_reverse_playback_end_time(&mut self, val: cm::Time);
123
124 #[objc::msg_send(seekableTimeRanges)]
125 pub fn seekable_time_ranges(&self) -> arc::R<ns::Array<ns::Value>>;
126
127 #[cfg(feature = "blocks")]
128 #[objc::msg_send(seekToTime:completionHandler:)]
129 pub unsafe fn seek_to_time_ch_throws(
130 &mut self,
131 val: cm::Time,
132 block: Option<&mut blocks::SendBlock<fn(finished: bool)>>,
133 );
134
135 #[cfg(feature = "blocks")]
136 pub fn seek_to_time_ch<'ear>(
137 &mut self,
138 val: cm::Time,
139 block: Option<&mut blocks::SendBlock<fn(finished: bool)>>,
140 ) -> ns::ExResult<'ear> {
141 unsafe { ns::try_catch(|| self.seek_to_time_ch_throws(val, block)) }
142 }
143
144 #[cfg(feature = "blocks")]
145 #[objc::msg_send(seekToTime:toleranceBefore:toleranceAfter:completionHandler:)]
146 pub unsafe fn seek_to_time_with_tolerance_ch_throws(
147 &mut self,
148 val: cm::Time,
149 tolerance_befor: cm::Time,
150 tolerance_after: cm::Time,
151 block: Option<&mut blocks::SendBlock<fn(finished: bool)>>,
152 );
153
154 #[cfg(feature = "blocks")]
155 pub fn seek_to_time_with_tolerance_ch<'ear>(
156 &mut self,
157 val: cm::Time,
158 tolerance_befor: cm::Time,
159 tolerance_after: cm::Time,
160 block: Option<&mut blocks::SendBlock<fn(finished: bool)>>,
161 ) -> ns::ExResult<'ear> {
162 unsafe {
163 ns::try_catch(|| {
164 self.seek_to_time_with_tolerance_ch_throws(
165 val,
166 tolerance_befor,
167 tolerance_after,
168 block,
169 )
170 })
171 }
172 }
173
174 #[objc::msg_send(cancelPendingSeeks)]
175 pub fn cancel_pending_seeks(&mut self);
176
177 #[objc::msg_send(currentDate)]
178 pub fn current_date(&self) -> Option<arc::R<ns::Date>>;
179
180 #[objc::msg_send(stepByCount:)]
181 pub fn step_by_count(&mut self, steps_count: ns::Integer);
182
183 #[objc::msg_send(timebase)]
184 pub fn timebase(&self) -> &cm::Timebase;
185
186 #[objc::msg_send(timebase)]
187 pub fn timebase_mut(&mut self) -> &mut cm::Timebase;
188}
189
190impl Item {}
192
193impl Item {
195 #[objc::msg_send(audioTimePitchAlgorithm)]
196 pub fn audio_time_pitch_algorithm(&self) -> Option<arc::R<av::AudioTimePitchAlgorithm>>;
197
198 #[objc::msg_send(setAudioTimePitchAlgorithm:)]
199 pub fn set_audio_time_pitch_algorithm(&mut self, val: Option<&av::AudioTimePitchAlgorithm>);
200
201 #[cfg(not(target_os = "watchos"))]
202 #[objc::msg_send(allowedAudioSpatializationFormats)]
203 pub fn allowed_audio_spatialization_formats(&self) -> av::AudioSpatializationFormats;
204
205 #[cfg(not(target_os = "watchos"))]
206 #[objc::msg_send(setAllowedAudioSpatializationFormats:)]
207 pub fn set_allowed_audio_spatialization_formats(&mut self, val: av::AudioSpatializationFormats);
208
209 #[objc::msg_send(audioMix)]
210 pub fn audio_mix(&self) -> Option<arc::R<av::AudioMix>>;
211
212 #[objc::msg_send(setAudioMix:)]
213 pub fn set_audio_mix(&mut self, val: Option<&av::AudioMix>);
214}
215
216impl Item {
218 #[objc::msg_send(loadedTimeRanges)]
219 pub fn loaded_time_ranges(&self) -> arc::R<ns::Array<ns::Value>>;
220
221 #[objc::msg_send(isPlaybackLikelyToKeepUp)]
222 pub fn is_playback_likely_to_keep_up(&self) -> bool;
223
224 #[objc::msg_send(isPlaybackBufferFull)]
225 pub fn is_playback_buffer_full(&self) -> bool;
226
227 #[objc::msg_send(isPlaybackBufferEmpty)]
228 pub fn is_playback_buffer_empty(&self) -> bool;
229
230 #[objc::msg_send(canUseNetworkResourcesForLiveStreamingWhilePaused)]
231 pub fn can_use_network_resources_for_live_streaming_while_paused(&self) -> bool;
232
233 #[objc::msg_send(setCanUseNetworkResourcesForLiveStreamingWhilePaused:)]
234 pub fn set_can_use_network_resources_for_live_streaming_while_paused(&mut self, val: bool);
235
236 #[objc::msg_send(preferredForwardBufferDuration)]
237 pub fn preferred_forward_buf_duration(&self) -> ns::TimeInterval;
238
239 #[objc::msg_send(setPreferredForwardBufferDuration:)]
240 pub fn set_preferred_forward_buf_duration(&mut self, val: ns::TimeInterval);
241}
242
243impl Item {
245 #[objc::msg_send(addOutput:)]
247 pub fn add_output(&mut self, output: &av::PlayerItemOutput);
248
249 #[objc::msg_send(removeOutput:)]
251 pub fn remove_output(&mut self, output: &av::PlayerItemOutput);
252
253 #[objc::msg_send(outputs)]
255 pub fn outputs(&self) -> arc::R<ns::Array<av::PlayerItemOutput>>;
256}
257
258impl ns::NotificationName {
259 #[doc(alias = "AVPlayerItemTimeJumpedNotification")]
265 #[inline]
266 pub fn av_player_item_time_jumped() -> &'static Self {
267 unsafe { AVPlayerItemTimeJumpedNotification }
268 }
269
270 #[doc(alias = "AVPlayerItemDidPlayToEndTimeNotification")]
276 #[inline]
277 pub fn av_player_item_did_play_to_end_time() -> &'static Self {
278 unsafe { AVPlayerItemDidPlayToEndTimeNotification }
279 }
280
281 #[doc(alias = "AVPlayerItemFailedToPlayToEndTimeNotification")]
287 #[inline]
288 pub fn av_player_item_failed_play_to_end_time() -> &'static Self {
289 unsafe { AVPlayerItemFailedToPlayToEndTimeNotification }
290 }
291
292 #[doc(alias = "AVPlayerItemPlaybackStalledNotification")]
301 #[inline]
302 pub fn av_player_item_playback_stalled() -> &'static Self {
303 unsafe { AVPlayerItemPlaybackStalledNotification }
304 }
305
306 #[doc(alias = "AVPlayerItemNewAccessLogEntryNotification")]
313 #[inline]
314 pub fn av_player_item_new_access_log_entry() -> &'static Self {
315 unsafe { AVPlayerItemNewAccessLogEntryNotification }
316 }
317
318 #[doc(alias = "AVPlayerItemNewErrorLogEntryNotification")]
324 #[inline]
325 pub fn av_player_item_error_access_log_entry() -> &'static Self {
326 unsafe { AVPlayerItemNewErrorLogEntryNotification }
327 }
328
329 #[doc(alias = "AVPlayerItemRecommendedTimeOffsetFromLiveDidChangeNotification")]
333 #[inline]
334 pub fn av_player_item_recommended_time_offset_from_live_did_change() -> &'static Self {
335 unsafe { AVPlayerItemRecommendedTimeOffsetFromLiveDidChangeNotification }
336 }
337
338 #[doc(alias = "AVPlayerItemMediaSelectionDidChangeNotification")]
340 #[inline]
341 pub fn av_player_item_media_selection_did_change() -> &'static Self {
342 unsafe { AVPlayerItemMediaSelectionDidChangeNotification }
343 }
344}
345
346unsafe extern "C" {
347 static AVPlayerItemTimeJumpedNotification: &'static ns::NotificationName;
348 static AVPlayerItemDidPlayToEndTimeNotification: &'static ns::NotificationName;
349 static AVPlayerItemFailedToPlayToEndTimeNotification: &'static ns::NotificationName;
350 static AVPlayerItemPlaybackStalledNotification: &'static ns::NotificationName;
351 static AVPlayerItemNewAccessLogEntryNotification: &'static ns::NotificationName;
352 static AVPlayerItemNewErrorLogEntryNotification: &'static ns::NotificationName;
353 static AVPlayerItemRecommendedTimeOffsetFromLiveDidChangeNotification:
354 &'static ns::NotificationName;
355 static AVPlayerItemMediaSelectionDidChangeNotification: &'static ns::NotificationName;
356}
357
358unsafe extern "C" {
359 static AV_PLAYER_ITEM: &'static objc::Class<Item>;
360}