Sunday, December 3, 2023
HomeiOS Developmentios - How one can preview chosen video from the gallery

ios – How one can 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 in a position to show my chosen video in display 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?
    personal var consumer: Person? {
        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("Sort 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(Coloration(.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: "photograph")
                                    }
                                
                            }
                            
                        }
                        
                        
                        Spacer()
                    }
                    .padding()
                    .toolbar {
                        ToolbarItem(placement: .navigationBarLeading) {
                            Button("Cancel") {
                                dismiss()
                            }
                            .font(.subheadline)
                            .foregroundStyle(Coloration.black)
                        }
                        
                        ToolbarItem(placement: .navigationBarTrailing) {
                            Button("Submit") {
                                Activity {
                                    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(Coloration.inexperienced)
                        }
                    }
                    .onDisappear { tabIndex = 0 }
                    
                }
                Divider()
                if uiImage != nil {
                    Picture(uiImage: uiImage!)
                        .resizable()
                        .scaledToFit()
                        .body(width: 200, peak: 200)
                }
            }
            .onChange(of: viewModel.selectedImage) { end in
                Activity {
                    do {
                        if let information = strive await viewModel.selectedImage?.loadTransferable(kind: Information.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))
                        }
                    



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments