mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-31 02:17:01 -04:00 
			
		
		
		
	Fix: iOS mobile audio stream support #180
This commit is contained in:
		
							parent
							
								
									72f9732b67
								
							
						
					
					
						commit
						41f05f7a7b
					
				| @ -567,6 +567,17 @@ export default { | |||||||
|       this.src = url |       this.src = url | ||||||
|       console.log('[AudioPlayer-Set] Set url', url) |       console.log('[AudioPlayer-Set] Set url', url) | ||||||
| 
 | 
 | ||||||
|  |       var audio = this.$refs.audio | ||||||
|  |       audio.volume = this.volume | ||||||
|  |       audio.defaultPlaybackRate = this.playbackRate | ||||||
|  | 
 | ||||||
|  |       // iOS does not support Media Elements but allows for HLS in the native audio player | ||||||
|  |       if (!Hls.isSupported()) { | ||||||
|  |         console.warn('HLS is not supported - fallback to using audio element') | ||||||
|  |         audio.src = this.src + '?token=' + this.token | ||||||
|  |         return | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|       var hlsOptions = { |       var hlsOptions = { | ||||||
|         startPosition: currentTime || -1, |         startPosition: currentTime || -1, | ||||||
|         xhrSetup: (xhr) => { |         xhrSetup: (xhr) => { | ||||||
| @ -576,9 +587,6 @@ export default { | |||||||
|       console.log('Starting HLS audio stream at time', currentTime) |       console.log('Starting HLS audio stream at time', currentTime) | ||||||
|       // console.log('[AudioPlayer-Set] HLS Config', hlsOptions) |       // console.log('[AudioPlayer-Set] HLS Config', hlsOptions) | ||||||
|       this.hlsInstance = new Hls(hlsOptions) |       this.hlsInstance = new Hls(hlsOptions) | ||||||
|       var audio = this.$refs.audio |  | ||||||
|       audio.volume = this.volume |  | ||||||
|       audio.defaultPlaybackRate = this.playbackRate |  | ||||||
| 
 | 
 | ||||||
|       this.hlsInstance.attachMedia(audio) |       this.hlsInstance.attachMedia(audio) | ||||||
|       this.hlsInstance.on(Hls.Events.MEDIA_ATTACHED, () => { |       this.hlsInstance.on(Hls.Events.MEDIA_ATTACHED, () => { | ||||||
|  | |||||||
| @ -95,6 +95,10 @@ class Stream extends EventEmitter { | |||||||
|     return this.client ? this.client.user || {} : null |     return this.client ? this.client.user || {} : null | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   get userToken() { | ||||||
|  |     return this.clientUser ? this.clientUser.token : null | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   get clientUserAudiobooks() { |   get clientUserAudiobooks() { | ||||||
|     return this.client ? this.clientUser.audiobooks || {} : null |     return this.client ? this.clientUser.audiobooks || {} : null | ||||||
|   } |   } | ||||||
| @ -205,7 +209,7 @@ class Stream extends EventEmitter { | |||||||
| 
 | 
 | ||||||
|   async generatePlaylist() { |   async generatePlaylist() { | ||||||
|     fs.ensureDirSync(this.streamPath) |     fs.ensureDirSync(this.streamPath) | ||||||
|     await hlsPlaylistGenerator(this.playlistPath, 'output', this.totalDuration, this.segmentLength, this.hlsSegmentType) |     await hlsPlaylistGenerator(this.playlistPath, 'output', this.totalDuration, this.segmentLength, this.hlsSegmentType, this.userToken) | ||||||
|     return this.clientPlaylistUri |     return this.clientPlaylistUri | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| const fs = require('fs-extra') | const fs = require('fs-extra') | ||||||
| 
 | 
 | ||||||
| function getPlaylistStr(segmentName, duration, segmentLength, hlsSegmentType) { | function getPlaylistStr(segmentName, duration, segmentLength, hlsSegmentType, token) { | ||||||
|   var ext = hlsSegmentType === 'fmp4' ? 'm4s' : 'ts' |   var ext = hlsSegmentType === 'fmp4' ? 'm4s' : 'ts' | ||||||
| 
 | 
 | ||||||
|   var lines = [ |   var lines = [ | ||||||
| @ -18,18 +18,18 @@ function getPlaylistStr(segmentName, duration, segmentLength, hlsSegmentType) { | |||||||
|   var lastSegment = duration - (numSegments * segmentLength) |   var lastSegment = duration - (numSegments * segmentLength) | ||||||
|   for (let i = 0; i < numSegments; i++) { |   for (let i = 0; i < numSegments; i++) { | ||||||
|     lines.push(`#EXTINF:6,`) |     lines.push(`#EXTINF:6,`) | ||||||
|     lines.push(`${segmentName}-${i}.${ext}`) |     lines.push(`${segmentName}-${i}.${ext}?token=${token}`) | ||||||
|   } |   } | ||||||
|   if (lastSegment > 0) { |   if (lastSegment > 0) { | ||||||
|     lines.push(`#EXTINF:${lastSegment},`) |     lines.push(`#EXTINF:${lastSegment},`) | ||||||
|     lines.push(`${segmentName}-${numSegments}.${ext}`) |     lines.push(`${segmentName}-${numSegments}.${ext}?token=${token}`) | ||||||
|   } |   } | ||||||
|   lines.push('#EXT-X-ENDLIST') |   lines.push('#EXT-X-ENDLIST') | ||||||
|   return lines.join('\n') |   return lines.join('\n') | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function generatePlaylist(outputPath, segmentName, duration, segmentLength, hlsSegmentType) { | function generatePlaylist(outputPath, segmentName, duration, segmentLength, hlsSegmentType, token) { | ||||||
|   var playlistStr = getPlaylistStr(segmentName, duration, segmentLength, hlsSegmentType) |   var playlistStr = getPlaylistStr(segmentName, duration, segmentLength, hlsSegmentType, token) | ||||||
|   return fs.writeFile(outputPath, playlistStr) |   return fs.writeFile(outputPath, playlistStr) | ||||||
| } | } | ||||||
| module.exports = generatePlaylist | module.exports = generatePlaylist | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user