- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一个处理音频和 tableView 的测试程序,现在我有 Controller 工作并正确播放所选歌曲,但我正在尝试显示 mp3 文件中的元数据并且目前我没有做任何事情像这样:
打印数据的函数:
func testAudioStuff(testURL testURL: NSURL) {
let audioInfo = AVPlayerItem(URL: testURL)
let metaDataList = audioInfo.asset.metadata as [AVMetadataItem]
//here it should print something it does not
for item in metaDataList {
if item.commonKey == nil {
continue
}
if let key = item.commonKey, let value = item.value {
print(key)
print(value as! String)
if key == "title" {
print(key)
print("here is the title" + (value as! String))
}
if key == "artist" {
print(key)
print("here is the artist" + (value as! String))
}
if key == "artwork" {
print("here is the artwork" + (value as! String))
}
}
}
}
播放音乐的函数:
func playSelectedMusic(song: Int, section: Int) {
if section == 1 {
//print(NSBundle.mainBundle().description + "\(song) \(section)")
if let starMusic = productsAndMusic["Music"] {
//print("We are looking at \(starMusic[song])")
let play = starMusic[song].componentsSeparatedByString(".")[0]
//print(play)
if let fileToPlay = NSBundle.mainBundle().pathForResource(play, ofType: "mp3") {
//print(fileToPlay)
testAudioStuff(testURL: NSURL(string: fileToPlay)!)
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(string: fileToPlay)!)
} catch Errors.GeneralError {
} catch let error as NSError {
print("i dunno this does not comes with instructions \(error)")
} catch let something as ErrorType {
print("somehting else \(something)")
}
player.prepareToPlay()
player.play()
}
//player = AVAudioPlayer(contentsOfURL: NSURL(string: NSBundle.mainBundle().pathForResource(play, ofType: "mp3")!))
//player.prepareToPlay()
//print(NSBundle.mainBundle().pathForResource(play, ofType: "mp3"))
}
//print(NSBundle.mainBundle().pathForResource((productsAndMusic["Music"]![song] as String).componentsSeparatedByString(".")[0], ofType: "mp3")!)
//print((productsAndMusic["Music"]![song] as String).componentsSeparatedByString(".")[0])
} else {
}
}
正如我提到的,它在模拟器中播放选定的歌曲,但它不打印元数据,为什么?有帮助吗?在 Xcode 7 beta 2 中。
我试过一些东西,但没有骰子,这个:
var secondTestTitle: AVAsset = AVAsset(URL: testURL)
print(secondTestTitle.description)
var metaStuff: [AVMetadataItem] = secondTestTitle.commonMetadata as [AVMetadataItem]
print(metaStuff.count)
结果:
<AVURLAsset: 0x78ea3930, URL = /Users/pedro/Library/Developer/CoreSimulator/Devices/304FE5A7-9506-4A9B-B685-5CDBE9AFB4C4/data/Containers/Bundle/Applica ... ock1.mp3>
0
最佳答案
如果这是您的应用程序包中的 MP3 文件,那么我们假设它名为 test.mp3。然后你可以说:
let url = NSBundle.mainBundle().URLForResource("test", withExtension:"mp3")
let asset = AVAsset(URL: url!)
let meta = asset.metadata
print(meta)
如果您在这么说时在控制台中没有看到任何元数据,则该文件没有元数据。
但是,这不是我会做的,因为这不是一个非常现实的测试 - 而且它不太可能非常有用,因为大多数信息不会作为元数据写入文件中。更有可能的是,您想了解用户音乐库中的一首歌曲。在这种情况下,您将使用媒体播放器框架,正如我所描述的 in my book .
关于ios - Swift 和 XCode 7 beta 2 不显示正在播放的歌曲的元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31210397/
我正在从事从媒体选择器中挑选歌曲并将数据发送到服务器的项目。我正在转换选择的歌曲。它适用于普通歌曲(即不属于购买的 iTunes 的歌曲),对于购买的歌曲,我收到错误消息。我集成了由苹果提供的这个示例
一旦进入包含.mp3 文件的目录,我就可以随机播放歌曲了 mpg123 -Z *.mp3 但是如果我想递归搜索目录及其子文件夹中的 .mp3 文件并随机播放它们,我尝试了以下命令,但它不起作用。 mp
我有 2 种不同的方法来使用内容解析器检索歌曲。一个用于获取手机上的所有歌曲,一个用于从手机中检索所有播放列表,然后,对于每个播放列表,我获取其中的歌曲并将其添加到播放列表对象。为此,我在所有歌曲列表
我正在从 SD 卡中获取我的歌曲并将其放入 ListView 。 我正在使用这个方法。但它需要一些时间,如果路径不同,我没有得到该数据。 所以,QUE 是否有任何有用的脚本可以显示我所有 SD 卡中的
我正在使用 MPMusicPlayerController.systemMusicPlayer 的一个实例来对商店 ID 数组进行排队。这已经工作了几个月了。今天早些时候我更新到 iOS 14.3,现
如果我使用mp3: "/Music/StreamUploadedSongs/1"在以下代码中: var player = new $("#jquery_jplayer_1").jPlayer({
我正在开发一个 iOS 应用程序,我需要允许用户将 iTunes 中的几首歌曲的预览播放到应用程序中。现在,通过查找 API 和 adamID,我可以轻松找到预览 URL 并让它播放。 我rad
我们可以使用 NAudio 播放 mp4 歌曲吗?请提供一些播放mp4歌曲的代码我需要一个 c# 代码来帮助我播放 mp4 歌曲 最佳答案 可以用NAudio播放.mp4文件,官网有demo。 下载演
我想获取歌曲在特定时间段内的收听次数。使用 MPMediaItemPropertyLastPlayedDate 我只能获取上次播放歌曲的日期,因此如果我每天多次播放歌曲,则只有最后一次才算数。基本上,
我们可以使用 NAudio 播放 mp4 歌曲吗?请提供一些播放mp4歌曲的代码我需要一个 c# 代码来帮助我播放 mp4 歌曲 最佳答案 可以用NAudio播放.mp4文件,官网有demo。 下载演
我正在制作一个闹钟。我有下面的代码。但是,通知音乐正在发挥作用。我想让它播放我设置的mp3文件。我该怎么办? @Override public void onReceive(Context c
我想在我的 Java 游戏中播放 .wav 格式的歌曲,下面是 SoundPlayer 类的一些代码: private static HashMap clips; private static int
我有一个可以播放本地歌曲的 Android 服务(我遵循了这个教程:https://code.tutsplus.com/tutorials/create-a-music-player-on-andro
这个问题在这里已经有了答案: HTML 5 video or audio playlist (12 个答案) 关闭 6 年前。 我想让我的网站播放多首 mp3/歌曲,但它一直在播放 soundtra
我正在从 android 中的 sdcard 访问歌曲,歌曲显示在 ListView 中,但我无法播放这些文件。 代码如下: package com.ex.imageGallery; import a
我正在尝试创建一个嵌入了一些 JavaScript 的 HTML 文件,该文件允许我按下按钮并开始淡出歌曲。我已经设法让它工作,以便它播放歌曲(这是一个开始)。但我一直在尝试使用第二个功能来尝试降低音
将 iTunes 中最后播放的歌曲的信息获取到 Java 程序中的最简单方法是什么?我看过 JACOB 和 iTunes COM,但它们似乎有点过分了。如果这是唯一的方法,有人可以在第一个谷歌结果旁边
我想从 python 播放我的歌曲 (mp3),你能给我一个最简单的命令吗? 这是不正确的: import wave w = wave.open("e:/LOCAL/Betrayer/Metalik
我有一个歌曲列表 - 有没有办法(使用 Spotify/Echo Nest API)批量查找每个轨道的 Spotify ID? 如果有帮助,我计划通过其 API 的“获取音频功能”部分运行这些 ID。
我正在为一个乐队制作一个 iPhone 应用程序,其中列出了该乐队的歌曲。当用户触摸歌曲旁边的按钮时,我想打开 iTunes 并显示该歌曲。目前我正在使用这段代码: [[UIApplication共享
我是一名优秀的程序员,十分优秀!