MPMusicPlayerControllerPlaybackStateDidChangeNotification确定歌曲是否已结束

时间:2016-08-23 03:26:01

标签: ios mpmediaplayercontroller

使用通知中心时,如何确定歌曲已经结束?

nw_endpoint_resolver_receive_report [8 i.ytimg.com:443 in_progress resolver (satisfied)] received child report:[8.1 206.248.149.148:443 waiting path (satisfied)]
2016-08-22 23:19:51.531570 XXXXAPPNAMEXXXXXXX[4561:195631] [] nw_connection_endpoint_report [8.1 206.248.149.148:443 waiting path (satisfied)] reported event path:satisfied
2016-08-22 23:19:51.531909 XXXXAPPNAMEXXXXXXX[4561:195631] [] nw_endpoint_proxy_handler_should_use_proxy Looking up proxy for hostname: <nil>, ifindex: 0
2016-08-22 23:19:51.533116 XXXXAPPNAMEXXXXXXX[4561:195631] [] -[NWConcrete_nw_endpoint_flow startWithHandler:] [8.1 206.248.149.148:443 waiting socket-flow (satisfied)]
2016-08-22 23:19:51.533548 XXXXAPPNAMEXXXXXXX[4561:195631] [] nw_endpoint_flow_setup_socket [8.1 206.248.149.148:443 in_progress socket-flow (satisfied)] creating socket
2016-08-22 23:19:51.534108 XXXXAPPNAMEXXXXXXX[4561:195631] [] nw_endpoint_flow_attach_protocols [8.1 206.248.149.148:443 in_progress socket-flow (satisfied)]
2016-08-22 23:19:51.534672 XXXXAPPNAMEXXXXXXX[4561:195631] [] __nwlog_err_simulate_crash simulate crash already simulated "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"
2016-08-22 23:19:51.535415 XXXXAPPNAMEXXXXXXX[4561:195631] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
        [x86_64] libnetcore-856.1.8
    0   libsystem_network.dylib             0x000000010c6e280e __nw_create_backtrace_string + 123
    1   libnetwork.dylib                    0x000000010e0d5194 nw_socket_add_input_handler + 3002
    2   libnetwork.dylib                    0x000000010e0b2db8 nw_endpoint_flow_attach_protocols + 3768
    3   libnetwork.dylib                    0x000000010e0b1dd5 nw_endpoint_flow_setup_socket + 563
    4   libnetwork.dylib                    0x000000010e0b0b34 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612
    5   libnetwork.dylib                    0x000000010e0cbd11 nw_endpoint_handler_path_change + 1261
    6   libnetwork.dylib                    0x000000010e0cb740 nw_endpoint_handler_start + 570
    7   libnetwork.dylib                    0x000000010e0e3003 nw_endpoint_resolver_start_next_child + 2240
    8   libdispatch.dylib                   0x000000
2016-08-22 23:19:51.535995 XXXXAPPNAMEXXXXXXX[4561:195631] [] nw_endpoint_flow_attach_protocols [8.1 206.248.149.148:443 in_progress socket-flow (satisfied)] Attached flow protocol
2016-08-22 23:19:51.536475 XXXXAPPNAMEXXXXXXX[4561:195631] [] nw_endpoint_resolver_receive_report [8 i.ytimg.com:443 in_progress resolver (satisfied)] received child report:[8.1 206.248.149.148:443 in_progress socket-flow (satisfied)]

2 个答案:

答案 0 :(得分:1)

updateNowPlayingInfo方法中,检查playbackState的{​​{1}}属性。如果歌曲结束,则值为MPMusicPlayerController。请注意,如果手动停止播放,您也将具有此状态,例如按下停止按钮,因此您必须检查该状态。

答案 1 :(得分:1)

歌曲播放完毕后,nowPlayingItem应该会改变。 结合播放状态,这应该足以确定歌曲是否已经播放完毕。