【问题标题】:Unable to separate metadata to different strings无法将元数据分离到不同的字符串
【发布时间】:2013-02-14 15:10:38
【问题描述】:

在不同的代码集中检索的元数据正在屏幕上显示在同一字符串上,并用“ - ”分隔它们。如何将每组信息放到各自的行或字符串中?

    NSDictionary *currentlyPlayingTrackInfo;
    NSString *msg = albumInfo;
    NSString *newArtist;
    NSString *newSongName;

    NSRange range = [msg rangeOfString:@" - "];

    if (range.location != NSNotFound){
        newArtist = [msg substringToIndex:range.location];
        newSongName = [msg substringFromIndex:(range.location + range.length)];
    }

    if (newArtist != nil){
        currentlyPlayingTrackInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:newArtist, newSongName, pmAlbumArt, nil] forKeys:[NSArray arrayWithObjects:MPMediaItemPropertyArtist, MPMediaItemPropertyTitle, MPMediaItemPropertyArtwork, nil]];
    }else{
        currentlyPlayingTrackInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:msg, pmAlbumArt, nil] forKeys:[NSArray arrayWithObjects:MPMediaItemPropertyTitle, MPMediaItemPropertyArtwork, nil]];
    }
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
  }
}

【问题讨论】:

  • 你现在有什么问题?
  • 它显示艺术家、标题和专辑很好,只是现在它们显示在一行上,我宁愿让它们都在自己的行上,以保持它们更加个性化。不确定这是否有意义。我想只是一种风格偏好:)
  • 你是如何展示它们的?看起来你把字符串分成了两部分,好的。
  • 好吧,现在字符串看起来像“艺术家 - 标题 - 专辑”,但需要的是“艺术家 /艺术家下面的下一行/ 标题 /下一行在标题/ 专辑下方”。如果你能理解的话。
  • 是的,我知道你想要什么。我不明白的是什么不起作用。您上面的代码将字符串分成 2 个字符串,对吗?那不工作吗?味精是否包含艺术家-标题-专辑?看起来你只分离了前 2 个。

标签: iphone ios metadata audio-streaming


【解决方案1】:

如果您想将 msg 保留为一个字符串,您可以将“-”替换为“\n”,这样会将其分成 3 行。

    NSString *s = @"Artist - Song - Album";
    NSString *newString = [s stringByReplacingOccurrencesOfString:@"-" withString:@"\n"];
    NSLog(@"%@",newString);

【讨论】:

    猜你喜欢
    • 2022-11-03
    • 2016-11-01
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多