小编Gab*_*urt的帖子

“一个 AVPlayerItem 不能与多个 AVPlayer 实例关联”

我知道这个问题遍布 Stack Overflow,但其中大多数都是旧问题,与我要在这里问的问题无关。

所以我有一个带有AVPlayerItems和 的数组AVQueuePlayer。首先,我设置 AVQueuePlayer 来播放数组项目:

func mediaPicker(mediaPicker: MPMediaPickerController!, didPickMediaItems mediaItemCollection: MPMediaItemCollection!) {

    mediaItems = mediaItemCollection.items

    for thisItem in mediaItems as [MPMediaItem] {

        var itemUrl = thisItem.valueForProperty(MPMediaItemPropertyAssetURL) as? NSURL
        var playerItem = AVPlayerItem(URL: itemUrl)
        mediaArray.append(playerItem)           

    }

    updateMetadata()

    audioPlayer = AVQueuePlayer(items: mediaArray)


    self.dismissViewControllerAnimated(true, completion: nil)

}
Run Code Online (Sandbox Code Playgroud)

但是,例如,当用户添加新项目或删除项目时,我尝试更新播放器(与我首先设置它的方式相同),但它给了我错误。我想知道是否有任何解决办法,或者有什么解决方案。这是用户删除歌曲的方式:

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == UITableViewCellEditingStyle.Delete{
            mediaArray.removeAtIndex(indexPath.row)
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
            audioPlayer = AVQueuePlayer(items: mediaArray) //here gives the error
        }
    }
Run Code Online (Sandbox Code Playgroud)

我为此自杀了,所以,如果有人能帮助我,我将不胜感激。

ios avqueueplayer swift avplayeritem

4
推荐指数
1
解决办法
8212
查看次数

在AVPlayer [Swift]中播放MPMediaItemCollection中的项目

这是事情,我有一个MPMediaItemCollection与用户选择项目(从库).我使用mediaPicker来做到这一点.现在,我需要从这些项目中获取URL,以便我可以在AVPlayer上播放它们.这是我能找到的最好的,但是当我"翻译"为快速时,它会变得混乱.如果有人可以帮助我,我会非常感激.

mpmediaitemcollection avplayer swift

2
推荐指数
1
解决办法
1911
查看次数

'UICollectionViewCell'没有名为'image'的成员[Swift]

我正在设置一个项目,UICollectionView其中显示带有标签的图像.我创造了ViewControllerCellViewController它一样,就像它应该的那样.

CellViewController代码中如下:

class CellController: UICollectionViewCell {

    @IBOutlet weak var image: UIImageView!
    @IBOutlet weak var label: UILabel!


}
Run Code Online (Sandbox Code Playgroud)

但是ViewController当我设置图像时,它给了我错误.这是代码:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell: UICollectionViewCell = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController

    cell.image.image = UIImage(named: "star")

    return cell
}
Run Code Online (Sandbox Code Playgroud)

最奇怪的是,我有一个从GitHub下载的项目,它与我的基本相同,而且工作正常.

提前致谢!

ios uicollectionview uicollectionviewcell swift

0
推荐指数
1
解决办法
1332
查看次数

如何在Angular 5中使用rxJS存储来自API的可观察数据?

我有一个角度服务,可以从API获取数据,并且此数据在许多组件中使用,因此每次调用API来获取相同数据都是浪费的。

因此,我继续尝试使用BehaviorSubjects来存储数据。我很好地工作了一点,像这样使用它:

服务内容

books = new BehaviorSubject<Book[]>(null);
setBooks(book: Book[]) {
    this.books.next(book);
}
getBooks() {
    this.http.get(...).do(
        (res) => {
            this.setBooks(res.books);
        }
    );
}
Run Code Online (Sandbox Code Playgroud)

组件:

ngOnInit() {
    this.booksService.books.subscribe(
        (books) => {
            // in case the api was never called
            if (books == null) {
                return this.booksService.getBooks().subscribe();
            }
            console.log(books);
            // ...
        }
    );
}
Run Code Online (Sandbox Code Playgroud)

有书籍时,它工作正常,但是如果书籍是一个空数组(这是预期的行为之一),则程序将陷入循环,并永远调用api。测试它,我发现它被卡在服务调用的.do()部分中,但是我不知道为什么。

在这里读到BehaviorSubject并不是要使用空初始值,而是像建议的@estus一样,使用ReplaySubject(1)也会发生同样的事情。

我想知道是否存在“正确”的方式来存储数据。我也不认为使用localstorage是最好的解决方案,因为它可能会存储大量数据,并且在使用应用程序时会发生很大变化。

observable rxjs behaviorsubject angular

0
推荐指数
1
解决办法
941
查看次数

选择多对多关系

我有一张products桌子和一张orders桌子。它们之间有很多对很多的关系,而product_order表是中介。现在,我有两个产品ID,并且想要选择包含两个产品ID的订单(如果存在)。如何用Laravel雄辩地做到这一点?

class Product extends Model
{
    // ...

    public function orders()
    {
        return $this->belongsToMany('App\Order', 'product_order');
    }
}

class Order extends Model
{
    // ...

    public function products()
    {
        return $this->belongsToMany('App\Products', 'product_order');
    }
}
Run Code Online (Sandbox Code Playgroud)

laravel eloquent

0
推荐指数
1
解决办法
42
查看次数