Post

Replies

Boosts

Views

Activity

Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
You should show code, that would be much easier to explain.  I want other players You want a single player to play at any time ? So, you should have a reference to the activePlayer declared at the class level. It is nil to begin with. When you Play, you should first stop the activePlayer (after testing it is not nil) Then dismiss and set to nil Then create a new player instance and set it to activePlayer. If you have a stop func, do the same: stop the active player, dismiss it and set to nil. Could you better explain your Extra question ?
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
You didn't tell it was a collectionView. So change with: if let collectionView = cell.superview as? UICollectionView { let visibleCells = collectionView.visibleCells for cell in visibleCells where cell is CollectionViewCell { // The type of your cells // now you can access to properties if cell.player != nil { // I suppose you named the podPlayer as player // stop it playing // dismiss // set to nil } } }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to How to declare a scope in code ?
"I want to program a function and I receive a 'scope' error". How do I declare a scope Just declare the property (which has the scope problem), in another place, for instance at the class level, not inside a func. If so, take care not to redeclare a property with the same name in the func. "I want to program a function and I receive a 'scope' error". Please also show the func and where you get the error message. To define AdvancedSettingsView, just do like any other SwiftUI View struct AdvancedSettingsView: View { var body: some View { Text("Hello") } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to UIPickerView button not worked
Why do you draw with animation ? What do you expect from it ? override func draw(_ rect: CGRect) { self.alpha = 0.0 UIView.animate(withDuration: 0.2, animations: { self.alpha = 1.0 }, completion: {_ in }) } Try removing this animation which may be conflicting with other animations.
Topic: UI Frameworks SubTopic: UIKit Tags:
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
Do you still get the error on line 93 ? If so, try the following: @IBAction func playPodcast(_ sender: Any) { if let collectionView = self.superview as? UICollectionView { let visibleCells = collectionView.visibleCells for cell in visibleCells { if let podCell = cell as? PodcastViewCell { print("cell is PodcastViewCell") if podCell.player != nil { print("podCell.player found") } else { print("podCell.player NOT found") } } else { print("cell is NOT PodcastViewCell") } } } And tell what you get exactly on console. Or simply change: if let collectionView = self.superview as? UICollectionView { let visibleCells = collectionView.visibleCells for cell in visibleCells where cell is PodcastViewCell { if (cell as! PodcastViewCell).player != nil { } }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
You should show code, that would be much easier to explain.  I want other players You want a single player to play at any time ? So, you should have a reference to the activePlayer declared at the class level. It is nil to begin with. When you Play, you should first stop the activePlayer (after testing it is not nil) Then dismiss and set to nil Then create a new player instance and set it to activePlayer. If you have a stop func, do the same: stop the active player, dismiss it and set to nil. Could you better explain your Extra question ?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
Why did you do so ? You could have just the button for the player, but have the active player at view level. However, you could do this: when you tap on play in a cell, explore all the cells and stop their player if not nil. That's not a very good design, but that could work.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
Iin the play button action of the cell: get the tableView with cell.superview. tableView.visibleCells, gives you all visible cells in an array [UITableViewCell] then loop through this array and test their player to stop if needed.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
It is not cell.superview.tableView.visibleCells But let tableView = cell.superview then use tableView.visibleCells You could have a safety check: if let tableView = cell.superview as? UITableView { // then use tableView.visibleCells }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
You didn't tell it was a collectionView. So change with: if let collectionView = cell.superview as? UICollectionView { let visibleCells = collectionView.visibleCells for cell in visibleCells where cell is CollectionViewCell { // The type of your cells // now you can access to properties if cell.player != nil { // I suppose you named the podPlayer as player // stop it playing // dismiss // set to nil } } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to How to declare a scope in code ?
"I want to program a function and I receive a 'scope' error". How do I declare a scope Just declare the property (which has the scope problem), in another place, for instance at the class level, not inside a func. If so, take care not to redeclare a property with the same name in the func. "I want to program a function and I receive a 'scope' error". Please also show the func and where you get the error message. To define AdvancedSettingsView, just do like any other SwiftUI View struct AdvancedSettingsView: View { var body: some View { Text("Hello") } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to UIPickerView button not worked
Why do you draw with animation ? What do you expect from it ? override func draw(_ rect: CGRect) { self.alpha = 0.0 UIView.animate(withDuration: 0.2, animations: { self.alpha = 1.0 }, completion: {_ in }) } Try removing this animation which may be conflicting with other animations.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
Sure. cell is not known. replace line 2 with: if let collectionView = self.superview as? UICollectionView {
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to How to declare a scope in code ?
@BesleagaMAlexandru1991 Does it work now ? If so, don't forget to close the thread by marking the correct answer.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to UICollectionView Layout Error: nil layout parameter
@Chris0309 Which line exactly (in your OP) do you get the error ? Did you try setting the frame ?
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Error while installing iOS 14.5
Which iPhone is it ? What exact error message do you get ? When you go to Settings General Software updates, what do you get ? Do you get proposed iOS 14.5.1 ? Did you download from there ?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
Could you show your code (complete for PodcastViewCell, the UICollectionViewCell). I have been guessing some missing parts, it is not very efficient. How did you name the player there ? Sure it compiles with self instead of cell, but it misses the point which is to stop players from any other cell, not the current one (self).
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
Do you still get the error on line 93 ? If so, try the following: @IBAction func playPodcast(_ sender: Any) { if let collectionView = self.superview as? UICollectionView { let visibleCells = collectionView.visibleCells for cell in visibleCells { if let podCell = cell as? PodcastViewCell { print("cell is PodcastViewCell") if podCell.player != nil { print("podCell.player found") } else { print("podCell.player NOT found") } } else { print("cell is NOT PodcastViewCell") } } } And tell what you get exactly on console. Or simply change: if let collectionView = self.superview as? UICollectionView { let visibleCells = collectionView.visibleCells for cell in visibleCells where cell is PodcastViewCell { if (cell as! PodcastViewCell).player != nil { } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Why are forum posts locked after two months of inactivity?
@Shoko You should file a bug report. There is effectively a big need to improve this forum which does not provide the needed capabilities and creates useless constraints.
Replies
Boosts
Views
Activity
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
It is normal at first pass, because no player yet defined. Could you add another print: if url != "" { let playerItem = AVPlayerItem( url:NSURL( string:url )! as URL ) print("New player for", url) player = AVPlayer(playerItem:playerItem) player!.rate = 1.0;
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21