mirror of
				https://github.com/immich-app/immich.git
				synced 2025-10-31 10:37:11 -04:00 
			
		
		
		
	* refactor: asset media endpoints * refactor: mobile upload livePhoto as separate request * refactor: change mobile backup flow to use new asset upload endpoints * chore: format and analyze dart code * feat: mark motion as hidden when linked * feat: upload video portion of live photo before image portion * fix: incorrect assetApi calls in mobile code * fix: download asset --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Zack Pollard <zackpollard@ymail.com>
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:immich_mobile/entities/asset.entity.dart';
 | |
| import 'package:immich_mobile/entities/store.entity.dart';
 | |
| import 'package:riverpod_annotation/riverpod_annotation.dart';
 | |
| import 'package:video_player/video_player.dart';
 | |
| 
 | |
| part 'video_player_controller_provider.g.dart';
 | |
| 
 | |
| @riverpod
 | |
| Future<VideoPlayerController> videoPlayerController(
 | |
|   VideoPlayerControllerRef ref, {
 | |
|   required Asset asset,
 | |
| }) async {
 | |
|   late VideoPlayerController controller;
 | |
|   if (asset.isLocal && asset.livePhotoVideoId == null) {
 | |
|     // Use a local file for the video player controller
 | |
|     final file = await asset.local!.file;
 | |
|     if (file == null) {
 | |
|       throw Exception('No file found for the video');
 | |
|     }
 | |
|     controller = VideoPlayerController.file(file);
 | |
|   } else {
 | |
|     // Use a network URL for the video player controller
 | |
|     final serverEndpoint = Store.get(StoreKey.serverEndpoint);
 | |
|     final String videoUrl = asset.livePhotoVideoId != null
 | |
|         ? '$serverEndpoint/assets/${asset.livePhotoVideoId}/video/playback'
 | |
|         : '$serverEndpoint/assets/${asset.remoteId}/video/playback';
 | |
| 
 | |
|     final url = Uri.parse(videoUrl);
 | |
|     final accessToken = Store.get(StoreKey.accessToken);
 | |
| 
 | |
|     controller = VideoPlayerController.networkUrl(
 | |
|       url,
 | |
|       httpHeaders: {"x-immich-user-token": accessToken},
 | |
|     );
 | |
|   }
 | |
| 
 | |
|   await controller.initialize();
 | |
| 
 | |
|   ref.onDispose(() {
 | |
|     controller.dispose();
 | |
|   });
 | |
| 
 | |
|   return controller;
 | |
| }
 |