10.2 C
London
Tuesday, September 10, 2024

ios – preview chosen video from the gallery


I’m attempting to show my chosen video as preview earlier than it uploaded, identical to my preview of the picture is being proven within the picture under the picture preview

I’m not capable of show my chosen video in display screen as preview due to these errors.

Results of ‘VideoPlayer’ initializer is unused

 VideoPlayer(participant: AVPlayer(url: url))
 @State var url: URL?
 var physique: some View {
 if let url {
                            VideoPlayer(participant: AVPlayer(url: url))
                        }

Full Code

import AVKit
struct CreateView: View {
   
    @State var url: URL?
    non-public var consumer: Consumer? {
        return UserService.shared.currentUser
    }
    var physique: some View {
        NavigationStack {
            
                VStack {
                    HStack(alignment: .prime) {
                        RectangularImageSize( dimension: .small)
                        
                        VStack(alignment: .main, spacing: 4) {
                            Textual content(consumer?.username ?? "")
                                .fontWeight(.semibold)
                            
                            TextField("Kind One thing", textual content: $viewModel.textual content, axis: .vertical)
                            Spacer()
                        }
                        .font(.footnote)
                        
                        
                        
                        if !viewModel.textual content.isEmpty {
                            Button {
                                viewModel.textual content = ""
                            } label: {
                                Picture(systemName: "xmark")
                                    .resizable()
                                    .body(width: 12, peak: 12)
                                    .foregroundColor(.grey)
                                
                                
                                Button(motion: {
                                    viewModel.selectedImage = nil
                                }, label: {
                                    Picture(systemName: "xmark")
                                        .resizable()
                                        .scaledToFit()
                                        .body(width: 10, peak: 10)
                                        .padding(8)
                                })
                                .background(Colour(.grey))
                                .foregroundColor(.white)
                                .clipShape(Circle())
                            }
                            .padding(8)
                            
                            Spacer()
                        } else {
                            if viewModel.textual content.isEmpty {
                                
                                PhotosPicker(
                                    choice: $viewModel.selectedImage,
                                    matching: .any(of: [.images,.videos, .not(.livePhotos)]),
                                    photoLibrary: .shared()) {
                                        Picture(systemName: "picture")
                                    }
                                
                            }
                            
                        }
                        
                        
                        Spacer()
                    }
                    .padding()
                    .toolbar {
                        ToolbarItem(placement: .navigationBarLeading) {
                            Button("Cancel") {
                                dismiss()
                            }
                            .font(.subheadline)
                            .foregroundStyle(Colour.black)
                        }
                        
                        ToolbarItem(placement: .navigationBarTrailing) {
                            Button("Submit") {
                                Process {
                                    strive await viewModel.uploadPost(caption: captionText)
                                    dismiss()
                                }
                            }
                            .opacity(viewModel.textual content.isEmpty ? 0.5 : 1.0)
                            .disabled(viewModel.textual content.isEmpty)
                            .font(.subheadline)
                            .fontWeight(.semibold)
                            .foregroundStyle(Colour.inexperienced)
                        }
                    }
                    .onDisappear { tabIndex = 0 }
                    
                }
                Divider()
                if uiImage != nil {
                    Picture(uiImage: uiImage!)
                        .resizable()
                        .scaledToFit()
                        .body(width: 200, peak: 200)
                }
            }
            .onChange(of: viewModel.selectedImage) { lead to
                Process {
                    do {
                        if let information = strive await viewModel.selectedImage?.loadTransferable(kind: Knowledge.self) {
                            if let uiImage = UIImage(information: information) {
                                self.uiImage = uiImage
                                if let url {
                                    
                                }
                            }
                        }
                    } catch {
                        print(error.localizedDescription)
                        viewModel.selectedImage = nil
                    }
                        if let url {
                            VideoPlayer(participant: AVPlayer(url: url))
                        }
                    

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here